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 | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 75 | /// Struct that associates a component with the clause kind where they are |
| 76 | /// found. |
| 77 | struct MappedExprComponentTy { |
| 78 | OMPClauseMappableExprCommon::MappableExprComponentLists Components; |
| 79 | OpenMPClauseKind Kind = OMPC_unknown; |
| 80 | }; |
| 81 | typedef llvm::DenseMap<ValueDecl *, MappedExprComponentTy> |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 82 | MappedExprComponentsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 83 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 84 | CriticalsWithHintsTy; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 85 | typedef llvm::DenseMap<OMPDependClause *, OperatorOffsetTy> |
| 86 | DoacrossDependMapTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 87 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 88 | struct SharingMapTy final { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 89 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 90 | AlignedMapTy AlignedMap; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 91 | MappedExprComponentsTy MappedExprComponents; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 92 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 93 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 94 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 95 | OpenMPDirectiveKind Directive = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 96 | DeclarationNameInfo DirectiveName; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 97 | Scope *CurScope = nullptr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 98 | SourceLocation ConstructLoc; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 99 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
| 100 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
| 101 | /// This data is required during codegen. |
| 102 | DoacrossDependMapTy DoacrossDepends; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 103 | /// \brief first argument (Expr *) contains optional argument of the |
| 104 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 105 | /// clause, false otherwise. |
| 106 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 107 | bool NowaitRegion = false; |
| 108 | bool CancelRegion = false; |
| 109 | unsigned AssociatedLoops = 1; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 110 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 111 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 112 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 113 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
| 114 | ConstructLoc(Loc) {} |
| 115 | SharingMapTy() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 118 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 119 | |
| 120 | /// \brief Stack of used declaration and their data-sharing attributes. |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 121 | DeclSAMapTy Threadprivates; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 122 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 123 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 124 | /// from current directive. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 125 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 126 | Sema &SemaRef; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 127 | bool ForceCapturing = false; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 128 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 129 | |
| 130 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 131 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 132 | DSAVarData getDSA(StackTy::reverse_iterator &Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 133 | |
| 134 | /// \brief Checks if the variable is a local for OpenMP region. |
| 135 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 136 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 137 | public: |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 138 | explicit DSAStackTy(Sema &S) : SemaRef(S) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 139 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 140 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 141 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 142 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 143 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 144 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 145 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 146 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 147 | Scope *CurScope, SourceLocation Loc) { |
| 148 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 149 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void pop() { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 153 | assert(!Stack.empty() && "Data-sharing attributes stack is empty!"); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 154 | Stack.pop_back(); |
| 155 | } |
| 156 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 157 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 158 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 159 | } |
| 160 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 161 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 162 | auto I = Criticals.find(Name.getAsString()); |
| 163 | if (I != Criticals.end()) |
| 164 | return I->second; |
| 165 | return std::make_pair(nullptr, llvm::APSInt()); |
| 166 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 167 | /// \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] | 168 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 169 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 170 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 171 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 172 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 173 | void addLoopControlVariable(ValueDecl *D, VarDecl *Capture); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 174 | /// \brief Check if the specified variable is a loop control variable for |
| 175 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 176 | /// \return The index of the loop control variable in the list of associated |
| 177 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 178 | LCDeclInfo isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 179 | /// \brief Check if the specified variable is a loop control variable for |
| 180 | /// parent region. |
| 181 | /// \return The index of the loop control variable in the list of associated |
| 182 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 183 | LCDeclInfo isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 184 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 185 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 186 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 187 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 188 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 189 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 190 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 191 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 192 | /// \brief Returns data sharing attributes from top of the stack for the |
| 193 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 194 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 195 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 196 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 197 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 198 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 199 | /// predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 200 | DSAVarData hasDSA(ValueDecl *D, |
| 201 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 202 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 203 | bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 204 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 205 | /// match specified \a CPred predicate in any innermost directive which |
| 206 | /// matches \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 207 | DSAVarData |
| 208 | hasInnermostDSA(ValueDecl *D, |
| 209 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 210 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 211 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 212 | /// \brief Checks if the specified variables has explicit data-sharing |
| 213 | /// attributes which match specified \a CPred predicate at the specified |
| 214 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 215 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 216 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 217 | unsigned Level, bool NotLastprivate = false); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 218 | |
| 219 | /// \brief Returns true if the directive at level \Level matches in the |
| 220 | /// specified \a DPred predicate. |
| 221 | bool hasExplicitDirective( |
| 222 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 223 | unsigned Level); |
| 224 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 225 | /// \brief Finds a directive which matches specified \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 226 | bool hasDirective(const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 227 | const DeclarationNameInfo &, |
| 228 | SourceLocation)> &DPred, |
| 229 | bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 230 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 231 | /// \brief Returns currently analyzed directive. |
| 232 | OpenMPDirectiveKind getCurrentDirective() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 233 | return Stack.empty() ? OMPD_unknown : Stack.back().Directive; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 234 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 235 | /// \brief Returns parent directive. |
| 236 | OpenMPDirectiveKind getParentDirective() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 237 | if (Stack.size() > 1) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 238 | return Stack[Stack.size() - 2].Directive; |
| 239 | return OMPD_unknown; |
| 240 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 241 | |
| 242 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 243 | void setDefaultDSANone(SourceLocation Loc) { |
| 244 | Stack.back().DefaultAttr = DSA_none; |
| 245 | Stack.back().DefaultAttrLoc = Loc; |
| 246 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 247 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 248 | void setDefaultDSAShared(SourceLocation Loc) { |
| 249 | Stack.back().DefaultAttr = DSA_shared; |
| 250 | Stack.back().DefaultAttrLoc = Loc; |
| 251 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 252 | |
| 253 | DefaultDataSharingAttributes getDefaultDSA() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 254 | return Stack.empty() ? DSA_unspecified : Stack.back().DefaultAttr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 255 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 256 | SourceLocation getDefaultDSALocation() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 257 | return Stack.empty() ? SourceLocation() : Stack.back().DefaultAttrLoc; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 258 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 259 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 260 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 261 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 262 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 263 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 266 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 267 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 268 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 269 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 270 | } |
| 271 | /// \brief Returns true, if parent region is ordered (has associated |
| 272 | /// 'ordered' clause), false - otherwise. |
| 273 | bool isParentOrderedRegion() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 274 | if (Stack.size() > 1) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 275 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 276 | return false; |
| 277 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 278 | /// \brief Returns optional parameter for the ordered region. |
| 279 | Expr *getParentOrderedRegionParam() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 280 | if (Stack.size() > 1) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 281 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 282 | return nullptr; |
| 283 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 284 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 285 | void setNowaitRegion(bool IsNowait = true) { |
| 286 | Stack.back().NowaitRegion = IsNowait; |
| 287 | } |
| 288 | /// \brief Returns true, if parent region is nowait (has associated |
| 289 | /// 'nowait' clause), false - otherwise. |
| 290 | bool isParentNowaitRegion() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 291 | if (Stack.size() > 1) |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 292 | return Stack[Stack.size() - 2].NowaitRegion; |
| 293 | return false; |
| 294 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 295 | /// \brief Marks parent region as cancel region. |
| 296 | void setParentCancelRegion(bool Cancel = true) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 297 | if (Stack.size() > 1) |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 298 | Stack[Stack.size() - 2].CancelRegion = |
| 299 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 300 | } |
| 301 | /// \brief Return true if current region has inner cancel construct. |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 302 | bool isCancelRegion() const { |
| 303 | return Stack.empty() ? false : Stack.back().CancelRegion; |
| 304 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 305 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 306 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 307 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 308 | /// \brief Return collapse value for region. |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 309 | unsigned getAssociatedLoops() const { |
| 310 | return Stack.empty() ? 0 : Stack.back().AssociatedLoops; |
| 311 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 312 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 313 | /// \brief Marks current target region as one with closely nested teams |
| 314 | /// region. |
| 315 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 316 | if (Stack.size() > 1) |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 317 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 318 | } |
| 319 | /// \brief Returns true, if current region has closely nested teams region. |
| 320 | bool hasInnerTeamsRegion() const { |
| 321 | return getInnerTeamsRegionLoc().isValid(); |
| 322 | } |
| 323 | /// \brief Returns location of the nested teams region (if any). |
| 324 | SourceLocation getInnerTeamsRegionLoc() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 325 | return Stack.empty() ? SourceLocation() : Stack.back().InnerTeamsRegionLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 328 | Scope *getCurScope() const { |
| 329 | return Stack.empty() ? nullptr : Stack.back().CurScope; |
| 330 | } |
| 331 | Scope *getCurScope() { |
| 332 | return Stack.empty() ? nullptr : Stack.back().CurScope; |
| 333 | } |
| 334 | SourceLocation getConstructLoc() { |
| 335 | return Stack.empty() ? SourceLocation() : Stack.back().ConstructLoc; |
| 336 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 337 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 338 | /// Do the check specified in \a Check to all component lists and return true |
| 339 | /// if any issue is found. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 340 | bool checkMappableExprComponentListsForDecl( |
| 341 | ValueDecl *VD, bool CurrentRegionOnly, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 342 | const llvm::function_ref< |
| 343 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 344 | OpenMPClauseKind)> &Check) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 345 | auto SI = Stack.rbegin(); |
| 346 | auto SE = Stack.rend(); |
| 347 | |
| 348 | if (SI == SE) |
| 349 | return false; |
| 350 | |
| 351 | if (CurrentRegionOnly) { |
| 352 | SE = std::next(SI); |
| 353 | } else { |
| 354 | ++SI; |
| 355 | } |
| 356 | |
| 357 | for (; SI != SE; ++SI) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 358 | auto MI = SI->MappedExprComponents.find(VD); |
| 359 | if (MI != SI->MappedExprComponents.end()) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 360 | for (auto &L : MI->second.Components) |
| 361 | if (Check(L, MI->second.Kind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 362 | return true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 363 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 364 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 367 | /// Create a new mappable expression component list associated with a given |
| 368 | /// declaration and initialize it with the provided list of components. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 369 | void addMappableExpressionComponents( |
| 370 | ValueDecl *VD, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 371 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components, |
| 372 | OpenMPClauseKind WhereFoundClauseKind) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 373 | assert(!Stack.empty() && |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 374 | "Not expecting to retrieve components from a empty stack!"); |
| 375 | auto &MEC = Stack.back().MappedExprComponents[VD]; |
| 376 | // Create new entry and append the new components there. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 377 | MEC.Components.resize(MEC.Components.size() + 1); |
| 378 | MEC.Components.back().append(Components.begin(), Components.end()); |
| 379 | MEC.Kind = WhereFoundClauseKind; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 380 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 381 | |
| 382 | unsigned getNestingLevel() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 383 | assert(!Stack.empty()); |
| 384 | return Stack.size() - 1; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 385 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 386 | void addDoacrossDependClause(OMPDependClause *C, OperatorOffsetTy &OpsOffs) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 387 | assert(Stack.size() > 1); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 388 | assert(isOpenMPWorksharingDirective(Stack[Stack.size() - 2].Directive)); |
| 389 | Stack[Stack.size() - 2].DoacrossDepends.insert({C, OpsOffs}); |
| 390 | } |
| 391 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 392 | getDoacrossDependClauses() const { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 393 | assert(!Stack.empty()); |
| 394 | if (isOpenMPWorksharingDirective(Stack.back().Directive)) { |
| 395 | auto &Ref = Stack.back().DoacrossDepends; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 396 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 397 | } |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 398 | return llvm::make_range(Stack.back().DoacrossDepends.end(), |
| 399 | Stack.back().DoacrossDepends.end()); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 400 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 401 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 402 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 403 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || |
| 404 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 405 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 406 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 407 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 408 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 409 | auto *VD = dyn_cast<VarDecl>(D); |
| 410 | auto *FD = dyn_cast<FieldDecl>(D); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 411 | if (VD != nullptr) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 412 | VD = VD->getCanonicalDecl(); |
| 413 | D = VD; |
| 414 | } else { |
| 415 | assert(FD); |
| 416 | FD = FD->getCanonicalDecl(); |
| 417 | D = FD; |
| 418 | } |
| 419 | return D; |
| 420 | } |
| 421 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 422 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator &Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 423 | ValueDecl *D) { |
| 424 | D = getCanonicalDecl(D); |
| 425 | auto *VD = dyn_cast<VarDecl>(D); |
| 426 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 427 | DSAVarData DVar; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 428 | if (Iter == Stack.rend()) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 429 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 430 | // in a region but not in construct] |
| 431 | // File-scope or namespace-scope variables referenced in called routines |
| 432 | // in the region are shared unless they appear in a threadprivate |
| 433 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 434 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 435 | DVar.CKind = OMPC_shared; |
| 436 | |
| 437 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 438 | // in a region but not in construct] |
| 439 | // Variables with static storage duration that are declared in called |
| 440 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 441 | if (VD && VD->hasGlobalStorage()) |
| 442 | DVar.CKind = OMPC_shared; |
| 443 | |
| 444 | // Non-static data members are shared by default. |
| 445 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 446 | DVar.CKind = OMPC_shared; |
| 447 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 448 | return DVar; |
| 449 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 450 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 451 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 452 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 453 | // in a Construct, C/C++, predetermined, p.1] |
| 454 | // Variables with automatic storage duration that are declared in a scope |
| 455 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 456 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 457 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 458 | DVar.CKind = OMPC_private; |
| 459 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 462 | // Explicitly specified attributes and local variables with predetermined |
| 463 | // attributes. |
| 464 | if (Iter->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 465 | DVar.RefExpr = Iter->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 466 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 467 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 468 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 469 | return DVar; |
| 470 | } |
| 471 | |
| 472 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 473 | // in a Construct, C/C++, implicitly determined, p.1] |
| 474 | // In a parallel or task construct, the data-sharing attributes of these |
| 475 | // variables are determined by the default clause, if present. |
| 476 | switch (Iter->DefaultAttr) { |
| 477 | case DSA_shared: |
| 478 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 479 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 480 | return DVar; |
| 481 | case DSA_none: |
| 482 | return DVar; |
| 483 | case DSA_unspecified: |
| 484 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 485 | // in a Construct, implicitly determined, p.2] |
| 486 | // In a parallel construct, if no default clause is present, these |
| 487 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 488 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 489 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 490 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 491 | DVar.CKind = OMPC_shared; |
| 492 | return DVar; |
| 493 | } |
| 494 | |
| 495 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 496 | // in a Construct, implicitly determined, p.4] |
| 497 | // In a task construct, if no default clause is present, a variable that in |
| 498 | // the enclosing context is determined to be shared by all implicit tasks |
| 499 | // bound to the current team is shared. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 500 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 501 | DSAVarData DVarTemp; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 502 | auto I = Iter, E = Stack.rend(); |
| 503 | do { |
| 504 | ++I; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 505 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 506 | // Referenced in a Construct, implicitly determined, p.6] |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 507 | // In a task construct, if no default clause is present, a variable |
| 508 | // whose data-sharing attribute is not determined by the rules above is |
| 509 | // firstprivate. |
| 510 | DVarTemp = getDSA(I, D); |
| 511 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 512 | DVar.RefExpr = nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 513 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 514 | return DVar; |
| 515 | } |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 516 | } while (I != E && !isParallelOrTaskRegion(I->Directive)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 517 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 518 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 519 | return DVar; |
| 520 | } |
| 521 | } |
| 522 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 523 | // in a Construct, implicitly determined, p.3] |
| 524 | // For constructs other than task, if no default clause is present, these |
| 525 | // variables inherit their data-sharing attributes from the enclosing |
| 526 | // context. |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 527 | return getDSA(++Iter, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 530 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 531 | assert(!Stack.empty() && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 532 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 533 | auto It = Stack.back().AlignedMap.find(D); |
| 534 | if (It == Stack.back().AlignedMap.end()) { |
| 535 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 536 | Stack.back().AlignedMap[D] = NewDE; |
| 537 | return nullptr; |
| 538 | } else { |
| 539 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 540 | return It->second; |
| 541 | } |
| 542 | return nullptr; |
| 543 | } |
| 544 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 545 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 546 | assert(!Stack.empty() && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 547 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 548 | Stack.back().LCVMap.insert( |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 549 | {D, LCDeclInfo(Stack.back().LCVMap.size() + 1, Capture)}); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 552 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 553 | assert(!Stack.empty() && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 554 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 555 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] |
| 556 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 559 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 560 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 561 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 562 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 563 | ? Stack[Stack.size() - 2].LCVMap[D] |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 564 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 567 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 568 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 569 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 570 | return nullptr; |
| 571 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 572 | if (Pair.second.first == I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 573 | return Pair.first; |
| 574 | } |
| 575 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 576 | } |
| 577 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 578 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 579 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 580 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 581 | if (A == OMPC_threadprivate) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 582 | auto &Data = Threadprivates[D]; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 583 | Data.Attributes = A; |
| 584 | Data.RefExpr.setPointer(E); |
| 585 | Data.PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 586 | } else { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 587 | assert(!Stack.empty() && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 588 | auto &Data = Stack.back().SharingMap[D]; |
| 589 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 590 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 591 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 592 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 593 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 594 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 595 | return; |
| 596 | } |
| 597 | const bool IsLastprivate = |
| 598 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 599 | Data.Attributes = A; |
| 600 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 601 | Data.PrivateCopy = PrivateCopy; |
| 602 | if (PrivateCopy) { |
| 603 | auto &Data = Stack.back().SharingMap[PrivateCopy->getDecl()]; |
| 604 | Data.Attributes = A; |
| 605 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 606 | Data.PrivateCopy = nullptr; |
| 607 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 611 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 612 | D = D->getCanonicalDecl(); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 613 | if (Stack.size() > 1) { |
| 614 | reverse_iterator I = Iter, E = Stack.rend(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 615 | Scope *TopScope = nullptr; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 616 | while (I != E && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 617 | ++I; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 618 | if (I == E) |
| 619 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 620 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 621 | Scope *CurScope = getCurScope(); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 622 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 623 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 624 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 625 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 626 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 629 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 630 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 631 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 632 | DeclContext *DC = SemaRef.CurContext; |
| 633 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 634 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 635 | VarDecl *Decl = |
| 636 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 637 | if (Attrs) { |
| 638 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 639 | I != E; ++I) |
| 640 | Decl->addAttr(*I); |
| 641 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 642 | Decl->setImplicit(); |
| 643 | return Decl; |
| 644 | } |
| 645 | |
| 646 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 647 | SourceLocation Loc, |
| 648 | bool RefersToCapture = false) { |
| 649 | D->setReferenced(); |
| 650 | D->markUsed(S.Context); |
| 651 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 652 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 653 | VK_LValue); |
| 654 | } |
| 655 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 656 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 657 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 658 | DSAVarData DVar; |
| 659 | |
| 660 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 661 | // in a Construct, C/C++, predetermined, p.1] |
| 662 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 663 | auto *VD = dyn_cast<VarDecl>(D); |
| 664 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 665 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 666 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 667 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 668 | (VD && VD->getStorageClass() == SC_Register && |
| 669 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 670 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 671 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 672 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 673 | } |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 674 | auto TI = Threadprivates.find(D); |
| 675 | if (TI != Threadprivates.end()) { |
| 676 | DVar.RefExpr = TI->getSecond().RefExpr.getPointer(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 677 | DVar.CKind = OMPC_threadprivate; |
| 678 | return DVar; |
| 679 | } |
| 680 | |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 681 | if (Stack.empty()) |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 682 | // Not in OpenMP execution region and top scope was already checked. |
| 683 | return DVar; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 684 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 685 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 686 | // in a Construct, C/C++, predetermined, p.4] |
| 687 | // Static data members are shared. |
| 688 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 689 | // in a Construct, C/C++, predetermined, p.7] |
| 690 | // Variables with static storage duration that are declared in a scope |
| 691 | // inside the construct are shared. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 692 | auto &&MatchesAlways = [](OpenMPDirectiveKind) -> bool { return true; }; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 693 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 694 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 695 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 696 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 697 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 698 | DVar.CKind = OMPC_shared; |
| 699 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 703 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 704 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 705 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 706 | // in a Construct, C/C++, predetermined, p.6] |
| 707 | // Variables with const qualified type having no mutable member are |
| 708 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 709 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 710 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 711 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 712 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 713 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 714 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 715 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 716 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 717 | // Variables with const-qualified type having no mutable member may be |
| 718 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 719 | DSAVarData DVarTemp = hasDSA( |
| 720 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; }, |
| 721 | MatchesAlways, FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 722 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 723 | return DVar; |
| 724 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 725 | DVar.CKind = OMPC_shared; |
| 726 | return DVar; |
| 727 | } |
| 728 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 729 | // Explicitly specified attributes and local variables with predetermined |
| 730 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 731 | auto StartI = std::next(Stack.rbegin()); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 732 | auto EndI = Stack.rend(); |
| 733 | if (FromParent && StartI != EndI) |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 734 | StartI = std::next(StartI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 735 | auto I = std::prev(StartI); |
| 736 | if (I->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 737 | DVar.RefExpr = I->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 738 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 739 | DVar.CKind = I->SharingMap[D].Attributes; |
| 740 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | return DVar; |
| 744 | } |
| 745 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 746 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 747 | bool FromParent) { |
| 748 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 749 | auto StartI = Stack.rbegin(); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 750 | auto EndI = Stack.rend(); |
| 751 | if (FromParent && StartI != EndI) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 752 | StartI = std::next(StartI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 753 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 756 | DSAStackTy::DSAVarData |
| 757 | DSAStackTy::hasDSA(ValueDecl *D, |
| 758 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 759 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 760 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 761 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 762 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 763 | auto EndI = Stack.rend(); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 764 | if (FromParent && StartI != EndI) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 765 | StartI = std::next(StartI); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 766 | if (StartI == EndI) |
| 767 | return {}; |
| 768 | auto I = std::prev(StartI); |
| 769 | do { |
| 770 | ++I; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 771 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 772 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 773 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 774 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 775 | return DVar; |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 776 | } while (I != EndI); |
| 777 | return {}; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 780 | DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| 781 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 782 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 783 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 784 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 785 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 786 | auto EndI = Stack.rend(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 787 | if (FromParent && StartI != EndI) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 788 | StartI = std::next(StartI); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 789 | if (StartI == EndI || !DPred(StartI->Directive)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 790 | return DSAVarData(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 791 | DSAVarData DVar = getDSA(StartI, D); |
| 792 | return CPred(DVar.CKind) ? DVar : DSAVarData(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 795 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 796 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 797 | unsigned Level, bool NotLastprivate) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 798 | if (CPred(ClauseKindMode)) |
| 799 | return true; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 800 | D = getCanonicalDecl(D); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 801 | auto StartI = Stack.begin(); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 802 | auto EndI = Stack.end(); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 803 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 804 | return false; |
| 805 | std::advance(StartI, Level); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 806 | return (StartI->SharingMap.count(D) > 0) && |
| 807 | StartI->SharingMap[D].RefExpr.getPointer() && |
| 808 | CPred(StartI->SharingMap[D].Attributes) && |
| 809 | (!NotLastprivate || !StartI->SharingMap[D].RefExpr.getInt()); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 812 | bool DSAStackTy::hasExplicitDirective( |
| 813 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 814 | unsigned Level) { |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 815 | auto StartI = Stack.begin(); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 816 | auto EndI = Stack.end(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 817 | if (std::distance(StartI, EndI) <= (int)Level) |
| 818 | return false; |
| 819 | std::advance(StartI, Level); |
| 820 | return DPred(StartI->Directive); |
| 821 | } |
| 822 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 823 | bool DSAStackTy::hasDirective( |
| 824 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 825 | const DeclarationNameInfo &, SourceLocation)> |
| 826 | &DPred, |
| 827 | bool FromParent) { |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 828 | // We look only in the enclosing region. |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 829 | if (Stack.size() < 1) |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 830 | return false; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 831 | auto StartI = std::next(Stack.rbegin()); |
Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame^] | 832 | auto EndI = Stack.rend(); |
| 833 | if (FromParent && StartI != EndI) |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 834 | StartI = std::next(StartI); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 835 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 836 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 837 | return true; |
| 838 | } |
| 839 | return false; |
| 840 | } |
| 841 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 842 | void Sema::InitDataSharingAttributesStack() { |
| 843 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 844 | } |
| 845 | |
| 846 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 847 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 848 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 849 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 850 | |
| 851 | auto &Ctx = getASTContext(); |
| 852 | bool IsByRef = true; |
| 853 | |
| 854 | // Find the directive that is associated with the provided scope. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 855 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 856 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 857 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 858 | // This table summarizes how a given variable should be passed to the device |
| 859 | // given its type and the clauses where it appears. This table is based on |
| 860 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 861 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 862 | // |
| 863 | // ========================================================================= |
| 864 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 865 | // | |(tofrom:scalar)| | pvt | | | | |
| 866 | // ========================================================================= |
| 867 | // | scl | | | | - | | bycopy| |
| 868 | // | scl | | - | x | - | - | bycopy| |
| 869 | // | scl | | x | - | - | - | null | |
| 870 | // | scl | x | | | - | | byref | |
| 871 | // | scl | x | - | x | - | - | bycopy| |
| 872 | // | scl | x | x | - | - | - | null | |
| 873 | // | scl | | - | - | - | x | byref | |
| 874 | // | scl | x | - | - | - | x | byref | |
| 875 | // |
| 876 | // | agg | n.a. | | | - | | byref | |
| 877 | // | agg | n.a. | - | x | - | - | byref | |
| 878 | // | agg | n.a. | x | - | - | - | null | |
| 879 | // | agg | n.a. | - | - | - | x | byref | |
| 880 | // | agg | n.a. | - | - | - | x[] | byref | |
| 881 | // |
| 882 | // | ptr | n.a. | | | - | | bycopy| |
| 883 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 884 | // | ptr | n.a. | x | - | - | - | null | |
| 885 | // | ptr | n.a. | - | - | - | x | byref | |
| 886 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 887 | // | ptr | n.a. | - | - | x | | bycopy| |
| 888 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 889 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 890 | // ========================================================================= |
| 891 | // Legend: |
| 892 | // scl - scalar |
| 893 | // ptr - pointer |
| 894 | // agg - aggregate |
| 895 | // x - applies |
| 896 | // - - invalid in this combination |
| 897 | // [] - mapped with an array section |
| 898 | // byref - should be mapped by reference |
| 899 | // byval - should be mapped by value |
| 900 | // null - initialize a local variable to null on the device |
| 901 | // |
| 902 | // Observations: |
| 903 | // - All scalar declarations that show up in a map clause have to be passed |
| 904 | // by reference, because they may have been mapped in the enclosing data |
| 905 | // environment. |
| 906 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 907 | // passed by reference, regardless the result in the table above. |
| 908 | // - For pointers mapped by value that have either an implicit map or an |
| 909 | // array section, the runtime library may pass the NULL value to the |
| 910 | // device instead of the value passed to it by the compiler. |
| 911 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 912 | if (Ty->isReferenceType()) |
| 913 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 914 | |
| 915 | // Locate map clauses and see if the variable being captured is referred to |
| 916 | // in any of those clauses. Here we only care about variables, not fields, |
| 917 | // because fields are part of aggregates. |
| 918 | bool IsVariableUsedInMapClause = false; |
| 919 | bool IsVariableAssociatedWithSection = false; |
| 920 | |
| 921 | DSAStack->checkMappableExprComponentListsForDecl( |
| 922 | D, /*CurrentRegionOnly=*/true, |
| 923 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 924 | MapExprComponents, |
| 925 | OpenMPClauseKind WhereFoundClauseKind) { |
| 926 | // Only the map clause information influences how a variable is |
| 927 | // captured. E.g. is_device_ptr does not require changing the default |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 928 | // behavior. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 929 | if (WhereFoundClauseKind != OMPC_map) |
| 930 | return false; |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 931 | |
| 932 | auto EI = MapExprComponents.rbegin(); |
| 933 | auto EE = MapExprComponents.rend(); |
| 934 | |
| 935 | assert(EI != EE && "Invalid map expression!"); |
| 936 | |
| 937 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 938 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 939 | |
| 940 | ++EI; |
| 941 | if (EI == EE) |
| 942 | return false; |
| 943 | |
| 944 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 945 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 946 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 947 | IsVariableAssociatedWithSection = true; |
| 948 | // There is nothing more we need to know about this variable. |
| 949 | return true; |
| 950 | } |
| 951 | |
| 952 | // Keep looking for more map info. |
| 953 | return false; |
| 954 | }); |
| 955 | |
| 956 | if (IsVariableUsedInMapClause) { |
| 957 | // If variable is identified in a map clause it is always captured by |
| 958 | // reference except if it is a pointer that is dereferenced somehow. |
| 959 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 960 | } else { |
| 961 | // By default, all the data that has a scalar type is mapped by copy. |
| 962 | IsByRef = !Ty->isScalarType(); |
| 963 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 964 | } |
| 965 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 966 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| 967 | IsByRef = !DSAStack->hasExplicitDSA( |
| 968 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 969 | Level, /*NotLastprivate=*/true); |
| 970 | } |
| 971 | |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 972 | // 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] | 973 | // and alignment, because the runtime library only deals with uintptr types. |
| 974 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 975 | // instead. |
| 976 | if (!IsByRef && |
| 977 | (Ctx.getTypeSizeInChars(Ty) > |
| 978 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 979 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 980 | IsByRef = true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 981 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 982 | |
| 983 | return IsByRef; |
| 984 | } |
| 985 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 986 | unsigned Sema::getOpenMPNestingLevel() const { |
| 987 | assert(getLangOpts().OpenMP); |
| 988 | return DSAStack->getNestingLevel(); |
| 989 | } |
| 990 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 991 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 992 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 993 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 994 | |
| 995 | // If we are attempting to capture a global variable in a directive with |
| 996 | // 'target' we return true so that this global is also mapped to the device. |
| 997 | // |
| 998 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 999 | // then it should not be captured. Therefore, an extra check has to be |
| 1000 | // inserted here once support for 'declare target' is added. |
| 1001 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1002 | auto *VD = dyn_cast<VarDecl>(D); |
| 1003 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1004 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1005 | !DSAStack->isClauseParsingMode()) |
| 1006 | return VD; |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1007 | if (DSAStack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1008 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 1009 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1010 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1011 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1012 | false)) |
| 1013 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 1016 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 1017 | (!DSAStack->isClauseParsingMode() || |
| 1018 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1019 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 1020 | if (Info.first || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1021 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1022 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1023 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1024 | return VD ? VD : Info.second; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1025 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1026 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1027 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1028 | DVarPrivate = DSAStack->hasDSA( |
| 1029 | D, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 1030 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1031 | if (DVarPrivate.CKind != OMPC_unknown) |
| 1032 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1033 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1034 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1037 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1038 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1039 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1040 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1043 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1044 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1045 | // Return true if the current level is no longer enclosed in a target region. |
| 1046 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1047 | auto *VD = dyn_cast<VarDecl>(D); |
| 1048 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1049 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1050 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1053 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1054 | |
| 1055 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1056 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1057 | Scope *CurScope, SourceLocation Loc) { |
| 1058 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 1059 | PushExpressionEvaluationContext( |
| 1060 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1063 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1064 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1067 | void Sema::EndOpenMPClause() { |
| 1068 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1071 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1072 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1073 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1074 | // clause requires an accessible, unambiguous default constructor for the |
| 1075 | // class type, unless the list item is also specified in a firstprivate |
| 1076 | // clause. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1077 | if (auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1078 | for (auto *C : D->clauses()) { |
| 1079 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1080 | SmallVector<Expr *, 8> PrivateCopies; |
| 1081 | for (auto *DE : Clause->varlists()) { |
| 1082 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1083 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1084 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1085 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1086 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1087 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1088 | QualType Type = VD->getType().getNonReferenceType(); |
| 1089 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1090 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1091 | // Generate helper private variable and initialize it with the |
| 1092 | // default value. The address of the original variable is replaced |
| 1093 | // by the address of the new private variable in CodeGen. This new |
| 1094 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1095 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1096 | auto *VDPrivate = buildVarDecl( |
| 1097 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1098 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1099 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1100 | if (VDPrivate->isInvalidDecl()) |
| 1101 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1102 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1103 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1104 | } else { |
| 1105 | // The variable is also a firstprivate, so initialization sequence |
| 1106 | // for private copy is generated already. |
| 1107 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1108 | } |
| 1109 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1110 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1111 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1112 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1117 | DSAStack->pop(); |
| 1118 | DiscardCleanupsInEvaluationContext(); |
| 1119 | PopExpressionEvaluationContext(); |
| 1120 | } |
| 1121 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1122 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1123 | Expr *NumIterations, Sema &SemaRef, |
| 1124 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1125 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1126 | namespace { |
| 1127 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1128 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1129 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1130 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1131 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1132 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1133 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1134 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1135 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1136 | if (auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1137 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1138 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1139 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1140 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1141 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1142 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1143 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1144 | |
| 1145 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { |
| 1146 | private: |
| 1147 | Sema &SemaRef; |
| 1148 | |
| 1149 | public: |
| 1150 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1151 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1152 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1153 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 1154 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1155 | SemaRef.getCurScope()); |
| 1156 | } |
| 1157 | return false; |
| 1158 | } |
| 1159 | }; |
| 1160 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1161 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1162 | |
| 1163 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1164 | CXXScopeSpec &ScopeSpec, |
| 1165 | const DeclarationNameInfo &Id) { |
| 1166 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1167 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1168 | |
| 1169 | if (Lookup.isAmbiguous()) |
| 1170 | return ExprError(); |
| 1171 | |
| 1172 | VarDecl *VD; |
| 1173 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1174 | if (TypoCorrection Corrected = CorrectTypo( |
| 1175 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1176 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1177 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1178 | PDiag(Lookup.empty() |
| 1179 | ? diag::err_undeclared_var_use_suggest |
| 1180 | : diag::err_omp_expected_var_arg_suggest) |
| 1181 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1182 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1183 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1184 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1185 | : diag::err_omp_expected_var_arg) |
| 1186 | << Id.getName(); |
| 1187 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1188 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1189 | } else { |
| 1190 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1191 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1192 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1193 | return ExprError(); |
| 1194 | } |
| 1195 | } |
| 1196 | Lookup.suppressDiagnostics(); |
| 1197 | |
| 1198 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1199 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1200 | if (!VD->hasGlobalStorage()) { |
| 1201 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1202 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1203 | bool IsDecl = |
| 1204 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1205 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1206 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1207 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1208 | return ExprError(); |
| 1209 | } |
| 1210 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1211 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1212 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1213 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1214 | // A threadprivate directive for file-scope variables must appear outside |
| 1215 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1216 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1217 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1218 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1219 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1220 | bool IsDecl = |
| 1221 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1222 | Diag(VD->getLocation(), |
| 1223 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1224 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1225 | return ExprError(); |
| 1226 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1227 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1228 | // A threadprivate directive for static class member variables must appear |
| 1229 | // in the class definition, in the same scope in which the member |
| 1230 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1231 | if (CanonicalVD->isStaticDataMember() && |
| 1232 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1233 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1234 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1235 | bool IsDecl = |
| 1236 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1237 | Diag(VD->getLocation(), |
| 1238 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1239 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1240 | return ExprError(); |
| 1241 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1242 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1243 | // A threadprivate directive for namespace-scope variables must appear |
| 1244 | // outside any definition or declaration other than the namespace |
| 1245 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1246 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1247 | (!getCurLexicalContext()->isFileContext() || |
| 1248 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1249 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1250 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1251 | bool IsDecl = |
| 1252 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1253 | Diag(VD->getLocation(), |
| 1254 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1255 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1256 | return ExprError(); |
| 1257 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1258 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1259 | // A threadprivate directive for static block-scope variables must appear |
| 1260 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1261 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1262 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1263 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1264 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1265 | bool IsDecl = |
| 1266 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1267 | Diag(VD->getLocation(), |
| 1268 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1269 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1270 | return ExprError(); |
| 1271 | } |
| 1272 | |
| 1273 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1274 | // A threadprivate directive must lexically precede all references to any |
| 1275 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1276 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1277 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1278 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1279 | return ExprError(); |
| 1280 | } |
| 1281 | |
| 1282 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1283 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1284 | SourceLocation(), VD, |
| 1285 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1286 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1287 | } |
| 1288 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1289 | Sema::DeclGroupPtrTy |
| 1290 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1291 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1292 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1293 | CurContext->addDecl(D); |
| 1294 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1295 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1296 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1297 | } |
| 1298 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1299 | namespace { |
| 1300 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1301 | Sema &SemaRef; |
| 1302 | |
| 1303 | public: |
| 1304 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1305 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1306 | if (VD->hasLocalStorage()) { |
| 1307 | SemaRef.Diag(E->getLocStart(), |
| 1308 | diag::err_omp_local_var_in_threadprivate_init) |
| 1309 | << E->getSourceRange(); |
| 1310 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1311 | << VD << VD->getSourceRange(); |
| 1312 | return true; |
| 1313 | } |
| 1314 | } |
| 1315 | return false; |
| 1316 | } |
| 1317 | bool VisitStmt(const Stmt *S) { |
| 1318 | for (auto Child : S->children()) { |
| 1319 | if (Child && Visit(Child)) |
| 1320 | return true; |
| 1321 | } |
| 1322 | return false; |
| 1323 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1324 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1325 | }; |
| 1326 | } // namespace |
| 1327 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1328 | OMPThreadPrivateDecl * |
| 1329 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1330 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1331 | for (auto &RefExpr : VarList) { |
| 1332 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1333 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1334 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1335 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1336 | // Mark variable as used. |
| 1337 | VD->setReferenced(); |
| 1338 | VD->markUsed(Context); |
| 1339 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1340 | QualType QType = VD->getType(); |
| 1341 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1342 | // It will be analyzed later. |
| 1343 | Vars.push_back(DE); |
| 1344 | continue; |
| 1345 | } |
| 1346 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1347 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1348 | // A threadprivate variable must not have an incomplete type. |
| 1349 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1350 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1351 | continue; |
| 1352 | } |
| 1353 | |
| 1354 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1355 | // A threadprivate variable must not have a reference type. |
| 1356 | if (VD->getType()->isReferenceType()) { |
| 1357 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1358 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 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 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1367 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1368 | // the corresponding diagnostic. |
| 1369 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1370 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1371 | getLangOpts().OpenMPUseTLS && |
| 1372 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1373 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1374 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1375 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1376 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1377 | bool IsDecl = |
| 1378 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1379 | Diag(VD->getLocation(), |
| 1380 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1381 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1382 | continue; |
| 1383 | } |
| 1384 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1385 | // Check if initial value of threadprivate variable reference variable with |
| 1386 | // local storage (it is not supported by runtime). |
| 1387 | if (auto Init = VD->getAnyInitializer()) { |
| 1388 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1389 | if (Checker.Visit(Init)) |
| 1390 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1391 | } |
| 1392 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1393 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1394 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1395 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1396 | Context, SourceRange(Loc, Loc))); |
| 1397 | if (auto *ML = Context.getASTMutationListener()) |
| 1398 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1399 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1400 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1401 | if (!Vars.empty()) { |
| 1402 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1403 | Vars); |
| 1404 | D->setAccess(AS_public); |
| 1405 | } |
| 1406 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1407 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1408 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1409 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1410 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1411 | bool IsLoopIterVar = false) { |
| 1412 | if (DVar.RefExpr) { |
| 1413 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1414 | << getOpenMPClauseName(DVar.CKind); |
| 1415 | return; |
| 1416 | } |
| 1417 | enum { |
| 1418 | PDSA_StaticMemberShared, |
| 1419 | PDSA_StaticLocalVarShared, |
| 1420 | PDSA_LoopIterVarPrivate, |
| 1421 | PDSA_LoopIterVarLinear, |
| 1422 | PDSA_LoopIterVarLastprivate, |
| 1423 | PDSA_ConstVarShared, |
| 1424 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1425 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1426 | PDSA_LocalVarPrivate, |
| 1427 | PDSA_Implicit |
| 1428 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1429 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1430 | auto ReportLoc = D->getLocation(); |
| 1431 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1432 | if (IsLoopIterVar) { |
| 1433 | if (DVar.CKind == OMPC_private) |
| 1434 | Reason = PDSA_LoopIterVarPrivate; |
| 1435 | else if (DVar.CKind == OMPC_lastprivate) |
| 1436 | Reason = PDSA_LoopIterVarLastprivate; |
| 1437 | else |
| 1438 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1439 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1440 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1441 | Reason = PDSA_TaskVarFirstprivate; |
| 1442 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1443 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1444 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1445 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1446 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1447 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1448 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1449 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1450 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1451 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1452 | ReportHint = true; |
| 1453 | Reason = PDSA_LocalVarPrivate; |
| 1454 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1455 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1456 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1457 | << Reason << ReportHint |
| 1458 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1459 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1460 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1461 | << getOpenMPClauseName(DVar.CKind); |
| 1462 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1465 | namespace { |
| 1466 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1467 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1468 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1469 | bool ErrorFound; |
| 1470 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1471 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1472 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1473 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1474 | public: |
| 1475 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1476 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1477 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1478 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1479 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1480 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1481 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1482 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1483 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1484 | auto DVar = Stack->getTopDSA(VD, false); |
| 1485 | // Check if the variable has explicit DSA set and stop analysis if it so. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1486 | if (DVar.RefExpr) |
| 1487 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1488 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1489 | auto ELoc = E->getExprLoc(); |
| 1490 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1491 | // The default(none) clause requires that each variable that is referenced |
| 1492 | // in the construct, and does not have a predetermined data-sharing |
| 1493 | // attribute, must have its data-sharing attribute explicitly determined |
| 1494 | // by being listed in a data-sharing attribute clause. |
| 1495 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1496 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1497 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1498 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1499 | return; |
| 1500 | } |
| 1501 | |
| 1502 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1503 | // A list item that appears in a reduction clause of the innermost |
| 1504 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1505 | // explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1506 | DVar = Stack->hasInnermostDSA( |
| 1507 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1508 | [](OpenMPDirectiveKind K) -> bool { |
| 1509 | return isOpenMPParallelDirective(K) || |
| 1510 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 1511 | }, |
| 1512 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1513 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1514 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1515 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1516 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1517 | return; |
| 1518 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1519 | |
| 1520 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1521 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1522 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1523 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1524 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1525 | } |
| 1526 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1527 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1528 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1529 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1530 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1531 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1532 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1533 | auto DVar = Stack->getTopDSA(FD, false); |
| 1534 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1535 | // so. |
| 1536 | if (DVar.RefExpr) |
| 1537 | return; |
| 1538 | |
| 1539 | auto ELoc = E->getExprLoc(); |
| 1540 | auto DKind = Stack->getCurrentDirective(); |
| 1541 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1542 | // A list item that appears in a reduction clause of the innermost |
| 1543 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1544 | // an explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1545 | DVar = Stack->hasInnermostDSA( |
| 1546 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1547 | [](OpenMPDirectiveKind K) -> bool { |
| 1548 | return isOpenMPParallelDirective(K) || |
| 1549 | isOpenMPWorksharingDirective(K) || |
| 1550 | isOpenMPTeamsDirective(K); |
| 1551 | }, |
| 1552 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1553 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1554 | ErrorFound = true; |
| 1555 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1556 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1557 | return; |
| 1558 | } |
| 1559 | |
| 1560 | // Define implicit data-sharing attributes for task. |
| 1561 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1562 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1563 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1564 | ImplicitFirstprivate.push_back(E); |
| 1565 | } |
Alexey Bataev | 7fcacd8 | 2016-11-28 15:55:15 +0000 | [diff] [blame] | 1566 | } else |
| 1567 | Visit(E->getBase()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1568 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1569 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1570 | for (auto *C : S->clauses()) { |
| 1571 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1572 | // for task directives. |
| 1573 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1574 | for (auto *CC : C->children()) { |
| 1575 | if (CC) |
| 1576 | Visit(CC); |
| 1577 | } |
| 1578 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1579 | } |
| 1580 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1581 | for (auto *C : S->children()) { |
| 1582 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1583 | Visit(C); |
| 1584 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1585 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1586 | |
| 1587 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1588 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1589 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1590 | return VarsWithInheritedDSA; |
| 1591 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1592 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1593 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1594 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1595 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1596 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1597 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1598 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1599 | switch (DKind) { |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1600 | case OMPD_parallel: |
| 1601 | case OMPD_parallel_for: |
| 1602 | case OMPD_parallel_for_simd: |
| 1603 | case OMPD_parallel_sections: |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1604 | case OMPD_teams: { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1605 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1606 | QualType KmpInt32PtrTy = |
| 1607 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1608 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1609 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1610 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1611 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1612 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1613 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1614 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1615 | break; |
| 1616 | } |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1617 | case OMPD_target_teams: |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1618 | case OMPD_target_parallel: { |
| 1619 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 1620 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1621 | }; |
| 1622 | // Start a captured region for 'target' with no implicit parameters. |
| 1623 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1624 | ParamsTarget); |
| 1625 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1626 | QualType KmpInt32PtrTy = |
| 1627 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1628 | Sema::CapturedParamNameType ParamsTeamsOrParallel[] = { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1629 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1630 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1631 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1632 | }; |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1633 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 1634 | // the same implicit parameters. |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1635 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1636 | ParamsTeamsOrParallel); |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1637 | break; |
| 1638 | } |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1639 | case OMPD_simd: |
| 1640 | case OMPD_for: |
| 1641 | case OMPD_for_simd: |
| 1642 | case OMPD_sections: |
| 1643 | case OMPD_section: |
| 1644 | case OMPD_single: |
| 1645 | case OMPD_master: |
| 1646 | case OMPD_critical: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1647 | case OMPD_taskgroup: |
| 1648 | case OMPD_distribute: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1649 | case OMPD_ordered: |
| 1650 | case OMPD_atomic: |
| 1651 | case OMPD_target_data: |
| 1652 | case OMPD_target: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1653 | case OMPD_target_parallel_for: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1654 | case OMPD_target_parallel_for_simd: |
| 1655 | case OMPD_target_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1656 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1657 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1658 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1659 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1660 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1661 | break; |
| 1662 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1663 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1664 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1665 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1666 | FunctionProtoType::ExtProtoInfo EPI; |
| 1667 | EPI.Variadic = true; |
| 1668 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1669 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1670 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1671 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1672 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1673 | std::make_pair(".copy_fn.", |
| 1674 | Context.getPointerType(CopyFnType).withConst()), |
| 1675 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1676 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1677 | }; |
| 1678 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1679 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1680 | // Mark this captured region as inlined, because we don't use outlined |
| 1681 | // function directly. |
| 1682 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1683 | AlwaysInlineAttr::CreateImplicit( |
| 1684 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1685 | break; |
| 1686 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1687 | case OMPD_taskloop: |
| 1688 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1689 | QualType KmpInt32Ty = |
| 1690 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1691 | QualType KmpUInt64Ty = |
| 1692 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1693 | QualType KmpInt64Ty = |
| 1694 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1695 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1696 | FunctionProtoType::ExtProtoInfo EPI; |
| 1697 | EPI.Variadic = true; |
| 1698 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1699 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1700 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1701 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1702 | std::make_pair(".privates.", |
| 1703 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1704 | std::make_pair( |
| 1705 | ".copy_fn.", |
| 1706 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1707 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1708 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1709 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1710 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1711 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1712 | }; |
| 1713 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1714 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1715 | // Mark this captured region as inlined, because we don't use outlined |
| 1716 | // function directly. |
| 1717 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1718 | AlwaysInlineAttr::CreateImplicit( |
| 1719 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1720 | break; |
| 1721 | } |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1722 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1723 | case OMPD_distribute_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1724 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1725 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1726 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1727 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1728 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1729 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1730 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1731 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 1732 | case OMPD_target_teams_distribute_simd: { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1733 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1734 | QualType KmpInt32PtrTy = |
| 1735 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1736 | Sema::CapturedParamNameType Params[] = { |
| 1737 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1738 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1739 | std::make_pair(".previous.lb.", Context.getSizeType()), |
| 1740 | std::make_pair(".previous.ub.", Context.getSizeType()), |
| 1741 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1742 | }; |
| 1743 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1744 | Params); |
| 1745 | break; |
| 1746 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1747 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1748 | case OMPD_taskyield: |
| 1749 | case OMPD_barrier: |
| 1750 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1751 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1752 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1753 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1754 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1755 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1756 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1757 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1758 | case OMPD_declare_target: |
| 1759 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1760 | case OMPD_target_update: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1761 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1762 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1763 | llvm_unreachable("Unknown OpenMP directive"); |
| 1764 | } |
| 1765 | } |
| 1766 | |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1767 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
| 1768 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 1769 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
| 1770 | return CaptureRegions.size(); |
| 1771 | } |
| 1772 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1773 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1774 | Expr *CaptureExpr, bool WithInit, |
| 1775 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1776 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1777 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1778 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1779 | QualType Ty = Init->getType(); |
| 1780 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1781 | if (S.getLangOpts().CPlusPlus) |
| 1782 | Ty = C.getLValueReferenceType(Ty); |
| 1783 | else { |
| 1784 | Ty = C.getPointerType(Ty); |
| 1785 | ExprResult Res = |
| 1786 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1787 | if (!Res.isUsable()) |
| 1788 | return nullptr; |
| 1789 | Init = Res.get(); |
| 1790 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1791 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1792 | } |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 1793 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
| 1794 | CaptureExpr->getLocStart()); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1795 | if (!WithInit) |
| 1796 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1797 | S.CurContext->addHiddenDecl(CED); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1798 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1799 | return CED; |
| 1800 | } |
| 1801 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1802 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1803 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1804 | OMPCapturedExprDecl *CD; |
| 1805 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1806 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1807 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1808 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1809 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1810 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1811 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1812 | } |
| 1813 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1814 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1815 | if (!Ref) { |
| 1816 | auto *CD = |
| 1817 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1818 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1819 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1820 | CaptureExpr->getExprLoc()); |
| 1821 | } |
| 1822 | ExprResult Res = Ref; |
| 1823 | if (!S.getLangOpts().CPlusPlus && |
| 1824 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1825 | Ref->getType()->isPointerType()) |
| 1826 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1827 | if (!Res.isUsable()) |
| 1828 | return ExprError(); |
| 1829 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1832 | namespace { |
| 1833 | // OpenMP directives parsed in this section are represented as a |
| 1834 | // CapturedStatement with an associated statement. If a syntax error |
| 1835 | // is detected during the parsing of the associated statement, the |
| 1836 | // compiler must abort processing and close the CapturedStatement. |
| 1837 | // |
| 1838 | // Combined directives such as 'target parallel' have more than one |
| 1839 | // nested CapturedStatements. This RAII ensures that we unwind out |
| 1840 | // of all the nested CapturedStatements when an error is found. |
| 1841 | class CaptureRegionUnwinderRAII { |
| 1842 | private: |
| 1843 | Sema &S; |
| 1844 | bool &ErrorFound; |
| 1845 | OpenMPDirectiveKind DKind; |
| 1846 | |
| 1847 | public: |
| 1848 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
| 1849 | OpenMPDirectiveKind DKind) |
| 1850 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
| 1851 | ~CaptureRegionUnwinderRAII() { |
| 1852 | if (ErrorFound) { |
| 1853 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
| 1854 | while (--ThisCaptureLevel >= 0) |
| 1855 | S.ActOnCapturedRegionError(); |
| 1856 | } |
| 1857 | } |
| 1858 | }; |
| 1859 | } // namespace |
| 1860 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1861 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1862 | ArrayRef<OMPClause *> Clauses) { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1863 | bool ErrorFound = false; |
| 1864 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
| 1865 | *this, ErrorFound, DSAStack->getCurrentDirective()); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1866 | if (!S.isUsable()) { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1867 | ErrorFound = true; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1868 | return StmtError(); |
| 1869 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1870 | |
| 1871 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1872 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1873 | SmallVector<OMPLinearClause *, 4> LCs; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 1874 | SmallVector<OMPClauseWithPreInit *, 8> PICs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1875 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1876 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1877 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1878 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1879 | (getLangOpts().OpenMPUseTLS && |
| 1880 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1881 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1882 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1883 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1884 | for (auto *VarRef : Clause->children()) { |
| 1885 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1886 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1887 | } |
| 1888 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1889 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1890 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 1891 | if (auto *C = OMPClauseWithPreInit::get(Clause)) |
| 1892 | PICs.push_back(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1893 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1894 | if (auto *E = C->getPostUpdateExpr()) |
| 1895 | MarkDeclarationsReferencedInExpr(E); |
| 1896 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1897 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1898 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1899 | SC = cast<OMPScheduleClause>(Clause); |
| 1900 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1901 | OC = cast<OMPOrderedClause>(Clause); |
| 1902 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1903 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1904 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1905 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1906 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1907 | // specified. |
| 1908 | if (SC && |
| 1909 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1910 | SC->getSecondScheduleModifier() == |
| 1911 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1912 | OC) { |
| 1913 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1914 | ? SC->getFirstScheduleModifierLoc() |
| 1915 | : SC->getSecondScheduleModifierLoc(), |
| 1916 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1917 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1918 | ErrorFound = true; |
| 1919 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1920 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1921 | for (auto *C : LCs) { |
| 1922 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1923 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1924 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1925 | ErrorFound = true; |
| 1926 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1927 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1928 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1929 | OC->getNumForLoops()) { |
| 1930 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1931 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1932 | ErrorFound = true; |
| 1933 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1934 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1935 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1936 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1937 | StmtResult SR = S; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 1938 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 1939 | getOpenMPCaptureRegions(CaptureRegions, DSAStack->getCurrentDirective()); |
| 1940 | for (auto ThisCaptureRegion : llvm::reverse(CaptureRegions)) { |
| 1941 | // Mark all variables in private list clauses as used in inner region. |
| 1942 | // Required for proper codegen of combined directives. |
| 1943 | // TODO: add processing for other clauses. |
| 1944 | if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 1945 | for (auto *C : PICs) { |
| 1946 | OpenMPDirectiveKind CaptureRegion = C->getCaptureRegion(); |
| 1947 | // Find the particular capture region for the clause if the |
| 1948 | // directive is a combined one with multiple capture regions. |
| 1949 | // If the directive is not a combined one, the capture region |
| 1950 | // associated with the clause is OMPD_unknown and is generated |
| 1951 | // only once. |
| 1952 | if (CaptureRegion == ThisCaptureRegion || |
| 1953 | CaptureRegion == OMPD_unknown) { |
| 1954 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1955 | for (auto *D : DS->decls()) |
| 1956 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1957 | } |
| 1958 | } |
| 1959 | } |
| 1960 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1961 | SR = ActOnCapturedRegionEnd(SR.get()); |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 1962 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1963 | return SR; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 1966 | static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, |
| 1967 | OpenMPDirectiveKind CancelRegion, |
| 1968 | SourceLocation StartLoc) { |
| 1969 | // CancelRegion is only needed for cancel and cancellation_point. |
| 1970 | if (CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_cancellation_point) |
| 1971 | return false; |
| 1972 | |
| 1973 | if (CancelRegion == OMPD_parallel || CancelRegion == OMPD_for || |
| 1974 | CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) |
| 1975 | return false; |
| 1976 | |
| 1977 | SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 1978 | << getOpenMPDirectiveName(CancelRegion); |
| 1979 | return true; |
| 1980 | } |
| 1981 | |
| 1982 | static bool checkNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1983 | OpenMPDirectiveKind CurrentRegion, |
| 1984 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1985 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1986 | SourceLocation StartLoc) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1987 | if (Stack->getCurScope()) { |
| 1988 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1989 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1990 | bool NestingProhibited = false; |
| 1991 | bool CloseNesting = true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1992 | bool OrphanSeen = false; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1993 | enum { |
| 1994 | NoRecommend, |
| 1995 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1996 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1997 | ShouldBeInTargetRegion, |
| 1998 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1999 | } Recommend = NoRecommend; |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2000 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2001 | // OpenMP [2.16, Nesting of Regions] |
| 2002 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2003 | // OpenMP [2.8.1,simd Construct, Restrictions] |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2004 | // An ordered construct with the simd clause is the only OpenMP |
| 2005 | // construct that can appear in the simd region. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2006 | // Allowing a SIMD construct nested in another SIMD construct is an |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2007 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 2008 | // message. |
| 2009 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 2010 | ? diag::err_omp_prohibited_region_simd |
| 2011 | : diag::warn_omp_nesting_simd); |
| 2012 | return CurrentRegion != OMPD_simd; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2013 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2014 | if (ParentRegion == OMPD_atomic) { |
| 2015 | // OpenMP [2.16, Nesting of Regions] |
| 2016 | // OpenMP constructs may not be nested inside an atomic region. |
| 2017 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2018 | return true; |
| 2019 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2020 | if (CurrentRegion == OMPD_section) { |
| 2021 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2022 | // Orphaned section directives are prohibited. That is, the section |
| 2023 | // directives must appear within the sections construct and must not be |
| 2024 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2025 | if (ParentRegion != OMPD_sections && |
| 2026 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2027 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2028 | << (ParentRegion != OMPD_unknown) |
| 2029 | << getOpenMPDirectiveName(ParentRegion); |
| 2030 | return true; |
| 2031 | } |
| 2032 | return false; |
| 2033 | } |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2034 | // Allow some constructs (except teams) to be orphaned (they could be |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2035 | // used in functions, called from OpenMP regions with the required |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2036 | // preconditions). |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2037 | if (ParentRegion == OMPD_unknown && |
| 2038 | !isOpenMPNestingTeamsDirective(CurrentRegion)) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2039 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2040 | if (CurrentRegion == OMPD_cancellation_point || |
| 2041 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2042 | // OpenMP [2.16, Nesting of Regions] |
| 2043 | // A cancellation point construct for which construct-type-clause is |
| 2044 | // taskgroup must be nested inside a task construct. A cancellation |
| 2045 | // point construct for which construct-type-clause is not taskgroup must |
| 2046 | // be closely nested inside an OpenMP construct that matches the type |
| 2047 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2048 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2049 | // nested inside a task construct. A cancel construct for which |
| 2050 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2051 | // OpenMP construct that matches the type specified in |
| 2052 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2053 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2054 | !((CancelRegion == OMPD_parallel && |
| 2055 | (ParentRegion == OMPD_parallel || |
| 2056 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2057 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2058 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2059 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2060 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2061 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2062 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2063 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2064 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2065 | // OpenMP [2.16, Nesting of Regions] |
| 2066 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2067 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2068 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2069 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2070 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2071 | // OpenMP [2.16, Nesting of Regions] |
| 2072 | // A critical region may not be nested (closely or otherwise) inside a |
| 2073 | // critical region with the same name. Note that this restriction is not |
| 2074 | // sufficient to prevent deadlock. |
| 2075 | SourceLocation PreviousCriticalLoc; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2076 | bool DeadLock = Stack->hasDirective( |
| 2077 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 2078 | const DeclarationNameInfo &DNI, |
| 2079 | SourceLocation Loc) -> bool { |
| 2080 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 2081 | PreviousCriticalLoc = Loc; |
| 2082 | return true; |
| 2083 | } else |
| 2084 | return false; |
| 2085 | }, |
| 2086 | false /* skip top directive */); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2087 | if (DeadLock) { |
| 2088 | SemaRef.Diag(StartLoc, |
| 2089 | diag::err_omp_prohibited_region_critical_same_name) |
| 2090 | << CurrentName.getName(); |
| 2091 | if (PreviousCriticalLoc.isValid()) |
| 2092 | SemaRef.Diag(PreviousCriticalLoc, |
| 2093 | diag::note_omp_previous_critical_region); |
| 2094 | return true; |
| 2095 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2096 | } else if (CurrentRegion == OMPD_barrier) { |
| 2097 | // OpenMP [2.16, Nesting of Regions] |
| 2098 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2099 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2100 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2101 | isOpenMPTaskingDirective(ParentRegion) || |
| 2102 | ParentRegion == OMPD_master || |
| 2103 | ParentRegion == OMPD_critical || |
| 2104 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2105 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2106 | !isOpenMPParallelDirective(CurrentRegion) && |
| 2107 | !isOpenMPTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2108 | // OpenMP [2.16, Nesting of Regions] |
| 2109 | // A worksharing region may not be closely nested inside a worksharing, |
| 2110 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2111 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2112 | isOpenMPTaskingDirective(ParentRegion) || |
| 2113 | ParentRegion == OMPD_master || |
| 2114 | ParentRegion == OMPD_critical || |
| 2115 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2116 | Recommend = ShouldBeInParallelRegion; |
| 2117 | } else if (CurrentRegion == OMPD_ordered) { |
| 2118 | // OpenMP [2.16, Nesting of Regions] |
| 2119 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2120 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2121 | // An ordered region must be closely nested inside a loop region (or |
| 2122 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2123 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2124 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2125 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2126 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2127 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2128 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2129 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2130 | Recommend = ShouldBeInOrderedRegion; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2131 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2132 | // OpenMP [2.16, Nesting of Regions] |
| 2133 | // If specified, a teams construct must be contained within a target |
| 2134 | // construct. |
| 2135 | NestingProhibited = ParentRegion != OMPD_target; |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2136 | OrphanSeen = ParentRegion == OMPD_unknown; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2137 | Recommend = ShouldBeInTargetRegion; |
| 2138 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2139 | } |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2140 | if (!NestingProhibited && |
| 2141 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
| 2142 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
| 2143 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2144 | // OpenMP [2.16, Nesting of Regions] |
| 2145 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2146 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2147 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2148 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2149 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2150 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2151 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2152 | if (!NestingProhibited && |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2153 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2154 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2155 | // The region associated with the distribute construct must be strictly |
| 2156 | // nested inside a teams region |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2157 | NestingProhibited = |
| 2158 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2159 | Recommend = ShouldBeInTeamsRegion; |
| 2160 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2161 | if (!NestingProhibited && |
| 2162 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2163 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2164 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2165 | // If a target, target update, target data, target enter data, or |
| 2166 | // target exit data construct is encountered during execution of a |
| 2167 | // target region, the behavior is unspecified. |
| 2168 | NestingProhibited = Stack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2169 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 2170 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2171 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2172 | OffendingRegion = K; |
| 2173 | return true; |
| 2174 | } else |
| 2175 | return false; |
| 2176 | }, |
| 2177 | false /* don't skip top directive */); |
| 2178 | CloseNesting = false; |
| 2179 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2180 | if (NestingProhibited) { |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2181 | if (OrphanSeen) { |
| 2182 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 2183 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 2184 | } else { |
| 2185 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 2186 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2187 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 2188 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2189 | return true; |
| 2190 | } |
| 2191 | } |
| 2192 | return false; |
| 2193 | } |
| 2194 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2195 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2196 | ArrayRef<OMPClause *> Clauses, |
| 2197 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2198 | bool ErrorFound = false; |
| 2199 | unsigned NamedModifiersNumber = 0; |
| 2200 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2201 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2202 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2203 | for (const auto *C : Clauses) { |
| 2204 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2205 | // At most one if clause without a directive-name-modifier can appear on |
| 2206 | // the directive. |
| 2207 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2208 | if (FoundNameModifiers[CurNM]) { |
| 2209 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2210 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2211 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2212 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2213 | } else if (CurNM != OMPD_unknown) { |
| 2214 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2215 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2216 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2217 | FoundNameModifiers[CurNM] = IC; |
| 2218 | if (CurNM == OMPD_unknown) |
| 2219 | continue; |
| 2220 | // Check if the specified name modifier is allowed for the current |
| 2221 | // directive. |
| 2222 | // At most one if clause with the particular directive-name-modifier can |
| 2223 | // appear on the directive. |
| 2224 | bool MatchFound = false; |
| 2225 | for (auto NM : AllowedNameModifiers) { |
| 2226 | if (CurNM == NM) { |
| 2227 | MatchFound = true; |
| 2228 | break; |
| 2229 | } |
| 2230 | } |
| 2231 | if (!MatchFound) { |
| 2232 | S.Diag(IC->getNameModifierLoc(), |
| 2233 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2234 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2235 | ErrorFound = true; |
| 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | // If any if clause on the directive includes a directive-name-modifier then |
| 2240 | // all if clauses on the directive must include a directive-name-modifier. |
| 2241 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2242 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2243 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2244 | diag::err_omp_no_more_if_clause); |
| 2245 | } else { |
| 2246 | std::string Values; |
| 2247 | std::string Sep(", "); |
| 2248 | unsigned AllowedCnt = 0; |
| 2249 | unsigned TotalAllowedNum = |
| 2250 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2251 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2252 | ++Cnt) { |
| 2253 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2254 | if (!FoundNameModifiers[NM]) { |
| 2255 | Values += "'"; |
| 2256 | Values += getOpenMPDirectiveName(NM); |
| 2257 | Values += "'"; |
| 2258 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2259 | Values += " or "; |
| 2260 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2261 | Values += Sep; |
| 2262 | ++AllowedCnt; |
| 2263 | } |
| 2264 | } |
| 2265 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2266 | diag::err_omp_unnamed_if_clause) |
| 2267 | << (TotalAllowedNum > 1) << Values; |
| 2268 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2269 | for (auto Loc : NameModifierLoc) { |
| 2270 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2271 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2272 | ErrorFound = true; |
| 2273 | } |
| 2274 | return ErrorFound; |
| 2275 | } |
| 2276 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2277 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2278 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2279 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2280 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2281 | StmtResult Res = StmtError(); |
Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 2282 | // First check CancelRegion which is then used in checkNestingOfRegions. |
| 2283 | if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) || |
| 2284 | checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2285 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2286 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2287 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2288 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2289 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2290 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2291 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2292 | if (AStmt) { |
| 2293 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2294 | |
| 2295 | // Check default data sharing attributes for referenced variables. |
| 2296 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
Arpith Chacko Jacob | 1f46b70 | 2017-01-23 15:38:49 +0000 | [diff] [blame] | 2297 | int ThisCaptureLevel = getOpenMPCaptureLevels(Kind); |
| 2298 | Stmt *S = AStmt; |
| 2299 | while (--ThisCaptureLevel >= 0) |
| 2300 | S = cast<CapturedStmt>(S)->getCapturedStmt(); |
| 2301 | DSAChecker.Visit(S); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2302 | if (DSAChecker.isErrorFound()) |
| 2303 | return StmtError(); |
| 2304 | // Generate list of implicitly defined firstprivate variables. |
| 2305 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2306 | |
| 2307 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2308 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2309 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2310 | SourceLocation(), SourceLocation())) { |
| 2311 | ClausesWithImplicit.push_back(Implicit); |
| 2312 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2313 | DSAChecker.getImplicitFirstprivate().size(); |
| 2314 | } else |
| 2315 | ErrorFound = true; |
| 2316 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2317 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2318 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2319 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2320 | switch (Kind) { |
| 2321 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2322 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2323 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2324 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2325 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2326 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2327 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2328 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2329 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2330 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2331 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2332 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2333 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2334 | case OMPD_for_simd: |
| 2335 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2336 | EndLoc, VarsWithInheritedDSA); |
| 2337 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2338 | case OMPD_sections: |
| 2339 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2340 | EndLoc); |
| 2341 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2342 | case OMPD_section: |
| 2343 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2344 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2345 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2346 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2347 | case OMPD_single: |
| 2348 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2349 | EndLoc); |
| 2350 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2351 | case OMPD_master: |
| 2352 | assert(ClausesWithImplicit.empty() && |
| 2353 | "No clauses are allowed for 'omp master' directive"); |
| 2354 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2355 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2356 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2357 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2358 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2359 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2360 | case OMPD_parallel_for: |
| 2361 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2362 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2363 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2364 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2365 | case OMPD_parallel_for_simd: |
| 2366 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2367 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2368 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2369 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2370 | case OMPD_parallel_sections: |
| 2371 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2372 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2373 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2374 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2375 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2376 | Res = |
| 2377 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2378 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2379 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2380 | case OMPD_taskyield: |
| 2381 | assert(ClausesWithImplicit.empty() && |
| 2382 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2383 | assert(AStmt == nullptr && |
| 2384 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2385 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2386 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2387 | case OMPD_barrier: |
| 2388 | assert(ClausesWithImplicit.empty() && |
| 2389 | "No clauses are allowed for 'omp barrier' directive"); |
| 2390 | assert(AStmt == nullptr && |
| 2391 | "No associated statement allowed for 'omp barrier' directive"); |
| 2392 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2393 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2394 | case OMPD_taskwait: |
| 2395 | assert(ClausesWithImplicit.empty() && |
| 2396 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2397 | assert(AStmt == nullptr && |
| 2398 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2399 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2400 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2401 | case OMPD_taskgroup: |
| 2402 | assert(ClausesWithImplicit.empty() && |
| 2403 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2404 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2405 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2406 | case OMPD_flush: |
| 2407 | assert(AStmt == nullptr && |
| 2408 | "No associated statement allowed for 'omp flush' directive"); |
| 2409 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2410 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2411 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2412 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2413 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2414 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2415 | case OMPD_atomic: |
| 2416 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2417 | EndLoc); |
| 2418 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2419 | case OMPD_teams: |
| 2420 | Res = |
| 2421 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2422 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2423 | case OMPD_target: |
| 2424 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2425 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2426 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2427 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2428 | case OMPD_target_parallel: |
| 2429 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 2430 | StartLoc, EndLoc); |
| 2431 | AllowedNameModifiers.push_back(OMPD_target); |
| 2432 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2433 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2434 | case OMPD_target_parallel_for: |
| 2435 | Res = ActOnOpenMPTargetParallelForDirective( |
| 2436 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2437 | AllowedNameModifiers.push_back(OMPD_target); |
| 2438 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2439 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2440 | case OMPD_cancellation_point: |
| 2441 | assert(ClausesWithImplicit.empty() && |
| 2442 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2443 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2444 | "cancellation point' directive"); |
| 2445 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2446 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2447 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2448 | assert(AStmt == nullptr && |
| 2449 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2450 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2451 | CancelRegion); |
| 2452 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2453 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2454 | case OMPD_target_data: |
| 2455 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2456 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2457 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2458 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2459 | case OMPD_target_enter_data: |
| 2460 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2461 | EndLoc); |
| 2462 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2463 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2464 | case OMPD_target_exit_data: |
| 2465 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2466 | EndLoc); |
| 2467 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2468 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2469 | case OMPD_taskloop: |
| 2470 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2471 | EndLoc, VarsWithInheritedDSA); |
| 2472 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2473 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2474 | case OMPD_taskloop_simd: |
| 2475 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2476 | EndLoc, VarsWithInheritedDSA); |
| 2477 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2478 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2479 | case OMPD_distribute: |
| 2480 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2481 | EndLoc, VarsWithInheritedDSA); |
| 2482 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 2483 | case OMPD_target_update: |
| 2484 | assert(!AStmt && "Statement is not allowed for target update"); |
| 2485 | Res = |
| 2486 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2487 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 2488 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2489 | case OMPD_distribute_parallel_for: |
| 2490 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 2491 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2492 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2493 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2494 | case OMPD_distribute_parallel_for_simd: |
| 2495 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 2496 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2497 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2498 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2499 | case OMPD_distribute_simd: |
| 2500 | Res = ActOnOpenMPDistributeSimdDirective( |
| 2501 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2502 | break; |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2503 | case OMPD_target_parallel_for_simd: |
| 2504 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 2505 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2506 | AllowedNameModifiers.push_back(OMPD_target); |
| 2507 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2508 | break; |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2509 | case OMPD_target_simd: |
| 2510 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2511 | EndLoc, VarsWithInheritedDSA); |
| 2512 | AllowedNameModifiers.push_back(OMPD_target); |
| 2513 | break; |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2514 | case OMPD_teams_distribute: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2515 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 2516 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2517 | break; |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 2518 | case OMPD_teams_distribute_simd: |
| 2519 | Res = ActOnOpenMPTeamsDistributeSimdDirective( |
| 2520 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2521 | break; |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2522 | case OMPD_teams_distribute_parallel_for_simd: |
| 2523 | Res = ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 2524 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2525 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2526 | break; |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 2527 | case OMPD_teams_distribute_parallel_for: |
| 2528 | Res = ActOnOpenMPTeamsDistributeParallelForDirective( |
| 2529 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2530 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2531 | break; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2532 | case OMPD_target_teams: |
| 2533 | Res = ActOnOpenMPTargetTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2534 | EndLoc); |
| 2535 | AllowedNameModifiers.push_back(OMPD_target); |
| 2536 | break; |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 2537 | case OMPD_target_teams_distribute: |
| 2538 | Res = ActOnOpenMPTargetTeamsDistributeDirective( |
| 2539 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2540 | AllowedNameModifiers.push_back(OMPD_target); |
| 2541 | break; |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 2542 | case OMPD_target_teams_distribute_parallel_for: |
| 2543 | Res = ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 2544 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2545 | AllowedNameModifiers.push_back(OMPD_target); |
| 2546 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2547 | break; |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 2548 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 2549 | Res = ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 2550 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2551 | AllowedNameModifiers.push_back(OMPD_target); |
| 2552 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2553 | break; |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 2554 | case OMPD_target_teams_distribute_simd: |
| 2555 | Res = ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 2556 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2557 | AllowedNameModifiers.push_back(OMPD_target); |
| 2558 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 2559 | case OMPD_declare_target: |
| 2560 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2561 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2562 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2563 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2564 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2565 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2566 | llvm_unreachable("Unknown OpenMP directive"); |
| 2567 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2568 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2569 | for (auto P : VarsWithInheritedDSA) { |
| 2570 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2571 | << P.first << P.second->getSourceRange(); |
| 2572 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2573 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2574 | |
| 2575 | if (!AllowedNameModifiers.empty()) |
| 2576 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2577 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2578 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2579 | if (ErrorFound) |
| 2580 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2581 | return Res; |
| 2582 | } |
| 2583 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2584 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 2585 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2586 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2587 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 2588 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2589 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2590 | assert(Linears.size() == LinModifiers.size()); |
| 2591 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2592 | if (!DG || DG.get().isNull()) |
| 2593 | return DeclGroupPtrTy(); |
| 2594 | |
| 2595 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 2596 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2597 | return DG; |
| 2598 | } |
| 2599 | auto *ADecl = DG.get().getSingleDecl(); |
| 2600 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 2601 | ADecl = FTD->getTemplatedDecl(); |
| 2602 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2603 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 2604 | if (!FD) { |
| 2605 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2606 | return DeclGroupPtrTy(); |
| 2607 | } |
| 2608 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2609 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2610 | // The parameter of the simdlen clause must be a constant positive integer |
| 2611 | // expression. |
| 2612 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2613 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2614 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2615 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2616 | // The special this pointer can be used as if was one of the arguments to the |
| 2617 | // function in any of the linear, aligned, or uniform clauses. |
| 2618 | // The uniform clause declares one or more arguments to have an invariant |
| 2619 | // value for all concurrent invocations of the function in the execution of a |
| 2620 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2621 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 2622 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2623 | for (auto *E : Uniforms) { |
| 2624 | E = E->IgnoreParenImpCasts(); |
| 2625 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2626 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 2627 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2628 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2629 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 2630 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2631 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2632 | } |
| 2633 | if (isa<CXXThisExpr>(E)) { |
| 2634 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2635 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2636 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2637 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2638 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2639 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2640 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2641 | // The aligned clause declares that the object to which each list item points |
| 2642 | // is aligned to the number of bytes expressed in the optional parameter of |
| 2643 | // the aligned clause. |
| 2644 | // The special this pointer can be used as if was one of the arguments to the |
| 2645 | // function in any of the linear, aligned, or uniform clauses. |
| 2646 | // The type of list items appearing in the aligned clause must be array, |
| 2647 | // pointer, reference to array, or reference to pointer. |
| 2648 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 2649 | Expr *AlignedThis = nullptr; |
| 2650 | for (auto *E : Aligneds) { |
| 2651 | E = E->IgnoreParenImpCasts(); |
| 2652 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2653 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2654 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2655 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2656 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2657 | ->getCanonicalDecl() == CanonPVD) { |
| 2658 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2659 | // A list-item cannot appear in more than one aligned clause. |
| 2660 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 2661 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2662 | << 1 << E->getSourceRange(); |
| 2663 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 2664 | diag::note_omp_explicit_dsa) |
| 2665 | << getOpenMPClauseName(OMPC_aligned); |
| 2666 | continue; |
| 2667 | } |
| 2668 | AlignedArgs[CanonPVD] = E; |
| 2669 | QualType QTy = PVD->getType() |
| 2670 | .getNonReferenceType() |
| 2671 | .getUnqualifiedType() |
| 2672 | .getCanonicalType(); |
| 2673 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 2674 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 2675 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 2676 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 2677 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 2678 | } |
| 2679 | continue; |
| 2680 | } |
| 2681 | } |
| 2682 | if (isa<CXXThisExpr>(E)) { |
| 2683 | if (AlignedThis) { |
| 2684 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2685 | << 2 << E->getSourceRange(); |
| 2686 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2687 | << getOpenMPClauseName(OMPC_aligned); |
| 2688 | } |
| 2689 | AlignedThis = E; |
| 2690 | continue; |
| 2691 | } |
| 2692 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2693 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2694 | } |
| 2695 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 2696 | // positive integer expression. If no optional parameter is specified, |
| 2697 | // implementation-defined default alignments for SIMD instructions on the |
| 2698 | // target platforms are assumed. |
| 2699 | SmallVector<Expr *, 4> NewAligns; |
| 2700 | for (auto *E : Alignments) { |
| 2701 | ExprResult Align; |
| 2702 | if (E) |
| 2703 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 2704 | NewAligns.push_back(Align.get()); |
| 2705 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2706 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2707 | // The linear clause declares one or more list items to be private to a SIMD |
| 2708 | // lane and to have a linear relationship with respect to the iteration space |
| 2709 | // of a loop. |
| 2710 | // The special this pointer can be used as if was one of the arguments to the |
| 2711 | // function in any of the linear, aligned, or uniform clauses. |
| 2712 | // When a linear-step expression is specified in a linear clause it must be |
| 2713 | // either a constant integer expression or an integer-typed parameter that is |
| 2714 | // specified in a uniform clause on the directive. |
| 2715 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 2716 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 2717 | auto MI = LinModifiers.begin(); |
| 2718 | for (auto *E : Linears) { |
| 2719 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 2720 | ++MI; |
| 2721 | E = E->IgnoreParenImpCasts(); |
| 2722 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2723 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2724 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2725 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2726 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2727 | ->getCanonicalDecl() == CanonPVD) { |
| 2728 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 2729 | // A list-item cannot appear in more than one linear clause. |
| 2730 | if (LinearArgs.count(CanonPVD) > 0) { |
| 2731 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2732 | << getOpenMPClauseName(OMPC_linear) |
| 2733 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 2734 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 2735 | diag::note_omp_explicit_dsa) |
| 2736 | << getOpenMPClauseName(OMPC_linear); |
| 2737 | continue; |
| 2738 | } |
| 2739 | // Each argument can appear in at most one uniform or linear clause. |
| 2740 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 2741 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2742 | << getOpenMPClauseName(OMPC_linear) |
| 2743 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 2744 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 2745 | diag::note_omp_explicit_dsa) |
| 2746 | << getOpenMPClauseName(OMPC_uniform); |
| 2747 | continue; |
| 2748 | } |
| 2749 | LinearArgs[CanonPVD] = E; |
| 2750 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2751 | E->isInstantiationDependent() || |
| 2752 | E->containsUnexpandedParameterPack()) |
| 2753 | continue; |
| 2754 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 2755 | PVD->getOriginalType()); |
| 2756 | continue; |
| 2757 | } |
| 2758 | } |
| 2759 | if (isa<CXXThisExpr>(E)) { |
| 2760 | if (UniformedLinearThis) { |
| 2761 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2762 | << getOpenMPClauseName(OMPC_linear) |
| 2763 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 2764 | << E->getSourceRange(); |
| 2765 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2766 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 2767 | : OMPC_linear); |
| 2768 | continue; |
| 2769 | } |
| 2770 | UniformedLinearThis = E; |
| 2771 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2772 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 2773 | continue; |
| 2774 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 2775 | E->getType()); |
| 2776 | continue; |
| 2777 | } |
| 2778 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2779 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2780 | } |
| 2781 | Expr *Step = nullptr; |
| 2782 | Expr *NewStep = nullptr; |
| 2783 | SmallVector<Expr *, 4> NewSteps; |
| 2784 | for (auto *E : Steps) { |
| 2785 | // Skip the same step expression, it was checked already. |
| 2786 | if (Step == E || !E) { |
| 2787 | NewSteps.push_back(E ? NewStep : nullptr); |
| 2788 | continue; |
| 2789 | } |
| 2790 | Step = E; |
| 2791 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 2792 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2793 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2794 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 2795 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 2796 | << Step->getSourceRange(); |
| 2797 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 2798 | E->isInstantiationDependent() || |
| 2799 | E->containsUnexpandedParameterPack() || |
| 2800 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 2801 | NewSteps.push_back(Step); |
| 2802 | else { |
| 2803 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 2804 | << Step->getSourceRange(); |
| 2805 | } |
| 2806 | continue; |
| 2807 | } |
| 2808 | NewStep = Step; |
| 2809 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 2810 | !Step->isInstantiationDependent() && |
| 2811 | !Step->containsUnexpandedParameterPack()) { |
| 2812 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 2813 | .get(); |
| 2814 | if (NewStep) |
| 2815 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 2816 | } |
| 2817 | NewSteps.push_back(NewStep); |
| 2818 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2819 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 2820 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2821 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2822 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 2823 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 2824 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 2825 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2826 | ADecl->addAttr(NewAttr); |
| 2827 | return ConvertDeclToDeclGroup(ADecl); |
| 2828 | } |
| 2829 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2830 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2831 | Stmt *AStmt, |
| 2832 | SourceLocation StartLoc, |
| 2833 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2834 | if (!AStmt) |
| 2835 | return StmtError(); |
| 2836 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2837 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2838 | // 1.2.2 OpenMP Language Terminology |
| 2839 | // Structured block - An executable statement with a single entry at the |
| 2840 | // top and a single exit at the bottom. |
| 2841 | // The point of exit cannot be a branch out of the structured block. |
| 2842 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2843 | CS->getCapturedDecl()->setNothrow(); |
| 2844 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2845 | getCurFunction()->setHasBranchProtectedScope(); |
| 2846 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2847 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2848 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2851 | namespace { |
| 2852 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2853 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2854 | /// for IR generation. |
| 2855 | class OpenMPIterationSpaceChecker { |
| 2856 | /// \brief Reference to Sema. |
| 2857 | Sema &SemaRef; |
| 2858 | /// \brief A location for diagnostics (when there is no some better location). |
| 2859 | SourceLocation DefaultLoc; |
| 2860 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2861 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2862 | /// \brief A source location for referring to loop init later. |
| 2863 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2864 | /// \brief A source location for referring to condition later. |
| 2865 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2866 | /// \brief A source location for referring to increment later. |
| 2867 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2868 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2869 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2870 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2871 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2872 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2873 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2874 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2875 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2876 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2877 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2878 | /// \brief This flag is true when condition is one of: |
| 2879 | /// Var < UB |
| 2880 | /// Var <= UB |
| 2881 | /// UB > Var |
| 2882 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2883 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2884 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2885 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2886 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2887 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2888 | |
| 2889 | public: |
| 2890 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2891 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2892 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2893 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2894 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2895 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2896 | /// for less/greater and for strict/non-strict comparison. |
| 2897 | bool CheckCond(Expr *S); |
| 2898 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2899 | /// does not conform, otherwise save loop step (#Step). |
| 2900 | bool CheckInc(Expr *S); |
| 2901 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2902 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2903 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2904 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2905 | /// \brief Source range of the loop init. |
| 2906 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2907 | /// \brief Source range of the loop condition. |
| 2908 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2909 | /// \brief Source range of the loop increment. |
| 2910 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2911 | /// \brief True if the step should be subtracted. |
| 2912 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2913 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2914 | Expr * |
| 2915 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 2916 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2917 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2918 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 2919 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2920 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 2921 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 2922 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2923 | /// \brief Build reference expression to the private counter be used for |
| 2924 | /// codegen. |
| 2925 | Expr *BuildPrivateCounterVar() const; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2926 | /// \brief Build initialization of the counter be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2927 | Expr *BuildCounterInit() const; |
| 2928 | /// \brief Build step of the counter be used for codegen. |
| 2929 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2930 | /// \brief Return true if any expression is dependent. |
| 2931 | bool Dependent() const; |
| 2932 | |
| 2933 | private: |
| 2934 | /// \brief Check the right-hand side of an assignment in the increment |
| 2935 | /// expression. |
| 2936 | bool CheckIncRHS(Expr *RHS); |
| 2937 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2938 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2939 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2940 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2941 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2942 | /// \brief Helper to set loop increment. |
| 2943 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2944 | }; |
| 2945 | |
| 2946 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2947 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2948 | assert(!LB && !UB && !Step); |
| 2949 | return false; |
| 2950 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2951 | return LCDecl->getType()->isDependentType() || |
| 2952 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 2953 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2956 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2957 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2958 | E = ExprTemp->getSubExpr(); |
| 2959 | |
| 2960 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2961 | E = MTE->GetTemporaryExpr(); |
| 2962 | |
| 2963 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2964 | E = Binder->getSubExpr(); |
| 2965 | |
| 2966 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2967 | E = ICE->getSubExprAsWritten(); |
| 2968 | return E->IgnoreParens(); |
| 2969 | } |
| 2970 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2971 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 2972 | Expr *NewLCRefExpr, |
| 2973 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2974 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2975 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2976 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2977 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2978 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2979 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 2980 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2981 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2982 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2983 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2984 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2985 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2986 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2987 | LB = NewLB; |
| 2988 | return false; |
| 2989 | } |
| 2990 | |
| 2991 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2992 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2993 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2994 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 2995 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2996 | if (!NewUB) |
| 2997 | return true; |
| 2998 | UB = NewUB; |
| 2999 | TestIsLessOp = LessOp; |
| 3000 | TestIsStrictOp = StrictOp; |
| 3001 | ConditionSrcRange = SR; |
| 3002 | ConditionLoc = SL; |
| 3003 | return false; |
| 3004 | } |
| 3005 | |
| 3006 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3007 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3008 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3009 | if (!NewStep) |
| 3010 | return true; |
| 3011 | if (!NewStep->isValueDependent()) { |
| 3012 | // Check that the step is integer expression. |
| 3013 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3014 | ExprResult Val = |
| 3015 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3016 | if (Val.isInvalid()) |
| 3017 | return true; |
| 3018 | NewStep = Val.get(); |
| 3019 | |
| 3020 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3021 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3022 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3023 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3024 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3025 | // the loop. |
| 3026 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3027 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3028 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3029 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3030 | // the loop. |
| 3031 | llvm::APSInt Result; |
| 3032 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3033 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3034 | bool IsConstNeg = |
| 3035 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3036 | bool IsConstPos = |
| 3037 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3038 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3039 | if (UB && (IsConstZero || |
| 3040 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3041 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3042 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3043 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3044 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3045 | SemaRef.Diag(ConditionLoc, |
| 3046 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3047 | << TestIsLessOp << ConditionSrcRange; |
| 3048 | return true; |
| 3049 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3050 | if (TestIsLessOp == Subtract) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3051 | NewStep = |
| 3052 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 3053 | .get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3054 | Subtract = !Subtract; |
| 3055 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | Step = NewStep; |
| 3059 | SubtractStep = Subtract; |
| 3060 | return false; |
| 3061 | } |
| 3062 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3063 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3064 | // Check init-expr for canonical loop form and save loop counter |
| 3065 | // variable - #Var and its initialization value - #LB. |
| 3066 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3067 | // var = lb |
| 3068 | // integer-type var = lb |
| 3069 | // random-access-iterator-type var = lb |
| 3070 | // pointer-type var = lb |
| 3071 | // |
| 3072 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3073 | if (EmitDiags) { |
| 3074 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3075 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3076 | return true; |
| 3077 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3078 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3079 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3080 | S = ExprTemp->getSubExpr(); |
| 3081 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3082 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3083 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3084 | S = E->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3085 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3086 | if (BO->getOpcode() == BO_Assign) { |
| 3087 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 3088 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3089 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3090 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3091 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3092 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 3093 | } |
| 3094 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3095 | if (ME->isArrow() && |
| 3096 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3097 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3098 | } |
| 3099 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3100 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3101 | if (DS->isSingleDecl()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3102 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3103 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3104 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3105 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3106 | SemaRef.Diag(S->getLocStart(), |
| 3107 | diag::ext_omp_loop_not_canonical_init) |
| 3108 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3109 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3110 | } |
| 3111 | } |
| 3112 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3113 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3114 | if (CE->getOperator() == OO_Equal) { |
| 3115 | auto *LHS = CE->getArg(0); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3116 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3117 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3118 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3119 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3120 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 3121 | } |
| 3122 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3123 | if (ME->isArrow() && |
| 3124 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3125 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3126 | } |
| 3127 | } |
| 3128 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3129 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3130 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3131 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3132 | if (EmitDiags) { |
| 3133 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3134 | << S->getSourceRange(); |
| 3135 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3136 | return true; |
| 3137 | } |
| 3138 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3139 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3140 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3141 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3142 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3143 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3144 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3145 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3146 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3147 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3148 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3149 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3150 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3151 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 3152 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 3153 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 3154 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3155 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3156 | return getCanonicalDecl(VD); |
| 3157 | } |
| 3158 | } |
| 3159 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 3160 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3161 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3162 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3166 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3167 | // less/greater and for strict/non-strict comparison. |
| 3168 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3169 | // var relational-op b |
| 3170 | // b relational-op var |
| 3171 | // |
| 3172 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3173 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3174 | return true; |
| 3175 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3176 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3177 | SourceLocation CondLoc = S->getLocStart(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3178 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3179 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3180 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3181 | return SetUB(BO->getRHS(), |
| 3182 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3183 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3184 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3185 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3186 | return SetUB(BO->getLHS(), |
| 3187 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3188 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3189 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3190 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3191 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3192 | if (CE->getNumArgs() == 2) { |
| 3193 | auto Op = CE->getOperator(); |
| 3194 | switch (Op) { |
| 3195 | case OO_Greater: |
| 3196 | case OO_GreaterEqual: |
| 3197 | case OO_Less: |
| 3198 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3199 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3200 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3201 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3202 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3203 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3204 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3205 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3206 | CE->getOperatorLoc()); |
| 3207 | break; |
| 3208 | default: |
| 3209 | break; |
| 3210 | } |
| 3211 | } |
| 3212 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3213 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3214 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3215 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3216 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3217 | return true; |
| 3218 | } |
| 3219 | |
| 3220 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3221 | // RHS of canonical loop form increment can be: |
| 3222 | // var + incr |
| 3223 | // incr + var |
| 3224 | // var - incr |
| 3225 | // |
| 3226 | RHS = RHS->IgnoreParenImpCasts(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3227 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3228 | if (BO->isAdditiveOp()) { |
| 3229 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3230 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3231 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3232 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3233 | return SetStep(BO->getLHS(), false); |
| 3234 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3235 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3236 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3237 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3238 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3239 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3240 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3241 | return SetStep(CE->getArg(0), false); |
| 3242 | } |
| 3243 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3244 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3245 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3246 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3247 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3248 | return true; |
| 3249 | } |
| 3250 | |
| 3251 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3252 | // Check incr-expr for canonical loop form and return true if it |
| 3253 | // does not conform. |
| 3254 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3255 | // ++var |
| 3256 | // var++ |
| 3257 | // --var |
| 3258 | // var-- |
| 3259 | // var += incr |
| 3260 | // var -= incr |
| 3261 | // var = var + incr |
| 3262 | // var = incr + var |
| 3263 | // var = var - incr |
| 3264 | // |
| 3265 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3266 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3267 | return true; |
| 3268 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3269 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3270 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3271 | S = ExprTemp->getSubExpr(); |
| 3272 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3273 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3274 | S = S->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3275 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3276 | if (UO->isIncrementDecrementOp() && |
| 3277 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3278 | return SetStep(SemaRef |
| 3279 | .ActOnIntegerConstant(UO->getLocStart(), |
| 3280 | (UO->isDecrementOp() ? -1 : 1)) |
| 3281 | .get(), |
| 3282 | false); |
| 3283 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3284 | switch (BO->getOpcode()) { |
| 3285 | case BO_AddAssign: |
| 3286 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3287 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3288 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3289 | break; |
| 3290 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3291 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3292 | return CheckIncRHS(BO->getRHS()); |
| 3293 | break; |
| 3294 | default: |
| 3295 | break; |
| 3296 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3297 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3298 | switch (CE->getOperator()) { |
| 3299 | case OO_PlusPlus: |
| 3300 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3301 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3302 | return SetStep(SemaRef |
| 3303 | .ActOnIntegerConstant( |
| 3304 | CE->getLocStart(), |
| 3305 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 3306 | .get(), |
| 3307 | false); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3308 | break; |
| 3309 | case OO_PlusEqual: |
| 3310 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3311 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3312 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3313 | break; |
| 3314 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3315 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3316 | return CheckIncRHS(CE->getArg(1)); |
| 3317 | break; |
| 3318 | default: |
| 3319 | break; |
| 3320 | } |
| 3321 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3322 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3323 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3324 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3325 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3326 | return true; |
| 3327 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3328 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3329 | static ExprResult |
| 3330 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 3331 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 3332 | if (SemaRef.CurContext->isDependentContext()) |
| 3333 | return ExprResult(Capture); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3334 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 3335 | return SemaRef.PerformImplicitConversion( |
| 3336 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 3337 | /*AllowExplicit=*/true); |
| 3338 | auto I = Captures.find(Capture); |
| 3339 | if (I != Captures.end()) |
| 3340 | return buildCapture(SemaRef, Capture, I->second); |
| 3341 | DeclRefExpr *Ref = nullptr; |
| 3342 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 3343 | Captures[Capture] = Ref; |
| 3344 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3345 | } |
| 3346 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3347 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3348 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 3349 | Scope *S, const bool LimitedType, |
| 3350 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3351 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3352 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3353 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3354 | SemaRef.getLangOpts().CPlusPlus) { |
| 3355 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3356 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3357 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3358 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 3359 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3360 | if (!Upper || !Lower) |
| 3361 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3362 | |
| 3363 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3364 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3365 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3366 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3367 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3368 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3369 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3370 | return nullptr; |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | if (!Diff.isUsable()) |
| 3375 | return nullptr; |
| 3376 | |
| 3377 | // Upper - Lower [- 1] |
| 3378 | if (TestIsStrictOp) |
| 3379 | Diff = SemaRef.BuildBinOp( |
| 3380 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3381 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3382 | if (!Diff.isUsable()) |
| 3383 | return nullptr; |
| 3384 | |
| 3385 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3386 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 3387 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3388 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3389 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3390 | if (!Diff.isUsable()) |
| 3391 | return nullptr; |
| 3392 | |
| 3393 | // Parentheses (for dumping/debugging purposes only). |
| 3394 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3395 | if (!Diff.isUsable()) |
| 3396 | return nullptr; |
| 3397 | |
| 3398 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3399 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3400 | if (!Diff.isUsable()) |
| 3401 | return nullptr; |
| 3402 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3403 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3404 | QualType Type = Diff.get()->getType(); |
| 3405 | auto &C = SemaRef.Context; |
| 3406 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3407 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3408 | if (!Type->isIntegerType() || UseVarType) { |
| 3409 | unsigned NewSize = |
| 3410 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3411 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3412 | : Type->hasSignedIntegerRepresentation(); |
| 3413 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3414 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3415 | Diff = SemaRef.PerformImplicitConversion( |
| 3416 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3417 | if (!Diff.isUsable()) |
| 3418 | return nullptr; |
| 3419 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3420 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3421 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3422 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3423 | if (NewSize != C.getTypeSize(Type)) { |
| 3424 | if (NewSize < C.getTypeSize(Type)) { |
| 3425 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3426 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3427 | << InitSrcRange << ConditionSrcRange; |
| 3428 | } |
| 3429 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3430 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3431 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3432 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3433 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3434 | Sema::AA_Converting, true); |
| 3435 | if (!Diff.isUsable()) |
| 3436 | return nullptr; |
| 3437 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3438 | } |
| 3439 | } |
| 3440 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3441 | return Diff.get(); |
| 3442 | } |
| 3443 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3444 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 3445 | Scope *S, Expr *Cond, |
| 3446 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3447 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3448 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3449 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3450 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3451 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 3452 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 3453 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 3454 | return nullptr; |
| 3455 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3456 | auto CondExpr = SemaRef.BuildBinOp( |
| 3457 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3458 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3459 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3460 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3461 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 3462 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3463 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3464 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3465 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3466 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3467 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3468 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3469 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3470 | } |
| 3471 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3472 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3473 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3474 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3475 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 3476 | if (!VD) { |
| 3477 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 3478 | auto *Ref = buildDeclRefExpr( |
| 3479 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3480 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 3481 | // If the loop control decl is explicitly marked as private, do not mark it |
| 3482 | // as captured again. |
| 3483 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 3484 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3485 | return Ref; |
| 3486 | } |
| 3487 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3488 | DefaultLoc); |
| 3489 | } |
| 3490 | |
| 3491 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3492 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 3493 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3494 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3495 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 3496 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3497 | if (PrivateVar->isInvalidDecl()) |
| 3498 | return nullptr; |
| 3499 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3500 | } |
| 3501 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3502 | } |
| 3503 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 3504 | /// \brief Build initialization of the counter to be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3505 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3506 | |
| 3507 | /// \brief Build step of the counter be used for codegen. |
| 3508 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3509 | |
| 3510 | /// \brief Iteration space of a single for loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3511 | struct LoopIterationSpace final { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3512 | /// \brief Condition of the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3513 | Expr *PreCond = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3514 | /// \brief This expression calculates the number of iterations in the loop. |
| 3515 | /// It is always possible to calculate it before starting the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3516 | Expr *NumIterations = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3517 | /// \brief The loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3518 | Expr *CounterVar = nullptr; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3519 | /// \brief Private loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3520 | Expr *PrivateCounterVar = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3521 | /// \brief This is initializer for the initial value of #CounterVar. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3522 | Expr *CounterInit = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3523 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3524 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3525 | Expr *CounterStep = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3526 | /// \brief Should step be subtracted? |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3527 | bool Subtract = false; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3528 | /// \brief Source range of the loop init. |
| 3529 | SourceRange InitSrcRange; |
| 3530 | /// \brief Source range of the loop condition. |
| 3531 | SourceRange CondSrcRange; |
| 3532 | /// \brief Source range of the loop increment. |
| 3533 | SourceRange IncSrcRange; |
| 3534 | }; |
| 3535 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3536 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3537 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3538 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3539 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3540 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3541 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3542 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3543 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3544 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3545 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3546 | if (auto *D = ISC.GetLoopDecl()) { |
| 3547 | auto *VD = dyn_cast<VarDecl>(D); |
| 3548 | if (!VD) { |
| 3549 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 3550 | VD = Private; |
| 3551 | else { |
| 3552 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 3553 | /*WithInit=*/false); |
| 3554 | VD = cast<VarDecl>(Ref->getDecl()); |
| 3555 | } |
| 3556 | } |
| 3557 | DSAStack->addLoopControlVariable(D, VD); |
| 3558 | } |
| 3559 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3560 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3564 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3565 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3566 | static bool CheckOpenMPIterationSpace( |
| 3567 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3568 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3569 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3570 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3571 | LoopIterationSpace &ResultIterSpace, |
| 3572 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3573 | // OpenMP [2.6, Canonical Loop Form] |
| 3574 | // for (init-expr; test-expr; incr-expr) structured-block |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3575 | auto *For = dyn_cast_or_null<ForStmt>(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3576 | if (!For) { |
| 3577 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3578 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3579 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3580 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3581 | if (NestedLoopCount > 1) { |
| 3582 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3583 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3584 | diag::note_omp_collapse_ordered_expr) |
| 3585 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3586 | << OrderedLoopCountExpr->getSourceRange(); |
| 3587 | else if (CollapseLoopCountExpr) |
| 3588 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3589 | diag::note_omp_collapse_ordered_expr) |
| 3590 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3591 | else |
| 3592 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3593 | diag::note_omp_collapse_ordered_expr) |
| 3594 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3595 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3596 | return true; |
| 3597 | } |
| 3598 | assert(For->getBody()); |
| 3599 | |
| 3600 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3601 | |
| 3602 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3603 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3604 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3605 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3606 | |
| 3607 | bool HasErrors = false; |
| 3608 | |
| 3609 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3610 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 3611 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3612 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3613 | // OpenMP [2.6, Canonical Loop Form] |
| 3614 | // Var is one of the following: |
| 3615 | // A variable of signed or unsigned integer type. |
| 3616 | // For C++, a variable of a random access iterator type. |
| 3617 | // For C, a variable of a pointer type. |
| 3618 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 3619 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3620 | !VarType->isPointerType() && |
| 3621 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3622 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3623 | << SemaRef.getLangOpts().CPlusPlus; |
| 3624 | HasErrors = true; |
| 3625 | } |
| 3626 | |
| 3627 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 3628 | // a Construct |
| 3629 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3630 | // parallel for construct is (are) private. |
| 3631 | // The loop iteration variable in the associated for-loop of a simd |
| 3632 | // construct with just one associated for-loop is linear with a |
| 3633 | // constant-linear-step that is the increment of the associated for-loop. |
| 3634 | // Exclude loop var from the list of variables with implicitly defined data |
| 3635 | // sharing attributes. |
| 3636 | VarsWithImplicitDSA.erase(LCDecl); |
| 3637 | |
| 3638 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 3639 | // in a Construct, C/C++]. |
| 3640 | // The loop iteration variable in the associated for-loop of a simd |
| 3641 | // construct with just one associated for-loop may be listed in a linear |
| 3642 | // clause with a constant-linear-step that is the increment of the |
| 3643 | // associated for-loop. |
| 3644 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3645 | // parallel for construct may be listed in a private or lastprivate clause. |
| 3646 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 3647 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3648 | // declared in the loop and it is predetermined as a private. |
| 3649 | auto PredeterminedCKind = |
| 3650 | isOpenMPSimdDirective(DKind) |
| 3651 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3652 | : OMPC_private; |
| 3653 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3654 | DVar.CKind != PredeterminedCKind) || |
| 3655 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 3656 | isOpenMPDistributeDirective(DKind)) && |
| 3657 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3658 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3659 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 3660 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 3661 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3662 | << getOpenMPClauseName(PredeterminedCKind); |
| 3663 | if (DVar.RefExpr == nullptr) |
| 3664 | DVar.CKind = PredeterminedCKind; |
| 3665 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 3666 | HasErrors = true; |
| 3667 | } else if (LoopDeclRefExpr != nullptr) { |
| 3668 | // Make the loop iteration variable private (for worksharing constructs), |
| 3669 | // linear (for simd directives with the only one associated loop) or |
| 3670 | // lastprivate (for simd directives with several collapsed or ordered |
| 3671 | // loops). |
| 3672 | if (DVar.CKind == OMPC_unknown) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3673 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 3674 | [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3675 | /*FromParent=*/false); |
| 3676 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 3677 | } |
| 3678 | |
| 3679 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 3680 | |
| 3681 | // Check test-expr. |
| 3682 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3683 | |
| 3684 | // Check incr-expr. |
| 3685 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3686 | } |
| 3687 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3688 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3689 | return HasErrors; |
| 3690 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3691 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3692 | ResultIterSpace.PreCond = |
| 3693 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3694 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3695 | DSA.getCurScope(), |
| 3696 | (isOpenMPWorksharingDirective(DKind) || |
| 3697 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 3698 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3699 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3700 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3701 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3702 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3703 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3704 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3705 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3706 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3707 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3708 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3709 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3710 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3711 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3712 | ResultIterSpace.CounterInit == nullptr || |
| 3713 | ResultIterSpace.CounterStep == nullptr); |
| 3714 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3715 | return HasErrors; |
| 3716 | } |
| 3717 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3718 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3719 | static ExprResult |
| 3720 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 3721 | ExprResult Start, |
| 3722 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3723 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3724 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 3725 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3726 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3727 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3728 | VarRef.get()->getType())) { |
| 3729 | NewStart = SemaRef.PerformImplicitConversion( |
| 3730 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3731 | /*AllowExplicit=*/true); |
| 3732 | if (!NewStart.isUsable()) |
| 3733 | return ExprError(); |
| 3734 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3735 | |
| 3736 | auto Init = |
| 3737 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3738 | return Init; |
| 3739 | } |
| 3740 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3741 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3742 | static ExprResult |
| 3743 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3744 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 3745 | ExprResult Step, bool Subtract, |
| 3746 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3747 | // Add parentheses (for debugging purposes only). |
| 3748 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3749 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3750 | !Step.isUsable()) |
| 3751 | return ExprError(); |
| 3752 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3753 | ExprResult NewStep = Step; |
| 3754 | if (Captures) |
| 3755 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3756 | if (NewStep.isInvalid()) |
| 3757 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3758 | ExprResult Update = |
| 3759 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3760 | if (!Update.isUsable()) |
| 3761 | return ExprError(); |
| 3762 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3763 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 3764 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3765 | ExprResult NewStart = Start; |
| 3766 | if (Captures) |
| 3767 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3768 | if (NewStart.isInvalid()) |
| 3769 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3770 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3771 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 3772 | ExprResult SavedUpdate = Update; |
| 3773 | ExprResult UpdateVal; |
| 3774 | if (VarRef.get()->getType()->isOverloadableType() || |
| 3775 | NewStart.get()->getType()->isOverloadableType() || |
| 3776 | Update.get()->getType()->isOverloadableType()) { |
| 3777 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3778 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 3779 | Update = |
| 3780 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3781 | if (Update.isUsable()) { |
| 3782 | UpdateVal = |
| 3783 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 3784 | VarRef.get(), SavedUpdate.get()); |
| 3785 | if (UpdateVal.isUsable()) { |
| 3786 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 3787 | UpdateVal.get()); |
| 3788 | } |
| 3789 | } |
| 3790 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3791 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3792 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3793 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 3794 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 3795 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 3796 | NewStart.get(), SavedUpdate.get()); |
| 3797 | if (!Update.isUsable()) |
| 3798 | return ExprError(); |
| 3799 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3800 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 3801 | VarRef.get()->getType())) { |
| 3802 | Update = SemaRef.PerformImplicitConversion( |
| 3803 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3804 | if (!Update.isUsable()) |
| 3805 | return ExprError(); |
| 3806 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3807 | |
| 3808 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3809 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3810 | return Update; |
| 3811 | } |
| 3812 | |
| 3813 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3814 | /// bits. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3815 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3816 | if (E == nullptr) |
| 3817 | return ExprError(); |
| 3818 | auto &C = SemaRef.Context; |
| 3819 | QualType OldType = E->getType(); |
| 3820 | unsigned HasBits = C.getTypeSize(OldType); |
| 3821 | if (HasBits >= Bits) |
| 3822 | return ExprResult(E); |
| 3823 | // OK to convert to signed, because new type has more bits than old. |
| 3824 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3825 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3826 | true); |
| 3827 | } |
| 3828 | |
| 3829 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3830 | /// into \a Bits bits. |
| 3831 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3832 | if (E == nullptr) |
| 3833 | return false; |
| 3834 | llvm::APSInt Result; |
| 3835 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3836 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3837 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3838 | } |
| 3839 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3840 | /// Build preinits statement for the given declarations. |
| 3841 | static Stmt *buildPreInits(ASTContext &Context, |
| 3842 | SmallVectorImpl<Decl *> &PreInits) { |
| 3843 | if (!PreInits.empty()) { |
| 3844 | return new (Context) DeclStmt( |
| 3845 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 3846 | SourceLocation(), SourceLocation()); |
| 3847 | } |
| 3848 | return nullptr; |
| 3849 | } |
| 3850 | |
| 3851 | /// Build preinits statement for the given declarations. |
| 3852 | static Stmt *buildPreInits(ASTContext &Context, |
| 3853 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 3854 | if (!Captures.empty()) { |
| 3855 | SmallVector<Decl *, 16> PreInits; |
| 3856 | for (auto &Pair : Captures) |
| 3857 | PreInits.push_back(Pair.second->getDecl()); |
| 3858 | return buildPreInits(Context, PreInits); |
| 3859 | } |
| 3860 | return nullptr; |
| 3861 | } |
| 3862 | |
| 3863 | /// Build postupdate expression for the given list of postupdates expressions. |
| 3864 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 3865 | Expr *PostUpdate = nullptr; |
| 3866 | if (!PostUpdates.empty()) { |
| 3867 | for (auto *E : PostUpdates) { |
| 3868 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 3869 | E->getExprLoc(), |
| 3870 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 3871 | E->getExprLoc(), E) |
| 3872 | .get(); |
| 3873 | PostUpdate = PostUpdate |
| 3874 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 3875 | PostUpdate, ConvE) |
| 3876 | .get() |
| 3877 | : ConvE; |
| 3878 | } |
| 3879 | } |
| 3880 | return PostUpdate; |
| 3881 | } |
| 3882 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3883 | /// \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] | 3884 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3885 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3886 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3887 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3888 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3889 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3890 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3891 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3892 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3893 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3894 | // Found 'collapse' clause - calculate collapse number. |
| 3895 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3896 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3897 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3898 | } |
| 3899 | if (OrderedLoopCountExpr) { |
| 3900 | // Found 'ordered' clause - calculate collapse number. |
| 3901 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3902 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3903 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3904 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3905 | diag::err_omp_wrong_ordered_loop_count) |
| 3906 | << OrderedLoopCountExpr->getSourceRange(); |
| 3907 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3908 | diag::note_collapse_loop_count) |
| 3909 | << CollapseLoopCountExpr->getSourceRange(); |
| 3910 | } |
| 3911 | NestedLoopCount = Result.getLimitedValue(); |
| 3912 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3913 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3914 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3915 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3916 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3917 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3918 | IterSpaces.resize(NestedLoopCount); |
| 3919 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3920 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3921 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3922 | NestedLoopCount, CollapseLoopCountExpr, |
| 3923 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3924 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3925 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3926 | // 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] | 3927 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3928 | // All loops associated with the construct must be perfectly nested; that |
| 3929 | // is, there must be no intervening code nor any OpenMP directive between |
| 3930 | // any two loops. |
| 3931 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3932 | } |
| 3933 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3934 | Built.clear(/* size */ NestedLoopCount); |
| 3935 | |
| 3936 | if (SemaRef.CurContext->isDependentContext()) |
| 3937 | return NestedLoopCount; |
| 3938 | |
| 3939 | // An example of what is generated for the following code: |
| 3940 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3941 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3942 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3943 | // for (k = 0; k < NK; ++k) |
| 3944 | // for (j = J0; j < NJ; j+=2) { |
| 3945 | // <loop body> |
| 3946 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3947 | // |
| 3948 | // We generate the code below. |
| 3949 | // Note: the loop body may be outlined in CodeGen. |
| 3950 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3951 | // iterations and operator+= to calculate counter value. |
| 3952 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3953 | // or i64 is currently supported). |
| 3954 | // |
| 3955 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3956 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3957 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3958 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3959 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3960 | // <loop body (using local i and j)> |
| 3961 | // } |
| 3962 | // i = NI; // assign final values of counters |
| 3963 | // j = NJ; |
| 3964 | // |
| 3965 | |
| 3966 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3967 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3968 | // Precondition tests if there is at least one iteration (all conditions are |
| 3969 | // true). |
| 3970 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3971 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3972 | ExprResult LastIteration32 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3973 | 32 /* Bits */, SemaRef |
| 3974 | .PerformImplicitConversion( |
| 3975 | N0->IgnoreImpCasts(), N0->getType(), |
| 3976 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3977 | .get(), |
| 3978 | SemaRef); |
| 3979 | ExprResult LastIteration64 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3980 | 64 /* Bits */, SemaRef |
| 3981 | .PerformImplicitConversion( |
| 3982 | N0->IgnoreImpCasts(), N0->getType(), |
| 3983 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3984 | .get(), |
| 3985 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3986 | |
| 3987 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3988 | return NestedLoopCount; |
| 3989 | |
| 3990 | auto &C = SemaRef.Context; |
| 3991 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3992 | |
| 3993 | Scope *CurScope = DSA.getCurScope(); |
| 3994 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3995 | if (PreCond.isUsable()) { |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3996 | PreCond = |
| 3997 | SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, |
| 3998 | PreCond.get(), IterSpaces[Cnt].PreCond); |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3999 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4000 | auto N = IterSpaces[Cnt].NumIterations; |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4001 | SourceLocation Loc = N->getExprLoc(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4002 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 4003 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4004 | LastIteration32 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4005 | CurScope, Loc, BO_Mul, LastIteration32.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4006 | SemaRef |
| 4007 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4008 | Sema::AA_Converting, |
| 4009 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4010 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4011 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4012 | LastIteration64 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4013 | CurScope, Loc, BO_Mul, LastIteration64.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4014 | SemaRef |
| 4015 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4016 | Sema::AA_Converting, |
| 4017 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4018 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4019 | } |
| 4020 | |
| 4021 | // Choose either the 32-bit or 64-bit version. |
| 4022 | ExprResult LastIteration = LastIteration64; |
| 4023 | if (LastIteration32.isUsable() && |
| 4024 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4025 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4026 | FitsInto( |
| 4027 | 32 /* Bits */, |
| 4028 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4029 | LastIteration64.get(), SemaRef))) |
| 4030 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4031 | QualType VType = LastIteration.get()->getType(); |
| 4032 | QualType RealVType = VType; |
| 4033 | QualType StrideVType = VType; |
| 4034 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 4035 | VType = |
| 4036 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 4037 | StrideVType = |
| 4038 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 4039 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4040 | |
| 4041 | if (!LastIteration.isUsable()) |
| 4042 | return 0; |
| 4043 | |
| 4044 | // Save the number of iterations. |
| 4045 | ExprResult NumIterations = LastIteration; |
| 4046 | { |
| 4047 | LastIteration = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4048 | CurScope, LastIteration.get()->getExprLoc(), BO_Sub, |
| 4049 | LastIteration.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4050 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4051 | if (!LastIteration.isUsable()) |
| 4052 | return 0; |
| 4053 | } |
| 4054 | |
| 4055 | // Calculate the last iteration number beforehand instead of doing this on |
| 4056 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4057 | llvm::APSInt Result; |
| 4058 | bool IsConstant = |
| 4059 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4060 | ExprResult CalcLastIteration; |
| 4061 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4062 | ExprResult SaveRef = |
| 4063 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4064 | LastIteration = SaveRef; |
| 4065 | |
| 4066 | // Prepare SaveRef + 1. |
| 4067 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4068 | CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4069 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4070 | if (!NumIterations.isUsable()) |
| 4071 | return 0; |
| 4072 | } |
| 4073 | |
| 4074 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4075 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4076 | // Build variables passed into runtime, necessary for worksharing directives. |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4077 | ExprResult LB, UB, IL, ST, EUB, CombLB, CombUB, PrevLB, PrevUB, CombEUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4078 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4079 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4080 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4081 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4082 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4083 | SemaRef.AddInitializerToDecl(LBDecl, |
| 4084 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4085 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4086 | |
| 4087 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4088 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4089 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4090 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4091 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4092 | |
| 4093 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4094 | // This will be used to implement clause 'lastprivate'. |
| 4095 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4096 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4097 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4098 | SemaRef.AddInitializerToDecl(ILDecl, |
| 4099 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4100 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4101 | |
| 4102 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4103 | VarDecl *STDecl = |
| 4104 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 4105 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4106 | SemaRef.AddInitializerToDecl(STDecl, |
| 4107 | SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4108 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4109 | |
| 4110 | // Build expression: UB = min(UB, LastIteration) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4111 | // It is necessary for CodeGen of directives with static scheduling. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4112 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4113 | UB.get(), LastIteration.get()); |
| 4114 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4115 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4116 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4117 | CondOp.get()); |
| 4118 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4119 | |
| 4120 | // If we have a combined directive that combines 'distribute', 'for' or |
| 4121 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 4122 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 4123 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 4124 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4125 | |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4126 | // Lower bound variable, initialized with zero. |
| 4127 | VarDecl *CombLBDecl = |
| 4128 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.lb"); |
| 4129 | CombLB = buildDeclRefExpr(SemaRef, CombLBDecl, VType, InitLoc); |
| 4130 | SemaRef.AddInitializerToDecl( |
| 4131 | CombLBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4132 | /*DirectInit*/ false); |
| 4133 | |
| 4134 | // Upper bound variable, initialized with last iteration number. |
| 4135 | VarDecl *CombUBDecl = |
| 4136 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.ub"); |
| 4137 | CombUB = buildDeclRefExpr(SemaRef, CombUBDecl, VType, InitLoc); |
| 4138 | SemaRef.AddInitializerToDecl(CombUBDecl, LastIteration.get(), |
| 4139 | /*DirectInit*/ false); |
| 4140 | |
| 4141 | ExprResult CombIsUBGreater = SemaRef.BuildBinOp( |
| 4142 | CurScope, InitLoc, BO_GT, CombUB.get(), LastIteration.get()); |
| 4143 | ExprResult CombCondOp = |
| 4144 | SemaRef.ActOnConditionalOp(InitLoc, InitLoc, CombIsUBGreater.get(), |
| 4145 | LastIteration.get(), CombUB.get()); |
| 4146 | CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(), |
| 4147 | CombCondOp.get()); |
| 4148 | CombEUB = SemaRef.ActOnFinishFullExpr(CombEUB.get()); |
| 4149 | |
| 4150 | auto *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4151 | // We expect to have at least 2 more parameters than the 'parallel' |
| 4152 | // directive does - the lower and upper bounds of the previous schedule. |
| 4153 | assert(CD->getNumParams() >= 4 && |
| 4154 | "Unexpected number of parameters in loop combined directive"); |
| 4155 | |
| 4156 | // Set the proper type for the bounds given what we learned from the |
| 4157 | // enclosed loops. |
| 4158 | auto *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 4159 | auto *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| 4160 | |
| 4161 | // Previous lower and upper bounds are obtained from the region |
| 4162 | // parameters. |
| 4163 | PrevLB = |
| 4164 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 4165 | PrevUB = |
| 4166 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 4167 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4168 | } |
| 4169 | |
| 4170 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4171 | ExprResult IV; |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4172 | ExprResult Init, CombInit; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4173 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4174 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 4175 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4176 | Expr *RHS = |
| 4177 | (isOpenMPWorksharingDirective(DKind) || |
| 4178 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 4179 | ? LB.get() |
| 4180 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4181 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4182 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4183 | |
| 4184 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4185 | Expr *CombRHS = |
| 4186 | (isOpenMPWorksharingDirective(DKind) || |
| 4187 | isOpenMPTaskLoopDirective(DKind) || |
| 4188 | isOpenMPDistributeDirective(DKind)) |
| 4189 | ? CombLB.get() |
| 4190 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4191 | CombInit = |
| 4192 | SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), CombRHS); |
| 4193 | CombInit = SemaRef.ActOnFinishFullExpr(CombInit.get()); |
| 4194 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4195 | } |
| 4196 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4197 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4198 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4199 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4200 | (isOpenMPWorksharingDirective(DKind) || |
| 4201 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4202 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4203 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4204 | NumIterations.get()); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4205 | ExprResult CombCond; |
| 4206 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4207 | CombCond = |
| 4208 | SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), CombUB.get()); |
| 4209 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4210 | // Loop increment (IV = IV + 1) |
| 4211 | SourceLocation IncLoc; |
| 4212 | ExprResult Inc = |
| 4213 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4214 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4215 | if (!Inc.isUsable()) |
| 4216 | return 0; |
| 4217 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4218 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4219 | if (!Inc.isUsable()) |
| 4220 | return 0; |
| 4221 | |
| 4222 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4223 | // Used for directives with static scheduling. |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4224 | // In combined construct, add combined version that use CombLB and CombUB |
| 4225 | // base variables for the update |
| 4226 | ExprResult NextLB, NextUB, CombNextLB, CombNextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4227 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4228 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4229 | // LB + ST |
| 4230 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4231 | if (!NextLB.isUsable()) |
| 4232 | return 0; |
| 4233 | // LB = LB + ST |
| 4234 | NextLB = |
| 4235 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4236 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4237 | if (!NextLB.isUsable()) |
| 4238 | return 0; |
| 4239 | // UB + ST |
| 4240 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4241 | if (!NextUB.isUsable()) |
| 4242 | return 0; |
| 4243 | // UB = UB + ST |
| 4244 | NextUB = |
| 4245 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4246 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4247 | if (!NextUB.isUsable()) |
| 4248 | return 0; |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4249 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4250 | CombNextLB = |
| 4251 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombLB.get(), ST.get()); |
| 4252 | if (!NextLB.isUsable()) |
| 4253 | return 0; |
| 4254 | // LB = LB + ST |
| 4255 | CombNextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombLB.get(), |
| 4256 | CombNextLB.get()); |
| 4257 | CombNextLB = SemaRef.ActOnFinishFullExpr(CombNextLB.get()); |
| 4258 | if (!CombNextLB.isUsable()) |
| 4259 | return 0; |
| 4260 | // UB + ST |
| 4261 | CombNextUB = |
| 4262 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombUB.get(), ST.get()); |
| 4263 | if (!CombNextUB.isUsable()) |
| 4264 | return 0; |
| 4265 | // UB = UB + ST |
| 4266 | CombNextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombUB.get(), |
| 4267 | CombNextUB.get()); |
| 4268 | CombNextUB = SemaRef.ActOnFinishFullExpr(CombNextUB.get()); |
| 4269 | if (!CombNextUB.isUsable()) |
| 4270 | return 0; |
| 4271 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4272 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4273 | |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4274 | // Create increment expression for distribute loop when combined in a same |
Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 4275 | // directive with for as IV = IV + ST; ensure upper bound expression based |
| 4276 | // on PrevUB instead of NumIterations - used to implement 'for' when found |
| 4277 | // in combination with 'distribute', like in 'distribute parallel for' |
| 4278 | SourceLocation DistIncLoc; |
| 4279 | ExprResult DistCond, DistInc, PrevEUB; |
| 4280 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4281 | DistCond = SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()); |
| 4282 | assert(DistCond.isUsable() && "distribute cond expr was not built"); |
| 4283 | |
| 4284 | DistInc = |
| 4285 | SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Add, IV.get(), ST.get()); |
| 4286 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 4287 | DistInc = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, IV.get(), |
| 4288 | DistInc.get()); |
| 4289 | DistInc = SemaRef.ActOnFinishFullExpr(DistInc.get()); |
| 4290 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 4291 | |
| 4292 | // Build expression: UB = min(UB, prevUB) for #for in composite or combined |
| 4293 | // construct |
| 4294 | SourceLocation DistEUBLoc; |
| 4295 | ExprResult IsUBGreater = |
| 4296 | SemaRef.BuildBinOp(CurScope, DistEUBLoc, BO_GT, UB.get(), PrevUB.get()); |
| 4297 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4298 | DistEUBLoc, DistEUBLoc, IsUBGreater.get(), PrevUB.get(), UB.get()); |
| 4299 | PrevEUB = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, UB.get(), |
| 4300 | CondOp.get()); |
| 4301 | PrevEUB = SemaRef.ActOnFinishFullExpr(PrevEUB.get()); |
| 4302 | } |
| 4303 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4304 | // Build updates and final values of the loop counters. |
| 4305 | bool HasErrors = false; |
| 4306 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4307 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4308 | Built.Updates.resize(NestedLoopCount); |
| 4309 | Built.Finals.resize(NestedLoopCount); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4310 | SmallVector<Expr *, 4> LoopMultipliers; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4311 | { |
| 4312 | ExprResult Div; |
| 4313 | // Go from inner nested loop to outer. |
| 4314 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4315 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4316 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4317 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4318 | // where Div is product of previous iterations' IS.NumIters. |
| 4319 | ExprResult Iter; |
| 4320 | if (Div.isUsable()) { |
| 4321 | Iter = |
| 4322 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4323 | } else { |
| 4324 | Iter = IV; |
| 4325 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4326 | "unusable div expected on first iteration only"); |
| 4327 | } |
| 4328 | |
| 4329 | if (Cnt != 0 && Iter.isUsable()) |
| 4330 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4331 | IS.NumIterations); |
| 4332 | if (!Iter.isUsable()) { |
| 4333 | HasErrors = true; |
| 4334 | break; |
| 4335 | } |
| 4336 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4337 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4338 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 4339 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 4340 | IS.CounterVar->getExprLoc(), |
| 4341 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4342 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4343 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4344 | if (!Init.isUsable()) { |
| 4345 | HasErrors = true; |
| 4346 | break; |
| 4347 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4348 | ExprResult Update = BuildCounterUpdate( |
| 4349 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 4350 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4351 | if (!Update.isUsable()) { |
| 4352 | HasErrors = true; |
| 4353 | break; |
| 4354 | } |
| 4355 | |
| 4356 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4357 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4358 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4359 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4360 | if (!Final.isUsable()) { |
| 4361 | HasErrors = true; |
| 4362 | break; |
| 4363 | } |
| 4364 | |
| 4365 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4366 | if (Cnt != 0) { |
| 4367 | if (Div.isUnset()) |
| 4368 | Div = IS.NumIterations; |
| 4369 | else |
| 4370 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4371 | IS.NumIterations); |
| 4372 | |
| 4373 | // Add parentheses (for debugging purposes only). |
| 4374 | if (Div.isUsable()) |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4375 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4376 | if (!Div.isUsable()) { |
| 4377 | HasErrors = true; |
| 4378 | break; |
| 4379 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4380 | LoopMultipliers.push_back(Div.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4381 | } |
| 4382 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4383 | HasErrors = true; |
| 4384 | break; |
| 4385 | } |
| 4386 | // Save results |
| 4387 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4388 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4389 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4390 | Built.Updates[Cnt] = Update.get(); |
| 4391 | Built.Finals[Cnt] = Final.get(); |
| 4392 | } |
| 4393 | } |
| 4394 | |
| 4395 | if (HasErrors) |
| 4396 | return 0; |
| 4397 | |
| 4398 | // Save results |
| 4399 | Built.IterationVarRef = IV.get(); |
| 4400 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4401 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4402 | Built.CalcLastIteration = |
| 4403 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4404 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4405 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4406 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4407 | Built.Init = Init.get(); |
| 4408 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4409 | Built.LB = LB.get(); |
| 4410 | Built.UB = UB.get(); |
| 4411 | Built.IL = IL.get(); |
| 4412 | Built.ST = ST.get(); |
| 4413 | Built.EUB = EUB.get(); |
| 4414 | Built.NLB = NextLB.get(); |
| 4415 | Built.NUB = NextUB.get(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4416 | Built.PrevLB = PrevLB.get(); |
| 4417 | Built.PrevUB = PrevUB.get(); |
Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 4418 | Built.DistInc = DistInc.get(); |
| 4419 | Built.PrevEUB = PrevEUB.get(); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4420 | Built.DistCombinedFields.LB = CombLB.get(); |
| 4421 | Built.DistCombinedFields.UB = CombUB.get(); |
| 4422 | Built.DistCombinedFields.EUB = CombEUB.get(); |
| 4423 | Built.DistCombinedFields.Init = CombInit.get(); |
| 4424 | Built.DistCombinedFields.Cond = CombCond.get(); |
| 4425 | Built.DistCombinedFields.NLB = CombNextLB.get(); |
| 4426 | Built.DistCombinedFields.NUB = CombNextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4427 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4428 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); |
| 4429 | // Fill data for doacross depend clauses. |
| 4430 | for (auto Pair : DSA.getDoacrossDependClauses()) { |
| 4431 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 4432 | Pair.first->setCounterValue(CounterVal); |
| 4433 | else { |
| 4434 | if (NestedLoopCount != Pair.second.size() || |
| 4435 | NestedLoopCount != LoopMultipliers.size() + 1) { |
| 4436 | // Erroneous case - clause has some problems. |
| 4437 | Pair.first->setCounterValue(CounterVal); |
| 4438 | continue; |
| 4439 | } |
| 4440 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink); |
| 4441 | auto I = Pair.second.rbegin(); |
| 4442 | auto IS = IterSpaces.rbegin(); |
| 4443 | auto ILM = LoopMultipliers.rbegin(); |
| 4444 | Expr *UpCounterVal = CounterVal; |
| 4445 | Expr *Multiplier = nullptr; |
| 4446 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4447 | if (I->first) { |
| 4448 | assert(IS->CounterStep); |
| 4449 | Expr *NormalizedOffset = |
| 4450 | SemaRef |
| 4451 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, |
| 4452 | I->first, IS->CounterStep) |
| 4453 | .get(); |
| 4454 | if (Multiplier) { |
| 4455 | NormalizedOffset = |
| 4456 | SemaRef |
| 4457 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, |
| 4458 | NormalizedOffset, Multiplier) |
| 4459 | .get(); |
| 4460 | } |
| 4461 | assert(I->second == OO_Plus || I->second == OO_Minus); |
| 4462 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4463 | UpCounterVal = SemaRef |
| 4464 | .BuildBinOp(CurScope, I->first->getExprLoc(), BOK, |
| 4465 | UpCounterVal, NormalizedOffset) |
| 4466 | .get(); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4467 | } |
| 4468 | Multiplier = *ILM; |
| 4469 | ++I; |
| 4470 | ++IS; |
| 4471 | ++ILM; |
| 4472 | } |
| 4473 | Pair.first->setCounterValue(UpCounterVal); |
| 4474 | } |
| 4475 | } |
| 4476 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4477 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4478 | } |
| 4479 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4480 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4481 | auto CollapseClauses = |
| 4482 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4483 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4484 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4485 | return nullptr; |
| 4486 | } |
| 4487 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4488 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4489 | auto OrderedClauses = |
| 4490 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4491 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4492 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4493 | return nullptr; |
| 4494 | } |
| 4495 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4496 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 4497 | const ArrayRef<OMPClause *> Clauses) { |
| 4498 | OMPSafelenClause *Safelen = nullptr; |
| 4499 | OMPSimdlenClause *Simdlen = nullptr; |
| 4500 | |
| 4501 | for (auto *Clause : Clauses) { |
| 4502 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4503 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4504 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4505 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4506 | if (Safelen && Simdlen) |
| 4507 | break; |
| 4508 | } |
| 4509 | |
| 4510 | if (Simdlen && Safelen) { |
| 4511 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4512 | auto SimdlenLength = Simdlen->getSimdlen(); |
| 4513 | auto SafelenLength = Safelen->getSafelen(); |
| 4514 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 4515 | SimdlenLength->isInstantiationDependent() || |
| 4516 | SimdlenLength->containsUnexpandedParameterPack()) |
| 4517 | return false; |
| 4518 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 4519 | SafelenLength->isInstantiationDependent() || |
| 4520 | SafelenLength->containsUnexpandedParameterPack()) |
| 4521 | return false; |
| 4522 | SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context); |
| 4523 | SafelenLength->EvaluateAsInt(SafelenRes, S.Context); |
| 4524 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 4525 | // If both simdlen and safelen clauses are specified, the value of the |
| 4526 | // simdlen parameter must be less than or equal to the value of the safelen |
| 4527 | // parameter. |
| 4528 | if (SimdlenRes > SafelenRes) { |
| 4529 | S.Diag(SimdlenLength->getExprLoc(), |
| 4530 | diag::err_omp_wrong_simdlen_safelen_values) |
| 4531 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 4532 | return true; |
| 4533 | } |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4534 | } |
| 4535 | return false; |
| 4536 | } |
| 4537 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4538 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4539 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4540 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4541 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4542 | if (!AStmt) |
| 4543 | return StmtError(); |
| 4544 | |
| 4545 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4546 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4547 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4548 | // define the nested loops number. |
| 4549 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4550 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4551 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4552 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4553 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4554 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4555 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4556 | "omp simd loop exprs were not built"); |
| 4557 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4558 | if (!CurContext->isDependentContext()) { |
| 4559 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4560 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4561 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4562 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4563 | B.NumIterations, *this, CurScope, |
| 4564 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4565 | return StmtError(); |
| 4566 | } |
| 4567 | } |
| 4568 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4569 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4570 | return StmtError(); |
| 4571 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4572 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4573 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4574 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4575 | } |
| 4576 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4577 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4578 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4579 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4580 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4581 | if (!AStmt) |
| 4582 | return StmtError(); |
| 4583 | |
| 4584 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4585 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4586 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4587 | // define the nested loops number. |
| 4588 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4589 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4590 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4591 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4592 | return StmtError(); |
| 4593 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4594 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4595 | "omp for loop exprs were not built"); |
| 4596 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4597 | if (!CurContext->isDependentContext()) { |
| 4598 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4599 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4600 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4601 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4602 | B.NumIterations, *this, CurScope, |
| 4603 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4604 | return StmtError(); |
| 4605 | } |
| 4606 | } |
| 4607 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4608 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4609 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4610 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4613 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4614 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4615 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4616 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4617 | if (!AStmt) |
| 4618 | return StmtError(); |
| 4619 | |
| 4620 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4621 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4622 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4623 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4624 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4625 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4626 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4627 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4628 | if (NestedLoopCount == 0) |
| 4629 | return StmtError(); |
| 4630 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4631 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4632 | "omp for simd loop exprs were not built"); |
| 4633 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4634 | if (!CurContext->isDependentContext()) { |
| 4635 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4636 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4637 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4638 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4639 | B.NumIterations, *this, CurScope, |
| 4640 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4641 | return StmtError(); |
| 4642 | } |
| 4643 | } |
| 4644 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4645 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4646 | return StmtError(); |
| 4647 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4648 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4649 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4650 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4651 | } |
| 4652 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4653 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4654 | Stmt *AStmt, |
| 4655 | SourceLocation StartLoc, |
| 4656 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4657 | if (!AStmt) |
| 4658 | return StmtError(); |
| 4659 | |
| 4660 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4661 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4662 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4663 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4664 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4665 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4666 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4667 | return StmtError(); |
| 4668 | // All associated statements must be '#pragma omp section' except for |
| 4669 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4670 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4671 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4672 | if (SectionStmt) |
| 4673 | Diag(SectionStmt->getLocStart(), |
| 4674 | diag::err_omp_sections_substmt_not_section); |
| 4675 | return StmtError(); |
| 4676 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4677 | cast<OMPSectionDirective>(SectionStmt) |
| 4678 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4679 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4680 | } else { |
| 4681 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4682 | return StmtError(); |
| 4683 | } |
| 4684 | |
| 4685 | getCurFunction()->setHasBranchProtectedScope(); |
| 4686 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4687 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4688 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4689 | } |
| 4690 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4691 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4692 | SourceLocation StartLoc, |
| 4693 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4694 | if (!AStmt) |
| 4695 | return StmtError(); |
| 4696 | |
| 4697 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4698 | |
| 4699 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4700 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4701 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4702 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4703 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4704 | } |
| 4705 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4706 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4707 | Stmt *AStmt, |
| 4708 | SourceLocation StartLoc, |
| 4709 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4710 | if (!AStmt) |
| 4711 | return StmtError(); |
| 4712 | |
| 4713 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4714 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4715 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4716 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4717 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4718 | // The copyprivate clause must not be used with the nowait clause. |
| 4719 | OMPClause *Nowait = nullptr; |
| 4720 | OMPClause *Copyprivate = nullptr; |
| 4721 | for (auto *Clause : Clauses) { |
| 4722 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4723 | Nowait = Clause; |
| 4724 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4725 | Copyprivate = Clause; |
| 4726 | if (Copyprivate && Nowait) { |
| 4727 | Diag(Copyprivate->getLocStart(), |
| 4728 | diag::err_omp_single_copyprivate_with_nowait); |
| 4729 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4730 | return StmtError(); |
| 4731 | } |
| 4732 | } |
| 4733 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4734 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4735 | } |
| 4736 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4737 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4738 | SourceLocation StartLoc, |
| 4739 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4740 | if (!AStmt) |
| 4741 | return StmtError(); |
| 4742 | |
| 4743 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4744 | |
| 4745 | getCurFunction()->setHasBranchProtectedScope(); |
| 4746 | |
| 4747 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4748 | } |
| 4749 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4750 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4751 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4752 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4753 | if (!AStmt) |
| 4754 | return StmtError(); |
| 4755 | |
| 4756 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4757 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4758 | bool ErrorFound = false; |
| 4759 | llvm::APSInt Hint; |
| 4760 | SourceLocation HintLoc; |
| 4761 | bool DependentHint = false; |
| 4762 | for (auto *C : Clauses) { |
| 4763 | if (C->getClauseKind() == OMPC_hint) { |
| 4764 | if (!DirName.getName()) { |
| 4765 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4766 | ErrorFound = true; |
| 4767 | } |
| 4768 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4769 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4770 | E->isInstantiationDependent()) |
| 4771 | DependentHint = true; |
| 4772 | else { |
| 4773 | Hint = E->EvaluateKnownConstInt(Context); |
| 4774 | HintLoc = C->getLocStart(); |
| 4775 | } |
| 4776 | } |
| 4777 | } |
| 4778 | if (ErrorFound) |
| 4779 | return StmtError(); |
| 4780 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4781 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4782 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4783 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4784 | if (HintLoc.isValid()) { |
| 4785 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4786 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4787 | } else |
| 4788 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4789 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4790 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4791 | << 1 |
| 4792 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4793 | /*Radix=*/10, /*Signed=*/false); |
| 4794 | } else |
| 4795 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4796 | } |
| 4797 | } |
| 4798 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4799 | getCurFunction()->setHasBranchProtectedScope(); |
| 4800 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4801 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4802 | Clauses, AStmt); |
| 4803 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4804 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4805 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4808 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4809 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4810 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4811 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4812 | if (!AStmt) |
| 4813 | return StmtError(); |
| 4814 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4815 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4816 | // 1.2.2 OpenMP Language Terminology |
| 4817 | // Structured block - An executable statement with a single entry at the |
| 4818 | // top and a single exit at the bottom. |
| 4819 | // The point of exit cannot be a branch out of the structured block. |
| 4820 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4821 | CS->getCapturedDecl()->setNothrow(); |
| 4822 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4823 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4824 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4825 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4826 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4827 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4828 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4829 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4830 | if (NestedLoopCount == 0) |
| 4831 | return StmtError(); |
| 4832 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4833 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4834 | "omp parallel for loop exprs were not built"); |
| 4835 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4836 | if (!CurContext->isDependentContext()) { |
| 4837 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4838 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4839 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4840 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4841 | B.NumIterations, *this, CurScope, |
| 4842 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4843 | return StmtError(); |
| 4844 | } |
| 4845 | } |
| 4846 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4847 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4848 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4849 | NestedLoopCount, Clauses, AStmt, B, |
| 4850 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4851 | } |
| 4852 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4853 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4854 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4855 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4856 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4857 | if (!AStmt) |
| 4858 | return StmtError(); |
| 4859 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4860 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4861 | // 1.2.2 OpenMP Language Terminology |
| 4862 | // Structured block - An executable statement with a single entry at the |
| 4863 | // top and a single exit at the bottom. |
| 4864 | // The point of exit cannot be a branch out of the structured block. |
| 4865 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4866 | CS->getCapturedDecl()->setNothrow(); |
| 4867 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4868 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4869 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4870 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4871 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4872 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4873 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4874 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4875 | if (NestedLoopCount == 0) |
| 4876 | return StmtError(); |
| 4877 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4878 | if (!CurContext->isDependentContext()) { |
| 4879 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4880 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4881 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4882 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4883 | B.NumIterations, *this, CurScope, |
| 4884 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4885 | return StmtError(); |
| 4886 | } |
| 4887 | } |
| 4888 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4889 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4890 | return StmtError(); |
| 4891 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4892 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4893 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4894 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4897 | StmtResult |
| 4898 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4899 | Stmt *AStmt, SourceLocation StartLoc, |
| 4900 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4901 | if (!AStmt) |
| 4902 | return StmtError(); |
| 4903 | |
| 4904 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4905 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4906 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4907 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4908 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4909 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4910 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4911 | return StmtError(); |
| 4912 | // All associated statements must be '#pragma omp section' except for |
| 4913 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4914 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4915 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4916 | if (SectionStmt) |
| 4917 | Diag(SectionStmt->getLocStart(), |
| 4918 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4919 | return StmtError(); |
| 4920 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4921 | cast<OMPSectionDirective>(SectionStmt) |
| 4922 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4923 | } |
| 4924 | } else { |
| 4925 | Diag(AStmt->getLocStart(), |
| 4926 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4927 | return StmtError(); |
| 4928 | } |
| 4929 | |
| 4930 | getCurFunction()->setHasBranchProtectedScope(); |
| 4931 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4932 | return OMPParallelSectionsDirective::Create( |
| 4933 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4936 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4937 | Stmt *AStmt, SourceLocation StartLoc, |
| 4938 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4939 | if (!AStmt) |
| 4940 | return StmtError(); |
| 4941 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4942 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4943 | // 1.2.2 OpenMP Language Terminology |
| 4944 | // Structured block - An executable statement with a single entry at the |
| 4945 | // top and a single exit at the bottom. |
| 4946 | // The point of exit cannot be a branch out of the structured block. |
| 4947 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4948 | CS->getCapturedDecl()->setNothrow(); |
| 4949 | |
| 4950 | getCurFunction()->setHasBranchProtectedScope(); |
| 4951 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4952 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4953 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4954 | } |
| 4955 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4956 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4957 | SourceLocation EndLoc) { |
| 4958 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4959 | } |
| 4960 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4961 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4962 | SourceLocation EndLoc) { |
| 4963 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4964 | } |
| 4965 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4966 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4967 | SourceLocation EndLoc) { |
| 4968 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4969 | } |
| 4970 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4971 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4972 | SourceLocation StartLoc, |
| 4973 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4974 | if (!AStmt) |
| 4975 | return StmtError(); |
| 4976 | |
| 4977 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4978 | |
| 4979 | getCurFunction()->setHasBranchProtectedScope(); |
| 4980 | |
| 4981 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4982 | } |
| 4983 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4984 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4985 | SourceLocation StartLoc, |
| 4986 | SourceLocation EndLoc) { |
| 4987 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4988 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4989 | } |
| 4990 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4991 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4992 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4993 | SourceLocation StartLoc, |
| 4994 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4995 | OMPClause *DependFound = nullptr; |
| 4996 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4997 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4998 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4999 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5000 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5001 | for (auto *C : Clauses) { |
| 5002 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5003 | DependFound = C; |
| 5004 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5005 | if (DependSourceClause) { |
| 5006 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5007 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5008 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5009 | ErrorFound = true; |
| 5010 | } else |
| 5011 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5012 | if (DependSinkClause) { |
| 5013 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5014 | << 0; |
| 5015 | ErrorFound = true; |
| 5016 | } |
| 5017 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5018 | if (DependSourceClause) { |
| 5019 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5020 | << 1; |
| 5021 | ErrorFound = true; |
| 5022 | } |
| 5023 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5024 | } |
| 5025 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5026 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5027 | else if (C->getClauseKind() == OMPC_simd) |
| 5028 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5029 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5030 | if (!ErrorFound && !SC && |
| 5031 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5032 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5033 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5034 | // that can appear in the simd region. |
| 5035 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5036 | ErrorFound = true; |
| 5037 | } else if (DependFound && (TC || SC)) { |
| 5038 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5039 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5040 | ErrorFound = true; |
| 5041 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5042 | Diag(DependFound->getLocStart(), |
| 5043 | diag::err_omp_ordered_directive_without_param); |
| 5044 | ErrorFound = true; |
| 5045 | } else if (TC || Clauses.empty()) { |
| 5046 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5047 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5048 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5049 | << (TC != nullptr); |
| 5050 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5051 | ErrorFound = true; |
| 5052 | } |
| 5053 | } |
| 5054 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5055 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5056 | |
| 5057 | if (AStmt) { |
| 5058 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5059 | |
| 5060 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5061 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5062 | |
| 5063 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5064 | } |
| 5065 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5066 | namespace { |
| 5067 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5068 | /// construct. |
| 5069 | class OpenMPAtomicUpdateChecker { |
| 5070 | /// \brief Error results for atomic update expressions. |
| 5071 | enum ExprAnalysisErrorCode { |
| 5072 | /// \brief A statement is not an expression statement. |
| 5073 | NotAnExpression, |
| 5074 | /// \brief Expression is not builtin binary or unary operation. |
| 5075 | NotABinaryOrUnaryExpression, |
| 5076 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5077 | NotAnUnaryIncDecExpression, |
| 5078 | /// \brief An expression is not of scalar type. |
| 5079 | NotAScalarType, |
| 5080 | /// \brief A binary operation is not an assignment operation. |
| 5081 | NotAnAssignmentOp, |
| 5082 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5083 | NotABinaryExpression, |
| 5084 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5085 | /// expression. |
| 5086 | NotABinaryOperator, |
| 5087 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5088 | /// part. |
| 5089 | NotAnUpdateExpression, |
| 5090 | /// \brief No errors is found. |
| 5091 | NoError |
| 5092 | }; |
| 5093 | /// \brief Reference to Sema. |
| 5094 | Sema &SemaRef; |
| 5095 | /// \brief A location for note diagnostics (when error is found). |
| 5096 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5097 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5098 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5099 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5100 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5101 | /// \brief Helper expression of the form |
| 5102 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5103 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5104 | Expr *UpdateExpr; |
| 5105 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5106 | /// important for non-associative operations. |
| 5107 | bool IsXLHSInRHSPart; |
| 5108 | BinaryOperatorKind Op; |
| 5109 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5110 | /// \brief true if the source expression is a postfix unary operation, false |
| 5111 | /// if it is a prefix unary operation. |
| 5112 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5113 | |
| 5114 | public: |
| 5115 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5116 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5117 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5118 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5119 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5120 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5121 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5122 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5123 | /// \param NoteId Diagnostic note for the main error message. |
| 5124 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5125 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5126 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5127 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5128 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5129 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5130 | /// \brief Return the update expression used in calculation of the updated |
| 5131 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5132 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5133 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5134 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5135 | /// false otherwise. |
| 5136 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5137 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5138 | /// \brief true if the source expression is a postfix unary operation, false |
| 5139 | /// if it is a prefix unary operation. |
| 5140 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5141 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5142 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5143 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5144 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5145 | }; |
| 5146 | } // namespace |
| 5147 | |
| 5148 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5149 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5150 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5151 | SourceLocation ErrorLoc, NoteLoc; |
| 5152 | SourceRange ErrorRange, NoteRange; |
| 5153 | // Allowed constructs are: |
| 5154 | // x = x binop expr; |
| 5155 | // x = expr binop x; |
| 5156 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5157 | X = AtomicBinOp->getLHS(); |
| 5158 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5159 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5160 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5161 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5162 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5163 | Op = AtomicInnerBinOp->getOpcode(); |
| 5164 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5165 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5166 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5167 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5168 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5169 | /*Canonical=*/true); |
| 5170 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5171 | /*Canonical=*/true); |
| 5172 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5173 | /*Canonical=*/true); |
| 5174 | if (XId == LHSId) { |
| 5175 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5176 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5177 | } else if (XId == RHSId) { |
| 5178 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5179 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5180 | } else { |
| 5181 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5182 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5183 | NoteLoc = X->getExprLoc(); |
| 5184 | NoteRange = X->getSourceRange(); |
| 5185 | ErrorFound = NotAnUpdateExpression; |
| 5186 | } |
| 5187 | } else { |
| 5188 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5189 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5190 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5191 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5192 | ErrorFound = NotABinaryOperator; |
| 5193 | } |
| 5194 | } else { |
| 5195 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5196 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5197 | ErrorFound = NotABinaryExpression; |
| 5198 | } |
| 5199 | } else { |
| 5200 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5201 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5202 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5203 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5204 | ErrorFound = NotAnAssignmentOp; |
| 5205 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5206 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5207 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5208 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5209 | return true; |
| 5210 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5211 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5212 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5216 | unsigned NoteId) { |
| 5217 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5218 | SourceLocation ErrorLoc, NoteLoc; |
| 5219 | SourceRange ErrorRange, NoteRange; |
| 5220 | // Allowed constructs are: |
| 5221 | // x++; |
| 5222 | // x--; |
| 5223 | // ++x; |
| 5224 | // --x; |
| 5225 | // x binop= expr; |
| 5226 | // x = x binop expr; |
| 5227 | // x = expr binop x; |
| 5228 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5229 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5230 | if (AtomicBody->getType()->isScalarType() || |
| 5231 | AtomicBody->isInstantiationDependent()) { |
| 5232 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5233 | AtomicBody->IgnoreParenImpCasts())) { |
| 5234 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5235 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5236 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5237 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5238 | E = AtomicCompAssignOp->getRHS(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5239 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5240 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5241 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5242 | AtomicBody->IgnoreParenImpCasts())) { |
| 5243 | // Check for Binary Operation |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5244 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5245 | return true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5246 | } else if (auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| 5247 | AtomicBody->IgnoreParenImpCasts())) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5248 | // Check for Unary Operation |
| 5249 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5250 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5251 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5252 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5253 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5254 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5255 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5256 | } else { |
| 5257 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5258 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5259 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5260 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5261 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5262 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5263 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5264 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5265 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5266 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5267 | } |
| 5268 | } else { |
| 5269 | ErrorFound = NotAScalarType; |
| 5270 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5271 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5272 | } |
| 5273 | } else { |
| 5274 | ErrorFound = NotAnExpression; |
| 5275 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5276 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5277 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5278 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5279 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5280 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5281 | return true; |
| 5282 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5283 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5284 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5285 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5286 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5287 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5288 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5289 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5290 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5291 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5292 | auto Update = |
| 5293 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5294 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5295 | if (Update.isInvalid()) |
| 5296 | return true; |
| 5297 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5298 | Sema::AA_Casting); |
| 5299 | if (Update.isInvalid()) |
| 5300 | return true; |
| 5301 | UpdateExpr = Update.get(); |
| 5302 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5303 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5304 | } |
| 5305 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5306 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5307 | Stmt *AStmt, |
| 5308 | SourceLocation StartLoc, |
| 5309 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5310 | if (!AStmt) |
| 5311 | return StmtError(); |
| 5312 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5313 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5314 | // 1.2.2 OpenMP Language Terminology |
| 5315 | // Structured block - An executable statement with a single entry at the |
| 5316 | // top and a single exit at the bottom. |
| 5317 | // The point of exit cannot be a branch out of the structured block. |
| 5318 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5319 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5320 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5321 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5322 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5323 | C->getClauseKind() == OMPC_update || |
| 5324 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5325 | if (AtomicKind != OMPC_unknown) { |
| 5326 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5327 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5328 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5329 | << getOpenMPClauseName(AtomicKind); |
| 5330 | } else { |
| 5331 | AtomicKind = C->getClauseKind(); |
| 5332 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5333 | } |
| 5334 | } |
| 5335 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5336 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5337 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5338 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5339 | Body = EWC->getSubExpr(); |
| 5340 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5341 | Expr *X = nullptr; |
| 5342 | Expr *V = nullptr; |
| 5343 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5344 | Expr *UE = nullptr; |
| 5345 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5346 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5347 | // OpenMP [2.12.6, atomic Construct] |
| 5348 | // In the next expressions: |
| 5349 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5350 | // * During the execution of an atomic region, multiple syntactic |
| 5351 | // occurrences of x must designate the same storage location. |
| 5352 | // * Neither of v and expr (as applicable) may access the storage location |
| 5353 | // designated by x. |
| 5354 | // * Neither of x and expr (as applicable) may access the storage location |
| 5355 | // designated by v. |
| 5356 | // * expr is an expression with scalar type. |
| 5357 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5358 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5359 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5360 | // (expr). This requirement is satisfied if the operators in expr have |
| 5361 | // precedence greater than binop, or by using parentheses around expr or |
| 5362 | // subexpressions of expr. |
| 5363 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5364 | // binop x. This requirement is satisfied if the operators in expr have |
| 5365 | // precedence equal to or greater than binop, or by using parentheses around |
| 5366 | // expr or subexpressions of expr. |
| 5367 | // * For forms that allow multiple occurrences of x, the number of times |
| 5368 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5369 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5370 | enum { |
| 5371 | NotAnExpression, |
| 5372 | NotAnAssignmentOp, |
| 5373 | NotAScalarType, |
| 5374 | NotAnLValue, |
| 5375 | NoError |
| 5376 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5377 | SourceLocation ErrorLoc, NoteLoc; |
| 5378 | SourceRange ErrorRange, NoteRange; |
| 5379 | // If clause is read: |
| 5380 | // v = x; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5381 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5382 | auto *AtomicBinOp = |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5383 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5384 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5385 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5386 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5387 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5388 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5389 | if (!X->isLValue() || !V->isLValue()) { |
| 5390 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5391 | ErrorFound = NotAnLValue; |
| 5392 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5393 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5394 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5395 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5396 | } |
| 5397 | } else if (!X->isInstantiationDependent() || |
| 5398 | !V->isInstantiationDependent()) { |
| 5399 | auto NotScalarExpr = |
| 5400 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5401 | ? V |
| 5402 | : X; |
| 5403 | ErrorFound = NotAScalarType; |
| 5404 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5405 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5406 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5407 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5408 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5409 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5410 | ErrorFound = NotAnAssignmentOp; |
| 5411 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5412 | ErrorRange = AtomicBody->getSourceRange(); |
| 5413 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5414 | : AtomicBody->getExprLoc(); |
| 5415 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5416 | : AtomicBody->getSourceRange(); |
| 5417 | } |
| 5418 | } else { |
| 5419 | ErrorFound = NotAnExpression; |
| 5420 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5421 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5422 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5423 | if (ErrorFound != NoError) { |
| 5424 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5425 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5426 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5427 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5428 | return StmtError(); |
| 5429 | } else if (CurContext->isDependentContext()) |
| 5430 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5431 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5432 | enum { |
| 5433 | NotAnExpression, |
| 5434 | NotAnAssignmentOp, |
| 5435 | NotAScalarType, |
| 5436 | NotAnLValue, |
| 5437 | NoError |
| 5438 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5439 | SourceLocation ErrorLoc, NoteLoc; |
| 5440 | SourceRange ErrorRange, NoteRange; |
| 5441 | // If clause is write: |
| 5442 | // x = expr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5443 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5444 | auto *AtomicBinOp = |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5445 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5446 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5447 | X = AtomicBinOp->getLHS(); |
| 5448 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5449 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5450 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5451 | if (!X->isLValue()) { |
| 5452 | ErrorFound = NotAnLValue; |
| 5453 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5454 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5455 | NoteLoc = X->getExprLoc(); |
| 5456 | NoteRange = X->getSourceRange(); |
| 5457 | } |
| 5458 | } else if (!X->isInstantiationDependent() || |
| 5459 | !E->isInstantiationDependent()) { |
| 5460 | auto NotScalarExpr = |
| 5461 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5462 | ? E |
| 5463 | : X; |
| 5464 | ErrorFound = NotAScalarType; |
| 5465 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5466 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5467 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5468 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5469 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5470 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5471 | ErrorFound = NotAnAssignmentOp; |
| 5472 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5473 | ErrorRange = AtomicBody->getSourceRange(); |
| 5474 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5475 | : AtomicBody->getExprLoc(); |
| 5476 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5477 | : AtomicBody->getSourceRange(); |
| 5478 | } |
| 5479 | } else { |
| 5480 | ErrorFound = NotAnExpression; |
| 5481 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5482 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5483 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5484 | if (ErrorFound != NoError) { |
| 5485 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5486 | << ErrorRange; |
| 5487 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5488 | << NoteRange; |
| 5489 | return StmtError(); |
| 5490 | } else if (CurContext->isDependentContext()) |
| 5491 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5492 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5493 | // If clause is update: |
| 5494 | // x++; |
| 5495 | // x--; |
| 5496 | // ++x; |
| 5497 | // --x; |
| 5498 | // x binop= expr; |
| 5499 | // x = x binop expr; |
| 5500 | // x = expr binop x; |
| 5501 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5502 | if (Checker.checkStatement( |
| 5503 | Body, (AtomicKind == OMPC_update) |
| 5504 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5505 | : diag::err_omp_atomic_not_expression_statement, |
| 5506 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5507 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5508 | if (!CurContext->isDependentContext()) { |
| 5509 | E = Checker.getExpr(); |
| 5510 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5511 | UE = Checker.getUpdateExpr(); |
| 5512 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5513 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5514 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5515 | enum { |
| 5516 | NotAnAssignmentOp, |
| 5517 | NotACompoundStatement, |
| 5518 | NotTwoSubstatements, |
| 5519 | NotASpecificExpression, |
| 5520 | NoError |
| 5521 | } ErrorFound = NoError; |
| 5522 | SourceLocation ErrorLoc, NoteLoc; |
| 5523 | SourceRange ErrorRange, NoteRange; |
| 5524 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5525 | // If clause is a capture: |
| 5526 | // v = x++; |
| 5527 | // v = x--; |
| 5528 | // v = ++x; |
| 5529 | // v = --x; |
| 5530 | // v = x binop= expr; |
| 5531 | // v = x = x binop expr; |
| 5532 | // v = x = expr binop x; |
| 5533 | auto *AtomicBinOp = |
| 5534 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5535 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5536 | V = AtomicBinOp->getLHS(); |
| 5537 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5538 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5539 | if (Checker.checkStatement( |
| 5540 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5541 | diag::note_omp_atomic_update)) |
| 5542 | return StmtError(); |
| 5543 | E = Checker.getExpr(); |
| 5544 | X = Checker.getX(); |
| 5545 | UE = Checker.getUpdateExpr(); |
| 5546 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5547 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5548 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5549 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5550 | ErrorRange = AtomicBody->getSourceRange(); |
| 5551 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5552 | : AtomicBody->getExprLoc(); |
| 5553 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5554 | : AtomicBody->getSourceRange(); |
| 5555 | ErrorFound = NotAnAssignmentOp; |
| 5556 | } |
| 5557 | if (ErrorFound != NoError) { |
| 5558 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5559 | << ErrorRange; |
| 5560 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5561 | return StmtError(); |
| 5562 | } else if (CurContext->isDependentContext()) { |
| 5563 | UE = V = E = X = nullptr; |
| 5564 | } |
| 5565 | } else { |
| 5566 | // If clause is a capture: |
| 5567 | // { v = x; x = expr; } |
| 5568 | // { v = x; x++; } |
| 5569 | // { v = x; x--; } |
| 5570 | // { v = x; ++x; } |
| 5571 | // { v = x; --x; } |
| 5572 | // { v = x; x binop= expr; } |
| 5573 | // { v = x; x = x binop expr; } |
| 5574 | // { v = x; x = expr binop x; } |
| 5575 | // { x++; v = x; } |
| 5576 | // { x--; v = x; } |
| 5577 | // { ++x; v = x; } |
| 5578 | // { --x; v = x; } |
| 5579 | // { x binop= expr; v = x; } |
| 5580 | // { x = x binop expr; v = x; } |
| 5581 | // { x = expr binop x; v = x; } |
| 5582 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5583 | // Check that this is { expr1; expr2; } |
| 5584 | if (CS->size() == 2) { |
| 5585 | auto *First = CS->body_front(); |
| 5586 | auto *Second = CS->body_back(); |
| 5587 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5588 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5589 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5590 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5591 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5592 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5593 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5594 | BinaryOperator *BinOp = nullptr; |
| 5595 | if (IsUpdateExprFound) { |
| 5596 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5597 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5598 | } |
| 5599 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5600 | // { v = x; x++; } |
| 5601 | // { v = x; x--; } |
| 5602 | // { v = x; ++x; } |
| 5603 | // { v = x; --x; } |
| 5604 | // { v = x; x binop= expr; } |
| 5605 | // { v = x; x = x binop expr; } |
| 5606 | // { v = x; x = expr binop x; } |
| 5607 | // Check that the first expression has form v = x. |
| 5608 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5609 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5610 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5611 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5612 | IsUpdateExprFound = XId == PossibleXId; |
| 5613 | if (IsUpdateExprFound) { |
| 5614 | V = BinOp->getLHS(); |
| 5615 | X = Checker.getX(); |
| 5616 | E = Checker.getExpr(); |
| 5617 | UE = Checker.getUpdateExpr(); |
| 5618 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5619 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5620 | } |
| 5621 | } |
| 5622 | if (!IsUpdateExprFound) { |
| 5623 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5624 | BinOp = nullptr; |
| 5625 | if (IsUpdateExprFound) { |
| 5626 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5627 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5628 | } |
| 5629 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5630 | // { x++; v = x; } |
| 5631 | // { x--; v = x; } |
| 5632 | // { ++x; v = x; } |
| 5633 | // { --x; v = x; } |
| 5634 | // { x binop= expr; v = x; } |
| 5635 | // { x = x binop expr; v = x; } |
| 5636 | // { x = expr binop x; v = x; } |
| 5637 | // Check that the second expression has form v = x. |
| 5638 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5639 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5640 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5641 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5642 | IsUpdateExprFound = XId == PossibleXId; |
| 5643 | if (IsUpdateExprFound) { |
| 5644 | V = BinOp->getLHS(); |
| 5645 | X = Checker.getX(); |
| 5646 | E = Checker.getExpr(); |
| 5647 | UE = Checker.getUpdateExpr(); |
| 5648 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5649 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5650 | } |
| 5651 | } |
| 5652 | } |
| 5653 | if (!IsUpdateExprFound) { |
| 5654 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5655 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5656 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5657 | if (!FirstExpr || !SecondExpr || |
| 5658 | !(FirstExpr->isInstantiationDependent() || |
| 5659 | SecondExpr->isInstantiationDependent())) { |
| 5660 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5661 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5662 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5663 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5664 | : First->getLocStart(); |
| 5665 | NoteRange = ErrorRange = FirstBinOp |
| 5666 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5667 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5668 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5669 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5670 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5671 | ErrorFound = NotAnAssignmentOp; |
| 5672 | NoteLoc = ErrorLoc = SecondBinOp |
| 5673 | ? SecondBinOp->getOperatorLoc() |
| 5674 | : Second->getLocStart(); |
| 5675 | NoteRange = ErrorRange = |
| 5676 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5677 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5678 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5679 | auto *PossibleXRHSInFirst = |
| 5680 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5681 | auto *PossibleXLHSInSecond = |
| 5682 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5683 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5684 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5685 | /*Canonical=*/true); |
| 5686 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5687 | /*Canonical=*/true); |
| 5688 | IsUpdateExprFound = X1Id == X2Id; |
| 5689 | if (IsUpdateExprFound) { |
| 5690 | V = FirstBinOp->getLHS(); |
| 5691 | X = SecondBinOp->getLHS(); |
| 5692 | E = SecondBinOp->getRHS(); |
| 5693 | UE = nullptr; |
| 5694 | IsXLHSInRHSPart = false; |
| 5695 | IsPostfixUpdate = true; |
| 5696 | } else { |
| 5697 | ErrorFound = NotASpecificExpression; |
| 5698 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5699 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5700 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5701 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5702 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5703 | } |
| 5704 | } |
| 5705 | } |
| 5706 | } |
| 5707 | } else { |
| 5708 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5709 | NoteRange = ErrorRange = |
| 5710 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5711 | ErrorFound = NotTwoSubstatements; |
| 5712 | } |
| 5713 | } else { |
| 5714 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5715 | NoteRange = ErrorRange = |
| 5716 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5717 | ErrorFound = NotACompoundStatement; |
| 5718 | } |
| 5719 | if (ErrorFound != NoError) { |
| 5720 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5721 | << ErrorRange; |
| 5722 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5723 | return StmtError(); |
| 5724 | } else if (CurContext->isDependentContext()) { |
| 5725 | UE = V = E = X = nullptr; |
| 5726 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5727 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5728 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5729 | |
| 5730 | getCurFunction()->setHasBranchProtectedScope(); |
| 5731 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5732 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5733 | X, V, E, UE, IsXLHSInRHSPart, |
| 5734 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5735 | } |
| 5736 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5737 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5738 | Stmt *AStmt, |
| 5739 | SourceLocation StartLoc, |
| 5740 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5741 | if (!AStmt) |
| 5742 | return StmtError(); |
| 5743 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5744 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5745 | // 1.2.2 OpenMP Language Terminology |
| 5746 | // Structured block - An executable statement with a single entry at the |
| 5747 | // top and a single exit at the bottom. |
| 5748 | // The point of exit cannot be a branch out of the structured block. |
| 5749 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5750 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5751 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5752 | // OpenMP [2.16, Nesting of Regions] |
| 5753 | // If specified, a teams construct must be contained within a target |
| 5754 | // construct. That target construct must contain no statements or directives |
| 5755 | // outside of the teams construct. |
| 5756 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5757 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5758 | bool OMPTeamsFound = true; |
| 5759 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5760 | auto I = CS->body_begin(); |
| 5761 | while (I != CS->body_end()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5762 | auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5763 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5764 | OMPTeamsFound = false; |
| 5765 | break; |
| 5766 | } |
| 5767 | ++I; |
| 5768 | } |
| 5769 | assert(I != CS->body_end() && "Not found statement"); |
| 5770 | S = *I; |
Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 5771 | } else { |
| 5772 | auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| 5773 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5774 | } |
| 5775 | if (!OMPTeamsFound) { |
| 5776 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5777 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5778 | diag::note_omp_nested_teams_construct_here); |
| 5779 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5780 | << isa<OMPExecutableDirective>(S); |
| 5781 | return StmtError(); |
| 5782 | } |
| 5783 | } |
| 5784 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5785 | getCurFunction()->setHasBranchProtectedScope(); |
| 5786 | |
| 5787 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5788 | } |
| 5789 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5790 | StmtResult |
| 5791 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5792 | Stmt *AStmt, SourceLocation StartLoc, |
| 5793 | SourceLocation EndLoc) { |
| 5794 | if (!AStmt) |
| 5795 | return StmtError(); |
| 5796 | |
| 5797 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5798 | // 1.2.2 OpenMP Language Terminology |
| 5799 | // Structured block - An executable statement with a single entry at the |
| 5800 | // top and a single exit at the bottom. |
| 5801 | // The point of exit cannot be a branch out of the structured block. |
| 5802 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5803 | CS->getCapturedDecl()->setNothrow(); |
| 5804 | |
| 5805 | getCurFunction()->setHasBranchProtectedScope(); |
| 5806 | |
| 5807 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5808 | AStmt); |
| 5809 | } |
| 5810 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5811 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5812 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5813 | SourceLocation EndLoc, |
| 5814 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5815 | if (!AStmt) |
| 5816 | return StmtError(); |
| 5817 | |
| 5818 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5819 | // 1.2.2 OpenMP Language Terminology |
| 5820 | // Structured block - An executable statement with a single entry at the |
| 5821 | // top and a single exit at the bottom. |
| 5822 | // The point of exit cannot be a branch out of the structured block. |
| 5823 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5824 | CS->getCapturedDecl()->setNothrow(); |
| 5825 | |
| 5826 | OMPLoopDirective::HelperExprs B; |
| 5827 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5828 | // define the nested loops number. |
| 5829 | unsigned NestedLoopCount = |
| 5830 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5831 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5832 | VarsWithImplicitDSA, B); |
| 5833 | if (NestedLoopCount == 0) |
| 5834 | return StmtError(); |
| 5835 | |
| 5836 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5837 | "omp target parallel for loop exprs were not built"); |
| 5838 | |
| 5839 | if (!CurContext->isDependentContext()) { |
| 5840 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5841 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5842 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5843 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5844 | B.NumIterations, *this, CurScope, |
| 5845 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5846 | return StmtError(); |
| 5847 | } |
| 5848 | } |
| 5849 | |
| 5850 | getCurFunction()->setHasBranchProtectedScope(); |
| 5851 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5852 | NestedLoopCount, Clauses, AStmt, |
| 5853 | B, DSAStack->isCancelRegion()); |
| 5854 | } |
| 5855 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5856 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5857 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5858 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5859 | I != E; ++I) { |
| 5860 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5861 | return true; |
| 5862 | } |
| 5863 | } |
| 5864 | |
| 5865 | return false; |
| 5866 | } |
| 5867 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5868 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5869 | Stmt *AStmt, |
| 5870 | SourceLocation StartLoc, |
| 5871 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5872 | if (!AStmt) |
| 5873 | return StmtError(); |
| 5874 | |
| 5875 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5876 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5877 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 5878 | // At least one map clause must appear on the directive. |
| 5879 | if (!HasMapClause(Clauses)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5880 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5881 | << getOpenMPDirectiveName(OMPD_target_data); |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5882 | return StmtError(); |
| 5883 | } |
| 5884 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5885 | getCurFunction()->setHasBranchProtectedScope(); |
| 5886 | |
| 5887 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5888 | AStmt); |
| 5889 | } |
| 5890 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5891 | StmtResult |
| 5892 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5893 | SourceLocation StartLoc, |
| 5894 | SourceLocation EndLoc) { |
| 5895 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5896 | // At least one map clause must appear on the directive. |
| 5897 | if (!HasMapClause(Clauses)) { |
| 5898 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5899 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5900 | return StmtError(); |
| 5901 | } |
| 5902 | |
| 5903 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5904 | Clauses); |
| 5905 | } |
| 5906 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5907 | StmtResult |
| 5908 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5909 | SourceLocation StartLoc, |
| 5910 | SourceLocation EndLoc) { |
| 5911 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5912 | // At least one map clause must appear on the directive. |
| 5913 | if (!HasMapClause(Clauses)) { |
| 5914 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5915 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5916 | return StmtError(); |
| 5917 | } |
| 5918 | |
| 5919 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5920 | } |
| 5921 | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5922 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 5923 | SourceLocation StartLoc, |
| 5924 | SourceLocation EndLoc) { |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5925 | bool seenMotionClause = false; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 5926 | for (auto *C : Clauses) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 5927 | if (C->getClauseKind() == OMPC_to || C->getClauseKind() == OMPC_from) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 5928 | seenMotionClause = true; |
| 5929 | } |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5930 | if (!seenMotionClause) { |
| 5931 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 5932 | return StmtError(); |
| 5933 | } |
| 5934 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5935 | } |
| 5936 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5937 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5938 | Stmt *AStmt, SourceLocation StartLoc, |
| 5939 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5940 | if (!AStmt) |
| 5941 | return StmtError(); |
| 5942 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5943 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5944 | // 1.2.2 OpenMP Language Terminology |
| 5945 | // Structured block - An executable statement with a single entry at the |
| 5946 | // top and a single exit at the bottom. |
| 5947 | // The point of exit cannot be a branch out of the structured block. |
| 5948 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5949 | CS->getCapturedDecl()->setNothrow(); |
| 5950 | |
| 5951 | getCurFunction()->setHasBranchProtectedScope(); |
| 5952 | |
| 5953 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5954 | } |
| 5955 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5956 | StmtResult |
| 5957 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5958 | SourceLocation EndLoc, |
| 5959 | OpenMPDirectiveKind CancelRegion) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5960 | if (DSAStack->isParentNowaitRegion()) { |
| 5961 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5962 | return StmtError(); |
| 5963 | } |
| 5964 | if (DSAStack->isParentOrderedRegion()) { |
| 5965 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5966 | return StmtError(); |
| 5967 | } |
| 5968 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5969 | CancelRegion); |
| 5970 | } |
| 5971 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5972 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5973 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5974 | SourceLocation EndLoc, |
| 5975 | OpenMPDirectiveKind CancelRegion) { |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5976 | if (DSAStack->isParentNowaitRegion()) { |
| 5977 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5978 | return StmtError(); |
| 5979 | } |
| 5980 | if (DSAStack->isParentOrderedRegion()) { |
| 5981 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5982 | return StmtError(); |
| 5983 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5984 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5985 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5986 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5987 | } |
| 5988 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5989 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5990 | ArrayRef<OMPClause *> Clauses) { |
| 5991 | OMPClause *PrevClause = nullptr; |
| 5992 | bool ErrorFound = false; |
| 5993 | for (auto *C : Clauses) { |
| 5994 | if (C->getClauseKind() == OMPC_grainsize || |
| 5995 | C->getClauseKind() == OMPC_num_tasks) { |
| 5996 | if (!PrevClause) |
| 5997 | PrevClause = C; |
| 5998 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5999 | S.Diag(C->getLocStart(), |
| 6000 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6001 | << getOpenMPClauseName(C->getClauseKind()) |
| 6002 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6003 | S.Diag(PrevClause->getLocStart(), |
| 6004 | diag::note_omp_previous_grainsize_num_tasks) |
| 6005 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6006 | ErrorFound = true; |
| 6007 | } |
| 6008 | } |
| 6009 | } |
| 6010 | return ErrorFound; |
| 6011 | } |
| 6012 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6013 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6014 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6015 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6016 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6017 | if (!AStmt) |
| 6018 | return StmtError(); |
| 6019 | |
| 6020 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6021 | OMPLoopDirective::HelperExprs B; |
| 6022 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6023 | // define the nested loops number. |
| 6024 | unsigned NestedLoopCount = |
| 6025 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6026 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6027 | VarsWithImplicitDSA, B); |
| 6028 | if (NestedLoopCount == 0) |
| 6029 | return StmtError(); |
| 6030 | |
| 6031 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6032 | "omp for loop exprs were not built"); |
| 6033 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6034 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6035 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6036 | // not appear on the same taskloop directive. |
| 6037 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6038 | return StmtError(); |
| 6039 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6040 | getCurFunction()->setHasBranchProtectedScope(); |
| 6041 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6042 | NestedLoopCount, Clauses, AStmt, B); |
| 6043 | } |
| 6044 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6045 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6046 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6047 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6048 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6049 | if (!AStmt) |
| 6050 | return StmtError(); |
| 6051 | |
| 6052 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6053 | OMPLoopDirective::HelperExprs B; |
| 6054 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6055 | // define the nested loops number. |
| 6056 | unsigned NestedLoopCount = |
| 6057 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6058 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6059 | VarsWithImplicitDSA, B); |
| 6060 | if (NestedLoopCount == 0) |
| 6061 | return StmtError(); |
| 6062 | |
| 6063 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6064 | "omp for loop exprs were not built"); |
| 6065 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6066 | if (!CurContext->isDependentContext()) { |
| 6067 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6068 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6069 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6070 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6071 | B.NumIterations, *this, CurScope, |
| 6072 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6073 | return StmtError(); |
| 6074 | } |
| 6075 | } |
| 6076 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6077 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6078 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6079 | // not appear on the same taskloop directive. |
| 6080 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6081 | return StmtError(); |
| 6082 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6083 | getCurFunction()->setHasBranchProtectedScope(); |
| 6084 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6085 | NestedLoopCount, Clauses, AStmt, B); |
| 6086 | } |
| 6087 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6088 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6089 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6090 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6091 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6092 | if (!AStmt) |
| 6093 | return StmtError(); |
| 6094 | |
| 6095 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6096 | OMPLoopDirective::HelperExprs B; |
| 6097 | // In presence of clause 'collapse' with number of loops, it will |
| 6098 | // define the nested loops number. |
| 6099 | unsigned NestedLoopCount = |
| 6100 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6101 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6102 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6103 | if (NestedLoopCount == 0) |
| 6104 | return StmtError(); |
| 6105 | |
| 6106 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6107 | "omp for loop exprs were not built"); |
| 6108 | |
| 6109 | getCurFunction()->setHasBranchProtectedScope(); |
| 6110 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6111 | NestedLoopCount, Clauses, AStmt, B); |
| 6112 | } |
| 6113 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 6114 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 6115 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6116 | SourceLocation EndLoc, |
| 6117 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6118 | if (!AStmt) |
| 6119 | return StmtError(); |
| 6120 | |
| 6121 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6122 | // 1.2.2 OpenMP Language Terminology |
| 6123 | // Structured block - An executable statement with a single entry at the |
| 6124 | // top and a single exit at the bottom. |
| 6125 | // The point of exit cannot be a branch out of the structured block. |
| 6126 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6127 | CS->getCapturedDecl()->setNothrow(); |
| 6128 | |
| 6129 | OMPLoopDirective::HelperExprs B; |
| 6130 | // In presence of clause 'collapse' with number of loops, it will |
| 6131 | // define the nested loops number. |
| 6132 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6133 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 6134 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6135 | VarsWithImplicitDSA, B); |
| 6136 | if (NestedLoopCount == 0) |
| 6137 | return StmtError(); |
| 6138 | |
| 6139 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6140 | "omp for loop exprs were not built"); |
| 6141 | |
| 6142 | getCurFunction()->setHasBranchProtectedScope(); |
| 6143 | return OMPDistributeParallelForDirective::Create( |
| 6144 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6145 | } |
| 6146 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6147 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 6148 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6149 | SourceLocation EndLoc, |
| 6150 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6151 | if (!AStmt) |
| 6152 | return StmtError(); |
| 6153 | |
| 6154 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6155 | // 1.2.2 OpenMP Language Terminology |
| 6156 | // Structured block - An executable statement with a single entry at the |
| 6157 | // top and a single exit at the bottom. |
| 6158 | // The point of exit cannot be a branch out of the structured block. |
| 6159 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6160 | CS->getCapturedDecl()->setNothrow(); |
| 6161 | |
| 6162 | OMPLoopDirective::HelperExprs B; |
| 6163 | // In presence of clause 'collapse' with number of loops, it will |
| 6164 | // define the nested loops number. |
| 6165 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6166 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6167 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6168 | VarsWithImplicitDSA, B); |
| 6169 | if (NestedLoopCount == 0) |
| 6170 | return StmtError(); |
| 6171 | |
| 6172 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6173 | "omp for loop exprs were not built"); |
| 6174 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6175 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6176 | return StmtError(); |
| 6177 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6178 | getCurFunction()->setHasBranchProtectedScope(); |
| 6179 | return OMPDistributeParallelForSimdDirective::Create( |
| 6180 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6181 | } |
| 6182 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6183 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 6184 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6185 | SourceLocation EndLoc, |
| 6186 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6187 | if (!AStmt) |
| 6188 | return StmtError(); |
| 6189 | |
| 6190 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6191 | // 1.2.2 OpenMP Language Terminology |
| 6192 | // Structured block - An executable statement with a single entry at the |
| 6193 | // top and a single exit at the bottom. |
| 6194 | // The point of exit cannot be a branch out of the structured block. |
| 6195 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6196 | CS->getCapturedDecl()->setNothrow(); |
| 6197 | |
| 6198 | OMPLoopDirective::HelperExprs B; |
| 6199 | // In presence of clause 'collapse' with number of loops, it will |
| 6200 | // define the nested loops number. |
| 6201 | unsigned NestedLoopCount = |
| 6202 | CheckOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6203 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6204 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6205 | if (NestedLoopCount == 0) |
| 6206 | return StmtError(); |
| 6207 | |
| 6208 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6209 | "omp for loop exprs were not built"); |
| 6210 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6211 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6212 | return StmtError(); |
| 6213 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6214 | getCurFunction()->setHasBranchProtectedScope(); |
| 6215 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6216 | NestedLoopCount, Clauses, AStmt, B); |
| 6217 | } |
| 6218 | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6219 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 6220 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6221 | SourceLocation EndLoc, |
| 6222 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6223 | if (!AStmt) |
| 6224 | return StmtError(); |
| 6225 | |
| 6226 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6227 | // 1.2.2 OpenMP Language Terminology |
| 6228 | // Structured block - An executable statement with a single entry at the |
| 6229 | // top and a single exit at the bottom. |
| 6230 | // The point of exit cannot be a branch out of the structured block. |
| 6231 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6232 | CS->getCapturedDecl()->setNothrow(); |
| 6233 | |
| 6234 | OMPLoopDirective::HelperExprs B; |
| 6235 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6236 | // define the nested loops number. |
| 6237 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6238 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6239 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6240 | VarsWithImplicitDSA, B); |
| 6241 | if (NestedLoopCount == 0) |
| 6242 | return StmtError(); |
| 6243 | |
| 6244 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6245 | "omp target parallel for simd loop exprs were not built"); |
| 6246 | |
| 6247 | if (!CurContext->isDependentContext()) { |
| 6248 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6249 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6250 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6251 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6252 | B.NumIterations, *this, CurScope, |
| 6253 | DSAStack)) |
| 6254 | return StmtError(); |
| 6255 | } |
| 6256 | } |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6257 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6258 | return StmtError(); |
| 6259 | |
| 6260 | getCurFunction()->setHasBranchProtectedScope(); |
| 6261 | return OMPTargetParallelForSimdDirective::Create( |
| 6262 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6263 | } |
| 6264 | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6265 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 6266 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6267 | SourceLocation EndLoc, |
| 6268 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6269 | if (!AStmt) |
| 6270 | return StmtError(); |
| 6271 | |
| 6272 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6273 | // 1.2.2 OpenMP Language Terminology |
| 6274 | // Structured block - An executable statement with a single entry at the |
| 6275 | // top and a single exit at the bottom. |
| 6276 | // The point of exit cannot be a branch out of the structured block. |
| 6277 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6278 | CS->getCapturedDecl()->setNothrow(); |
| 6279 | |
| 6280 | OMPLoopDirective::HelperExprs B; |
| 6281 | // In presence of clause 'collapse' with number of loops, it will define the |
| 6282 | // nested loops number. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6283 | unsigned NestedLoopCount = |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6284 | CheckOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| 6285 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6286 | VarsWithImplicitDSA, B); |
| 6287 | if (NestedLoopCount == 0) |
| 6288 | return StmtError(); |
| 6289 | |
| 6290 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6291 | "omp target simd loop exprs were not built"); |
| 6292 | |
| 6293 | if (!CurContext->isDependentContext()) { |
| 6294 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6295 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6296 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6297 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6298 | B.NumIterations, *this, CurScope, |
| 6299 | DSAStack)) |
| 6300 | return StmtError(); |
| 6301 | } |
| 6302 | } |
| 6303 | |
| 6304 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6305 | return StmtError(); |
| 6306 | |
| 6307 | getCurFunction()->setHasBranchProtectedScope(); |
| 6308 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6309 | NestedLoopCount, Clauses, AStmt, B); |
| 6310 | } |
| 6311 | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6312 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 6313 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6314 | SourceLocation EndLoc, |
| 6315 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6316 | if (!AStmt) |
| 6317 | return StmtError(); |
| 6318 | |
| 6319 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6320 | // 1.2.2 OpenMP Language Terminology |
| 6321 | // Structured block - An executable statement with a single entry at the |
| 6322 | // top and a single exit at the bottom. |
| 6323 | // The point of exit cannot be a branch out of the structured block. |
| 6324 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6325 | CS->getCapturedDecl()->setNothrow(); |
| 6326 | |
| 6327 | OMPLoopDirective::HelperExprs B; |
| 6328 | // In presence of clause 'collapse' with number of loops, it will |
| 6329 | // define the nested loops number. |
| 6330 | unsigned NestedLoopCount = |
| 6331 | CheckOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| 6332 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6333 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6334 | if (NestedLoopCount == 0) |
| 6335 | return StmtError(); |
| 6336 | |
| 6337 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6338 | "omp teams distribute loop exprs were not built"); |
| 6339 | |
| 6340 | getCurFunction()->setHasBranchProtectedScope(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6341 | return OMPTeamsDistributeDirective::Create( |
| 6342 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6343 | } |
| 6344 | |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6345 | StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective( |
| 6346 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6347 | SourceLocation EndLoc, |
| 6348 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6349 | if (!AStmt) |
| 6350 | return StmtError(); |
| 6351 | |
| 6352 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6353 | // 1.2.2 OpenMP Language Terminology |
| 6354 | // Structured block - An executable statement with a single entry at the |
| 6355 | // top and a single exit at the bottom. |
| 6356 | // The point of exit cannot be a branch out of the structured block. |
| 6357 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6358 | CS->getCapturedDecl()->setNothrow(); |
| 6359 | |
| 6360 | OMPLoopDirective::HelperExprs B; |
| 6361 | // In presence of clause 'collapse' with number of loops, it will |
| 6362 | // define the nested loops number. |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 6363 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6364 | OMPD_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6365 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6366 | VarsWithImplicitDSA, B); |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6367 | |
| 6368 | if (NestedLoopCount == 0) |
| 6369 | return StmtError(); |
| 6370 | |
| 6371 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6372 | "omp teams distribute simd loop exprs were not built"); |
| 6373 | |
| 6374 | if (!CurContext->isDependentContext()) { |
| 6375 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6376 | for (auto C : Clauses) { |
| 6377 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6378 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6379 | B.NumIterations, *this, CurScope, |
| 6380 | DSAStack)) |
| 6381 | return StmtError(); |
| 6382 | } |
| 6383 | } |
| 6384 | |
| 6385 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6386 | return StmtError(); |
| 6387 | |
| 6388 | getCurFunction()->setHasBranchProtectedScope(); |
| 6389 | return OMPTeamsDistributeSimdDirective::Create( |
| 6390 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6391 | } |
| 6392 | |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 6393 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 6394 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6395 | SourceLocation EndLoc, |
| 6396 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6397 | if (!AStmt) |
| 6398 | return StmtError(); |
| 6399 | |
| 6400 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6401 | // 1.2.2 OpenMP Language Terminology |
| 6402 | // Structured block - An executable statement with a single entry at the |
| 6403 | // top and a single exit at the bottom. |
| 6404 | // The point of exit cannot be a branch out of the structured block. |
| 6405 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6406 | CS->getCapturedDecl()->setNothrow(); |
| 6407 | |
| 6408 | OMPLoopDirective::HelperExprs B; |
| 6409 | // In presence of clause 'collapse' with number of loops, it will |
| 6410 | // define the nested loops number. |
| 6411 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6412 | OMPD_teams_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6413 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6414 | VarsWithImplicitDSA, B); |
| 6415 | |
| 6416 | if (NestedLoopCount == 0) |
| 6417 | return StmtError(); |
| 6418 | |
| 6419 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6420 | "omp for loop exprs were not built"); |
| 6421 | |
| 6422 | if (!CurContext->isDependentContext()) { |
| 6423 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6424 | for (auto C : Clauses) { |
| 6425 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6426 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6427 | B.NumIterations, *this, CurScope, |
| 6428 | DSAStack)) |
| 6429 | return StmtError(); |
| 6430 | } |
| 6431 | } |
| 6432 | |
| 6433 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6434 | return StmtError(); |
| 6435 | |
| 6436 | getCurFunction()->setHasBranchProtectedScope(); |
| 6437 | return OMPTeamsDistributeParallelForSimdDirective::Create( |
| 6438 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6439 | } |
| 6440 | |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 6441 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective( |
| 6442 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6443 | SourceLocation EndLoc, |
| 6444 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6445 | if (!AStmt) |
| 6446 | return StmtError(); |
| 6447 | |
| 6448 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6449 | // 1.2.2 OpenMP Language Terminology |
| 6450 | // Structured block - An executable statement with a single entry at the |
| 6451 | // top and a single exit at the bottom. |
| 6452 | // The point of exit cannot be a branch out of the structured block. |
| 6453 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6454 | CS->getCapturedDecl()->setNothrow(); |
| 6455 | |
| 6456 | OMPLoopDirective::HelperExprs B; |
| 6457 | // In presence of clause 'collapse' with number of loops, it will |
| 6458 | // define the nested loops number. |
| 6459 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6460 | OMPD_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 6461 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6462 | VarsWithImplicitDSA, B); |
| 6463 | |
| 6464 | if (NestedLoopCount == 0) |
| 6465 | return StmtError(); |
| 6466 | |
| 6467 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6468 | "omp for loop exprs were not built"); |
| 6469 | |
| 6470 | if (!CurContext->isDependentContext()) { |
| 6471 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6472 | for (auto C : Clauses) { |
| 6473 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6474 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6475 | B.NumIterations, *this, CurScope, |
| 6476 | DSAStack)) |
| 6477 | return StmtError(); |
| 6478 | } |
| 6479 | } |
| 6480 | |
| 6481 | getCurFunction()->setHasBranchProtectedScope(); |
| 6482 | return OMPTeamsDistributeParallelForDirective::Create( |
| 6483 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6484 | } |
| 6485 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 6486 | StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6487 | Stmt *AStmt, |
| 6488 | SourceLocation StartLoc, |
| 6489 | SourceLocation EndLoc) { |
| 6490 | if (!AStmt) |
| 6491 | return StmtError(); |
| 6492 | |
| 6493 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6494 | // 1.2.2 OpenMP Language Terminology |
| 6495 | // Structured block - An executable statement with a single entry at the |
| 6496 | // top and a single exit at the bottom. |
| 6497 | // The point of exit cannot be a branch out of the structured block. |
| 6498 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6499 | CS->getCapturedDecl()->setNothrow(); |
| 6500 | |
| 6501 | getCurFunction()->setHasBranchProtectedScope(); |
| 6502 | |
| 6503 | return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6504 | AStmt); |
| 6505 | } |
| 6506 | |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 6507 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeDirective( |
| 6508 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6509 | SourceLocation EndLoc, |
| 6510 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6511 | if (!AStmt) |
| 6512 | return StmtError(); |
| 6513 | |
| 6514 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6515 | // 1.2.2 OpenMP Language Terminology |
| 6516 | // Structured block - An executable statement with a single entry at the |
| 6517 | // top and a single exit at the bottom. |
| 6518 | // The point of exit cannot be a branch out of the structured block. |
| 6519 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6520 | CS->getCapturedDecl()->setNothrow(); |
| 6521 | |
| 6522 | OMPLoopDirective::HelperExprs B; |
| 6523 | // In presence of clause 'collapse' with number of loops, it will |
| 6524 | // define the nested loops number. |
| 6525 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6526 | OMPD_target_teams_distribute, |
| 6527 | getCollapseNumberExpr(Clauses), |
| 6528 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6529 | VarsWithImplicitDSA, B); |
| 6530 | if (NestedLoopCount == 0) |
| 6531 | return StmtError(); |
| 6532 | |
| 6533 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6534 | "omp target teams distribute loop exprs were not built"); |
| 6535 | |
| 6536 | getCurFunction()->setHasBranchProtectedScope(); |
| 6537 | return OMPTargetTeamsDistributeDirective::Create( |
| 6538 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6539 | } |
| 6540 | |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 6541 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 6542 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6543 | SourceLocation EndLoc, |
| 6544 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6545 | if (!AStmt) |
| 6546 | return StmtError(); |
| 6547 | |
| 6548 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6549 | // 1.2.2 OpenMP Language Terminology |
| 6550 | // Structured block - An executable statement with a single entry at the |
| 6551 | // top and a single exit at the bottom. |
| 6552 | // The point of exit cannot be a branch out of the structured block. |
| 6553 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6554 | CS->getCapturedDecl()->setNothrow(); |
| 6555 | |
| 6556 | OMPLoopDirective::HelperExprs B; |
| 6557 | // In presence of clause 'collapse' with number of loops, it will |
| 6558 | // define the nested loops number. |
| 6559 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6560 | OMPD_target_teams_distribute_parallel_for, |
| 6561 | getCollapseNumberExpr(Clauses), |
| 6562 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6563 | VarsWithImplicitDSA, B); |
| 6564 | if (NestedLoopCount == 0) |
| 6565 | return StmtError(); |
| 6566 | |
| 6567 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6568 | "omp target teams distribute parallel for loop exprs were not built"); |
| 6569 | |
| 6570 | if (!CurContext->isDependentContext()) { |
| 6571 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6572 | for (auto C : Clauses) { |
| 6573 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6574 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6575 | B.NumIterations, *this, CurScope, |
| 6576 | DSAStack)) |
| 6577 | return StmtError(); |
| 6578 | } |
| 6579 | } |
| 6580 | |
| 6581 | getCurFunction()->setHasBranchProtectedScope(); |
| 6582 | return OMPTargetTeamsDistributeParallelForDirective::Create( |
| 6583 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6584 | } |
| 6585 | |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 6586 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 6587 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6588 | SourceLocation EndLoc, |
| 6589 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6590 | if (!AStmt) |
| 6591 | return StmtError(); |
| 6592 | |
| 6593 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6594 | // 1.2.2 OpenMP Language Terminology |
| 6595 | // Structured block - An executable statement with a single entry at the |
| 6596 | // top and a single exit at the bottom. |
| 6597 | // The point of exit cannot be a branch out of the structured block. |
| 6598 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6599 | CS->getCapturedDecl()->setNothrow(); |
| 6600 | |
| 6601 | OMPLoopDirective::HelperExprs B; |
| 6602 | // In presence of clause 'collapse' with number of loops, it will |
| 6603 | // define the nested loops number. |
| 6604 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6605 | OMPD_target_teams_distribute_parallel_for_simd, |
| 6606 | getCollapseNumberExpr(Clauses), |
| 6607 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6608 | VarsWithImplicitDSA, B); |
| 6609 | if (NestedLoopCount == 0) |
| 6610 | return StmtError(); |
| 6611 | |
| 6612 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6613 | "omp target teams distribute parallel for simd loop exprs were not " |
| 6614 | "built"); |
| 6615 | |
| 6616 | if (!CurContext->isDependentContext()) { |
| 6617 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6618 | for (auto C : Clauses) { |
| 6619 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6620 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6621 | B.NumIterations, *this, CurScope, |
| 6622 | DSAStack)) |
| 6623 | return StmtError(); |
| 6624 | } |
| 6625 | } |
| 6626 | |
| 6627 | getCurFunction()->setHasBranchProtectedScope(); |
| 6628 | return OMPTargetTeamsDistributeParallelForSimdDirective::Create( |
| 6629 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6630 | } |
| 6631 | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 6632 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 6633 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6634 | SourceLocation EndLoc, |
| 6635 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6636 | if (!AStmt) |
| 6637 | return StmtError(); |
| 6638 | |
| 6639 | auto *CS = cast<CapturedStmt>(AStmt); |
| 6640 | // 1.2.2 OpenMP Language Terminology |
| 6641 | // Structured block - An executable statement with a single entry at the |
| 6642 | // top and a single exit at the bottom. |
| 6643 | // The point of exit cannot be a branch out of the structured block. |
| 6644 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6645 | CS->getCapturedDecl()->setNothrow(); |
| 6646 | |
| 6647 | OMPLoopDirective::HelperExprs B; |
| 6648 | // In presence of clause 'collapse' with number of loops, it will |
| 6649 | // define the nested loops number. |
| 6650 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6651 | OMPD_target_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6652 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6653 | VarsWithImplicitDSA, B); |
| 6654 | if (NestedLoopCount == 0) |
| 6655 | return StmtError(); |
| 6656 | |
| 6657 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6658 | "omp target teams distribute simd loop exprs were not built"); |
| 6659 | |
| 6660 | getCurFunction()->setHasBranchProtectedScope(); |
| 6661 | return OMPTargetTeamsDistributeSimdDirective::Create( |
| 6662 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6663 | } |
| 6664 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6665 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6666 | SourceLocation StartLoc, |
| 6667 | SourceLocation LParenLoc, |
| 6668 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6669 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6670 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6671 | case OMPC_final: |
| 6672 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6673 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6674 | case OMPC_num_threads: |
| 6675 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6676 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6677 | case OMPC_safelen: |
| 6678 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6679 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6680 | case OMPC_simdlen: |
| 6681 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6682 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6683 | case OMPC_collapse: |
| 6684 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6685 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6686 | case OMPC_ordered: |
| 6687 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6688 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6689 | case OMPC_device: |
| 6690 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6691 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6692 | case OMPC_num_teams: |
| 6693 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6694 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6695 | case OMPC_thread_limit: |
| 6696 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6697 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6698 | case OMPC_priority: |
| 6699 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6700 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6701 | case OMPC_grainsize: |
| 6702 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6703 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6704 | case OMPC_num_tasks: |
| 6705 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6706 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6707 | case OMPC_hint: |
| 6708 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6709 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6710 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6711 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6712 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6713 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6714 | case OMPC_private: |
| 6715 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6716 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6717 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6718 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6719 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6720 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6721 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6722 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6723 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6724 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6725 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6726 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6727 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6728 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6729 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6730 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6731 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6732 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6733 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6734 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6735 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6736 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6737 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6738 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6739 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6740 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6741 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6742 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6743 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 6744 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 6745 | case OMPC_is_device_ptr: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6746 | llvm_unreachable("Clause is not allowed."); |
| 6747 | } |
| 6748 | return Res; |
| 6749 | } |
| 6750 | |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 6751 | // An OpenMP directive such as 'target parallel' has two captured regions: |
| 6752 | // for the 'target' and 'parallel' respectively. This function returns |
| 6753 | // the region in which to capture expressions associated with a clause. |
| 6754 | // A return value of OMPD_unknown signifies that the expression should not |
| 6755 | // be captured. |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 6756 | static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( |
| 6757 | OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
| 6758 | OpenMPDirectiveKind NameModifier = OMPD_unknown) { |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 6759 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| 6760 | |
| 6761 | switch (CKind) { |
| 6762 | case OMPC_if: |
| 6763 | switch (DKind) { |
| 6764 | case OMPD_target_parallel: |
| 6765 | // If this clause applies to the nested 'parallel' region, capture within |
| 6766 | // the 'target' region, otherwise do not capture. |
| 6767 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 6768 | CaptureRegion = OMPD_target; |
| 6769 | break; |
| 6770 | case OMPD_cancel: |
| 6771 | case OMPD_parallel: |
| 6772 | case OMPD_parallel_sections: |
| 6773 | case OMPD_parallel_for: |
| 6774 | case OMPD_parallel_for_simd: |
| 6775 | case OMPD_target: |
| 6776 | case OMPD_target_simd: |
| 6777 | case OMPD_target_parallel_for: |
| 6778 | case OMPD_target_parallel_for_simd: |
| 6779 | case OMPD_target_teams: |
| 6780 | case OMPD_target_teams_distribute: |
| 6781 | case OMPD_target_teams_distribute_simd: |
| 6782 | case OMPD_target_teams_distribute_parallel_for: |
| 6783 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 6784 | case OMPD_teams_distribute_parallel_for: |
| 6785 | case OMPD_teams_distribute_parallel_for_simd: |
| 6786 | case OMPD_distribute_parallel_for: |
| 6787 | case OMPD_distribute_parallel_for_simd: |
| 6788 | case OMPD_task: |
| 6789 | case OMPD_taskloop: |
| 6790 | case OMPD_taskloop_simd: |
| 6791 | case OMPD_target_data: |
| 6792 | case OMPD_target_enter_data: |
| 6793 | case OMPD_target_exit_data: |
| 6794 | case OMPD_target_update: |
| 6795 | // Do not capture if-clause expressions. |
| 6796 | break; |
| 6797 | case OMPD_threadprivate: |
| 6798 | case OMPD_taskyield: |
| 6799 | case OMPD_barrier: |
| 6800 | case OMPD_taskwait: |
| 6801 | case OMPD_cancellation_point: |
| 6802 | case OMPD_flush: |
| 6803 | case OMPD_declare_reduction: |
| 6804 | case OMPD_declare_simd: |
| 6805 | case OMPD_declare_target: |
| 6806 | case OMPD_end_declare_target: |
| 6807 | case OMPD_teams: |
| 6808 | case OMPD_simd: |
| 6809 | case OMPD_for: |
| 6810 | case OMPD_for_simd: |
| 6811 | case OMPD_sections: |
| 6812 | case OMPD_section: |
| 6813 | case OMPD_single: |
| 6814 | case OMPD_master: |
| 6815 | case OMPD_critical: |
| 6816 | case OMPD_taskgroup: |
| 6817 | case OMPD_distribute: |
| 6818 | case OMPD_ordered: |
| 6819 | case OMPD_atomic: |
| 6820 | case OMPD_distribute_simd: |
| 6821 | case OMPD_teams_distribute: |
| 6822 | case OMPD_teams_distribute_simd: |
| 6823 | llvm_unreachable("Unexpected OpenMP directive with if-clause"); |
| 6824 | case OMPD_unknown: |
| 6825 | llvm_unreachable("Unknown OpenMP directive"); |
| 6826 | } |
| 6827 | break; |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 6828 | case OMPC_num_threads: |
| 6829 | switch (DKind) { |
| 6830 | case OMPD_target_parallel: |
| 6831 | CaptureRegion = OMPD_target; |
| 6832 | break; |
| 6833 | case OMPD_cancel: |
| 6834 | case OMPD_parallel: |
| 6835 | case OMPD_parallel_sections: |
| 6836 | case OMPD_parallel_for: |
| 6837 | case OMPD_parallel_for_simd: |
| 6838 | case OMPD_target: |
| 6839 | case OMPD_target_simd: |
| 6840 | case OMPD_target_parallel_for: |
| 6841 | case OMPD_target_parallel_for_simd: |
| 6842 | case OMPD_target_teams: |
| 6843 | case OMPD_target_teams_distribute: |
| 6844 | case OMPD_target_teams_distribute_simd: |
| 6845 | case OMPD_target_teams_distribute_parallel_for: |
| 6846 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 6847 | case OMPD_teams_distribute_parallel_for: |
| 6848 | case OMPD_teams_distribute_parallel_for_simd: |
| 6849 | case OMPD_distribute_parallel_for: |
| 6850 | case OMPD_distribute_parallel_for_simd: |
| 6851 | case OMPD_task: |
| 6852 | case OMPD_taskloop: |
| 6853 | case OMPD_taskloop_simd: |
| 6854 | case OMPD_target_data: |
| 6855 | case OMPD_target_enter_data: |
| 6856 | case OMPD_target_exit_data: |
| 6857 | case OMPD_target_update: |
| 6858 | // Do not capture num_threads-clause expressions. |
| 6859 | break; |
| 6860 | case OMPD_threadprivate: |
| 6861 | case OMPD_taskyield: |
| 6862 | case OMPD_barrier: |
| 6863 | case OMPD_taskwait: |
| 6864 | case OMPD_cancellation_point: |
| 6865 | case OMPD_flush: |
| 6866 | case OMPD_declare_reduction: |
| 6867 | case OMPD_declare_simd: |
| 6868 | case OMPD_declare_target: |
| 6869 | case OMPD_end_declare_target: |
| 6870 | case OMPD_teams: |
| 6871 | case OMPD_simd: |
| 6872 | case OMPD_for: |
| 6873 | case OMPD_for_simd: |
| 6874 | case OMPD_sections: |
| 6875 | case OMPD_section: |
| 6876 | case OMPD_single: |
| 6877 | case OMPD_master: |
| 6878 | case OMPD_critical: |
| 6879 | case OMPD_taskgroup: |
| 6880 | case OMPD_distribute: |
| 6881 | case OMPD_ordered: |
| 6882 | case OMPD_atomic: |
| 6883 | case OMPD_distribute_simd: |
| 6884 | case OMPD_teams_distribute: |
| 6885 | case OMPD_teams_distribute_simd: |
| 6886 | llvm_unreachable("Unexpected OpenMP directive with num_threads-clause"); |
| 6887 | case OMPD_unknown: |
| 6888 | llvm_unreachable("Unknown OpenMP directive"); |
| 6889 | } |
| 6890 | break; |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 6891 | case OMPC_num_teams: |
| 6892 | switch (DKind) { |
| 6893 | case OMPD_target_teams: |
| 6894 | CaptureRegion = OMPD_target; |
| 6895 | break; |
| 6896 | case OMPD_cancel: |
| 6897 | case OMPD_parallel: |
| 6898 | case OMPD_parallel_sections: |
| 6899 | case OMPD_parallel_for: |
| 6900 | case OMPD_parallel_for_simd: |
| 6901 | case OMPD_target: |
| 6902 | case OMPD_target_simd: |
| 6903 | case OMPD_target_parallel: |
| 6904 | case OMPD_target_parallel_for: |
| 6905 | case OMPD_target_parallel_for_simd: |
| 6906 | case OMPD_target_teams_distribute: |
| 6907 | case OMPD_target_teams_distribute_simd: |
| 6908 | case OMPD_target_teams_distribute_parallel_for: |
| 6909 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 6910 | case OMPD_teams_distribute_parallel_for: |
| 6911 | case OMPD_teams_distribute_parallel_for_simd: |
| 6912 | case OMPD_distribute_parallel_for: |
| 6913 | case OMPD_distribute_parallel_for_simd: |
| 6914 | case OMPD_task: |
| 6915 | case OMPD_taskloop: |
| 6916 | case OMPD_taskloop_simd: |
| 6917 | case OMPD_target_data: |
| 6918 | case OMPD_target_enter_data: |
| 6919 | case OMPD_target_exit_data: |
| 6920 | case OMPD_target_update: |
| 6921 | case OMPD_teams: |
| 6922 | case OMPD_teams_distribute: |
| 6923 | case OMPD_teams_distribute_simd: |
| 6924 | // Do not capture num_teams-clause expressions. |
| 6925 | break; |
| 6926 | case OMPD_threadprivate: |
| 6927 | case OMPD_taskyield: |
| 6928 | case OMPD_barrier: |
| 6929 | case OMPD_taskwait: |
| 6930 | case OMPD_cancellation_point: |
| 6931 | case OMPD_flush: |
| 6932 | case OMPD_declare_reduction: |
| 6933 | case OMPD_declare_simd: |
| 6934 | case OMPD_declare_target: |
| 6935 | case OMPD_end_declare_target: |
| 6936 | case OMPD_simd: |
| 6937 | case OMPD_for: |
| 6938 | case OMPD_for_simd: |
| 6939 | case OMPD_sections: |
| 6940 | case OMPD_section: |
| 6941 | case OMPD_single: |
| 6942 | case OMPD_master: |
| 6943 | case OMPD_critical: |
| 6944 | case OMPD_taskgroup: |
| 6945 | case OMPD_distribute: |
| 6946 | case OMPD_ordered: |
| 6947 | case OMPD_atomic: |
| 6948 | case OMPD_distribute_simd: |
| 6949 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 6950 | case OMPD_unknown: |
| 6951 | llvm_unreachable("Unknown OpenMP directive"); |
| 6952 | } |
| 6953 | break; |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 6954 | case OMPC_thread_limit: |
| 6955 | switch (DKind) { |
| 6956 | case OMPD_target_teams: |
| 6957 | CaptureRegion = OMPD_target; |
| 6958 | break; |
| 6959 | case OMPD_cancel: |
| 6960 | case OMPD_parallel: |
| 6961 | case OMPD_parallel_sections: |
| 6962 | case OMPD_parallel_for: |
| 6963 | case OMPD_parallel_for_simd: |
| 6964 | case OMPD_target: |
| 6965 | case OMPD_target_simd: |
| 6966 | case OMPD_target_parallel: |
| 6967 | case OMPD_target_parallel_for: |
| 6968 | case OMPD_target_parallel_for_simd: |
| 6969 | case OMPD_target_teams_distribute: |
| 6970 | case OMPD_target_teams_distribute_simd: |
| 6971 | case OMPD_target_teams_distribute_parallel_for: |
| 6972 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 6973 | case OMPD_teams_distribute_parallel_for: |
| 6974 | case OMPD_teams_distribute_parallel_for_simd: |
| 6975 | case OMPD_distribute_parallel_for: |
| 6976 | case OMPD_distribute_parallel_for_simd: |
| 6977 | case OMPD_task: |
| 6978 | case OMPD_taskloop: |
| 6979 | case OMPD_taskloop_simd: |
| 6980 | case OMPD_target_data: |
| 6981 | case OMPD_target_enter_data: |
| 6982 | case OMPD_target_exit_data: |
| 6983 | case OMPD_target_update: |
| 6984 | case OMPD_teams: |
| 6985 | case OMPD_teams_distribute: |
| 6986 | case OMPD_teams_distribute_simd: |
| 6987 | // Do not capture thread_limit-clause expressions. |
| 6988 | break; |
| 6989 | case OMPD_threadprivate: |
| 6990 | case OMPD_taskyield: |
| 6991 | case OMPD_barrier: |
| 6992 | case OMPD_taskwait: |
| 6993 | case OMPD_cancellation_point: |
| 6994 | case OMPD_flush: |
| 6995 | case OMPD_declare_reduction: |
| 6996 | case OMPD_declare_simd: |
| 6997 | case OMPD_declare_target: |
| 6998 | case OMPD_end_declare_target: |
| 6999 | case OMPD_simd: |
| 7000 | case OMPD_for: |
| 7001 | case OMPD_for_simd: |
| 7002 | case OMPD_sections: |
| 7003 | case OMPD_section: |
| 7004 | case OMPD_single: |
| 7005 | case OMPD_master: |
| 7006 | case OMPD_critical: |
| 7007 | case OMPD_taskgroup: |
| 7008 | case OMPD_distribute: |
| 7009 | case OMPD_ordered: |
| 7010 | case OMPD_atomic: |
| 7011 | case OMPD_distribute_simd: |
| 7012 | llvm_unreachable("Unexpected OpenMP directive with thread_limit-clause"); |
| 7013 | case OMPD_unknown: |
| 7014 | llvm_unreachable("Unknown OpenMP directive"); |
| 7015 | } |
| 7016 | break; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7017 | case OMPC_schedule: |
| 7018 | case OMPC_dist_schedule: |
| 7019 | case OMPC_firstprivate: |
| 7020 | case OMPC_lastprivate: |
| 7021 | case OMPC_reduction: |
| 7022 | case OMPC_linear: |
| 7023 | case OMPC_default: |
| 7024 | case OMPC_proc_bind: |
| 7025 | case OMPC_final: |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7026 | case OMPC_safelen: |
| 7027 | case OMPC_simdlen: |
| 7028 | case OMPC_collapse: |
| 7029 | case OMPC_private: |
| 7030 | case OMPC_shared: |
| 7031 | case OMPC_aligned: |
| 7032 | case OMPC_copyin: |
| 7033 | case OMPC_copyprivate: |
| 7034 | case OMPC_ordered: |
| 7035 | case OMPC_nowait: |
| 7036 | case OMPC_untied: |
| 7037 | case OMPC_mergeable: |
| 7038 | case OMPC_threadprivate: |
| 7039 | case OMPC_flush: |
| 7040 | case OMPC_read: |
| 7041 | case OMPC_write: |
| 7042 | case OMPC_update: |
| 7043 | case OMPC_capture: |
| 7044 | case OMPC_seq_cst: |
| 7045 | case OMPC_depend: |
| 7046 | case OMPC_device: |
| 7047 | case OMPC_threads: |
| 7048 | case OMPC_simd: |
| 7049 | case OMPC_map: |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7050 | case OMPC_priority: |
| 7051 | case OMPC_grainsize: |
| 7052 | case OMPC_nogroup: |
| 7053 | case OMPC_num_tasks: |
| 7054 | case OMPC_hint: |
| 7055 | case OMPC_defaultmap: |
| 7056 | case OMPC_unknown: |
| 7057 | case OMPC_uniform: |
| 7058 | case OMPC_to: |
| 7059 | case OMPC_from: |
| 7060 | case OMPC_use_device_ptr: |
| 7061 | case OMPC_is_device_ptr: |
| 7062 | llvm_unreachable("Unexpected OpenMP clause."); |
| 7063 | } |
| 7064 | return CaptureRegion; |
| 7065 | } |
| 7066 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7067 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 7068 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7069 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7070 | SourceLocation NameModifierLoc, |
| 7071 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7072 | SourceLocation EndLoc) { |
| 7073 | Expr *ValExpr = Condition; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7074 | Stmt *HelperValStmt = nullptr; |
| 7075 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7076 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7077 | !Condition->isInstantiationDependent() && |
| 7078 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7079 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7080 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7081 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7082 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7083 | ValExpr = MakeFullExpr(Val.get()).get(); |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7084 | |
| 7085 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 7086 | CaptureRegion = |
| 7087 | getOpenMPCaptureRegionForClause(DKind, OMPC_if, NameModifier); |
| 7088 | if (CaptureRegion != OMPD_unknown) { |
| 7089 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7090 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7091 | HelperValStmt = buildPreInits(Context, Captures); |
| 7092 | } |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7093 | } |
| 7094 | |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7095 | return new (Context) |
| 7096 | OMPIfClause(NameModifier, ValExpr, HelperValStmt, CaptureRegion, StartLoc, |
| 7097 | LParenLoc, NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7098 | } |
| 7099 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7100 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 7101 | SourceLocation StartLoc, |
| 7102 | SourceLocation LParenLoc, |
| 7103 | SourceLocation EndLoc) { |
| 7104 | Expr *ValExpr = Condition; |
| 7105 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7106 | !Condition->isInstantiationDependent() && |
| 7107 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7108 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7109 | if (Val.isInvalid()) |
| 7110 | return nullptr; |
| 7111 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7112 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7113 | } |
| 7114 | |
| 7115 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7116 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7117 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 7118 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7119 | if (!Op) |
| 7120 | return ExprError(); |
| 7121 | |
| 7122 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 7123 | public: |
| 7124 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7125 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 7126 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 7127 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7128 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 7129 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7130 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 7131 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7132 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 7133 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7134 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 7135 | QualType T, |
| 7136 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7137 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 7138 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7139 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 7140 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7141 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7142 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7143 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7144 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 7145 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7146 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 7147 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7148 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 7149 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7150 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7151 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7152 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7153 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 7154 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7155 | llvm_unreachable("conversion functions are permitted"); |
| 7156 | } |
| 7157 | } ConvertDiagnoser; |
| 7158 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 7159 | } |
| 7160 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7161 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7162 | OpenMPClauseKind CKind, |
| 7163 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7164 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7165 | !ValExpr->isInstantiationDependent()) { |
| 7166 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7167 | ExprResult Value = |
| 7168 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7169 | if (Value.isInvalid()) |
| 7170 | return false; |
| 7171 | |
| 7172 | ValExpr = Value.get(); |
| 7173 | // The expression must evaluate to a non-negative integer value. |
| 7174 | llvm::APSInt Result; |
| 7175 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7176 | Result.isSigned() && |
| 7177 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 7178 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7179 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7180 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7181 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7182 | return false; |
| 7183 | } |
| 7184 | } |
| 7185 | return true; |
| 7186 | } |
| 7187 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7188 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 7189 | SourceLocation StartLoc, |
| 7190 | SourceLocation LParenLoc, |
| 7191 | SourceLocation EndLoc) { |
| 7192 | Expr *ValExpr = NumThreads; |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7193 | Stmt *HelperValStmt = nullptr; |
| 7194 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7195 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7196 | // OpenMP [2.5, Restrictions] |
| 7197 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7198 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 7199 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7200 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7201 | |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7202 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 7203 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_num_threads); |
| 7204 | if (CaptureRegion != OMPD_unknown) { |
| 7205 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7206 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7207 | HelperValStmt = buildPreInits(Context, Captures); |
| 7208 | } |
| 7209 | |
| 7210 | return new (Context) OMPNumThreadsClause( |
| 7211 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7212 | } |
| 7213 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7214 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7215 | OpenMPClauseKind CKind, |
| 7216 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7217 | if (!E) |
| 7218 | return ExprError(); |
| 7219 | if (E->isValueDependent() || E->isTypeDependent() || |
| 7220 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7221 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7222 | llvm::APSInt Result; |
| 7223 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 7224 | if (ICE.isInvalid()) |
| 7225 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7226 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 7227 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7228 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7229 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7230 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7231 | return ExprError(); |
| 7232 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 7233 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 7234 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 7235 | << E->getSourceRange(); |
| 7236 | return ExprError(); |
| 7237 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7238 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 7239 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 7240 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7241 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7242 | return ICE; |
| 7243 | } |
| 7244 | |
| 7245 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 7246 | SourceLocation LParenLoc, |
| 7247 | SourceLocation EndLoc) { |
| 7248 | // OpenMP [2.8.1, simd construct, Description] |
| 7249 | // The parameter of the safelen clause must be a constant |
| 7250 | // positive integer expression. |
| 7251 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 7252 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7253 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7254 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7255 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7256 | } |
| 7257 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7258 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 7259 | SourceLocation LParenLoc, |
| 7260 | SourceLocation EndLoc) { |
| 7261 | // OpenMP [2.8.1, simd construct, Description] |
| 7262 | // The parameter of the simdlen clause must be a constant |
| 7263 | // positive integer expression. |
| 7264 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 7265 | if (Simdlen.isInvalid()) |
| 7266 | return nullptr; |
| 7267 | return new (Context) |
| 7268 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 7269 | } |
| 7270 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7271 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 7272 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7273 | SourceLocation LParenLoc, |
| 7274 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7275 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7276 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7277 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7278 | // The parameter of the collapse clause must be a constant |
| 7279 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7280 | ExprResult NumForLoopsResult = |
| 7281 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 7282 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7283 | return nullptr; |
| 7284 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7285 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7286 | } |
| 7287 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7288 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 7289 | SourceLocation EndLoc, |
| 7290 | SourceLocation LParenLoc, |
| 7291 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7292 | // OpenMP [2.7.1, loop construct, Description] |
| 7293 | // OpenMP [2.8.1, simd construct, Description] |
| 7294 | // OpenMP [2.9.6, distribute construct, Description] |
| 7295 | // The parameter of the ordered clause must be a constant |
| 7296 | // positive integer expression if any. |
| 7297 | if (NumForLoops && LParenLoc.isValid()) { |
| 7298 | ExprResult NumForLoopsResult = |
| 7299 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 7300 | if (NumForLoopsResult.isInvalid()) |
| 7301 | return nullptr; |
| 7302 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7303 | } else |
| 7304 | NumForLoops = nullptr; |
| 7305 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7306 | return new (Context) |
| 7307 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 7308 | } |
| 7309 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7310 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 7311 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 7312 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7313 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7314 | switch (Kind) { |
| 7315 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7316 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7317 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 7318 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7319 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7320 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7321 | Res = ActOnOpenMPProcBindClause( |
| 7322 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 7323 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7324 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7325 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7326 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7327 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7328 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7329 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7330 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7331 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7332 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7333 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7334 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7335 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7336 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7337 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7338 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7339 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7340 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7341 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7342 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7343 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7344 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7345 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7346 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7347 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7348 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7349 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7350 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7351 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7352 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7353 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7354 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7355 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7356 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7357 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7358 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7359 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7360 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7361 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7362 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7363 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7364 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7365 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7366 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7367 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7368 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7369 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7370 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7371 | case OMPC_is_device_ptr: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7372 | llvm_unreachable("Clause is not allowed."); |
| 7373 | } |
| 7374 | return Res; |
| 7375 | } |
| 7376 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7377 | static std::string |
| 7378 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 7379 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 7380 | std::string Values; |
| 7381 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 7382 | unsigned Skipped = Exclude.size(); |
| 7383 | auto S = Exclude.begin(), E = Exclude.end(); |
| 7384 | for (unsigned i = First; i < Last; ++i) { |
| 7385 | if (std::find(S, E, i) != E) { |
| 7386 | --Skipped; |
| 7387 | continue; |
| 7388 | } |
| 7389 | Values += "'"; |
| 7390 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 7391 | Values += "'"; |
| 7392 | if (i == Bound - Skipped) |
| 7393 | Values += " or "; |
| 7394 | else if (i != Bound + 1 - Skipped) |
| 7395 | Values += ", "; |
| 7396 | } |
| 7397 | return Values; |
| 7398 | } |
| 7399 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7400 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 7401 | SourceLocation KindKwLoc, |
| 7402 | SourceLocation StartLoc, |
| 7403 | SourceLocation LParenLoc, |
| 7404 | SourceLocation EndLoc) { |
| 7405 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 7406 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 7407 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7408 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7409 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 7410 | /*Last=*/OMPC_DEFAULT_unknown) |
| 7411 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7412 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7413 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7414 | switch (Kind) { |
| 7415 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7416 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7417 | break; |
| 7418 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7419 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7420 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7421 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7422 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7423 | break; |
| 7424 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7425 | return new (Context) |
| 7426 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7427 | } |
| 7428 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7429 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 7430 | SourceLocation KindKwLoc, |
| 7431 | SourceLocation StartLoc, |
| 7432 | SourceLocation LParenLoc, |
| 7433 | SourceLocation EndLoc) { |
| 7434 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7435 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7436 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 7437 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 7438 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7439 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7440 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7441 | return new (Context) |
| 7442 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7443 | } |
| 7444 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7445 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7446 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7447 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7448 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7449 | SourceLocation EndLoc) { |
| 7450 | OMPClause *Res = nullptr; |
| 7451 | switch (Kind) { |
| 7452 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7453 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 7454 | assert(Argument.size() == NumberOfElements && |
| 7455 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7456 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7457 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 7458 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 7459 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 7460 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 7461 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7462 | break; |
| 7463 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7464 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 7465 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 7466 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 7467 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7468 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7469 | case OMPC_dist_schedule: |
| 7470 | Res = ActOnOpenMPDistScheduleClause( |
| 7471 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 7472 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 7473 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7474 | case OMPC_defaultmap: |
| 7475 | enum { Modifier, DefaultmapKind }; |
| 7476 | Res = ActOnOpenMPDefaultmapClause( |
| 7477 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7478 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7479 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 7480 | EndLoc); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7481 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7482 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7483 | case OMPC_num_threads: |
| 7484 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7485 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7486 | case OMPC_collapse: |
| 7487 | case OMPC_default: |
| 7488 | case OMPC_proc_bind: |
| 7489 | case OMPC_private: |
| 7490 | case OMPC_firstprivate: |
| 7491 | case OMPC_lastprivate: |
| 7492 | case OMPC_shared: |
| 7493 | case OMPC_reduction: |
| 7494 | case OMPC_linear: |
| 7495 | case OMPC_aligned: |
| 7496 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7497 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7498 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7499 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7500 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7501 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7502 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7503 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7504 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7505 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7506 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7507 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7508 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7509 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7510 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7511 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7512 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7513 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7514 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7515 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7516 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7517 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7518 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7519 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7520 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7521 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7522 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7523 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7524 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7525 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7526 | case OMPC_is_device_ptr: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7527 | llvm_unreachable("Clause is not allowed."); |
| 7528 | } |
| 7529 | return Res; |
| 7530 | } |
| 7531 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7532 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7533 | OpenMPScheduleClauseModifier M2, |
| 7534 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 7535 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 7536 | SmallVector<unsigned, 2> Excluded; |
| 7537 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 7538 | Excluded.push_back(M2); |
| 7539 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 7540 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 7541 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 7542 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 7543 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 7544 | << getListOfPossibleValues(OMPC_schedule, |
| 7545 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 7546 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7547 | Excluded) |
| 7548 | << getOpenMPClauseName(OMPC_schedule); |
| 7549 | return true; |
| 7550 | } |
| 7551 | return false; |
| 7552 | } |
| 7553 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7554 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7555 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7556 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7557 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 7558 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 7559 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 7560 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 7561 | return nullptr; |
| 7562 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7563 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 7564 | // but not both. |
| 7565 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 7566 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 7567 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 7568 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 7569 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 7570 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 7571 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 7572 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 7573 | return nullptr; |
| 7574 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7575 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 7576 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7577 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 7578 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 7579 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7580 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7581 | Exclude); |
| 7582 | } else { |
| 7583 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7584 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7585 | } |
| 7586 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 7587 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 7588 | return nullptr; |
| 7589 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7590 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7591 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 7592 | // schedule(guided). |
| 7593 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 7594 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 7595 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 7596 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 7597 | diag::err_omp_schedule_nonmonotonic_static); |
| 7598 | return nullptr; |
| 7599 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7600 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7601 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7602 | if (ChunkSize) { |
| 7603 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 7604 | !ChunkSize->isInstantiationDependent() && |
| 7605 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 7606 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 7607 | ExprResult Val = |
| 7608 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 7609 | if (Val.isInvalid()) |
| 7610 | return nullptr; |
| 7611 | |
| 7612 | ValExpr = Val.get(); |
| 7613 | |
| 7614 | // OpenMP [2.7.1, Restrictions] |
| 7615 | // chunk_size must be a loop invariant integer expression with a positive |
| 7616 | // value. |
| 7617 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7618 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 7619 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7620 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7621 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7622 | return nullptr; |
| 7623 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 7624 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 7625 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7626 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7627 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7628 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7629 | } |
| 7630 | } |
| 7631 | } |
| 7632 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7633 | return new (Context) |
| 7634 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7635 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7636 | } |
| 7637 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7638 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 7639 | SourceLocation StartLoc, |
| 7640 | SourceLocation EndLoc) { |
| 7641 | OMPClause *Res = nullptr; |
| 7642 | switch (Kind) { |
| 7643 | case OMPC_ordered: |
| 7644 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 7645 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7646 | case OMPC_nowait: |
| 7647 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 7648 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7649 | case OMPC_untied: |
| 7650 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 7651 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7652 | case OMPC_mergeable: |
| 7653 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 7654 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7655 | case OMPC_read: |
| 7656 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 7657 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7658 | case OMPC_write: |
| 7659 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 7660 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7661 | case OMPC_update: |
| 7662 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 7663 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7664 | case OMPC_capture: |
| 7665 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 7666 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7667 | case OMPC_seq_cst: |
| 7668 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 7669 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7670 | case OMPC_threads: |
| 7671 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 7672 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7673 | case OMPC_simd: |
| 7674 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 7675 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7676 | case OMPC_nogroup: |
| 7677 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 7678 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7679 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7680 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7681 | case OMPC_num_threads: |
| 7682 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7683 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7684 | case OMPC_collapse: |
| 7685 | case OMPC_schedule: |
| 7686 | case OMPC_private: |
| 7687 | case OMPC_firstprivate: |
| 7688 | case OMPC_lastprivate: |
| 7689 | case OMPC_shared: |
| 7690 | case OMPC_reduction: |
| 7691 | case OMPC_linear: |
| 7692 | case OMPC_aligned: |
| 7693 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7694 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7695 | case OMPC_default: |
| 7696 | case OMPC_proc_bind: |
| 7697 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7698 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7699 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7700 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7701 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7702 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7703 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7704 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7705 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7706 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7707 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7708 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7709 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7710 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7711 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7712 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7713 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7714 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7715 | case OMPC_is_device_ptr: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7716 | llvm_unreachable("Clause is not allowed."); |
| 7717 | } |
| 7718 | return Res; |
| 7719 | } |
| 7720 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7721 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 7722 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7723 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7724 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 7725 | } |
| 7726 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7727 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 7728 | SourceLocation EndLoc) { |
| 7729 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 7730 | } |
| 7731 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7732 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 7733 | SourceLocation EndLoc) { |
| 7734 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 7735 | } |
| 7736 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7737 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 7738 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7739 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 7740 | } |
| 7741 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7742 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 7743 | SourceLocation EndLoc) { |
| 7744 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 7745 | } |
| 7746 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7747 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 7748 | SourceLocation EndLoc) { |
| 7749 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 7750 | } |
| 7751 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7752 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 7753 | SourceLocation EndLoc) { |
| 7754 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 7755 | } |
| 7756 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7757 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 7758 | SourceLocation EndLoc) { |
| 7759 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 7760 | } |
| 7761 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7762 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 7763 | SourceLocation EndLoc) { |
| 7764 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 7765 | } |
| 7766 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7767 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 7768 | SourceLocation EndLoc) { |
| 7769 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 7770 | } |
| 7771 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7772 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 7773 | SourceLocation EndLoc) { |
| 7774 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 7775 | } |
| 7776 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7777 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7778 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7779 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7780 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7781 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7782 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7783 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7784 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7785 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7786 | switch (Kind) { |
| 7787 | case OMPC_private: |
| 7788 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7789 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7790 | case OMPC_firstprivate: |
| 7791 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7792 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7793 | case OMPC_lastprivate: |
| 7794 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7795 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7796 | case OMPC_shared: |
| 7797 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7798 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7799 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7800 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7801 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7802 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7803 | case OMPC_linear: |
| 7804 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7805 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7806 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7807 | case OMPC_aligned: |
| 7808 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7809 | ColonLoc, EndLoc); |
| 7810 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7811 | case OMPC_copyin: |
| 7812 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7813 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7814 | case OMPC_copyprivate: |
| 7815 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7816 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7817 | case OMPC_flush: |
| 7818 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7819 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7820 | case OMPC_depend: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7821 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7822 | StartLoc, LParenLoc, EndLoc); |
| 7823 | break; |
| 7824 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7825 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7826 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7827 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7828 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7829 | case OMPC_to: |
| 7830 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7831 | break; |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7832 | case OMPC_from: |
| 7833 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7834 | break; |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7835 | case OMPC_use_device_ptr: |
| 7836 | Res = ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7837 | break; |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7838 | case OMPC_is_device_ptr: |
| 7839 | Res = ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7840 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7841 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7842 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7843 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7844 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7845 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7846 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7847 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7848 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7849 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7850 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7851 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7852 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7853 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7854 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7855 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7856 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7857 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7858 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7859 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7860 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7861 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7862 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7863 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7864 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7865 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7866 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7867 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7868 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7869 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7870 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7871 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7872 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7873 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7874 | llvm_unreachable("Clause is not allowed."); |
| 7875 | } |
| 7876 | return Res; |
| 7877 | } |
| 7878 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7879 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7880 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7881 | ExprResult Res = BuildDeclRefExpr( |
| 7882 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7883 | if (!Res.isUsable()) |
| 7884 | return ExprError(); |
| 7885 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7886 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7887 | if (!Res.isUsable()) |
| 7888 | return ExprError(); |
| 7889 | } |
| 7890 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7891 | Res = DefaultLvalueConversion(Res.get()); |
| 7892 | if (!Res.isUsable()) |
| 7893 | return ExprError(); |
| 7894 | } |
| 7895 | return Res; |
| 7896 | } |
| 7897 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7898 | static std::pair<ValueDecl *, bool> |
| 7899 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7900 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7901 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7902 | RefExpr->containsUnexpandedParameterPack()) |
| 7903 | return std::make_pair(nullptr, true); |
| 7904 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7905 | // OpenMP [3.1, C/C++] |
| 7906 | // A list item is a variable name. |
| 7907 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7908 | // A variable that is part of another variable (as an array or |
| 7909 | // structure element) cannot appear in a private clause. |
| 7910 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7911 | enum { |
| 7912 | NoArrayExpr = -1, |
| 7913 | ArraySubscript = 0, |
| 7914 | OMPArraySection = 1 |
| 7915 | } IsArrayExpr = NoArrayExpr; |
| 7916 | if (AllowArraySection) { |
| 7917 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7918 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7919 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7920 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7921 | RefExpr = Base; |
| 7922 | IsArrayExpr = ArraySubscript; |
| 7923 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7924 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7925 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7926 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7927 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7928 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7929 | RefExpr = Base; |
| 7930 | IsArrayExpr = OMPArraySection; |
| 7931 | } |
| 7932 | } |
| 7933 | ELoc = RefExpr->getExprLoc(); |
| 7934 | ERange = RefExpr->getSourceRange(); |
| 7935 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7936 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7937 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7938 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7939 | (S.getCurrentThisType().isNull() || !ME || |
| 7940 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7941 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7942 | if (IsArrayExpr != NoArrayExpr) |
| 7943 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7944 | << ERange; |
| 7945 | else { |
| 7946 | S.Diag(ELoc, |
| 7947 | AllowArraySection |
| 7948 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7949 | : diag::err_omp_expected_var_name_member_expr) |
| 7950 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7951 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7952 | return std::make_pair(nullptr, false); |
| 7953 | } |
| 7954 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7955 | } |
| 7956 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7957 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7958 | SourceLocation StartLoc, |
| 7959 | SourceLocation LParenLoc, |
| 7960 | SourceLocation EndLoc) { |
| 7961 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7962 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7963 | for (auto &RefExpr : VarList) { |
| 7964 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7965 | SourceLocation ELoc; |
| 7966 | SourceRange ERange; |
| 7967 | Expr *SimpleRefExpr = RefExpr; |
| 7968 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7969 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7970 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7971 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7972 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7973 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7974 | ValueDecl *D = Res.first; |
| 7975 | if (!D) |
| 7976 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7977 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7978 | QualType Type = D->getType(); |
| 7979 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7980 | |
| 7981 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7982 | // A variable that appears in a private clause must not have an incomplete |
| 7983 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7984 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7985 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7986 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7987 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7988 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7989 | // in a Construct] |
| 7990 | // Variables with the predetermined data-sharing attributes may not be |
| 7991 | // listed in data-sharing attributes clauses, except for the cases |
| 7992 | // listed below. For these exceptions only, listing a predetermined |
| 7993 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7994 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7995 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7996 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7997 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7998 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7999 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8000 | continue; |
| 8001 | } |
| 8002 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8003 | auto CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8004 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8005 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8006 | isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8007 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8008 | << getOpenMPClauseName(OMPC_private) << Type |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8009 | << getOpenMPDirectiveName(CurrDir); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8010 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8011 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8012 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8013 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8014 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8015 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8016 | continue; |
| 8017 | } |
| 8018 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8019 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8020 | // A list item cannot appear in both a map clause and a data-sharing |
| 8021 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8022 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8023 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8024 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8025 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 8026 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8027 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 8028 | CurrDir == OMPD_target_parallel_for_simd || |
| 8029 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8030 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8031 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8032 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8033 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 8034 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 8035 | ConflictKind = WhereFoundClauseKind; |
| 8036 | return true; |
| 8037 | })) { |
| 8038 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8039 | << getOpenMPClauseName(OMPC_private) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8040 | << getOpenMPClauseName(ConflictKind) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8041 | << getOpenMPDirectiveName(CurrDir); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8042 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8043 | continue; |
| 8044 | } |
| 8045 | } |
| 8046 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8047 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 8048 | // A variable of class type (or array thereof) that appears in a private |
| 8049 | // clause requires an accessible, unambiguous default constructor for the |
| 8050 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8051 | // Generate helper private variable and initialize it with the default |
| 8052 | // value. The address of the original variable is replaced by the address of |
| 8053 | // the new private variable in CodeGen. This new variable is not added to |
| 8054 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 8055 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8056 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8057 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8058 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8059 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8060 | if (VDPrivate->isInvalidDecl()) |
| 8061 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8062 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8063 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8064 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8065 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8066 | if (!VD && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8067 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8068 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8069 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8070 | ? RefExpr->IgnoreParens() |
| 8071 | : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8072 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8073 | } |
| 8074 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8075 | if (Vars.empty()) |
| 8076 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8077 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8078 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8079 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8080 | } |
| 8081 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8082 | namespace { |
| 8083 | class DiagsUninitializedSeveretyRAII { |
| 8084 | private: |
| 8085 | DiagnosticsEngine &Diags; |
| 8086 | SourceLocation SavedLoc; |
| 8087 | bool IsIgnored; |
| 8088 | |
| 8089 | public: |
| 8090 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 8091 | bool IsIgnored) |
| 8092 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 8093 | if (!IsIgnored) { |
| 8094 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 8095 | /*Map*/ diag::Severity::Ignored, Loc); |
| 8096 | } |
| 8097 | } |
| 8098 | ~DiagsUninitializedSeveretyRAII() { |
| 8099 | if (!IsIgnored) |
| 8100 | Diags.popMappings(SavedLoc); |
| 8101 | } |
| 8102 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 8103 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8104 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8105 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 8106 | SourceLocation StartLoc, |
| 8107 | SourceLocation LParenLoc, |
| 8108 | SourceLocation EndLoc) { |
| 8109 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8110 | SmallVector<Expr *, 8> PrivateCopies; |
| 8111 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8112 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8113 | bool IsImplicitClause = |
| 8114 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 8115 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 8116 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8117 | for (auto &RefExpr : VarList) { |
| 8118 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8119 | SourceLocation ELoc; |
| 8120 | SourceRange ERange; |
| 8121 | Expr *SimpleRefExpr = RefExpr; |
| 8122 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8123 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8124 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8125 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8126 | PrivateCopies.push_back(nullptr); |
| 8127 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8128 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8129 | ValueDecl *D = Res.first; |
| 8130 | if (!D) |
| 8131 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8132 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8133 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8134 | QualType Type = D->getType(); |
| 8135 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8136 | |
| 8137 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8138 | // A variable that appears in a private clause must not have an incomplete |
| 8139 | // type or a reference type. |
| 8140 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8141 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8142 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8143 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8144 | |
| 8145 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 8146 | // 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] | 8147 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8148 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8149 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8150 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8151 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8152 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8153 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8154 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8155 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8156 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8157 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 8158 | // A list item that specifies a given variable may not appear in more |
| 8159 | // than one clause on the same directive, except that a variable may be |
| 8160 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8161 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8162 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8163 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8164 | << getOpenMPClauseName(DVar.CKind) |
| 8165 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8166 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8167 | continue; |
| 8168 | } |
| 8169 | |
| 8170 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8171 | // in a Construct] |
| 8172 | // Variables with the predetermined data-sharing attributes may not be |
| 8173 | // listed in data-sharing attributes clauses, except for the cases |
| 8174 | // listed below. For these exceptions only, listing a predetermined |
| 8175 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8176 | // the variable's predetermined data-sharing attributes. |
| 8177 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8178 | // in a Construct, C/C++, p.2] |
| 8179 | // Variables with const-qualified type having no mutable member may be |
| 8180 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8181 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8182 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 8183 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8184 | << getOpenMPClauseName(DVar.CKind) |
| 8185 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8186 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8187 | continue; |
| 8188 | } |
| 8189 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8190 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8191 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 8192 | // A list item that is private within a parallel region must not appear |
| 8193 | // in a firstprivate clause on a worksharing construct if any of the |
| 8194 | // worksharing regions arising from the worksharing construct ever bind |
| 8195 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8196 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8197 | !isOpenMPParallelDirective(CurrDir) && |
| 8198 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8199 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8200 | if (DVar.CKind != OMPC_shared && |
| 8201 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8202 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8203 | Diag(ELoc, diag::err_omp_required_access) |
| 8204 | << getOpenMPClauseName(OMPC_firstprivate) |
| 8205 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8206 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8207 | continue; |
| 8208 | } |
| 8209 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8210 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 8211 | // A list item that appears in a reduction clause of a parallel construct |
| 8212 | // must not appear in a firstprivate clause on a worksharing or task |
| 8213 | // construct if any of the worksharing or task regions arising from the |
| 8214 | // worksharing or task construct ever bind to any of the parallel regions |
| 8215 | // arising from the parallel construct. |
| 8216 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 8217 | // A list item that appears in a reduction clause in worksharing |
| 8218 | // construct must not appear in a firstprivate clause in a task construct |
| 8219 | // encountered during execution of any of the worksharing regions arising |
| 8220 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8221 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8222 | DVar = DSAStack->hasInnermostDSA( |
| 8223 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8224 | [](OpenMPDirectiveKind K) -> bool { |
| 8225 | return isOpenMPParallelDirective(K) || |
| 8226 | isOpenMPWorksharingDirective(K); |
| 8227 | }, |
| 8228 | false); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8229 | if (DVar.CKind == OMPC_reduction && |
| 8230 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8231 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 8232 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 8233 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8234 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8235 | continue; |
| 8236 | } |
| 8237 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8238 | |
| 8239 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8240 | // A list item that is private within a teams region must not appear in a |
| 8241 | // firstprivate clause on a distribute construct if any of the distribute |
| 8242 | // regions arising from the distribute construct ever bind to any of the |
| 8243 | // teams regions arising from the teams construct. |
| 8244 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8245 | // A list item that appears in a reduction clause of a teams construct |
| 8246 | // must not appear in a firstprivate clause on a distribute construct if |
| 8247 | // any of the distribute regions arising from the distribute construct |
| 8248 | // ever bind to any of the teams regions arising from the teams construct. |
| 8249 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8250 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8251 | // both. |
| 8252 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8253 | DVar = DSAStack->hasInnermostDSA( |
| 8254 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_private; }, |
| 8255 | [](OpenMPDirectiveKind K) -> bool { |
| 8256 | return isOpenMPTeamsDirective(K); |
| 8257 | }, |
| 8258 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8259 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 8260 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8261 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8262 | continue; |
| 8263 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8264 | DVar = DSAStack->hasInnermostDSA( |
| 8265 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8266 | [](OpenMPDirectiveKind K) -> bool { |
| 8267 | return isOpenMPTeamsDirective(K); |
| 8268 | }, |
| 8269 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8270 | if (DVar.CKind == OMPC_reduction && |
| 8271 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 8272 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8273 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8274 | continue; |
| 8275 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8276 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8277 | if (DVar.CKind == OMPC_lastprivate) { |
| 8278 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8279 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8280 | continue; |
| 8281 | } |
| 8282 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8283 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8284 | // A list item cannot appear in both a map clause and a data-sharing |
| 8285 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8286 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8287 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8288 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8289 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 8290 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8291 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 8292 | CurrDir == OMPD_target_parallel_for_simd || |
| 8293 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8294 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8295 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8296 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8297 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 8298 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 8299 | ConflictKind = WhereFoundClauseKind; |
| 8300 | return true; |
| 8301 | })) { |
| 8302 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8303 | << getOpenMPClauseName(OMPC_firstprivate) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8304 | << getOpenMPClauseName(ConflictKind) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8305 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8306 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8307 | continue; |
| 8308 | } |
| 8309 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8310 | } |
| 8311 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8312 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8313 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8314 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8315 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8316 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 8317 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8318 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8319 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8320 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8321 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8322 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8323 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8324 | continue; |
| 8325 | } |
| 8326 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8327 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8328 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8329 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8330 | // Generate helper private variable and initialize it with the value of the |
| 8331 | // original variable. The address of the original variable is replaced by |
| 8332 | // the address of the new private variable in the CodeGen. This new variable |
| 8333 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 8334 | // original variable for proper diagnostics and variable capturing. |
| 8335 | Expr *VDInitRefExpr = nullptr; |
| 8336 | // For arrays generate initializer for single element and replace it by the |
| 8337 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8338 | if (Type->isArrayType()) { |
| 8339 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8340 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8341 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8342 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8343 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8344 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8345 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8346 | InitializedEntity Entity = |
| 8347 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8348 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 8349 | |
| 8350 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 8351 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 8352 | if (Result.isInvalid()) |
| 8353 | VDPrivate->setInvalidDecl(); |
| 8354 | else |
| 8355 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8356 | // Remove temp variable declaration. |
| 8357 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8358 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8359 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 8360 | ".firstprivate.temp"); |
| 8361 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 8362 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8363 | AddInitializerToDecl(VDPrivate, |
| 8364 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8365 | /*DirectInit=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8366 | } |
| 8367 | if (VDPrivate->isInvalidDecl()) { |
| 8368 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8369 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8370 | diag::note_omp_task_predetermined_firstprivate_here); |
| 8371 | } |
| 8372 | continue; |
| 8373 | } |
| 8374 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8375 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8376 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 8377 | RefExpr->getExprLoc()); |
| 8378 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8379 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8380 | if (TopDVar.CKind == OMPC_lastprivate) |
| 8381 | Ref = TopDVar.PrivateCopy; |
| 8382 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8383 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8384 | if (!IsOpenMPCapturedDecl(D)) |
| 8385 | ExprCaptures.push_back(Ref->getDecl()); |
| 8386 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8387 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8388 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8389 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8390 | ? RefExpr->IgnoreParens() |
| 8391 | : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8392 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 8393 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8394 | } |
| 8395 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8396 | if (Vars.empty()) |
| 8397 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8398 | |
| 8399 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8400 | Vars, PrivateCopies, Inits, |
| 8401 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8402 | } |
| 8403 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8404 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 8405 | SourceLocation StartLoc, |
| 8406 | SourceLocation LParenLoc, |
| 8407 | SourceLocation EndLoc) { |
| 8408 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8409 | SmallVector<Expr *, 8> SrcExprs; |
| 8410 | SmallVector<Expr *, 8> DstExprs; |
| 8411 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8412 | SmallVector<Decl *, 4> ExprCaptures; |
| 8413 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8414 | for (auto &RefExpr : VarList) { |
| 8415 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8416 | SourceLocation ELoc; |
| 8417 | SourceRange ERange; |
| 8418 | Expr *SimpleRefExpr = RefExpr; |
| 8419 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8420 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8421 | // It will be analyzed later. |
| 8422 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8423 | SrcExprs.push_back(nullptr); |
| 8424 | DstExprs.push_back(nullptr); |
| 8425 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8426 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8427 | ValueDecl *D = Res.first; |
| 8428 | if (!D) |
| 8429 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8430 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8431 | QualType Type = D->getType(); |
| 8432 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8433 | |
| 8434 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 8435 | // A variable that appears in a lastprivate clause must not have an |
| 8436 | // incomplete type or a reference type. |
| 8437 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8438 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8439 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8440 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8441 | |
| 8442 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8443 | // in a Construct] |
| 8444 | // Variables with the predetermined data-sharing attributes may not be |
| 8445 | // listed in data-sharing attributes clauses, except for the cases |
| 8446 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8447 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8448 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 8449 | DVar.CKind != OMPC_firstprivate && |
| 8450 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 8451 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8452 | << getOpenMPClauseName(DVar.CKind) |
| 8453 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8454 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8455 | continue; |
| 8456 | } |
| 8457 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8458 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8459 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 8460 | // A list item that is private within a parallel region, or that appears in |
| 8461 | // the reduction clause of a parallel construct, must not appear in a |
| 8462 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 8463 | // worksharing regions ever binds to any of the corresponding parallel |
| 8464 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8465 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8466 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8467 | !isOpenMPParallelDirective(CurrDir) && |
| 8468 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8469 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8470 | if (DVar.CKind != OMPC_shared) { |
| 8471 | Diag(ELoc, diag::err_omp_required_access) |
| 8472 | << getOpenMPClauseName(OMPC_lastprivate) |
| 8473 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8474 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8475 | continue; |
| 8476 | } |
| 8477 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8478 | |
| 8479 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8480 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8481 | // both. |
| 8482 | if (CurrDir == OMPD_distribute) { |
| 8483 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 8484 | if (DVar.CKind == OMPC_firstprivate) { |
| 8485 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 8486 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8487 | continue; |
| 8488 | } |
| 8489 | } |
| 8490 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8491 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8492 | // A variable of class type (or array thereof) that appears in a |
| 8493 | // lastprivate clause requires an accessible, unambiguous default |
| 8494 | // constructor for the class type, unless the list item is also specified |
| 8495 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8496 | // A variable of class type (or array thereof) that appears in a |
| 8497 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8498 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8499 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8500 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8501 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8502 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8503 | auto *PseudoSrcExpr = |
| 8504 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8505 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8506 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8507 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8508 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8509 | // For arrays generate assignment operation for single element and replace |
| 8510 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8511 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8512 | PseudoDstExpr, PseudoSrcExpr); |
| 8513 | if (AssignmentOp.isInvalid()) |
| 8514 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8515 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8516 | /*DiscardedValue=*/true); |
| 8517 | if (AssignmentOp.isInvalid()) |
| 8518 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8519 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8520 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8521 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8522 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8523 | Ref = TopDVar.PrivateCopy; |
| 8524 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8525 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8526 | if (!IsOpenMPCapturedDecl(D)) |
| 8527 | ExprCaptures.push_back(Ref->getDecl()); |
| 8528 | } |
| 8529 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8530 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8531 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8532 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8533 | if (!RefRes.isUsable()) |
| 8534 | continue; |
| 8535 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8536 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8537 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8538 | if (!PostUpdateRes.isUsable()) |
| 8539 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8540 | ExprPostUpdates.push_back( |
| 8541 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8542 | } |
| 8543 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8544 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8545 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8546 | ? RefExpr->IgnoreParens() |
| 8547 | : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8548 | SrcExprs.push_back(PseudoSrcExpr); |
| 8549 | DstExprs.push_back(PseudoDstExpr); |
| 8550 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8551 | } |
| 8552 | |
| 8553 | if (Vars.empty()) |
| 8554 | return nullptr; |
| 8555 | |
| 8556 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8557 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8558 | buildPreInits(Context, ExprCaptures), |
| 8559 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8560 | } |
| 8561 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8562 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 8563 | SourceLocation StartLoc, |
| 8564 | SourceLocation LParenLoc, |
| 8565 | SourceLocation EndLoc) { |
| 8566 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8567 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8568 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8569 | SourceLocation ELoc; |
| 8570 | SourceRange ERange; |
| 8571 | Expr *SimpleRefExpr = RefExpr; |
| 8572 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8573 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8574 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8575 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8576 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8577 | ValueDecl *D = Res.first; |
| 8578 | if (!D) |
| 8579 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8580 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8581 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8582 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8583 | // in a Construct] |
| 8584 | // Variables with the predetermined data-sharing attributes may not be |
| 8585 | // listed in data-sharing attributes clauses, except for the cases |
| 8586 | // listed below. For these exceptions only, listing a predetermined |
| 8587 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8588 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8589 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8590 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 8591 | DVar.RefExpr) { |
| 8592 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8593 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8594 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8595 | continue; |
| 8596 | } |
| 8597 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8598 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8599 | if (!VD && IsOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8600 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8601 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8602 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 8603 | ? RefExpr->IgnoreParens() |
| 8604 | : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8605 | } |
| 8606 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8607 | if (Vars.empty()) |
| 8608 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8609 | |
| 8610 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 8611 | } |
| 8612 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8613 | namespace { |
| 8614 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 8615 | DSAStackTy *Stack; |
| 8616 | |
| 8617 | public: |
| 8618 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 8619 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8620 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8621 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 8622 | return false; |
| 8623 | if (DVar.CKind != OMPC_unknown) |
| 8624 | return true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8625 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| 8626 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 8627 | false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8628 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8629 | return true; |
| 8630 | return false; |
| 8631 | } |
| 8632 | return false; |
| 8633 | } |
| 8634 | bool VisitStmt(Stmt *S) { |
| 8635 | for (auto Child : S->children()) { |
| 8636 | if (Child && Visit(Child)) |
| 8637 | return true; |
| 8638 | } |
| 8639 | return false; |
| 8640 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8641 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8642 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8643 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8644 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8645 | namespace { |
| 8646 | // Transform MemberExpression for specified FieldDecl of current class to |
| 8647 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 8648 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 8649 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 8650 | ValueDecl *Field; |
| 8651 | DeclRefExpr *CapturedExpr; |
| 8652 | |
| 8653 | public: |
| 8654 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 8655 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 8656 | |
| 8657 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 8658 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 8659 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8660 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8661 | return CapturedExpr; |
| 8662 | } |
| 8663 | return BaseTransform::TransformMemberExpr(E); |
| 8664 | } |
| 8665 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 8666 | }; |
| 8667 | } // namespace |
| 8668 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8669 | template <typename T> |
| 8670 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 8671 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 8672 | for (auto &Set : Lookups) { |
| 8673 | for (auto *D : Set) { |
| 8674 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 8675 | return Res; |
| 8676 | } |
| 8677 | } |
| 8678 | return T(); |
| 8679 | } |
| 8680 | |
| 8681 | static ExprResult |
| 8682 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 8683 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 8684 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 8685 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 8686 | if (ReductionIdScopeSpec.isInvalid()) |
| 8687 | return ExprError(); |
| 8688 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 8689 | if (S) { |
| 8690 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 8691 | Lookup.suppressDiagnostics(); |
| 8692 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 8693 | auto *D = Lookup.getRepresentativeDecl(); |
| 8694 | do { |
| 8695 | S = S->getParent(); |
| 8696 | } while (S && !S->isDeclScope(D)); |
| 8697 | if (S) |
| 8698 | S = S->getParent(); |
| 8699 | Lookups.push_back(UnresolvedSet<8>()); |
| 8700 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 8701 | Lookup.clear(); |
| 8702 | } |
| 8703 | } else if (auto *ULE = |
| 8704 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 8705 | Lookups.push_back(UnresolvedSet<8>()); |
| 8706 | Decl *PrevD = nullptr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8707 | for (auto *D : ULE->decls()) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8708 | if (D == PrevD) |
| 8709 | Lookups.push_back(UnresolvedSet<8>()); |
| 8710 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 8711 | Lookups.back().addDecl(DRD); |
| 8712 | PrevD = D; |
| 8713 | } |
| 8714 | } |
| 8715 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 8716 | Ty->containsUnexpandedParameterPack() || |
| 8717 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 8718 | return !D->isInvalidDecl() && |
| 8719 | (D->getType()->isDependentType() || |
| 8720 | D->getType()->isInstantiationDependentType() || |
| 8721 | D->getType()->containsUnexpandedParameterPack()); |
| 8722 | })) { |
| 8723 | UnresolvedSet<8> ResSet; |
| 8724 | for (auto &Set : Lookups) { |
| 8725 | ResSet.append(Set.begin(), Set.end()); |
| 8726 | // The last item marks the end of all declarations at the specified scope. |
| 8727 | ResSet.addDecl(Set[Set.size() - 1]); |
| 8728 | } |
| 8729 | return UnresolvedLookupExpr::Create( |
| 8730 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8731 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 8732 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 8733 | } |
| 8734 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8735 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 8736 | if (!D->isInvalidDecl() && |
| 8737 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 8738 | return D; |
| 8739 | return nullptr; |
| 8740 | })) |
| 8741 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8742 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8743 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 8744 | if (!D->isInvalidDecl() && |
| 8745 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 8746 | !Ty.isMoreQualifiedThan(D->getType())) |
| 8747 | return D; |
| 8748 | return nullptr; |
| 8749 | })) { |
| 8750 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 8751 | /*DetectVirtual=*/false); |
| 8752 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 8753 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 8754 | VD->getType().getUnqualifiedType()))) { |
| 8755 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 8756 | /*DiagID=*/0) != |
| 8757 | Sema::AR_inaccessible) { |
| 8758 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 8759 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8760 | } |
| 8761 | } |
| 8762 | } |
| 8763 | } |
| 8764 | if (ReductionIdScopeSpec.isSet()) { |
| 8765 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 8766 | return ExprError(); |
| 8767 | } |
| 8768 | return ExprEmpty(); |
| 8769 | } |
| 8770 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8771 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 8772 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 8773 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8774 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 8775 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8776 | auto DN = ReductionId.getName(); |
| 8777 | auto OOK = DN.getCXXOverloadedOperator(); |
| 8778 | BinaryOperatorKind BOK = BO_Comma; |
| 8779 | |
| 8780 | // OpenMP [2.14.3.6, reduction clause] |
| 8781 | // C |
| 8782 | // reduction-identifier is either an identifier or one of the following |
| 8783 | // operators: +, -, *, &, |, ^, && and || |
| 8784 | // C++ |
| 8785 | // reduction-identifier is either an id-expression or one of the following |
| 8786 | // operators: +, -, *, &, |, ^, && and || |
| 8787 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 8788 | switch (OOK) { |
| 8789 | case OO_Plus: |
| 8790 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8791 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8792 | break; |
| 8793 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8794 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8795 | break; |
| 8796 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8797 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8798 | break; |
| 8799 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8800 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8801 | break; |
| 8802 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8803 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8804 | break; |
| 8805 | case OO_AmpAmp: |
| 8806 | BOK = BO_LAnd; |
| 8807 | break; |
| 8808 | case OO_PipePipe: |
| 8809 | BOK = BO_LOr; |
| 8810 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8811 | case OO_New: |
| 8812 | case OO_Delete: |
| 8813 | case OO_Array_New: |
| 8814 | case OO_Array_Delete: |
| 8815 | case OO_Slash: |
| 8816 | case OO_Percent: |
| 8817 | case OO_Tilde: |
| 8818 | case OO_Exclaim: |
| 8819 | case OO_Equal: |
| 8820 | case OO_Less: |
| 8821 | case OO_Greater: |
| 8822 | case OO_LessEqual: |
| 8823 | case OO_GreaterEqual: |
| 8824 | case OO_PlusEqual: |
| 8825 | case OO_MinusEqual: |
| 8826 | case OO_StarEqual: |
| 8827 | case OO_SlashEqual: |
| 8828 | case OO_PercentEqual: |
| 8829 | case OO_CaretEqual: |
| 8830 | case OO_AmpEqual: |
| 8831 | case OO_PipeEqual: |
| 8832 | case OO_LessLess: |
| 8833 | case OO_GreaterGreater: |
| 8834 | case OO_LessLessEqual: |
| 8835 | case OO_GreaterGreaterEqual: |
| 8836 | case OO_EqualEqual: |
| 8837 | case OO_ExclaimEqual: |
| 8838 | case OO_PlusPlus: |
| 8839 | case OO_MinusMinus: |
| 8840 | case OO_Comma: |
| 8841 | case OO_ArrowStar: |
| 8842 | case OO_Arrow: |
| 8843 | case OO_Call: |
| 8844 | case OO_Subscript: |
| 8845 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 8846 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8847 | case NUM_OVERLOADED_OPERATORS: |
| 8848 | llvm_unreachable("Unexpected reduction identifier"); |
| 8849 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8850 | if (auto II = DN.getAsIdentifierInfo()) { |
| 8851 | if (II->isStr("max")) |
| 8852 | BOK = BO_GT; |
| 8853 | else if (II->isStr("min")) |
| 8854 | BOK = BO_LT; |
| 8855 | } |
| 8856 | break; |
| 8857 | } |
| 8858 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8859 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8860 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8861 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8862 | |
| 8863 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8864 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8865 | SmallVector<Expr *, 8> LHSs; |
| 8866 | SmallVector<Expr *, 8> RHSs; |
| 8867 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8868 | SmallVector<Decl *, 4> ExprCaptures; |
| 8869 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8870 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 8871 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8872 | for (auto RefExpr : VarList) { |
| 8873 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8874 | // OpenMP [2.1, C/C++] |
| 8875 | // A list item is a variable or array section, subject to the restrictions |
| 8876 | // specified in Section 2.4 on page 42 and in each of the sections |
| 8877 | // describing clauses and directives for which a list appears. |
| 8878 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8879 | // A variable that is part of another variable (as an array or |
| 8880 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8881 | if (!FirstIter && IR != ER) |
| 8882 | ++IR; |
| 8883 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8884 | SourceLocation ELoc; |
| 8885 | SourceRange ERange; |
| 8886 | Expr *SimpleRefExpr = RefExpr; |
| 8887 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8888 | /*AllowArraySection=*/true); |
| 8889 | if (Res.second) { |
| 8890 | // It will be analyzed later. |
| 8891 | Vars.push_back(RefExpr); |
| 8892 | Privates.push_back(nullptr); |
| 8893 | LHSs.push_back(nullptr); |
| 8894 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8895 | // Try to find 'declare reduction' corresponding construct before using |
| 8896 | // builtin/overloaded operators. |
| 8897 | QualType Type = Context.DependentTy; |
| 8898 | CXXCastPath BasePath; |
| 8899 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8900 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8901 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8902 | if (CurContext->isDependentContext() && |
| 8903 | (DeclareReductionRef.isUnset() || |
| 8904 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 8905 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8906 | else |
| 8907 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8908 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8909 | ValueDecl *D = Res.first; |
| 8910 | if (!D) |
| 8911 | continue; |
| 8912 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8913 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8914 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 8915 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 8916 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8917 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8918 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8919 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 8920 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 8921 | Type = ATy->getElementType(); |
| 8922 | else |
| 8923 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8924 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8925 | } else |
| 8926 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 8927 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8928 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8929 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8930 | // A variable that appears in a private clause must not have an incomplete |
| 8931 | // type or a reference type. |
| 8932 | if (RequireCompleteType(ELoc, Type, |
| 8933 | diag::err_omp_reduction_incomplete_type)) |
| 8934 | continue; |
| 8935 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8936 | // A list item that appears in a reduction clause must not be |
| 8937 | // const-qualified. |
| 8938 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8939 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8940 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8941 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8942 | bool IsDecl = !VD || |
| 8943 | VD->isThisDeclarationADefinition(Context) == |
| 8944 | VarDecl::DeclarationOnly; |
| 8945 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8946 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8947 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8948 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8949 | continue; |
| 8950 | } |
| 8951 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8952 | // If a list-item is a reference type then it must bind to the same object |
| 8953 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8954 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8955 | VarDecl *VDDef = VD->getDefinition(); |
David Sheinkman | 9258999 | 2016-10-04 14:41:36 +0000 | [diff] [blame] | 8956 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8957 | DSARefChecker Check(DSAStack); |
| 8958 | if (Check.Visit(VDDef->getInit())) { |
| 8959 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8960 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8961 | continue; |
| 8962 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8963 | } |
| 8964 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8965 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8966 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8967 | // in a Construct] |
| 8968 | // Variables with the predetermined data-sharing attributes may not be |
| 8969 | // listed in data-sharing attributes clauses, except for the cases |
| 8970 | // listed below. For these exceptions only, listing a predetermined |
| 8971 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8972 | // the variable's predetermined data-sharing attributes. |
| 8973 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8974 | // Any number of reduction clauses can be specified on the directive, |
| 8975 | // but a list item can appear only once in the reduction clauses for that |
| 8976 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8977 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8978 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8979 | if (DVar.CKind == OMPC_reduction) { |
| 8980 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8981 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8982 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8983 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8984 | } else if (DVar.CKind != OMPC_unknown) { |
| 8985 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8986 | << getOpenMPClauseName(DVar.CKind) |
| 8987 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8988 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8989 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8990 | } |
| 8991 | |
| 8992 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8993 | // A list item that appears in a reduction clause of a worksharing |
| 8994 | // construct must be shared in the parallel regions to which any of the |
| 8995 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8996 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8997 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8998 | !isOpenMPParallelDirective(CurrDir) && |
| 8999 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9000 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9001 | if (DVar.CKind != OMPC_shared) { |
| 9002 | Diag(ELoc, diag::err_omp_required_access) |
| 9003 | << getOpenMPClauseName(OMPC_reduction) |
| 9004 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9005 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9006 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9007 | } |
| 9008 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9009 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9010 | // Try to find 'declare reduction' corresponding construct before using |
| 9011 | // builtin/overloaded operators. |
| 9012 | CXXCastPath BasePath; |
| 9013 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 9014 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 9015 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9016 | if (DeclareReductionRef.isInvalid()) |
| 9017 | continue; |
| 9018 | if (CurContext->isDependentContext() && |
| 9019 | (DeclareReductionRef.isUnset() || |
| 9020 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 9021 | Vars.push_back(RefExpr); |
| 9022 | Privates.push_back(nullptr); |
| 9023 | LHSs.push_back(nullptr); |
| 9024 | RHSs.push_back(nullptr); |
| 9025 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 9026 | continue; |
| 9027 | } |
| 9028 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 9029 | // Not allowed reduction identifier is found. |
| 9030 | Diag(ReductionId.getLocStart(), |
| 9031 | diag::err_omp_unknown_reduction_identifier) |
| 9032 | << Type << ReductionIdRange; |
| 9033 | continue; |
| 9034 | } |
| 9035 | |
| 9036 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 9037 | // The type of a list item that appears in a reduction clause must be valid |
| 9038 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 9039 | // of the list item must be an allowed arithmetic data type: char, int, |
| 9040 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 9041 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 9042 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 9043 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 9044 | if (DeclareReductionRef.isUnset()) { |
| 9045 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 9046 | !(Type->isScalarType() || |
| 9047 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 9048 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 9049 | << getLangOpts().CPlusPlus; |
| 9050 | if (!ASE && !OASE) { |
| 9051 | bool IsDecl = !VD || |
| 9052 | VD->isThisDeclarationADefinition(Context) == |
| 9053 | VarDecl::DeclarationOnly; |
| 9054 | Diag(D->getLocation(), |
| 9055 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9056 | << D; |
| 9057 | } |
| 9058 | continue; |
| 9059 | } |
| 9060 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 9061 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 9062 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 9063 | if (!ASE && !OASE) { |
| 9064 | bool IsDecl = !VD || |
| 9065 | VD->isThisDeclarationADefinition(Context) == |
| 9066 | VarDecl::DeclarationOnly; |
| 9067 | Diag(D->getLocation(), |
| 9068 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9069 | << D; |
| 9070 | } |
| 9071 | continue; |
| 9072 | } |
| 9073 | } |
| 9074 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9075 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9076 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9077 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9078 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9079 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9080 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 9081 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9082 | (!ASE && |
| 9083 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9084 | // For arrays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9085 | // Create pseudo array type for private copy. The size for this array will |
| 9086 | // be generated during codegen. |
| 9087 | // For array subscripts or single variables Private Ty is the same as Type |
| 9088 | // (type of the variable or single array element). |
| 9089 | PrivateTy = Context.getVariableArrayType( |
| 9090 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 9091 | Context.getSizeType(), VK_RValue), |
| 9092 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9093 | } else if (!ASE && !OASE && |
| 9094 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 9095 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9096 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9097 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 9098 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9099 | // Add initializer for private variable. |
| 9100 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9101 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 9102 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 9103 | if (DeclareReductionRef.isUsable()) { |
| 9104 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 9105 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 9106 | if (DRD->getInitializer()) { |
| 9107 | Init = DRDRef; |
| 9108 | RHSVD->setInit(DRDRef); |
| 9109 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9110 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9111 | } else { |
| 9112 | switch (BOK) { |
| 9113 | case BO_Add: |
| 9114 | case BO_Xor: |
| 9115 | case BO_Or: |
| 9116 | case BO_LOr: |
| 9117 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 9118 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 9119 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 9120 | break; |
| 9121 | case BO_Mul: |
| 9122 | case BO_LAnd: |
| 9123 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 9124 | // '*' and '&&' reduction ops - initializer is '1'. |
| 9125 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9126 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9127 | break; |
| 9128 | case BO_And: { |
| 9129 | // '&' reduction op - initializer is '~0'. |
| 9130 | QualType OrigType = Type; |
| 9131 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 9132 | Type = ComplexTy->getElementType(); |
| 9133 | if (Type->isRealFloatingType()) { |
| 9134 | llvm::APFloat InitValue = |
| 9135 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 9136 | /*isIEEE=*/true); |
| 9137 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9138 | Type, ELoc); |
| 9139 | } else if (Type->isScalarType()) { |
| 9140 | auto Size = Context.getTypeSize(Type); |
| 9141 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 9142 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 9143 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9144 | } |
| 9145 | if (Init && OrigType->isAnyComplexType()) { |
| 9146 | // Init = 0xFFFF + 0xFFFFi; |
| 9147 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 9148 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 9149 | } |
| 9150 | Type = OrigType; |
| 9151 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9152 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9153 | case BO_LT: |
| 9154 | case BO_GT: { |
| 9155 | // 'min' reduction op - initializer is 'Largest representable number in |
| 9156 | // the reduction list item type'. |
| 9157 | // 'max' reduction op - initializer is 'Least representable number in |
| 9158 | // the reduction list item type'. |
| 9159 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 9160 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 9161 | auto Size = Context.getTypeSize(Type); |
| 9162 | QualType IntTy = |
| 9163 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 9164 | llvm::APInt InitValue = |
| 9165 | (BOK != BO_LT) |
| 9166 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 9167 | : llvm::APInt::getMinValue(Size) |
| 9168 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 9169 | : llvm::APInt::getMaxValue(Size); |
| 9170 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9171 | if (Type->isPointerType()) { |
| 9172 | // Cast to pointer type. |
| 9173 | auto CastExpr = BuildCStyleCastExpr( |
| 9174 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 9175 | SourceLocation(), Init); |
| 9176 | if (CastExpr.isInvalid()) |
| 9177 | continue; |
| 9178 | Init = CastExpr.get(); |
| 9179 | } |
| 9180 | } else if (Type->isRealFloatingType()) { |
| 9181 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 9182 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 9183 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9184 | Type, ELoc); |
| 9185 | } |
| 9186 | break; |
| 9187 | } |
| 9188 | case BO_PtrMemD: |
| 9189 | case BO_PtrMemI: |
| 9190 | case BO_MulAssign: |
| 9191 | case BO_Div: |
| 9192 | case BO_Rem: |
| 9193 | case BO_Sub: |
| 9194 | case BO_Shl: |
| 9195 | case BO_Shr: |
| 9196 | case BO_LE: |
| 9197 | case BO_GE: |
| 9198 | case BO_EQ: |
| 9199 | case BO_NE: |
| 9200 | case BO_AndAssign: |
| 9201 | case BO_XorAssign: |
| 9202 | case BO_OrAssign: |
| 9203 | case BO_Assign: |
| 9204 | case BO_AddAssign: |
| 9205 | case BO_SubAssign: |
| 9206 | case BO_DivAssign: |
| 9207 | case BO_RemAssign: |
| 9208 | case BO_ShlAssign: |
| 9209 | case BO_ShrAssign: |
| 9210 | case BO_Comma: |
| 9211 | llvm_unreachable("Unexpected reduction operation"); |
| 9212 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9213 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9214 | if (Init && DeclareReductionRef.isUnset()) { |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9215 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9216 | } else if (!Init) |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9217 | ActOnUninitializedDecl(RHSVD); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9218 | if (RHSVD->isInvalidDecl()) |
| 9219 | continue; |
| 9220 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9221 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 9222 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9223 | bool IsDecl = |
| 9224 | !VD || |
| 9225 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9226 | Diag(D->getLocation(), |
| 9227 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9228 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9229 | continue; |
| 9230 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9231 | // Store initializer for single element in private copy. Will be used during |
| 9232 | // codegen. |
| 9233 | PrivateVD->setInit(RHSVD->getInit()); |
| 9234 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9235 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9236 | ExprResult ReductionOp; |
| 9237 | if (DeclareReductionRef.isUsable()) { |
| 9238 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 9239 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 9240 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 9241 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 9242 | if (!BasePath.empty()) { |
| 9243 | LHS = DefaultLvalueConversion(LHS.get()); |
| 9244 | RHS = DefaultLvalueConversion(RHS.get()); |
| 9245 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9246 | CK_UncheckedDerivedToBase, LHS.get(), |
| 9247 | &BasePath, LHS.get()->getValueKind()); |
| 9248 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9249 | CK_UncheckedDerivedToBase, RHS.get(), |
| 9250 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9251 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9252 | FunctionProtoType::ExtProtoInfo EPI; |
| 9253 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 9254 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 9255 | auto *OVE = new (Context) OpaqueValueExpr( |
| 9256 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 9257 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 9258 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 9259 | ReductionOp = new (Context) |
| 9260 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 9261 | } else { |
| 9262 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 9263 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 9264 | if (ReductionOp.isUsable()) { |
| 9265 | if (BOK != BO_LT && BOK != BO_GT) { |
| 9266 | ReductionOp = |
| 9267 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9268 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 9269 | } else { |
| 9270 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 9271 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 9272 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 9273 | ReductionOp = |
| 9274 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9275 | BO_Assign, LHSDRE, ConditionalOp); |
| 9276 | } |
| 9277 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 9278 | } |
| 9279 | if (ReductionOp.isInvalid()) |
| 9280 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9281 | } |
| 9282 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9283 | DeclRefExpr *Ref = nullptr; |
| 9284 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9285 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9286 | if (ASE || OASE) { |
| 9287 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 9288 | VarsExpr = |
| 9289 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 9290 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9291 | } else { |
| 9292 | VarsExpr = Ref = |
| 9293 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9294 | } |
| 9295 | if (!IsOpenMPCapturedDecl(D)) { |
| 9296 | ExprCaptures.push_back(Ref->getDecl()); |
| 9297 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9298 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9299 | if (!RefRes.isUsable()) |
| 9300 | continue; |
| 9301 | ExprResult PostUpdateRes = |
| 9302 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9303 | SimpleRefExpr, RefRes.get()); |
| 9304 | if (!PostUpdateRes.isUsable()) |
| 9305 | continue; |
| 9306 | ExprPostUpdates.push_back( |
| 9307 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9308 | } |
| 9309 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9310 | } |
| 9311 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 9312 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9313 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9314 | LHSs.push_back(LHSDRE); |
| 9315 | RHSs.push_back(RHSDRE); |
| 9316 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9317 | } |
| 9318 | |
| 9319 | if (Vars.empty()) |
| 9320 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9321 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9322 | return OMPReductionClause::Create( |
| 9323 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9324 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9325 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 9326 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9327 | } |
| 9328 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9329 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 9330 | SourceLocation LinLoc) { |
| 9331 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 9332 | LinKind == OMPC_LINEAR_unknown) { |
| 9333 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 9334 | return true; |
| 9335 | } |
| 9336 | return false; |
| 9337 | } |
| 9338 | |
| 9339 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 9340 | OpenMPLinearClauseKind LinKind, |
| 9341 | QualType Type) { |
| 9342 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 9343 | // A variable must not have an incomplete type or a reference type. |
| 9344 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 9345 | return true; |
| 9346 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 9347 | !Type->isReferenceType()) { |
| 9348 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 9349 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 9350 | return true; |
| 9351 | } |
| 9352 | Type = Type.getNonReferenceType(); |
| 9353 | |
| 9354 | // A list item must not be const-qualified. |
| 9355 | if (Type.isConstant(Context)) { |
| 9356 | Diag(ELoc, diag::err_omp_const_variable) |
| 9357 | << getOpenMPClauseName(OMPC_linear); |
| 9358 | if (D) { |
| 9359 | bool IsDecl = |
| 9360 | !VD || |
| 9361 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9362 | Diag(D->getLocation(), |
| 9363 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9364 | << D; |
| 9365 | } |
| 9366 | return true; |
| 9367 | } |
| 9368 | |
| 9369 | // A list item must be of integral or pointer type. |
| 9370 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 9371 | const auto *Ty = Type.getTypePtrOrNull(); |
| 9372 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 9373 | !Ty->isPointerType())) { |
| 9374 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 9375 | if (D) { |
| 9376 | bool IsDecl = |
| 9377 | !VD || |
| 9378 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9379 | Diag(D->getLocation(), |
| 9380 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9381 | << D; |
| 9382 | } |
| 9383 | return true; |
| 9384 | } |
| 9385 | return false; |
| 9386 | } |
| 9387 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9388 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 9389 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 9390 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 9391 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9392 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9393 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9394 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9395 | SmallVector<Decl *, 4> ExprCaptures; |
| 9396 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9397 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9398 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9399 | for (auto &RefExpr : VarList) { |
| 9400 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9401 | SourceLocation ELoc; |
| 9402 | SourceRange ERange; |
| 9403 | Expr *SimpleRefExpr = RefExpr; |
| 9404 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9405 | /*AllowArraySection=*/false); |
| 9406 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9407 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9408 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9409 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9410 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9411 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9412 | ValueDecl *D = Res.first; |
| 9413 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9414 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9415 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9416 | QualType Type = D->getType(); |
| 9417 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9418 | |
| 9419 | // OpenMP [2.14.3.7, linear clause] |
| 9420 | // A list-item cannot appear in more than one linear clause. |
| 9421 | // A list-item that appears in a linear clause cannot appear in any |
| 9422 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9423 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9424 | if (DVar.RefExpr) { |
| 9425 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9426 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9427 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9428 | continue; |
| 9429 | } |
| 9430 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9431 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9432 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9433 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9434 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9435 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9436 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9437 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9438 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9439 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9440 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9441 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9442 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9443 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9444 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 9445 | if (!IsOpenMPCapturedDecl(D)) { |
| 9446 | ExprCaptures.push_back(Ref->getDecl()); |
| 9447 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9448 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9449 | if (!RefRes.isUsable()) |
| 9450 | continue; |
| 9451 | ExprResult PostUpdateRes = |
| 9452 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9453 | SimpleRefExpr, RefRes.get()); |
| 9454 | if (!PostUpdateRes.isUsable()) |
| 9455 | continue; |
| 9456 | ExprPostUpdates.push_back( |
| 9457 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 9458 | } |
| 9459 | } |
| 9460 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9461 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9462 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9463 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9464 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9465 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9466 | /*DirectInit=*/false); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9467 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 9468 | |
| 9469 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9470 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 9471 | ? RefExpr->IgnoreParens() |
| 9472 | : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9473 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9474 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9475 | } |
| 9476 | |
| 9477 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9478 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9479 | |
| 9480 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9481 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9482 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9483 | !Step->isInstantiationDependent() && |
| 9484 | !Step->containsUnexpandedParameterPack()) { |
| 9485 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9486 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9487 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9488 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9489 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9490 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9491 | // Build var to save the step value. |
| 9492 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9493 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9494 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9495 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9496 | ExprResult CalcStep = |
| 9497 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9498 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9499 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9500 | // Warn about zero linear step (it would be probably better specified as |
| 9501 | // making corresponding variables 'const'). |
| 9502 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9503 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9504 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9505 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9506 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9507 | if (!IsConstant && CalcStep.isUsable()) { |
| 9508 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9509 | // (This is not used if the number of iterations may be kfold-ed). |
| 9510 | CalcStepExpr = CalcStep.get(); |
| 9511 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9512 | } |
| 9513 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9514 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9515 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9516 | StepExpr, CalcStepExpr, |
| 9517 | buildPreInits(Context, ExprCaptures), |
| 9518 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9519 | } |
| 9520 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9521 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9522 | Expr *NumIterations, Sema &SemaRef, |
| 9523 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9524 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9525 | SmallVector<Expr *, 8> Updates; |
| 9526 | SmallVector<Expr *, 8> Finals; |
| 9527 | Expr *Step = Clause.getStep(); |
| 9528 | Expr *CalcStep = Clause.getCalcStep(); |
| 9529 | // OpenMP [2.14.3.7, linear clause] |
| 9530 | // If linear-step is not specified it is assumed to be 1. |
| 9531 | if (Step == nullptr) |
| 9532 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9533 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9534 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9535 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9536 | bool HasErrors = false; |
| 9537 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9538 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9539 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9540 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9541 | SourceLocation ELoc; |
| 9542 | SourceRange ERange; |
| 9543 | Expr *SimpleRefExpr = RefExpr; |
| 9544 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9545 | /*AllowArraySection=*/false); |
| 9546 | ValueDecl *D = Res.first; |
| 9547 | if (Res.second || !D) { |
| 9548 | Updates.push_back(nullptr); |
| 9549 | Finals.push_back(nullptr); |
| 9550 | HasErrors = true; |
| 9551 | continue; |
| 9552 | } |
| 9553 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { |
| 9554 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) |
| 9555 | ->getMemberDecl(); |
| 9556 | } |
| 9557 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9558 | Expr *InitExpr = *CurInit; |
| 9559 | |
| 9560 | // Build privatized reference to the current linear var. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9561 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9562 | Expr *CapturedRef; |
| 9563 | if (LinKind == OMPC_LINEAR_uval) |
| 9564 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 9565 | else |
| 9566 | CapturedRef = |
| 9567 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 9568 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 9569 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9570 | |
| 9571 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9572 | ExprResult Update; |
| 9573 | if (!Info.first) { |
| 9574 | Update = |
| 9575 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 9576 | InitExpr, IV, Step, /* Subtract */ false); |
| 9577 | } else |
| 9578 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9579 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 9580 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9581 | |
| 9582 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9583 | ExprResult Final; |
| 9584 | if (!Info.first) { |
| 9585 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 9586 | InitExpr, NumIterations, Step, |
| 9587 | /* Subtract */ false); |
| 9588 | } else |
| 9589 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9590 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 9591 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9592 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9593 | if (!Update.isUsable() || !Final.isUsable()) { |
| 9594 | Updates.push_back(nullptr); |
| 9595 | Finals.push_back(nullptr); |
| 9596 | HasErrors = true; |
| 9597 | } else { |
| 9598 | Updates.push_back(Update.get()); |
| 9599 | Finals.push_back(Final.get()); |
| 9600 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 9601 | ++CurInit; |
| 9602 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9603 | } |
| 9604 | Clause.setUpdates(Updates); |
| 9605 | Clause.setFinals(Finals); |
| 9606 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9607 | } |
| 9608 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9609 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 9610 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 9611 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 9612 | |
| 9613 | SmallVector<Expr *, 8> Vars; |
| 9614 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9615 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9616 | SourceLocation ELoc; |
| 9617 | SourceRange ERange; |
| 9618 | Expr *SimpleRefExpr = RefExpr; |
| 9619 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9620 | /*AllowArraySection=*/false); |
| 9621 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9622 | // It will be analyzed later. |
| 9623 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9624 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9625 | ValueDecl *D = Res.first; |
| 9626 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9627 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9628 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9629 | QualType QType = D->getType(); |
| 9630 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9631 | |
| 9632 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9633 | // The type of list items appearing in the aligned clause must be |
| 9634 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9635 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9636 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9637 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9638 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9639 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9640 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9641 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9642 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9643 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9644 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9645 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9646 | continue; |
| 9647 | } |
| 9648 | |
| 9649 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9650 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9651 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 9652 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9653 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 9654 | << getOpenMPClauseName(OMPC_aligned); |
| 9655 | continue; |
| 9656 | } |
| 9657 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9658 | DeclRefExpr *Ref = nullptr; |
| 9659 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 9660 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 9661 | Vars.push_back(DefaultFunctionArrayConversion( |
| 9662 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 9663 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9664 | } |
| 9665 | |
| 9666 | // OpenMP [2.8.1, simd construct, Description] |
| 9667 | // The parameter of the aligned clause, alignment, must be a constant |
| 9668 | // positive integer expression. |
| 9669 | // If no optional parameter is specified, implementation-defined default |
| 9670 | // alignments for SIMD instructions on the target platforms are assumed. |
| 9671 | if (Alignment != nullptr) { |
| 9672 | ExprResult AlignResult = |
| 9673 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 9674 | if (AlignResult.isInvalid()) |
| 9675 | return nullptr; |
| 9676 | Alignment = AlignResult.get(); |
| 9677 | } |
| 9678 | if (Vars.empty()) |
| 9679 | return nullptr; |
| 9680 | |
| 9681 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 9682 | EndLoc, Vars, Alignment); |
| 9683 | } |
| 9684 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9685 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 9686 | SourceLocation StartLoc, |
| 9687 | SourceLocation LParenLoc, |
| 9688 | SourceLocation EndLoc) { |
| 9689 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9690 | SmallVector<Expr *, 8> SrcExprs; |
| 9691 | SmallVector<Expr *, 8> DstExprs; |
| 9692 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9693 | for (auto &RefExpr : VarList) { |
| 9694 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 9695 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9696 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9697 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9698 | SrcExprs.push_back(nullptr); |
| 9699 | DstExprs.push_back(nullptr); |
| 9700 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9701 | continue; |
| 9702 | } |
| 9703 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9704 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9705 | // OpenMP [2.1, C/C++] |
| 9706 | // A list item is a variable name. |
| 9707 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 9708 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9709 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9710 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9711 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 9712 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9713 | continue; |
| 9714 | } |
| 9715 | |
| 9716 | Decl *D = DE->getDecl(); |
| 9717 | VarDecl *VD = cast<VarDecl>(D); |
| 9718 | |
| 9719 | QualType Type = VD->getType(); |
| 9720 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 9721 | // It will be analyzed later. |
| 9722 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9723 | SrcExprs.push_back(nullptr); |
| 9724 | DstExprs.push_back(nullptr); |
| 9725 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9726 | continue; |
| 9727 | } |
| 9728 | |
| 9729 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 9730 | // A list item that appears in a copyin clause must be threadprivate. |
| 9731 | if (!DSAStack->isThreadPrivate(VD)) { |
| 9732 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9733 | << getOpenMPClauseName(OMPC_copyin) |
| 9734 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9735 | continue; |
| 9736 | } |
| 9737 | |
| 9738 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9739 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9740 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9741 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9742 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9743 | auto *SrcVD = |
| 9744 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 9745 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9746 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9747 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 9748 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9749 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 9750 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9751 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9752 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9753 | // For arrays generate assignment operation for single element and replace |
| 9754 | // it by the original array element in CodeGen. |
| 9755 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 9756 | PseudoDstExpr, PseudoSrcExpr); |
| 9757 | if (AssignmentOp.isInvalid()) |
| 9758 | continue; |
| 9759 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 9760 | /*DiscardedValue=*/true); |
| 9761 | if (AssignmentOp.isInvalid()) |
| 9762 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9763 | |
| 9764 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 9765 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9766 | SrcExprs.push_back(PseudoSrcExpr); |
| 9767 | DstExprs.push_back(PseudoDstExpr); |
| 9768 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9769 | } |
| 9770 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9771 | if (Vars.empty()) |
| 9772 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9773 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9774 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 9775 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9776 | } |
| 9777 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9778 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 9779 | SourceLocation StartLoc, |
| 9780 | SourceLocation LParenLoc, |
| 9781 | SourceLocation EndLoc) { |
| 9782 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9783 | SmallVector<Expr *, 8> SrcExprs; |
| 9784 | SmallVector<Expr *, 8> DstExprs; |
| 9785 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9786 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9787 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9788 | SourceLocation ELoc; |
| 9789 | SourceRange ERange; |
| 9790 | Expr *SimpleRefExpr = RefExpr; |
| 9791 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9792 | /*AllowArraySection=*/false); |
| 9793 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9794 | // It will be analyzed later. |
| 9795 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9796 | SrcExprs.push_back(nullptr); |
| 9797 | DstExprs.push_back(nullptr); |
| 9798 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9799 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9800 | ValueDecl *D = Res.first; |
| 9801 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9802 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9803 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9804 | QualType Type = D->getType(); |
| 9805 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9806 | |
| 9807 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 9808 | // A list item that appears in a copyprivate clause may not appear in a |
| 9809 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9810 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 9811 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9812 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 9813 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9814 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9815 | << getOpenMPClauseName(DVar.CKind) |
| 9816 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9817 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9818 | continue; |
| 9819 | } |
| 9820 | |
| 9821 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 9822 | // All list items that appear in a copyprivate clause must be either |
| 9823 | // threadprivate or private in the enclosing context. |
| 9824 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9825 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9826 | if (DVar.CKind == OMPC_shared) { |
| 9827 | Diag(ELoc, diag::err_omp_required_access) |
| 9828 | << getOpenMPClauseName(OMPC_copyprivate) |
| 9829 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9830 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9831 | continue; |
| 9832 | } |
| 9833 | } |
| 9834 | } |
| 9835 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9836 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9837 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9838 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9839 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 9840 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9841 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9842 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9843 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9844 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9845 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9846 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9847 | continue; |
| 9848 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9849 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9850 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9851 | // A variable of class type (or array thereof) that appears in a |
| 9852 | // copyin clause requires an accessible, unambiguous copy assignment |
| 9853 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9854 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 9855 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9856 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9857 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 9858 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9859 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9860 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9861 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 9862 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9863 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9864 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9865 | PseudoDstExpr, PseudoSrcExpr); |
| 9866 | if (AssignmentOp.isInvalid()) |
| 9867 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9868 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9869 | /*DiscardedValue=*/true); |
| 9870 | if (AssignmentOp.isInvalid()) |
| 9871 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9872 | |
| 9873 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 9874 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9875 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 9876 | Vars.push_back( |
| 9877 | VD ? RefExpr->IgnoreParens() |
| 9878 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9879 | SrcExprs.push_back(PseudoSrcExpr); |
| 9880 | DstExprs.push_back(PseudoDstExpr); |
| 9881 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9882 | } |
| 9883 | |
| 9884 | if (Vars.empty()) |
| 9885 | return nullptr; |
| 9886 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9887 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9888 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9889 | } |
| 9890 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9891 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 9892 | SourceLocation StartLoc, |
| 9893 | SourceLocation LParenLoc, |
| 9894 | SourceLocation EndLoc) { |
| 9895 | if (VarList.empty()) |
| 9896 | return nullptr; |
| 9897 | |
| 9898 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 9899 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9900 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9901 | OMPClause * |
| 9902 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 9903 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 9904 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9905 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9906 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9907 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9908 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9909 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9910 | return nullptr; |
| 9911 | } |
| 9912 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9913 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 9914 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9915 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9916 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9917 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 9918 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 9919 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9920 | return nullptr; |
| 9921 | } |
| 9922 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9923 | DSAStackTy::OperatorOffsetTy OpsOffs; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9924 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 9925 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 9926 | if (DepKind == OMPC_DEPEND_sink) { |
| 9927 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 9928 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 9929 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9930 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9931 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9932 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 9933 | DSAStack->getParentOrderedRegionParam()) { |
| 9934 | for (auto &RefExpr : VarList) { |
| 9935 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9936 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9937 | // It will be analyzed later. |
| 9938 | Vars.push_back(RefExpr); |
| 9939 | continue; |
| 9940 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9941 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9942 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 9943 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 9944 | if (DepKind == OMPC_DEPEND_sink) { |
| 9945 | if (DepCounter >= TotalDepCount) { |
| 9946 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 9947 | continue; |
| 9948 | } |
| 9949 | ++DepCounter; |
| 9950 | // OpenMP [2.13.9, Summary] |
| 9951 | // depend(dependence-type : vec), where dependence-type is: |
| 9952 | // 'sink' and where vec is the iteration vector, which has the form: |
| 9953 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 9954 | // where n is the value specified by the ordered clause in the loop |
| 9955 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 9956 | // loop associated with the loop directive, and di is a constant |
| 9957 | // non-negative integer. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9958 | if (CurContext->isDependentContext()) { |
| 9959 | // It will be analyzed later. |
| 9960 | Vars.push_back(RefExpr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9961 | continue; |
| 9962 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9963 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 9964 | OverloadedOperatorKind OOK = OO_None; |
| 9965 | SourceLocation OOLoc; |
| 9966 | Expr *LHS = SimpleExpr; |
| 9967 | Expr *RHS = nullptr; |
| 9968 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 9969 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 9970 | OOLoc = BO->getOperatorLoc(); |
| 9971 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 9972 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 9973 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 9974 | OOK = OCE->getOperator(); |
| 9975 | OOLoc = OCE->getOperatorLoc(); |
| 9976 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9977 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 9978 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 9979 | OOK = MCE->getMethodDecl() |
| 9980 | ->getNameInfo() |
| 9981 | .getName() |
| 9982 | .getCXXOverloadedOperator(); |
| 9983 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 9984 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 9985 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9986 | } |
| 9987 | SourceLocation ELoc; |
| 9988 | SourceRange ERange; |
| 9989 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 9990 | /*AllowArraySection=*/false); |
| 9991 | if (Res.second) { |
| 9992 | // It will be analyzed later. |
| 9993 | Vars.push_back(RefExpr); |
| 9994 | } |
| 9995 | ValueDecl *D = Res.first; |
| 9996 | if (!D) |
| 9997 | continue; |
| 9998 | |
| 9999 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 10000 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 10001 | continue; |
| 10002 | } |
| 10003 | if (RHS) { |
| 10004 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 10005 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 10006 | if (RHSRes.isInvalid()) |
| 10007 | continue; |
| 10008 | } |
| 10009 | if (!CurContext->isDependentContext() && |
| 10010 | DSAStack->getParentOrderedRegionParam() && |
| 10011 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| 10012 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10013 | << DSAStack->getParentLoopControlVariable( |
| 10014 | DepCounter.getZExtValue()); |
| 10015 | continue; |
| 10016 | } |
| 10017 | OpsOffs.push_back({RHS, OOK}); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10018 | } else { |
| 10019 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 10020 | // A variable that is part of another variable (such as a field of a |
| 10021 | // structure) but is not an array element or an array section cannot |
| 10022 | // appear in a depend clause. |
| 10023 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 10024 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 10025 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 10026 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 10027 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 10028 | (ASE && |
| 10029 | !ASE->getBase() |
| 10030 | ->getType() |
| 10031 | .getNonReferenceType() |
| 10032 | ->isPointerType() && |
| 10033 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10034 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 10035 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10036 | continue; |
| 10037 | } |
| 10038 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10039 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 10040 | } |
| 10041 | |
| 10042 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 10043 | TotalDepCount > VarList.size() && |
| 10044 | DSAStack->getParentOrderedRegionParam()) { |
| 10045 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10046 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 10047 | } |
| 10048 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 10049 | Vars.empty()) |
| 10050 | return nullptr; |
| 10051 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10052 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10053 | DepKind, DepLoc, ColonLoc, Vars); |
| 10054 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) |
| 10055 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 10056 | return C; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10057 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10058 | |
| 10059 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 10060 | SourceLocation LParenLoc, |
| 10061 | SourceLocation EndLoc) { |
| 10062 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10063 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10064 | // OpenMP [2.9.1, Restrictions] |
| 10065 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10066 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 10067 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10068 | return nullptr; |
| 10069 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10070 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10071 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10072 | |
| 10073 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 10074 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 10075 | if (!RD || RD->isInvalidDecl()) |
| 10076 | return true; |
| 10077 | |
| 10078 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 10079 | if (RD->isDynamicClass()) { |
| 10080 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10081 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 10082 | return false; |
| 10083 | } |
| 10084 | auto *DC = RD; |
| 10085 | bool IsCorrect = true; |
| 10086 | for (auto *I : DC->decls()) { |
| 10087 | if (I) { |
| 10088 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 10089 | if (MD->isStatic()) { |
| 10090 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10091 | SemaRef.Diag(MD->getLocation(), |
| 10092 | diag::note_omp_static_member_in_target); |
| 10093 | IsCorrect = false; |
| 10094 | } |
| 10095 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 10096 | if (VD->isStaticDataMember()) { |
| 10097 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10098 | SemaRef.Diag(VD->getLocation(), |
| 10099 | diag::note_omp_static_member_in_target); |
| 10100 | IsCorrect = false; |
| 10101 | } |
| 10102 | } |
| 10103 | } |
| 10104 | } |
| 10105 | |
| 10106 | for (auto &I : RD->bases()) { |
| 10107 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 10108 | I.getType()->getAsCXXRecordDecl())) |
| 10109 | IsCorrect = false; |
| 10110 | } |
| 10111 | return IsCorrect; |
| 10112 | } |
| 10113 | |
| 10114 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 10115 | DSAStackTy *Stack, QualType QTy) { |
| 10116 | NamedDecl *ND; |
| 10117 | if (QTy->isIncompleteType(&ND)) { |
| 10118 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 10119 | return false; |
| 10120 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10121 | if (!RD->isInvalidDecl() && !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10122 | return false; |
| 10123 | } |
| 10124 | return true; |
| 10125 | } |
| 10126 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10127 | /// \brief Return true if it can be proven that the provided array expression |
| 10128 | /// (array section or array subscript) does NOT specify the whole size of the |
| 10129 | /// array whose base type is \a BaseQTy. |
| 10130 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 10131 | const Expr *E, |
| 10132 | QualType BaseQTy) { |
| 10133 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10134 | |
| 10135 | // If this is an array subscript, it refers to the whole size if the size of |
| 10136 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 10137 | // format of an array subscript if no colon is used. |
| 10138 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 10139 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10140 | return ATy->getSize().getSExtValue() != 1; |
| 10141 | // Size can't be evaluated statically. |
| 10142 | return false; |
| 10143 | } |
| 10144 | |
| 10145 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10146 | auto *LowerBound = OASE->getLowerBound(); |
| 10147 | auto *Length = OASE->getLength(); |
| 10148 | |
| 10149 | // If there is a lower bound that does not evaluates to zero, we are not |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10150 | // covering the whole dimension. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10151 | if (LowerBound) { |
| 10152 | llvm::APSInt ConstLowerBound; |
| 10153 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 10154 | return false; // Can't get the integer value as a constant. |
| 10155 | if (ConstLowerBound.getSExtValue()) |
| 10156 | return true; |
| 10157 | } |
| 10158 | |
| 10159 | // If we don't have a length we covering the whole dimension. |
| 10160 | if (!Length) |
| 10161 | return false; |
| 10162 | |
| 10163 | // If the base is a pointer, we don't have a way to get the size of the |
| 10164 | // pointee. |
| 10165 | if (BaseQTy->isPointerType()) |
| 10166 | return false; |
| 10167 | |
| 10168 | // We can only check if the length is the same as the size of the dimension |
| 10169 | // if we have a constant array. |
| 10170 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 10171 | if (!CATy) |
| 10172 | return false; |
| 10173 | |
| 10174 | llvm::APSInt ConstLength; |
| 10175 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10176 | return false; // Can't get the integer value as a constant. |
| 10177 | |
| 10178 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 10179 | } |
| 10180 | |
| 10181 | // Return true if it can be proven that the provided array expression (array |
| 10182 | // section or array subscript) does NOT specify a single element of the array |
| 10183 | // whose base type is \a BaseQTy. |
| 10184 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10185 | const Expr *E, |
| 10186 | QualType BaseQTy) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10187 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10188 | |
| 10189 | // An array subscript always refer to a single element. Also, an array section |
| 10190 | // assumes the format of an array subscript if no colon is used. |
| 10191 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 10192 | return false; |
| 10193 | |
| 10194 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10195 | auto *Length = OASE->getLength(); |
| 10196 | |
| 10197 | // If we don't have a length we have to check if the array has unitary size |
| 10198 | // for this dimension. Also, we should always expect a length if the base type |
| 10199 | // is pointer. |
| 10200 | if (!Length) { |
| 10201 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10202 | return ATy->getSize().getSExtValue() != 1; |
| 10203 | // We cannot assume anything. |
| 10204 | return false; |
| 10205 | } |
| 10206 | |
| 10207 | // Check if the length evaluates to 1. |
| 10208 | llvm::APSInt ConstLength; |
| 10209 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10210 | return false; // Can't get the integer value as a constant. |
| 10211 | |
| 10212 | return ConstLength.getSExtValue() != 1; |
| 10213 | } |
| 10214 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10215 | // Return the expression of the base of the mappable expression or null if it |
| 10216 | // cannot be determined and do all the necessary checks to see if the expression |
| 10217 | // 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] | 10218 | // components of the expression. |
| 10219 | static Expr *CheckMapClauseExpressionBase( |
| 10220 | Sema &SemaRef, Expr *E, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10221 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| 10222 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10223 | SourceLocation ELoc = E->getExprLoc(); |
| 10224 | SourceRange ERange = E->getSourceRange(); |
| 10225 | |
| 10226 | // The base of elements of list in a map clause have to be either: |
| 10227 | // - a reference to variable or field. |
| 10228 | // - a member expression. |
| 10229 | // - an array expression. |
| 10230 | // |
| 10231 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 10232 | // reference to 'r'. |
| 10233 | // |
| 10234 | // If we have: |
| 10235 | // |
| 10236 | // struct SS { |
| 10237 | // Bla S; |
| 10238 | // foo() { |
| 10239 | // #pragma omp target map (S.Arr[:12]); |
| 10240 | // } |
| 10241 | // } |
| 10242 | // |
| 10243 | // We want to retrieve the member expression 'this->S'; |
| 10244 | |
| 10245 | Expr *RelevantExpr = nullptr; |
| 10246 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10247 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 10248 | // If a list item is an array section, it must specify contiguous storage. |
| 10249 | // |
| 10250 | // For this restriction it is sufficient that we make sure only references |
| 10251 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10252 | // exist except in the rightmost expression (unless they cover the whole |
| 10253 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10254 | // |
| 10255 | // r.ArrS[3:5].Arr[6:7] |
| 10256 | // |
| 10257 | // r.ArrS[3:5].x |
| 10258 | // |
| 10259 | // but these would be valid: |
| 10260 | // r.ArrS[3].Arr[6:7] |
| 10261 | // |
| 10262 | // r.ArrS[3].x |
| 10263 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10264 | bool AllowUnitySizeArraySection = true; |
| 10265 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10266 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 10267 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10268 | E = E->IgnoreParenImpCasts(); |
| 10269 | |
| 10270 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 10271 | if (!isa<VarDecl>(CurE->getDecl())) |
| 10272 | break; |
| 10273 | |
| 10274 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10275 | |
| 10276 | // If we got a reference to a declaration, we should not expect any array |
| 10277 | // section before that. |
| 10278 | AllowUnitySizeArraySection = false; |
| 10279 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10280 | |
| 10281 | // Record the component. |
| 10282 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 10283 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10284 | continue; |
| 10285 | } |
| 10286 | |
| 10287 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 10288 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 10289 | |
| 10290 | if (isa<CXXThisExpr>(BaseE)) |
| 10291 | // We found a base expression: this->Val. |
| 10292 | RelevantExpr = CurE; |
| 10293 | else |
| 10294 | E = BaseE; |
| 10295 | |
| 10296 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 10297 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 10298 | << CurE->getSourceRange(); |
| 10299 | break; |
| 10300 | } |
| 10301 | |
| 10302 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 10303 | |
| 10304 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 10305 | // A bit-field cannot appear in a map clause. |
| 10306 | // |
| 10307 | if (FD->isBitField()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10308 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 10309 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10310 | break; |
| 10311 | } |
| 10312 | |
| 10313 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10314 | // If the type of a list item is a reference to a type T then the type |
| 10315 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10316 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10317 | |
| 10318 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 10319 | // A list item cannot be a variable that is a member of a structure with |
| 10320 | // a union type. |
| 10321 | // |
| 10322 | if (auto *RT = CurType->getAs<RecordType>()) |
| 10323 | if (RT->isUnionType()) { |
| 10324 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 10325 | << CurE->getSourceRange(); |
| 10326 | break; |
| 10327 | } |
| 10328 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10329 | // If we got a member expression, we should not expect any array section |
| 10330 | // before that: |
| 10331 | // |
| 10332 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 10333 | // If a list item is an element of a structure, only the rightmost symbol |
| 10334 | // of the variable reference can be an array section. |
| 10335 | // |
| 10336 | AllowUnitySizeArraySection = false; |
| 10337 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10338 | |
| 10339 | // Record the component. |
| 10340 | CurComponents.push_back( |
| 10341 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10342 | continue; |
| 10343 | } |
| 10344 | |
| 10345 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 10346 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10347 | |
| 10348 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 10349 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10350 | << 0 << CurE->getSourceRange(); |
| 10351 | break; |
| 10352 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10353 | |
| 10354 | // If we got an array subscript that express the whole dimension we |
| 10355 | // can have any array expressions before. If it only expressing part of |
| 10356 | // the dimension, we can only have unitary-size array expressions. |
| 10357 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 10358 | E->getType())) |
| 10359 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10360 | |
| 10361 | // Record the component - we don't have any declaration associated. |
| 10362 | CurComponents.push_back( |
| 10363 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10364 | continue; |
| 10365 | } |
| 10366 | |
| 10367 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10368 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10369 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10370 | auto CurType = |
| 10371 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10372 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10373 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10374 | // If the type of a list item is a reference to a type T then the type |
| 10375 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10376 | if (CurType->isReferenceType()) |
| 10377 | CurType = CurType->getPointeeType(); |
| 10378 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10379 | bool IsPointer = CurType->isAnyPointerType(); |
| 10380 | |
| 10381 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10382 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10383 | << 0 << CurE->getSourceRange(); |
| 10384 | break; |
| 10385 | } |
| 10386 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10387 | bool NotWhole = |
| 10388 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 10389 | bool NotUnity = |
| 10390 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 10391 | |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10392 | if (AllowWholeSizeArraySection) { |
| 10393 | // Any array section is currently allowed. Allowing a whole size array |
| 10394 | // section implies allowing a unity array section as well. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10395 | // |
| 10396 | // If this array section refers to the whole dimension we can still |
| 10397 | // accept other array sections before this one, except if the base is a |
| 10398 | // pointer. Otherwise, only unitary sections are accepted. |
| 10399 | if (NotWhole || IsPointer) |
| 10400 | AllowWholeSizeArraySection = false; |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10401 | } else if (AllowUnitySizeArraySection && NotUnity) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10402 | // A unity or whole array section is not allowed and that is not |
| 10403 | // compatible with the properties of the current array section. |
| 10404 | SemaRef.Diag( |
| 10405 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 10406 | << CurE->getSourceRange(); |
| 10407 | break; |
| 10408 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10409 | |
| 10410 | // Record the component - we don't have any declaration associated. |
| 10411 | CurComponents.push_back( |
| 10412 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10413 | continue; |
| 10414 | } |
| 10415 | |
| 10416 | // If nothing else worked, this is not a valid map clause expression. |
| 10417 | SemaRef.Diag(ELoc, |
| 10418 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 10419 | << ERange; |
| 10420 | break; |
| 10421 | } |
| 10422 | |
| 10423 | return RelevantExpr; |
| 10424 | } |
| 10425 | |
| 10426 | // Return true if expression E associated with value VD has conflicts with other |
| 10427 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10428 | static bool CheckMapConflicts( |
| 10429 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 10430 | bool CurrentRegionOnly, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10431 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 10432 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10433 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10434 | SourceLocation ELoc = E->getExprLoc(); |
| 10435 | SourceRange ERange = E->getSourceRange(); |
| 10436 | |
| 10437 | // In order to easily check the conflicts we need to match each component of |
| 10438 | // the expression under test with the components of the expressions that are |
| 10439 | // already in the stack. |
| 10440 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10441 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10442 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10443 | "Map clause expression with unexpected base!"); |
| 10444 | |
| 10445 | // Variables to help detecting enclosing problems in data environment nests. |
| 10446 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10447 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10448 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10449 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 10450 | VD, CurrentRegionOnly, |
| 10451 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10452 | StackComponents, |
| 10453 | OpenMPClauseKind) -> bool { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10454 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10455 | assert(!StackComponents.empty() && |
| 10456 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10457 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10458 | "Map clause expression with unexpected base!"); |
| 10459 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10460 | // The whole expression in the stack. |
| 10461 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 10462 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10463 | // Expressions must start from the same base. Here we detect at which |
| 10464 | // point both expressions diverge from each other and see if we can |
| 10465 | // detect if the memory referred to both expressions is contiguous and |
| 10466 | // do not overlap. |
| 10467 | auto CI = CurComponents.rbegin(); |
| 10468 | auto CE = CurComponents.rend(); |
| 10469 | auto SI = StackComponents.rbegin(); |
| 10470 | auto SE = StackComponents.rend(); |
| 10471 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 10472 | |
| 10473 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 10474 | // At most one list item can be an array item derived from a given |
| 10475 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10476 | if (CurrentRegionOnly && |
| 10477 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10478 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10479 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10480 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10481 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10482 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10483 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10484 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10485 | diag::note_used_here) |
| 10486 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10487 | return true; |
| 10488 | } |
| 10489 | |
| 10490 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10491 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10492 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10493 | break; |
| 10494 | |
| 10495 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10496 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10497 | break; |
| 10498 | } |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10499 | // Check if the extra components of the expressions in the enclosing |
| 10500 | // data environment are redundant for the current base declaration. |
| 10501 | // If they are, the maps completely overlap, which is legal. |
| 10502 | for (; SI != SE; ++SI) { |
| 10503 | QualType Type; |
| 10504 | if (auto *ASE = |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10505 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10506 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10507 | } else if (auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| 10508 | SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10509 | auto *E = OASE->getBase()->IgnoreParenImpCasts(); |
| 10510 | Type = |
| 10511 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10512 | } |
| 10513 | if (Type.isNull() || Type->isAnyPointerType() || |
| 10514 | CheckArrayExpressionDoesNotReferToWholeSize( |
| 10515 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 10516 | break; |
| 10517 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10518 | |
| 10519 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10520 | // List items of map clauses in the same construct must not share |
| 10521 | // original storage. |
| 10522 | // |
| 10523 | // If the expressions are exactly the same or one is a subset of the |
| 10524 | // other, it means they are sharing storage. |
| 10525 | if (CI == CE && SI == SE) { |
| 10526 | if (CurrentRegionOnly) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10527 | if (CKind == OMPC_map) |
| 10528 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10529 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10530 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10531 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10532 | << ERange; |
| 10533 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10534 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10535 | << RE->getSourceRange(); |
| 10536 | return true; |
| 10537 | } else { |
| 10538 | // If we find the same expression in the enclosing data environment, |
| 10539 | // that is legal. |
| 10540 | IsEnclosedByDataEnvironmentExpr = true; |
| 10541 | return false; |
| 10542 | } |
| 10543 | } |
| 10544 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10545 | QualType DerivedType = |
| 10546 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10547 | SourceLocation DerivedLoc = |
| 10548 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10549 | |
| 10550 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10551 | // If the type of a list item is a reference to a type T then the type |
| 10552 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10553 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10554 | |
| 10555 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 10556 | // A variable for which the type is pointer and an array section |
| 10557 | // derived from that variable must not appear as list items of map |
| 10558 | // clauses of the same construct. |
| 10559 | // |
| 10560 | // Also, cover one of the cases in: |
| 10561 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10562 | // If any part of the original storage of a list item has corresponding |
| 10563 | // storage in the device data environment, all of the original storage |
| 10564 | // must have corresponding storage in the device data environment. |
| 10565 | // |
| 10566 | if (DerivedType->isAnyPointerType()) { |
| 10567 | if (CI == CE || SI == SE) { |
| 10568 | SemaRef.Diag( |
| 10569 | DerivedLoc, |
| 10570 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 10571 | << DerivedLoc; |
| 10572 | } else { |
| 10573 | assert(CI != CE && SI != SE); |
| 10574 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 10575 | << DerivedLoc; |
| 10576 | } |
| 10577 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10578 | << RE->getSourceRange(); |
| 10579 | return true; |
| 10580 | } |
| 10581 | |
| 10582 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10583 | // List items of map clauses in the same construct must not share |
| 10584 | // original storage. |
| 10585 | // |
| 10586 | // An expression is a subset of the other. |
| 10587 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10588 | if (CKind == OMPC_map) |
| 10589 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10590 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10591 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10592 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10593 | << ERange; |
| 10594 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10595 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10596 | << RE->getSourceRange(); |
| 10597 | return true; |
| 10598 | } |
| 10599 | |
| 10600 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10601 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10602 | if (!CurrentRegionOnly && SI != SE) |
| 10603 | EnclosingExpr = RE; |
| 10604 | |
| 10605 | // The current expression is a subset of the expression in the data |
| 10606 | // environment. |
| 10607 | IsEnclosedByDataEnvironmentExpr |= |
| 10608 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 10609 | |
| 10610 | return false; |
| 10611 | }); |
| 10612 | |
| 10613 | if (CurrentRegionOnly) |
| 10614 | return FoundError; |
| 10615 | |
| 10616 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10617 | // If any part of the original storage of a list item has corresponding |
| 10618 | // storage in the device data environment, all of the original storage must |
| 10619 | // have corresponding storage in the device data environment. |
| 10620 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 10621 | // If a list item is an element of a structure, and a different element of |
| 10622 | // the structure has a corresponding list item in the device data environment |
| 10623 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10624 | // 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] | 10625 | // data environment prior to the task encountering the construct. |
| 10626 | // |
| 10627 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 10628 | SemaRef.Diag(ELoc, |
| 10629 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 10630 | << ERange; |
| 10631 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 10632 | << EnclosingExpr->getSourceRange(); |
| 10633 | return true; |
| 10634 | } |
| 10635 | |
| 10636 | return FoundError; |
| 10637 | } |
| 10638 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10639 | namespace { |
| 10640 | // Utility struct that gathers all the related lists associated with a mappable |
| 10641 | // expression. |
| 10642 | struct MappableVarListInfo final { |
| 10643 | // The list of expressions. |
| 10644 | ArrayRef<Expr *> VarList; |
| 10645 | // The list of processed expressions. |
| 10646 | SmallVector<Expr *, 16> ProcessedVarList; |
| 10647 | // The mappble components for each expression. |
| 10648 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 10649 | // The base declaration of the variable. |
| 10650 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 10651 | |
| 10652 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 10653 | // We have a list of components and base declarations for each entry in the |
| 10654 | // variable list. |
| 10655 | VarComponents.reserve(VarList.size()); |
| 10656 | VarBaseDeclarations.reserve(VarList.size()); |
| 10657 | } |
| 10658 | }; |
| 10659 | } |
| 10660 | |
| 10661 | // Check the validity of the provided variable list for the provided clause kind |
| 10662 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 10663 | // components and variables are extracted and used to fill \a Vars, |
| 10664 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 10665 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 10666 | static void |
| 10667 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 10668 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 10669 | SourceLocation StartLoc, |
| 10670 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 10671 | bool IsMapTypeImplicit = false) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10672 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 10673 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10674 | "Unexpected clause kind with mappable expressions!"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10675 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10676 | // Keep track of the mappable components and base declarations in this clause. |
| 10677 | // Each entry in the list is going to have a list of components associated. We |
| 10678 | // record each set of the components so that we can build the clause later on. |
| 10679 | // In the end we should have the same amount of declarations and component |
| 10680 | // lists. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10681 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10682 | for (auto &RE : MVLI.VarList) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10683 | assert(RE && "Null expr in omp to/from/map clause"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10684 | SourceLocation ELoc = RE->getExprLoc(); |
| 10685 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10686 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 10687 | |
| 10688 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 10689 | VE->isInstantiationDependent() || |
| 10690 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10691 | // We can only analyze this information once the missing information is |
| 10692 | // resolved. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10693 | MVLI.ProcessedVarList.push_back(RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10694 | continue; |
| 10695 | } |
| 10696 | |
| 10697 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10698 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10699 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10700 | SemaRef.Diag(ELoc, |
| 10701 | diag::err_omp_expected_named_var_member_or_array_expression) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10702 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10703 | continue; |
| 10704 | } |
| 10705 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10706 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 10707 | ValueDecl *CurDeclaration = nullptr; |
| 10708 | |
| 10709 | // Obtain the array or member expression bases if required. Also, fill the |
| 10710 | // components array with all the components identified in the process. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10711 | auto *BE = |
| 10712 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10713 | if (!BE) |
| 10714 | continue; |
| 10715 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10716 | assert(!CurComponents.empty() && |
| 10717 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10718 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10719 | // For the following checks, we rely on the base declaration which is |
| 10720 | // expected to be associated with the last component. The declaration is |
| 10721 | // expected to be a variable or a field (if 'this' is being mapped). |
| 10722 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 10723 | assert(CurDeclaration && "Null decl on map clause."); |
| 10724 | assert( |
| 10725 | CurDeclaration->isCanonicalDecl() && |
| 10726 | "Expecting components to have associated only canonical declarations."); |
| 10727 | |
| 10728 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 10729 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10730 | |
| 10731 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 10732 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10733 | |
| 10734 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10735 | // threadprivate variables cannot appear in a map clause. |
| 10736 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 10737 | // threadprivate variables cannot appear in a from clause. |
| 10738 | if (VD && DSAS->isThreadPrivate(VD)) { |
| 10739 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10740 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 10741 | << getOpenMPClauseName(CKind); |
| 10742 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10743 | continue; |
| 10744 | } |
| 10745 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10746 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 10747 | // A list item cannot appear in both a map clause and a data-sharing |
| 10748 | // attribute clause on the same construct. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10749 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10750 | // Check conflicts with other map clause expressions. We check the conflicts |
| 10751 | // with the current construct separately from the enclosing data |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10752 | // environment, because the restrictions are different. We only have to |
| 10753 | // check conflicts across regions for the map clauses. |
| 10754 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10755 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10756 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10757 | if (CKind == OMPC_map && |
| 10758 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10759 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10760 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10761 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10762 | // OpenMP 4.5 [2.10.5, target update Construct] |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10763 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10764 | // If the type of a list item is a reference to a type T then the type will |
| 10765 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10766 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10767 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10768 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 10769 | // 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] | 10770 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10771 | // A list item must have a mappable type. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10772 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| 10773 | DSAS, Type)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10774 | continue; |
| 10775 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10776 | if (CKind == OMPC_map) { |
| 10777 | // target enter data |
| 10778 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 10779 | // A map-type must be specified in all map clauses and must be either |
| 10780 | // to or alloc. |
| 10781 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 10782 | if (DKind == OMPD_target_enter_data && |
| 10783 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 10784 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10785 | << (IsMapTypeImplicit ? 1 : 0) |
| 10786 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10787 | << getOpenMPDirectiveName(DKind); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10788 | continue; |
| 10789 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10790 | |
| 10791 | // target exit_data |
| 10792 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 10793 | // A map-type must be specified in all map clauses and must be either |
| 10794 | // from, release, or delete. |
| 10795 | if (DKind == OMPD_target_exit_data && |
| 10796 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 10797 | MapType == OMPC_MAP_delete)) { |
| 10798 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10799 | << (IsMapTypeImplicit ? 1 : 0) |
| 10800 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10801 | << getOpenMPDirectiveName(DKind); |
| 10802 | continue; |
| 10803 | } |
| 10804 | |
| 10805 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 10806 | // A list item cannot appear in both a map clause and a data-sharing |
| 10807 | // attribute clause on the same construct |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10808 | if ((DKind == OMPD_target || DKind == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10809 | DKind == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10810 | DKind == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10811 | DKind == OMPD_target_teams_distribute_parallel_for_simd || |
| 10812 | DKind == OMPD_target_teams_distribute_simd) && VD) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10813 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10814 | if (isOpenMPPrivate(DVar.CKind)) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10815 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10816 | << getOpenMPClauseName(DVar.CKind) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10817 | << getOpenMPClauseName(OMPC_map) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10818 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| 10819 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); |
| 10820 | continue; |
| 10821 | } |
| 10822 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10823 | } |
| 10824 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10825 | // Save the current expression. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10826 | MVLI.ProcessedVarList.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10827 | |
| 10828 | // Store the components in the stack so that they can be used to check |
| 10829 | // against other clauses later on. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10830 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 10831 | /*WhereFoundClauseKind=*/OMPC_map); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10832 | |
| 10833 | // Save the components and declaration to create the clause. For purposes of |
| 10834 | // the clause creation, any component list that has has base 'this' uses |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 10835 | // null as base declaration. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10836 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 10837 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 10838 | CurComponents.end()); |
| 10839 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 10840 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10841 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10842 | } |
| 10843 | |
| 10844 | OMPClause * |
| 10845 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 10846 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 10847 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 10848 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10849 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 10850 | MappableVarListInfo MVLI(VarList); |
| 10851 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 10852 | MapType, IsMapTypeImplicit); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10853 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10854 | // We need to produce a map clause even if we don't have variables so that |
| 10855 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10856 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10857 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 10858 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 10859 | IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10860 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10861 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10862 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 10863 | TypeResult ParsedType) { |
| 10864 | assert(ParsedType.isUsable()); |
| 10865 | |
| 10866 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 10867 | if (ReductionType.isNull()) |
| 10868 | return QualType(); |
| 10869 | |
| 10870 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 10871 | // A type name in a declare reduction directive cannot be a function type, an |
| 10872 | // array type, a reference type, or a type qualified with const, volatile or |
| 10873 | // restrict. |
| 10874 | if (ReductionType.hasQualifiers()) { |
| 10875 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 10876 | return QualType(); |
| 10877 | } |
| 10878 | |
| 10879 | if (ReductionType->isFunctionType()) { |
| 10880 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 10881 | return QualType(); |
| 10882 | } |
| 10883 | if (ReductionType->isReferenceType()) { |
| 10884 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 10885 | return QualType(); |
| 10886 | } |
| 10887 | if (ReductionType->isArrayType()) { |
| 10888 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 10889 | return QualType(); |
| 10890 | } |
| 10891 | return ReductionType; |
| 10892 | } |
| 10893 | |
| 10894 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 10895 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 10896 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 10897 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 10898 | SmallVector<Decl *, 8> Decls; |
| 10899 | Decls.reserve(ReductionTypes.size()); |
| 10900 | |
| 10901 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 10902 | ForRedeclaration); |
| 10903 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 10904 | // A reduction-identifier may not be re-declared in the current scope for the |
| 10905 | // same type or for a type that is compatible according to the base language |
| 10906 | // rules. |
| 10907 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 10908 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 10909 | bool InCompoundScope = true; |
| 10910 | if (S != nullptr) { |
| 10911 | // Find previous declaration with the same name not referenced in other |
| 10912 | // declarations. |
| 10913 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 10914 | InCompoundScope = |
| 10915 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 10916 | LookupName(Lookup, S); |
| 10917 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 10918 | /*AllowInlineNamespace=*/false); |
| 10919 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 10920 | auto Filter = Lookup.makeFilter(); |
| 10921 | while (Filter.hasNext()) { |
| 10922 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 10923 | if (InCompoundScope) { |
| 10924 | auto I = UsedAsPrevious.find(PrevDecl); |
| 10925 | if (I == UsedAsPrevious.end()) |
| 10926 | UsedAsPrevious[PrevDecl] = false; |
| 10927 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 10928 | UsedAsPrevious[D] = true; |
| 10929 | } |
| 10930 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 10931 | PrevDecl->getLocation(); |
| 10932 | } |
| 10933 | Filter.done(); |
| 10934 | if (InCompoundScope) { |
| 10935 | for (auto &PrevData : UsedAsPrevious) { |
| 10936 | if (!PrevData.second) { |
| 10937 | PrevDRD = PrevData.first; |
| 10938 | break; |
| 10939 | } |
| 10940 | } |
| 10941 | } |
| 10942 | } else if (PrevDeclInScope != nullptr) { |
| 10943 | auto *PrevDRDInScope = PrevDRD = |
| 10944 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 10945 | do { |
| 10946 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 10947 | PrevDRDInScope->getLocation(); |
| 10948 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 10949 | } while (PrevDRDInScope != nullptr); |
| 10950 | } |
| 10951 | for (auto &TyData : ReductionTypes) { |
| 10952 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 10953 | bool Invalid = false; |
| 10954 | if (I != PreviousRedeclTypes.end()) { |
| 10955 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 10956 | << TyData.first; |
| 10957 | Diag(I->second, diag::note_previous_definition); |
| 10958 | Invalid = true; |
| 10959 | } |
| 10960 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 10961 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 10962 | Name, TyData.first, PrevDRD); |
| 10963 | DC->addDecl(DRD); |
| 10964 | DRD->setAccess(AS); |
| 10965 | Decls.push_back(DRD); |
| 10966 | if (Invalid) |
| 10967 | DRD->setInvalidDecl(); |
| 10968 | else |
| 10969 | PrevDRD = DRD; |
| 10970 | } |
| 10971 | |
| 10972 | return DeclGroupPtrTy::make( |
| 10973 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 10974 | } |
| 10975 | |
| 10976 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 10977 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10978 | |
| 10979 | // Enter new function scope. |
| 10980 | PushFunctionScope(); |
| 10981 | getCurFunction()->setHasBranchProtectedScope(); |
| 10982 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 10983 | |
| 10984 | if (S != nullptr) |
| 10985 | PushDeclContext(S, DRD); |
| 10986 | else |
| 10987 | CurContext = DRD; |
| 10988 | |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10989 | PushExpressionEvaluationContext( |
| 10990 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10991 | |
| 10992 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10993 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 10994 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 10995 | // uses semantics of argument handles by value, but it should be passed by |
| 10996 | // reference. C lang does not support references, so pass all parameters as |
| 10997 | // pointers. |
| 10998 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10999 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11000 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11001 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 11002 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 11003 | // uses semantics of argument handles by value, but it should be passed by |
| 11004 | // reference. C lang does not support references, so pass all parameters as |
| 11005 | // pointers. |
| 11006 | // Create 'T omp_out;' variable. |
| 11007 | auto *OmpOutParm = |
| 11008 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 11009 | if (S != nullptr) { |
| 11010 | PushOnScopeChains(OmpInParm, S); |
| 11011 | PushOnScopeChains(OmpOutParm, S); |
| 11012 | } else { |
| 11013 | DRD->addDecl(OmpInParm); |
| 11014 | DRD->addDecl(OmpOutParm); |
| 11015 | } |
| 11016 | } |
| 11017 | |
| 11018 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 11019 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11020 | DiscardCleanupsInEvaluationContext(); |
| 11021 | PopExpressionEvaluationContext(); |
| 11022 | |
| 11023 | PopDeclContext(); |
| 11024 | PopFunctionScopeInfo(); |
| 11025 | |
| 11026 | if (Combiner != nullptr) |
| 11027 | DRD->setCombiner(Combiner); |
| 11028 | else |
| 11029 | DRD->setInvalidDecl(); |
| 11030 | } |
| 11031 | |
| 11032 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 11033 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11034 | |
| 11035 | // Enter new function scope. |
| 11036 | PushFunctionScope(); |
| 11037 | getCurFunction()->setHasBranchProtectedScope(); |
| 11038 | |
| 11039 | if (S != nullptr) |
| 11040 | PushDeclContext(S, DRD); |
| 11041 | else |
| 11042 | CurContext = DRD; |
| 11043 | |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11044 | PushExpressionEvaluationContext( |
| 11045 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11046 | |
| 11047 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11048 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 11049 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 11050 | // uses semantics of argument handles by value, but it should be passed by |
| 11051 | // reference. C lang does not support references, so pass all parameters as |
| 11052 | // pointers. |
| 11053 | // Create 'T omp_priv;' variable. |
| 11054 | auto *OmpPrivParm = |
| 11055 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11056 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 11057 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 11058 | // uses semantics of argument handles by value, but it should be passed by |
| 11059 | // reference. C lang does not support references, so pass all parameters as |
| 11060 | // pointers. |
| 11061 | // Create 'T omp_orig;' variable. |
| 11062 | auto *OmpOrigParm = |
| 11063 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11064 | if (S != nullptr) { |
| 11065 | PushOnScopeChains(OmpPrivParm, S); |
| 11066 | PushOnScopeChains(OmpOrigParm, S); |
| 11067 | } else { |
| 11068 | DRD->addDecl(OmpPrivParm); |
| 11069 | DRD->addDecl(OmpOrigParm); |
| 11070 | } |
| 11071 | } |
| 11072 | |
| 11073 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 11074 | Expr *Initializer) { |
| 11075 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11076 | DiscardCleanupsInEvaluationContext(); |
| 11077 | PopExpressionEvaluationContext(); |
| 11078 | |
| 11079 | PopDeclContext(); |
| 11080 | PopFunctionScopeInfo(); |
| 11081 | |
| 11082 | if (Initializer != nullptr) |
| 11083 | DRD->setInitializer(Initializer); |
| 11084 | else |
| 11085 | DRD->setInvalidDecl(); |
| 11086 | } |
| 11087 | |
| 11088 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 11089 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 11090 | for (auto *D : DeclReductions.get()) { |
| 11091 | if (IsValid) { |
| 11092 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11093 | if (S != nullptr) |
| 11094 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 11095 | } else |
| 11096 | D->setInvalidDecl(); |
| 11097 | } |
| 11098 | return DeclReductions; |
| 11099 | } |
| 11100 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11101 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11102 | SourceLocation StartLoc, |
| 11103 | SourceLocation LParenLoc, |
| 11104 | SourceLocation EndLoc) { |
| 11105 | Expr *ValExpr = NumTeams; |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 11106 | Stmt *HelperValStmt = nullptr; |
| 11107 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11108 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11109 | // OpenMP [teams Constrcut, Restrictions] |
| 11110 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11111 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 11112 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11113 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11114 | |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 11115 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 11116 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_num_teams); |
| 11117 | if (CaptureRegion != OMPD_unknown) { |
| 11118 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11119 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11120 | HelperValStmt = buildPreInits(Context, Captures); |
| 11121 | } |
| 11122 | |
| 11123 | return new (Context) OMPNumTeamsClause(ValExpr, HelperValStmt, CaptureRegion, |
| 11124 | StartLoc, LParenLoc, EndLoc); |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11125 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11126 | |
| 11127 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 11128 | SourceLocation StartLoc, |
| 11129 | SourceLocation LParenLoc, |
| 11130 | SourceLocation EndLoc) { |
| 11131 | Expr *ValExpr = ThreadLimit; |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 11132 | Stmt *HelperValStmt = nullptr; |
| 11133 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11134 | |
| 11135 | // OpenMP [teams Constrcut, Restrictions] |
| 11136 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11137 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 11138 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11139 | return nullptr; |
| 11140 | |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 11141 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 11142 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_thread_limit); |
| 11143 | if (CaptureRegion != OMPD_unknown) { |
| 11144 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11145 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11146 | HelperValStmt = buildPreInits(Context, Captures); |
| 11147 | } |
| 11148 | |
| 11149 | return new (Context) OMPThreadLimitClause( |
| 11150 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11151 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11152 | |
| 11153 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 11154 | SourceLocation StartLoc, |
| 11155 | SourceLocation LParenLoc, |
| 11156 | SourceLocation EndLoc) { |
| 11157 | Expr *ValExpr = Priority; |
| 11158 | |
| 11159 | // OpenMP [2.9.1, task Constrcut] |
| 11160 | // The priority-value is a non-negative numerical scalar expression. |
| 11161 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 11162 | /*StrictlyPositive=*/false)) |
| 11163 | return nullptr; |
| 11164 | |
| 11165 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11166 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 11167 | |
| 11168 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 11169 | SourceLocation StartLoc, |
| 11170 | SourceLocation LParenLoc, |
| 11171 | SourceLocation EndLoc) { |
| 11172 | Expr *ValExpr = Grainsize; |
| 11173 | |
| 11174 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11175 | // The parameter of the grainsize clause must be a positive integer |
| 11176 | // expression. |
| 11177 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 11178 | /*StrictlyPositive=*/true)) |
| 11179 | return nullptr; |
| 11180 | |
| 11181 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11182 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 11183 | |
| 11184 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 11185 | SourceLocation StartLoc, |
| 11186 | SourceLocation LParenLoc, |
| 11187 | SourceLocation EndLoc) { |
| 11188 | Expr *ValExpr = NumTasks; |
| 11189 | |
| 11190 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11191 | // The parameter of the num_tasks clause must be a positive integer |
| 11192 | // expression. |
| 11193 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 11194 | /*StrictlyPositive=*/true)) |
| 11195 | return nullptr; |
| 11196 | |
| 11197 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11198 | } |
| 11199 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 11200 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 11201 | SourceLocation LParenLoc, |
| 11202 | SourceLocation EndLoc) { |
| 11203 | // OpenMP [2.13.2, critical construct, Description] |
| 11204 | // ... where hint-expression is an integer constant expression that evaluates |
| 11205 | // to a valid lock hint. |
| 11206 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 11207 | if (HintExpr.isInvalid()) |
| 11208 | return nullptr; |
| 11209 | return new (Context) |
| 11210 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 11211 | } |
| 11212 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11213 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 11214 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 11215 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 11216 | SourceLocation EndLoc) { |
| 11217 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 11218 | std::string Values; |
| 11219 | Values += "'"; |
| 11220 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 11221 | Values += "'"; |
| 11222 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 11223 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 11224 | return nullptr; |
| 11225 | } |
| 11226 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11227 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11228 | if (ChunkSize) { |
| 11229 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 11230 | !ChunkSize->isInstantiationDependent() && |
| 11231 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 11232 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 11233 | ExprResult Val = |
| 11234 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 11235 | if (Val.isInvalid()) |
| 11236 | return nullptr; |
| 11237 | |
| 11238 | ValExpr = Val.get(); |
| 11239 | |
| 11240 | // OpenMP [2.7.1, Restrictions] |
| 11241 | // chunk_size must be a loop invariant integer expression with a positive |
| 11242 | // value. |
| 11243 | llvm::APSInt Result; |
| 11244 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 11245 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 11246 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 11247 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 11248 | return nullptr; |
| 11249 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 11250 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 11251 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11252 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11253 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11254 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11255 | } |
| 11256 | } |
| 11257 | } |
| 11258 | |
| 11259 | return new (Context) |
| 11260 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11261 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11262 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11263 | |
| 11264 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 11265 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 11266 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 11267 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 11268 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11269 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || Kind != OMPC_DEFAULTMAP_scalar) { |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11270 | std::string Value; |
| 11271 | SourceLocation Loc; |
| 11272 | Value += "'"; |
| 11273 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 11274 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11275 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11276 | Loc = MLoc; |
| 11277 | } else { |
| 11278 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11279 | OMPC_DEFAULTMAP_scalar); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11280 | Loc = KindLoc; |
| 11281 | } |
| 11282 | Value += "'"; |
| 11283 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 11284 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 11285 | return nullptr; |
| 11286 | } |
| 11287 | |
| 11288 | return new (Context) |
| 11289 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 11290 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11291 | |
| 11292 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 11293 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 11294 | if (!CurLexicalContext->isFileContext() && |
| 11295 | !CurLexicalContext->isExternCContext() && |
| 11296 | !CurLexicalContext->isExternCXXContext()) { |
| 11297 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 11298 | return false; |
| 11299 | } |
| 11300 | if (IsInOpenMPDeclareTargetContext) { |
| 11301 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 11302 | return false; |
| 11303 | } |
| 11304 | |
| 11305 | IsInOpenMPDeclareTargetContext = true; |
| 11306 | return true; |
| 11307 | } |
| 11308 | |
| 11309 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 11310 | assert(IsInOpenMPDeclareTargetContext && |
| 11311 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 11312 | |
| 11313 | IsInOpenMPDeclareTargetContext = false; |
| 11314 | } |
| 11315 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11316 | void Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, |
| 11317 | CXXScopeSpec &ScopeSpec, |
| 11318 | const DeclarationNameInfo &Id, |
| 11319 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 11320 | NamedDeclSetType &SameDirectiveDecls) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11321 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 11322 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 11323 | |
| 11324 | if (Lookup.isAmbiguous()) |
| 11325 | return; |
| 11326 | Lookup.suppressDiagnostics(); |
| 11327 | |
| 11328 | if (!Lookup.isSingleResult()) { |
| 11329 | if (TypoCorrection Corrected = |
| 11330 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 11331 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 11332 | CTK_ErrorRecovery)) { |
| 11333 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 11334 | << Id.getName()); |
| 11335 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 11336 | return; |
| 11337 | } |
| 11338 | |
| 11339 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 11340 | return; |
| 11341 | } |
| 11342 | |
| 11343 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| 11344 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 11345 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 11346 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 11347 | |
| 11348 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { |
| 11349 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| 11350 | ND->addAttr(A); |
| 11351 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 11352 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 11353 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); |
| 11354 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { |
| 11355 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 11356 | << Id.getName(); |
| 11357 | } |
| 11358 | } else |
| 11359 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| 11360 | } |
| 11361 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11362 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 11363 | Sema &SemaRef, Decl *D) { |
| 11364 | if (!D) |
| 11365 | return; |
| 11366 | Decl *LD = nullptr; |
| 11367 | if (isa<TagDecl>(D)) { |
| 11368 | LD = cast<TagDecl>(D)->getDefinition(); |
| 11369 | } else if (isa<VarDecl>(D)) { |
| 11370 | LD = cast<VarDecl>(D)->getDefinition(); |
| 11371 | |
| 11372 | // If this is an implicit variable that is legal and we do not need to do |
| 11373 | // anything. |
| 11374 | if (cast<VarDecl>(D)->isImplicit()) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11375 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11376 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11377 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11378 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11379 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11380 | return; |
| 11381 | } |
| 11382 | |
| 11383 | } else if (isa<FunctionDecl>(D)) { |
| 11384 | const FunctionDecl *FD = nullptr; |
| 11385 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 11386 | LD = const_cast<FunctionDecl *>(FD); |
| 11387 | |
| 11388 | // If the definition is associated with the current declaration in the |
| 11389 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 11390 | // to do anything else. |
| 11391 | if (LD == D) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11392 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11393 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11394 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11395 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11396 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11397 | return; |
| 11398 | } |
| 11399 | } |
| 11400 | if (!LD) |
| 11401 | LD = D; |
| 11402 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11403 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 11404 | // Outlined declaration is not declared target. |
| 11405 | if (LD->isOutOfLine()) { |
| 11406 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11407 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11408 | } else { |
| 11409 | DeclContext *DC = LD->getDeclContext(); |
| 11410 | while (DC) { |
| 11411 | if (isa<FunctionDecl>(DC) && |
| 11412 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11413 | break; |
| 11414 | DC = DC->getParent(); |
| 11415 | } |
| 11416 | if (DC) |
| 11417 | return; |
| 11418 | |
| 11419 | // Is not declared in target context. |
| 11420 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11421 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11422 | } |
| 11423 | // Mark decl as declared target to prevent further diagnostic. |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11424 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11425 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11426 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11427 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11428 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11429 | } |
| 11430 | } |
| 11431 | |
| 11432 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 11433 | Sema &SemaRef, DSAStackTy *Stack, |
| 11434 | ValueDecl *VD) { |
| 11435 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11436 | return true; |
| 11437 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 11438 | return false; |
| 11439 | return true; |
| 11440 | } |
| 11441 | |
| 11442 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 11443 | if (!D || D->isInvalidDecl()) |
| 11444 | return; |
| 11445 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 11446 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 11447 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 11448 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 11449 | if (DSAStack->isThreadPrivate(VD)) { |
| 11450 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 11451 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 11452 | return; |
| 11453 | } |
| 11454 | } |
| 11455 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 11456 | // Problem if any with var declared with incomplete type will be reported |
| 11457 | // as normal, so no need to check it here. |
| 11458 | if ((E || !VD->getType()->isIncompleteType()) && |
| 11459 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 11460 | // Mark decl as declared target to prevent further diagnostic. |
| 11461 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11462 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11463 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11464 | VD->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11465 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11466 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11467 | } |
| 11468 | return; |
| 11469 | } |
| 11470 | } |
| 11471 | if (!E) { |
| 11472 | // Checking declaration inside declare target region. |
| 11473 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11474 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11475 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11476 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11477 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11478 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11479 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11480 | } |
| 11481 | return; |
| 11482 | } |
| 11483 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 11484 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11485 | |
| 11486 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 11487 | SourceLocation StartLoc, |
| 11488 | SourceLocation LParenLoc, |
| 11489 | SourceLocation EndLoc) { |
| 11490 | MappableVarListInfo MVLI(VarList); |
| 11491 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 11492 | if (MVLI.ProcessedVarList.empty()) |
| 11493 | return nullptr; |
| 11494 | |
| 11495 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11496 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11497 | MVLI.VarComponents); |
| 11498 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11499 | |
| 11500 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 11501 | SourceLocation StartLoc, |
| 11502 | SourceLocation LParenLoc, |
| 11503 | SourceLocation EndLoc) { |
| 11504 | MappableVarListInfo MVLI(VarList); |
| 11505 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 11506 | if (MVLI.ProcessedVarList.empty()) |
| 11507 | return nullptr; |
| 11508 | |
| 11509 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11510 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11511 | MVLI.VarComponents); |
| 11512 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11513 | |
| 11514 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11515 | SourceLocation StartLoc, |
| 11516 | SourceLocation LParenLoc, |
| 11517 | SourceLocation EndLoc) { |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11518 | MappableVarListInfo MVLI(VarList); |
| 11519 | SmallVector<Expr *, 8> PrivateCopies; |
| 11520 | SmallVector<Expr *, 8> Inits; |
| 11521 | |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11522 | for (auto &RefExpr : VarList) { |
| 11523 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 11524 | SourceLocation ELoc; |
| 11525 | SourceRange ERange; |
| 11526 | Expr *SimpleRefExpr = RefExpr; |
| 11527 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11528 | if (Res.second) { |
| 11529 | // It will be analyzed later. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11530 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 11531 | PrivateCopies.push_back(nullptr); |
| 11532 | Inits.push_back(nullptr); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11533 | } |
| 11534 | ValueDecl *D = Res.first; |
| 11535 | if (!D) |
| 11536 | continue; |
| 11537 | |
| 11538 | QualType Type = D->getType(); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11539 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 11540 | |
| 11541 | auto *VD = dyn_cast<VarDecl>(D); |
| 11542 | |
| 11543 | // Item should be a pointer or reference to pointer. |
| 11544 | if (!Type->isPointerType()) { |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11545 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 11546 | << 0 << RefExpr->getSourceRange(); |
| 11547 | continue; |
| 11548 | } |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11549 | |
| 11550 | // Build the private variable and the expression that refers to it. |
| 11551 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11552 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11553 | if (VDPrivate->isInvalidDecl()) |
| 11554 | continue; |
| 11555 | |
| 11556 | CurContext->addDecl(VDPrivate); |
| 11557 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 11558 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 11559 | |
| 11560 | // Add temporary variable to initialize the private copy of the pointer. |
| 11561 | auto *VDInit = |
| 11562 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| 11563 | auto *VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 11564 | RefExpr->getExprLoc()); |
| 11565 | AddInitializerToDecl(VDPrivate, |
| 11566 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 11567 | /*DirectInit=*/false); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11568 | |
| 11569 | // If required, build a capture to implement the privatization initialized |
| 11570 | // with the current list item value. |
| 11571 | DeclRefExpr *Ref = nullptr; |
| 11572 | if (!VD) |
| 11573 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11574 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 11575 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 11576 | Inits.push_back(VDInitRefExpr); |
| 11577 | |
| 11578 | // We need to add a data sharing attribute for this variable to make sure it |
| 11579 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 11580 | // similar properties of a first private variable. |
| 11581 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 11582 | |
| 11583 | // Create a mappable component for the list item. List items in this clause |
| 11584 | // only need a component. |
| 11585 | MVLI.VarBaseDeclarations.push_back(D); |
| 11586 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11587 | MVLI.VarComponents.back().push_back( |
| 11588 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11589 | } |
| 11590 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11591 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11592 | return nullptr; |
| 11593 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11594 | return OMPUseDevicePtrClause::Create( |
| 11595 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11596 | PrivateCopies, Inits, MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11597 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11598 | |
| 11599 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11600 | SourceLocation StartLoc, |
| 11601 | SourceLocation LParenLoc, |
| 11602 | SourceLocation EndLoc) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11603 | MappableVarListInfo MVLI(VarList); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11604 | for (auto &RefExpr : VarList) { |
Kelvin Li | 8437625 | 2016-12-14 15:39:58 +0000 | [diff] [blame] | 11605 | assert(RefExpr && "NULL expr in OpenMP is_device_ptr clause."); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11606 | SourceLocation ELoc; |
| 11607 | SourceRange ERange; |
| 11608 | Expr *SimpleRefExpr = RefExpr; |
| 11609 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11610 | if (Res.second) { |
| 11611 | // It will be analyzed later. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11612 | MVLI.ProcessedVarList.push_back(RefExpr); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11613 | } |
| 11614 | ValueDecl *D = Res.first; |
| 11615 | if (!D) |
| 11616 | continue; |
| 11617 | |
| 11618 | QualType Type = D->getType(); |
| 11619 | // item should be a pointer or array or reference to pointer or array |
| 11620 | if (!Type.getNonReferenceType()->isPointerType() && |
| 11621 | !Type.getNonReferenceType()->isArrayType()) { |
| 11622 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 11623 | << 0 << RefExpr->getSourceRange(); |
| 11624 | continue; |
| 11625 | } |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11626 | |
| 11627 | // Check if the declaration in the clause does not show up in any data |
| 11628 | // sharing attribute. |
| 11629 | auto DVar = DSAStack->getTopDSA(D, false); |
| 11630 | if (isOpenMPPrivate(DVar.CKind)) { |
| 11631 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 11632 | << getOpenMPClauseName(DVar.CKind) |
| 11633 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 11634 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 11635 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 11636 | continue; |
| 11637 | } |
| 11638 | |
| 11639 | Expr *ConflictExpr; |
| 11640 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11641 | D, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11642 | [&ConflictExpr]( |
| 11643 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 11644 | OpenMPClauseKind) -> bool { |
| 11645 | ConflictExpr = R.front().getAssociatedExpression(); |
| 11646 | return true; |
| 11647 | })) { |
| 11648 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 11649 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 11650 | << ConflictExpr->getSourceRange(); |
| 11651 | continue; |
| 11652 | } |
| 11653 | |
| 11654 | // Store the components in the stack so that they can be used to check |
| 11655 | // against other clauses later on. |
| 11656 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 11657 | DSAStack->addMappableExpressionComponents( |
| 11658 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 11659 | |
| 11660 | // Record the expression we've just processed. |
| 11661 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 11662 | |
| 11663 | // Create a mappable component for the list item. List items in this clause |
| 11664 | // only need a component. We use a null declaration to signal fields in |
| 11665 | // 'this'. |
| 11666 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 11667 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 11668 | "Unexpected device pointer expression!"); |
| 11669 | MVLI.VarBaseDeclarations.push_back( |
| 11670 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 11671 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11672 | MVLI.VarComponents.back().push_back(MC); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11673 | } |
| 11674 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11675 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11676 | return nullptr; |
| 11677 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11678 | return OMPIsDevicePtrClause::Create( |
| 11679 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11680 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11681 | } |