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. |
| 121 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 122 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 123 | /// from current directive. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 124 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 125 | Sema &SemaRef; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 126 | bool ForceCapturing = false; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 127 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 128 | |
| 129 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 130 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 131 | DSAVarData getDSA(StackTy::reverse_iterator &Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 132 | |
| 133 | /// \brief Checks if the variable is a local for OpenMP region. |
| 134 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 135 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 136 | public: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 137 | explicit DSAStackTy(Sema &S) : Stack(1), SemaRef(S) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 138 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 139 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 140 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 141 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 142 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 143 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 144 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 145 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 146 | Scope *CurScope, SourceLocation Loc) { |
| 147 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 148 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void pop() { |
| 152 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 153 | Stack.pop_back(); |
| 154 | } |
| 155 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 156 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 157 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 158 | } |
| 159 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 160 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 161 | auto I = Criticals.find(Name.getAsString()); |
| 162 | if (I != Criticals.end()) |
| 163 | return I->second; |
| 164 | return std::make_pair(nullptr, llvm::APSInt()); |
| 165 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 166 | /// \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] | 167 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 168 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 169 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 170 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 171 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 172 | void addLoopControlVariable(ValueDecl *D, VarDecl *Capture); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 173 | /// \brief Check if the specified variable is a loop control variable for |
| 174 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 175 | /// \return The index of the loop control variable in the list of associated |
| 176 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 177 | LCDeclInfo isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 178 | /// \brief Check if the specified variable is a loop control variable for |
| 179 | /// parent region. |
| 180 | /// \return The index of the loop control variable in the list of associated |
| 181 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 182 | LCDeclInfo isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 183 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 184 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 185 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 186 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 187 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 188 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 189 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 190 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 191 | /// \brief Returns data sharing attributes from top of the stack for the |
| 192 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 193 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 194 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 195 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 196 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 197 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 198 | /// predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 199 | DSAVarData hasDSA(ValueDecl *D, |
| 200 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 201 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 202 | bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 203 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 204 | /// match specified \a CPred predicate in any innermost directive which |
| 205 | /// matches \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 206 | DSAVarData |
| 207 | hasInnermostDSA(ValueDecl *D, |
| 208 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 209 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 210 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 211 | /// \brief Checks if the specified variables has explicit data-sharing |
| 212 | /// attributes which match specified \a CPred predicate at the specified |
| 213 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 214 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 215 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 216 | unsigned Level, bool NotLastprivate = false); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 217 | |
| 218 | /// \brief Returns true if the directive at level \Level matches in the |
| 219 | /// specified \a DPred predicate. |
| 220 | bool hasExplicitDirective( |
| 221 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 222 | unsigned Level); |
| 223 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 224 | /// \brief Finds a directive which matches specified \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 225 | bool hasDirective(const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 226 | const DeclarationNameInfo &, |
| 227 | SourceLocation)> &DPred, |
| 228 | bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 229 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 230 | /// \brief Returns currently analyzed directive. |
| 231 | OpenMPDirectiveKind getCurrentDirective() const { |
| 232 | return Stack.back().Directive; |
| 233 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 234 | /// \brief Returns parent directive. |
| 235 | OpenMPDirectiveKind getParentDirective() const { |
| 236 | if (Stack.size() > 2) |
| 237 | return Stack[Stack.size() - 2].Directive; |
| 238 | return OMPD_unknown; |
| 239 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 240 | |
| 241 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 242 | void setDefaultDSANone(SourceLocation Loc) { |
| 243 | Stack.back().DefaultAttr = DSA_none; |
| 244 | Stack.back().DefaultAttrLoc = Loc; |
| 245 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 246 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 247 | void setDefaultDSAShared(SourceLocation Loc) { |
| 248 | Stack.back().DefaultAttr = DSA_shared; |
| 249 | Stack.back().DefaultAttrLoc = Loc; |
| 250 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 251 | |
| 252 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 253 | return Stack.back().DefaultAttr; |
| 254 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 255 | SourceLocation getDefaultDSALocation() const { |
| 256 | return Stack.back().DefaultAttrLoc; |
| 257 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 258 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 259 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 260 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 261 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 262 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 265 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 266 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 267 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 268 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 269 | } |
| 270 | /// \brief Returns true, if parent region is ordered (has associated |
| 271 | /// 'ordered' clause), false - otherwise. |
| 272 | bool isParentOrderedRegion() const { |
| 273 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 274 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 275 | return false; |
| 276 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 277 | /// \brief Returns optional parameter for the ordered region. |
| 278 | Expr *getParentOrderedRegionParam() const { |
| 279 | if (Stack.size() > 2) |
| 280 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 281 | return nullptr; |
| 282 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 283 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 284 | void setNowaitRegion(bool IsNowait = true) { |
| 285 | Stack.back().NowaitRegion = IsNowait; |
| 286 | } |
| 287 | /// \brief Returns true, if parent region is nowait (has associated |
| 288 | /// 'nowait' clause), false - otherwise. |
| 289 | bool isParentNowaitRegion() const { |
| 290 | if (Stack.size() > 2) |
| 291 | return Stack[Stack.size() - 2].NowaitRegion; |
| 292 | return false; |
| 293 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 294 | /// \brief Marks parent region as cancel region. |
| 295 | void setParentCancelRegion(bool Cancel = true) { |
| 296 | if (Stack.size() > 2) |
| 297 | Stack[Stack.size() - 2].CancelRegion = |
| 298 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 299 | } |
| 300 | /// \brief Return true if current region has inner cancel construct. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 301 | bool isCancelRegion() const { return Stack.back().CancelRegion; } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 302 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 303 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 304 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 305 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 306 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 307 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 308 | /// \brief Marks current target region as one with closely nested teams |
| 309 | /// region. |
| 310 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 311 | if (Stack.size() > 2) |
| 312 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 313 | } |
| 314 | /// \brief Returns true, if current region has closely nested teams region. |
| 315 | bool hasInnerTeamsRegion() const { |
| 316 | return getInnerTeamsRegionLoc().isValid(); |
| 317 | } |
| 318 | /// \brief Returns location of the nested teams region (if any). |
| 319 | SourceLocation getInnerTeamsRegionLoc() const { |
| 320 | if (Stack.size() > 1) |
| 321 | return Stack.back().InnerTeamsRegionLoc; |
| 322 | return SourceLocation(); |
| 323 | } |
| 324 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 325 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 326 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 327 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 328 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 329 | /// Do the check specified in \a Check to all component lists and return true |
| 330 | /// if any issue is found. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 331 | bool checkMappableExprComponentListsForDecl( |
| 332 | ValueDecl *VD, bool CurrentRegionOnly, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 333 | const llvm::function_ref< |
| 334 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 335 | OpenMPClauseKind)> &Check) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 336 | auto SI = Stack.rbegin(); |
| 337 | auto SE = Stack.rend(); |
| 338 | |
| 339 | if (SI == SE) |
| 340 | return false; |
| 341 | |
| 342 | if (CurrentRegionOnly) { |
| 343 | SE = std::next(SI); |
| 344 | } else { |
| 345 | ++SI; |
| 346 | } |
| 347 | |
| 348 | for (; SI != SE; ++SI) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 349 | auto MI = SI->MappedExprComponents.find(VD); |
| 350 | if (MI != SI->MappedExprComponents.end()) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 351 | for (auto &L : MI->second.Components) |
| 352 | if (Check(L, MI->second.Kind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 353 | return true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 354 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 355 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 358 | /// Create a new mappable expression component list associated with a given |
| 359 | /// declaration and initialize it with the provided list of components. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 360 | void addMappableExpressionComponents( |
| 361 | ValueDecl *VD, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 362 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components, |
| 363 | OpenMPClauseKind WhereFoundClauseKind) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 364 | assert(Stack.size() > 1 && |
| 365 | "Not expecting to retrieve components from a empty stack!"); |
| 366 | auto &MEC = Stack.back().MappedExprComponents[VD]; |
| 367 | // Create new entry and append the new components there. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 368 | MEC.Components.resize(MEC.Components.size() + 1); |
| 369 | MEC.Components.back().append(Components.begin(), Components.end()); |
| 370 | MEC.Kind = WhereFoundClauseKind; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 371 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 372 | |
| 373 | unsigned getNestingLevel() const { |
| 374 | assert(Stack.size() > 1); |
| 375 | return Stack.size() - 2; |
| 376 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 377 | void addDoacrossDependClause(OMPDependClause *C, OperatorOffsetTy &OpsOffs) { |
| 378 | assert(Stack.size() > 2); |
| 379 | assert(isOpenMPWorksharingDirective(Stack[Stack.size() - 2].Directive)); |
| 380 | Stack[Stack.size() - 2].DoacrossDepends.insert({C, OpsOffs}); |
| 381 | } |
| 382 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 383 | getDoacrossDependClauses() const { |
| 384 | assert(Stack.size() > 1); |
| 385 | if (isOpenMPWorksharingDirective(Stack[Stack.size() - 1].Directive)) { |
| 386 | auto &Ref = Stack[Stack.size() - 1].DoacrossDepends; |
| 387 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 388 | } |
| 389 | return llvm::make_range(Stack[0].DoacrossDepends.end(), |
| 390 | Stack[0].DoacrossDepends.end()); |
| 391 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 392 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 393 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 394 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || |
| 395 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 396 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 397 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 398 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 399 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 400 | auto *VD = dyn_cast<VarDecl>(D); |
| 401 | auto *FD = dyn_cast<FieldDecl>(D); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 402 | if (VD != nullptr) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 403 | VD = VD->getCanonicalDecl(); |
| 404 | D = VD; |
| 405 | } else { |
| 406 | assert(FD); |
| 407 | FD = FD->getCanonicalDecl(); |
| 408 | D = FD; |
| 409 | } |
| 410 | return D; |
| 411 | } |
| 412 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 413 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator &Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 414 | ValueDecl *D) { |
| 415 | D = getCanonicalDecl(D); |
| 416 | auto *VD = dyn_cast<VarDecl>(D); |
| 417 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 418 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 419 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 420 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 421 | // in a region but not in construct] |
| 422 | // File-scope or namespace-scope variables referenced in called routines |
| 423 | // in the region are shared unless they appear in a threadprivate |
| 424 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 425 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 426 | DVar.CKind = OMPC_shared; |
| 427 | |
| 428 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 429 | // in a region but not in construct] |
| 430 | // Variables with static storage duration that are declared in called |
| 431 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 432 | if (VD && VD->hasGlobalStorage()) |
| 433 | DVar.CKind = OMPC_shared; |
| 434 | |
| 435 | // Non-static data members are shared by default. |
| 436 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 437 | DVar.CKind = OMPC_shared; |
| 438 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 439 | return DVar; |
| 440 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 441 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 442 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 443 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 444 | // in a Construct, C/C++, predetermined, p.1] |
| 445 | // Variables with automatic storage duration that are declared in a scope |
| 446 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 447 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 448 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 449 | DVar.CKind = OMPC_private; |
| 450 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 453 | // Explicitly specified attributes and local variables with predetermined |
| 454 | // attributes. |
| 455 | if (Iter->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 456 | DVar.RefExpr = Iter->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 457 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 458 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 459 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 460 | return DVar; |
| 461 | } |
| 462 | |
| 463 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 464 | // in a Construct, C/C++, implicitly determined, p.1] |
| 465 | // In a parallel or task construct, the data-sharing attributes of these |
| 466 | // variables are determined by the default clause, if present. |
| 467 | switch (Iter->DefaultAttr) { |
| 468 | case DSA_shared: |
| 469 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 470 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 471 | return DVar; |
| 472 | case DSA_none: |
| 473 | return DVar; |
| 474 | case DSA_unspecified: |
| 475 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 476 | // in a Construct, implicitly determined, p.2] |
| 477 | // In a parallel construct, if no default clause is present, these |
| 478 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 479 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 480 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 481 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 482 | DVar.CKind = OMPC_shared; |
| 483 | return DVar; |
| 484 | } |
| 485 | |
| 486 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 487 | // in a Construct, implicitly determined, p.4] |
| 488 | // In a task construct, if no default clause is present, a variable that in |
| 489 | // the enclosing context is determined to be shared by all implicit tasks |
| 490 | // bound to the current team is shared. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 491 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 492 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 493 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 494 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 495 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 496 | // Referenced in a Construct, implicitly determined, p.6] |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 497 | // In a task construct, if no default clause is present, a variable |
| 498 | // whose data-sharing attribute is not determined by the rules above is |
| 499 | // firstprivate. |
| 500 | DVarTemp = getDSA(I, D); |
| 501 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 502 | DVar.RefExpr = nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 503 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 504 | return DVar; |
| 505 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 506 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 507 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 508 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 509 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 510 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 511 | return DVar; |
| 512 | } |
| 513 | } |
| 514 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 515 | // in a Construct, implicitly determined, p.3] |
| 516 | // For constructs other than task, if no default clause is present, these |
| 517 | // variables inherit their data-sharing attributes from the enclosing |
| 518 | // context. |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 519 | return getDSA(++Iter, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 522 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 523 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 524 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 525 | auto It = Stack.back().AlignedMap.find(D); |
| 526 | if (It == Stack.back().AlignedMap.end()) { |
| 527 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 528 | Stack.back().AlignedMap[D] = NewDE; |
| 529 | return nullptr; |
| 530 | } else { |
| 531 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 532 | return It->second; |
| 533 | } |
| 534 | return nullptr; |
| 535 | } |
| 536 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 537 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 538 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 539 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 540 | Stack.back().LCVMap.insert( |
| 541 | std::make_pair(D, LCDeclInfo(Stack.back().LCVMap.size() + 1, Capture))); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 544 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 545 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 546 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 547 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] |
| 548 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 551 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 552 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 553 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 554 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 555 | ? Stack[Stack.size() - 2].LCVMap[D] |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 556 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 559 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 560 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 561 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 562 | return nullptr; |
| 563 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 564 | if (Pair.second.first == I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 565 | return Pair.first; |
| 566 | } |
| 567 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 570 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 571 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 572 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 573 | if (A == OMPC_threadprivate) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 574 | auto &Data = Stack[0].SharingMap[D]; |
| 575 | Data.Attributes = A; |
| 576 | Data.RefExpr.setPointer(E); |
| 577 | Data.PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 578 | } else { |
| 579 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 580 | auto &Data = Stack.back().SharingMap[D]; |
| 581 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 582 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 583 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 584 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 585 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 586 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 587 | return; |
| 588 | } |
| 589 | const bool IsLastprivate = |
| 590 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 591 | Data.Attributes = A; |
| 592 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 593 | Data.PrivateCopy = PrivateCopy; |
| 594 | if (PrivateCopy) { |
| 595 | auto &Data = Stack.back().SharingMap[PrivateCopy->getDecl()]; |
| 596 | Data.Attributes = A; |
| 597 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 598 | Data.PrivateCopy = nullptr; |
| 599 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 603 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 604 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 605 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 606 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 607 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 608 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 609 | ++I; |
| 610 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 611 | if (I == E) |
| 612 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 613 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 614 | Scope *CurScope = getCurScope(); |
| 615 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 616 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 617 | } |
| 618 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 619 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 620 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 623 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 624 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 625 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 626 | DeclContext *DC = SemaRef.CurContext; |
| 627 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 628 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 629 | VarDecl *Decl = |
| 630 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 631 | if (Attrs) { |
| 632 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 633 | I != E; ++I) |
| 634 | Decl->addAttr(*I); |
| 635 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 636 | Decl->setImplicit(); |
| 637 | return Decl; |
| 638 | } |
| 639 | |
| 640 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 641 | SourceLocation Loc, |
| 642 | bool RefersToCapture = false) { |
| 643 | D->setReferenced(); |
| 644 | D->markUsed(S.Context); |
| 645 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 646 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 647 | VK_LValue); |
| 648 | } |
| 649 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 650 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 651 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 652 | DSAVarData DVar; |
| 653 | |
| 654 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 655 | // in a Construct, C/C++, predetermined, p.1] |
| 656 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 657 | auto *VD = dyn_cast<VarDecl>(D); |
| 658 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 659 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 660 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 661 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 662 | (VD && VD->getStorageClass() == SC_Register && |
| 663 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 664 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 665 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 666 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 667 | } |
| 668 | if (Stack[0].SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 669 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 670 | DVar.CKind = OMPC_threadprivate; |
| 671 | return DVar; |
| 672 | } |
| 673 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 674 | if (Stack.size() == 1) { |
| 675 | // Not in OpenMP execution region and top scope was already checked. |
| 676 | return DVar; |
| 677 | } |
| 678 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 679 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 680 | // in a Construct, C/C++, predetermined, p.4] |
| 681 | // Static data members are shared. |
| 682 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 683 | // in a Construct, C/C++, predetermined, p.7] |
| 684 | // Variables with static storage duration that are declared in a scope |
| 685 | // inside the construct are shared. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 686 | auto &&MatchesAlways = [](OpenMPDirectiveKind) -> bool { return true; }; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 687 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 688 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 689 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 690 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 691 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 692 | DVar.CKind = OMPC_shared; |
| 693 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 697 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 698 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 699 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 700 | // in a Construct, C/C++, predetermined, p.6] |
| 701 | // Variables with const qualified type having no mutable member are |
| 702 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 703 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 704 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 705 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 706 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 707 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 708 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 709 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 710 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 711 | // Variables with const-qualified type having no mutable member may be |
| 712 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 713 | DSAVarData DVarTemp = hasDSA( |
| 714 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; }, |
| 715 | MatchesAlways, FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 716 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 717 | return DVar; |
| 718 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 719 | DVar.CKind = OMPC_shared; |
| 720 | return DVar; |
| 721 | } |
| 722 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 723 | // Explicitly specified attributes and local variables with predetermined |
| 724 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 725 | auto StartI = std::next(Stack.rbegin()); |
| 726 | auto EndI = std::prev(Stack.rend()); |
| 727 | if (FromParent && StartI != EndI) { |
| 728 | StartI = std::next(StartI); |
| 729 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 730 | auto I = std::prev(StartI); |
| 731 | if (I->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 732 | DVar.RefExpr = I->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 733 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 734 | DVar.CKind = I->SharingMap[D].Attributes; |
| 735 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | return DVar; |
| 739 | } |
| 740 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 741 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 742 | bool FromParent) { |
| 743 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 744 | auto StartI = Stack.rbegin(); |
| 745 | auto EndI = std::prev(Stack.rend()); |
| 746 | if (FromParent && StartI != EndI) { |
| 747 | StartI = std::next(StartI); |
| 748 | } |
| 749 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 752 | DSAStackTy::DSAVarData |
| 753 | DSAStackTy::hasDSA(ValueDecl *D, |
| 754 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 755 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 756 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 757 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 758 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 759 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 760 | if (FromParent && StartI != EndI) { |
| 761 | StartI = std::next(StartI); |
| 762 | } |
| 763 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 764 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 765 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 766 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 767 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 768 | return DVar; |
| 769 | } |
| 770 | return DSAVarData(); |
| 771 | } |
| 772 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 773 | DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| 774 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 775 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 776 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 777 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 778 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 779 | auto EndI = Stack.rend(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 780 | if (FromParent && StartI != EndI) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 781 | StartI = std::next(StartI); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 782 | if (StartI == EndI || !DPred(StartI->Directive)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 783 | return DSAVarData(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 784 | DSAVarData DVar = getDSA(StartI, D); |
| 785 | return CPred(DVar.CKind) ? DVar : DSAVarData(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 786 | } |
| 787 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 788 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 789 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 790 | unsigned Level, bool NotLastprivate) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 791 | if (CPred(ClauseKindMode)) |
| 792 | return true; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 793 | D = getCanonicalDecl(D); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 794 | auto StartI = std::next(Stack.begin()); |
| 795 | auto EndI = Stack.end(); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 796 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 797 | return false; |
| 798 | std::advance(StartI, Level); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 799 | return (StartI->SharingMap.count(D) > 0) && |
| 800 | StartI->SharingMap[D].RefExpr.getPointer() && |
| 801 | CPred(StartI->SharingMap[D].Attributes) && |
| 802 | (!NotLastprivate || !StartI->SharingMap[D].RefExpr.getInt()); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 805 | bool DSAStackTy::hasExplicitDirective( |
| 806 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 807 | unsigned Level) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 808 | auto StartI = std::next(Stack.begin()); |
| 809 | auto EndI = Stack.end(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 810 | if (std::distance(StartI, EndI) <= (int)Level) |
| 811 | return false; |
| 812 | std::advance(StartI, Level); |
| 813 | return DPred(StartI->Directive); |
| 814 | } |
| 815 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 816 | bool DSAStackTy::hasDirective( |
| 817 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 818 | const DeclarationNameInfo &, SourceLocation)> |
| 819 | &DPred, |
| 820 | bool FromParent) { |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 821 | // We look only in the enclosing region. |
| 822 | if (Stack.size() < 2) |
| 823 | return false; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 824 | auto StartI = std::next(Stack.rbegin()); |
| 825 | auto EndI = std::prev(Stack.rend()); |
| 826 | if (FromParent && StartI != EndI) { |
| 827 | StartI = std::next(StartI); |
| 828 | } |
| 829 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 830 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 831 | return true; |
| 832 | } |
| 833 | return false; |
| 834 | } |
| 835 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 836 | void Sema::InitDataSharingAttributesStack() { |
| 837 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 838 | } |
| 839 | |
| 840 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 841 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 842 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 843 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 844 | |
| 845 | auto &Ctx = getASTContext(); |
| 846 | bool IsByRef = true; |
| 847 | |
| 848 | // Find the directive that is associated with the provided scope. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 849 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 850 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 851 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 852 | // This table summarizes how a given variable should be passed to the device |
| 853 | // given its type and the clauses where it appears. This table is based on |
| 854 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 855 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 856 | // |
| 857 | // ========================================================================= |
| 858 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 859 | // | |(tofrom:scalar)| | pvt | | | | |
| 860 | // ========================================================================= |
| 861 | // | scl | | | | - | | bycopy| |
| 862 | // | scl | | - | x | - | - | bycopy| |
| 863 | // | scl | | x | - | - | - | null | |
| 864 | // | scl | x | | | - | | byref | |
| 865 | // | scl | x | - | x | - | - | bycopy| |
| 866 | // | scl | x | x | - | - | - | null | |
| 867 | // | scl | | - | - | - | x | byref | |
| 868 | // | scl | x | - | - | - | x | byref | |
| 869 | // |
| 870 | // | agg | n.a. | | | - | | byref | |
| 871 | // | agg | n.a. | - | x | - | - | byref | |
| 872 | // | agg | n.a. | x | - | - | - | null | |
| 873 | // | agg | n.a. | - | - | - | x | byref | |
| 874 | // | agg | n.a. | - | - | - | x[] | byref | |
| 875 | // |
| 876 | // | ptr | n.a. | | | - | | bycopy| |
| 877 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 878 | // | ptr | n.a. | x | - | - | - | null | |
| 879 | // | ptr | n.a. | - | - | - | x | byref | |
| 880 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 881 | // | ptr | n.a. | - | - | x | | bycopy| |
| 882 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 883 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 884 | // ========================================================================= |
| 885 | // Legend: |
| 886 | // scl - scalar |
| 887 | // ptr - pointer |
| 888 | // agg - aggregate |
| 889 | // x - applies |
| 890 | // - - invalid in this combination |
| 891 | // [] - mapped with an array section |
| 892 | // byref - should be mapped by reference |
| 893 | // byval - should be mapped by value |
| 894 | // null - initialize a local variable to null on the device |
| 895 | // |
| 896 | // Observations: |
| 897 | // - All scalar declarations that show up in a map clause have to be passed |
| 898 | // by reference, because they may have been mapped in the enclosing data |
| 899 | // environment. |
| 900 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 901 | // passed by reference, regardless the result in the table above. |
| 902 | // - For pointers mapped by value that have either an implicit map or an |
| 903 | // array section, the runtime library may pass the NULL value to the |
| 904 | // device instead of the value passed to it by the compiler. |
| 905 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 906 | if (Ty->isReferenceType()) |
| 907 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 908 | |
| 909 | // Locate map clauses and see if the variable being captured is referred to |
| 910 | // in any of those clauses. Here we only care about variables, not fields, |
| 911 | // because fields are part of aggregates. |
| 912 | bool IsVariableUsedInMapClause = false; |
| 913 | bool IsVariableAssociatedWithSection = false; |
| 914 | |
| 915 | DSAStack->checkMappableExprComponentListsForDecl( |
| 916 | D, /*CurrentRegionOnly=*/true, |
| 917 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 918 | MapExprComponents, |
| 919 | OpenMPClauseKind WhereFoundClauseKind) { |
| 920 | // Only the map clause information influences how a variable is |
| 921 | // captured. E.g. is_device_ptr does not require changing the default |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 922 | // behavior. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 923 | if (WhereFoundClauseKind != OMPC_map) |
| 924 | return false; |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 925 | |
| 926 | auto EI = MapExprComponents.rbegin(); |
| 927 | auto EE = MapExprComponents.rend(); |
| 928 | |
| 929 | assert(EI != EE && "Invalid map expression!"); |
| 930 | |
| 931 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 932 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 933 | |
| 934 | ++EI; |
| 935 | if (EI == EE) |
| 936 | return false; |
| 937 | |
| 938 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 939 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 940 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 941 | IsVariableAssociatedWithSection = true; |
| 942 | // There is nothing more we need to know about this variable. |
| 943 | return true; |
| 944 | } |
| 945 | |
| 946 | // Keep looking for more map info. |
| 947 | return false; |
| 948 | }); |
| 949 | |
| 950 | if (IsVariableUsedInMapClause) { |
| 951 | // If variable is identified in a map clause it is always captured by |
| 952 | // reference except if it is a pointer that is dereferenced somehow. |
| 953 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 954 | } else { |
| 955 | // By default, all the data that has a scalar type is mapped by copy. |
| 956 | IsByRef = !Ty->isScalarType(); |
| 957 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 960 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| 961 | IsByRef = !DSAStack->hasExplicitDSA( |
| 962 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 963 | Level, /*NotLastprivate=*/true); |
| 964 | } |
| 965 | |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 966 | // 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] | 967 | // and alignment, because the runtime library only deals with uintptr types. |
| 968 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 969 | // instead. |
| 970 | if (!IsByRef && |
| 971 | (Ctx.getTypeSizeInChars(Ty) > |
| 972 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 973 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 974 | IsByRef = true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 975 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 976 | |
| 977 | return IsByRef; |
| 978 | } |
| 979 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 980 | unsigned Sema::getOpenMPNestingLevel() const { |
| 981 | assert(getLangOpts().OpenMP); |
| 982 | return DSAStack->getNestingLevel(); |
| 983 | } |
| 984 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 985 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 986 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 987 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 988 | |
| 989 | // If we are attempting to capture a global variable in a directive with |
| 990 | // 'target' we return true so that this global is also mapped to the device. |
| 991 | // |
| 992 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 993 | // then it should not be captured. Therefore, an extra check has to be |
| 994 | // inserted here once support for 'declare target' is added. |
| 995 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 996 | auto *VD = dyn_cast<VarDecl>(D); |
| 997 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 998 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 999 | !DSAStack->isClauseParsingMode()) |
| 1000 | return VD; |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1001 | if (DSAStack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1002 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 1003 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1004 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1005 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1006 | false)) |
| 1007 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 1010 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 1011 | (!DSAStack->isClauseParsingMode() || |
| 1012 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1013 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 1014 | if (Info.first || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1015 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1016 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1017 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1018 | return VD ? VD : Info.second; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1019 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1020 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1021 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1022 | DVarPrivate = DSAStack->hasDSA( |
| 1023 | D, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 1024 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1025 | if (DVarPrivate.CKind != OMPC_unknown) |
| 1026 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1027 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1028 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1031 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1032 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1033 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1034 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1037 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1038 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1039 | // Return true if the current level is no longer enclosed in a target region. |
| 1040 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1041 | auto *VD = dyn_cast<VarDecl>(D); |
| 1042 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1043 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1044 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1047 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1048 | |
| 1049 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1050 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1051 | Scope *CurScope, SourceLocation Loc) { |
| 1052 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1053 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 1054 | } |
| 1055 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1056 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1057 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1060 | void Sema::EndOpenMPClause() { |
| 1061 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1064 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1065 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1066 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1067 | // clause requires an accessible, unambiguous default constructor for the |
| 1068 | // class type, unless the list item is also specified in a firstprivate |
| 1069 | // clause. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1070 | if (auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1071 | for (auto *C : D->clauses()) { |
| 1072 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1073 | SmallVector<Expr *, 8> PrivateCopies; |
| 1074 | for (auto *DE : Clause->varlists()) { |
| 1075 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1076 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1077 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1078 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1079 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1080 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1081 | QualType Type = VD->getType().getNonReferenceType(); |
| 1082 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1083 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1084 | // Generate helper private variable and initialize it with the |
| 1085 | // default value. The address of the original variable is replaced |
| 1086 | // by the address of the new private variable in CodeGen. This new |
| 1087 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1088 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1089 | auto *VDPrivate = buildVarDecl( |
| 1090 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1091 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1092 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1093 | if (VDPrivate->isInvalidDecl()) |
| 1094 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1095 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1096 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1097 | } else { |
| 1098 | // The variable is also a firstprivate, so initialization sequence |
| 1099 | // for private copy is generated already. |
| 1100 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1101 | } |
| 1102 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1103 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1104 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1105 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1110 | DSAStack->pop(); |
| 1111 | DiscardCleanupsInEvaluationContext(); |
| 1112 | PopExpressionEvaluationContext(); |
| 1113 | } |
| 1114 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1115 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1116 | Expr *NumIterations, Sema &SemaRef, |
| 1117 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1118 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1119 | namespace { |
| 1120 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1121 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1122 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1123 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1124 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1125 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1126 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1127 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1128 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1129 | if (auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1130 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1131 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1132 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1133 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1134 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1135 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1136 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1137 | |
| 1138 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { |
| 1139 | private: |
| 1140 | Sema &SemaRef; |
| 1141 | |
| 1142 | public: |
| 1143 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1144 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1145 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1146 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 1147 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1148 | SemaRef.getCurScope()); |
| 1149 | } |
| 1150 | return false; |
| 1151 | } |
| 1152 | }; |
| 1153 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1154 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1155 | |
| 1156 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1157 | CXXScopeSpec &ScopeSpec, |
| 1158 | const DeclarationNameInfo &Id) { |
| 1159 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1160 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1161 | |
| 1162 | if (Lookup.isAmbiguous()) |
| 1163 | return ExprError(); |
| 1164 | |
| 1165 | VarDecl *VD; |
| 1166 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1167 | if (TypoCorrection Corrected = CorrectTypo( |
| 1168 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1169 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1170 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1171 | PDiag(Lookup.empty() |
| 1172 | ? diag::err_undeclared_var_use_suggest |
| 1173 | : diag::err_omp_expected_var_arg_suggest) |
| 1174 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1175 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1176 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1177 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1178 | : diag::err_omp_expected_var_arg) |
| 1179 | << Id.getName(); |
| 1180 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1181 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1182 | } else { |
| 1183 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1184 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1185 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1186 | return ExprError(); |
| 1187 | } |
| 1188 | } |
| 1189 | Lookup.suppressDiagnostics(); |
| 1190 | |
| 1191 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1192 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1193 | if (!VD->hasGlobalStorage()) { |
| 1194 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1195 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1196 | bool IsDecl = |
| 1197 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1198 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1199 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1200 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1201 | return ExprError(); |
| 1202 | } |
| 1203 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1204 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1205 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1206 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1207 | // A threadprivate directive for file-scope variables must appear outside |
| 1208 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1209 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1210 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1211 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1212 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1213 | bool IsDecl = |
| 1214 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1215 | Diag(VD->getLocation(), |
| 1216 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1217 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1218 | return ExprError(); |
| 1219 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1220 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1221 | // A threadprivate directive for static class member variables must appear |
| 1222 | // in the class definition, in the same scope in which the member |
| 1223 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1224 | if (CanonicalVD->isStaticDataMember() && |
| 1225 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1226 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1227 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1228 | bool IsDecl = |
| 1229 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1230 | Diag(VD->getLocation(), |
| 1231 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1232 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1233 | return ExprError(); |
| 1234 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1235 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1236 | // A threadprivate directive for namespace-scope variables must appear |
| 1237 | // outside any definition or declaration other than the namespace |
| 1238 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1239 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1240 | (!getCurLexicalContext()->isFileContext() || |
| 1241 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1242 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1243 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1244 | bool IsDecl = |
| 1245 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1246 | Diag(VD->getLocation(), |
| 1247 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1248 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1249 | return ExprError(); |
| 1250 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1251 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1252 | // A threadprivate directive for static block-scope variables must appear |
| 1253 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1254 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1255 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1256 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1257 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1258 | bool IsDecl = |
| 1259 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1260 | Diag(VD->getLocation(), |
| 1261 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1262 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1263 | return ExprError(); |
| 1264 | } |
| 1265 | |
| 1266 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1267 | // A threadprivate directive must lexically precede all references to any |
| 1268 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1269 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1270 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1271 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1272 | return ExprError(); |
| 1273 | } |
| 1274 | |
| 1275 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1276 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1277 | SourceLocation(), VD, |
| 1278 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1279 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1282 | Sema::DeclGroupPtrTy |
| 1283 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1284 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1285 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1286 | CurContext->addDecl(D); |
| 1287 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1288 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1289 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1292 | namespace { |
| 1293 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1294 | Sema &SemaRef; |
| 1295 | |
| 1296 | public: |
| 1297 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1298 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1299 | if (VD->hasLocalStorage()) { |
| 1300 | SemaRef.Diag(E->getLocStart(), |
| 1301 | diag::err_omp_local_var_in_threadprivate_init) |
| 1302 | << E->getSourceRange(); |
| 1303 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1304 | << VD << VD->getSourceRange(); |
| 1305 | return true; |
| 1306 | } |
| 1307 | } |
| 1308 | return false; |
| 1309 | } |
| 1310 | bool VisitStmt(const Stmt *S) { |
| 1311 | for (auto Child : S->children()) { |
| 1312 | if (Child && Visit(Child)) |
| 1313 | return true; |
| 1314 | } |
| 1315 | return false; |
| 1316 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1317 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1318 | }; |
| 1319 | } // namespace |
| 1320 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1321 | OMPThreadPrivateDecl * |
| 1322 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1323 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1324 | for (auto &RefExpr : VarList) { |
| 1325 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1326 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1327 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1328 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1329 | // Mark variable as used. |
| 1330 | VD->setReferenced(); |
| 1331 | VD->markUsed(Context); |
| 1332 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1333 | QualType QType = VD->getType(); |
| 1334 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1335 | // It will be analyzed later. |
| 1336 | Vars.push_back(DE); |
| 1337 | continue; |
| 1338 | } |
| 1339 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1340 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1341 | // A threadprivate variable must not have an incomplete type. |
| 1342 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1343 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1344 | continue; |
| 1345 | } |
| 1346 | |
| 1347 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1348 | // A threadprivate variable must not have a reference type. |
| 1349 | if (VD->getType()->isReferenceType()) { |
| 1350 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1351 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1352 | bool IsDecl = |
| 1353 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1354 | Diag(VD->getLocation(), |
| 1355 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1356 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1357 | continue; |
| 1358 | } |
| 1359 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1360 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1361 | // the corresponding diagnostic. |
| 1362 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1363 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1364 | getLangOpts().OpenMPUseTLS && |
| 1365 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1366 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1367 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1368 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1369 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1370 | bool IsDecl = |
| 1371 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1372 | Diag(VD->getLocation(), |
| 1373 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1374 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1375 | continue; |
| 1376 | } |
| 1377 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1378 | // Check if initial value of threadprivate variable reference variable with |
| 1379 | // local storage (it is not supported by runtime). |
| 1380 | if (auto Init = VD->getAnyInitializer()) { |
| 1381 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1382 | if (Checker.Visit(Init)) |
| 1383 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1386 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1387 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1388 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1389 | Context, SourceRange(Loc, Loc))); |
| 1390 | if (auto *ML = Context.getASTMutationListener()) |
| 1391 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1392 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1393 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1394 | if (!Vars.empty()) { |
| 1395 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1396 | Vars); |
| 1397 | D->setAccess(AS_public); |
| 1398 | } |
| 1399 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1400 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1401 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1402 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1403 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1404 | bool IsLoopIterVar = false) { |
| 1405 | if (DVar.RefExpr) { |
| 1406 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1407 | << getOpenMPClauseName(DVar.CKind); |
| 1408 | return; |
| 1409 | } |
| 1410 | enum { |
| 1411 | PDSA_StaticMemberShared, |
| 1412 | PDSA_StaticLocalVarShared, |
| 1413 | PDSA_LoopIterVarPrivate, |
| 1414 | PDSA_LoopIterVarLinear, |
| 1415 | PDSA_LoopIterVarLastprivate, |
| 1416 | PDSA_ConstVarShared, |
| 1417 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1418 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1419 | PDSA_LocalVarPrivate, |
| 1420 | PDSA_Implicit |
| 1421 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1422 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1423 | auto ReportLoc = D->getLocation(); |
| 1424 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1425 | if (IsLoopIterVar) { |
| 1426 | if (DVar.CKind == OMPC_private) |
| 1427 | Reason = PDSA_LoopIterVarPrivate; |
| 1428 | else if (DVar.CKind == OMPC_lastprivate) |
| 1429 | Reason = PDSA_LoopIterVarLastprivate; |
| 1430 | else |
| 1431 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1432 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1433 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1434 | Reason = PDSA_TaskVarFirstprivate; |
| 1435 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1436 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1437 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1438 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1439 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1440 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1441 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1442 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1443 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1444 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1445 | ReportHint = true; |
| 1446 | Reason = PDSA_LocalVarPrivate; |
| 1447 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1448 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1449 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1450 | << Reason << ReportHint |
| 1451 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1452 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1453 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1454 | << getOpenMPClauseName(DVar.CKind); |
| 1455 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1458 | namespace { |
| 1459 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1460 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1461 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1462 | bool ErrorFound; |
| 1463 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1464 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1465 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1466 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1467 | public: |
| 1468 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1469 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1470 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1471 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1472 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1473 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1474 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1475 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1476 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1477 | auto DVar = Stack->getTopDSA(VD, false); |
| 1478 | // 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] | 1479 | if (DVar.RefExpr) |
| 1480 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1481 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1482 | auto ELoc = E->getExprLoc(); |
| 1483 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1484 | // The default(none) clause requires that each variable that is referenced |
| 1485 | // in the construct, and does not have a predetermined data-sharing |
| 1486 | // attribute, must have its data-sharing attribute explicitly determined |
| 1487 | // by being listed in a data-sharing attribute clause. |
| 1488 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1489 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1490 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1491 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1492 | return; |
| 1493 | } |
| 1494 | |
| 1495 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1496 | // A list item that appears in a reduction clause of the innermost |
| 1497 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1498 | // explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1499 | DVar = Stack->hasInnermostDSA( |
| 1500 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1501 | [](OpenMPDirectiveKind K) -> bool { |
| 1502 | return isOpenMPParallelDirective(K) || |
| 1503 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 1504 | }, |
| 1505 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1506 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1507 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1508 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1509 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1510 | return; |
| 1511 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1512 | |
| 1513 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1514 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1515 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1516 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1517 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1518 | } |
| 1519 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1520 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1521 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1522 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1523 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1524 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1525 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1526 | auto DVar = Stack->getTopDSA(FD, false); |
| 1527 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1528 | // so. |
| 1529 | if (DVar.RefExpr) |
| 1530 | return; |
| 1531 | |
| 1532 | auto ELoc = E->getExprLoc(); |
| 1533 | auto DKind = Stack->getCurrentDirective(); |
| 1534 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1535 | // A list item that appears in a reduction clause of the innermost |
| 1536 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1537 | // an explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1538 | DVar = Stack->hasInnermostDSA( |
| 1539 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1540 | [](OpenMPDirectiveKind K) -> bool { |
| 1541 | return isOpenMPParallelDirective(K) || |
| 1542 | isOpenMPWorksharingDirective(K) || |
| 1543 | isOpenMPTeamsDirective(K); |
| 1544 | }, |
| 1545 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1546 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1547 | ErrorFound = true; |
| 1548 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1549 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1550 | return; |
| 1551 | } |
| 1552 | |
| 1553 | // Define implicit data-sharing attributes for task. |
| 1554 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1555 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1556 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1557 | ImplicitFirstprivate.push_back(E); |
| 1558 | } |
Alexey Bataev | 7fcacd8 | 2016-11-28 15:55:15 +0000 | [diff] [blame] | 1559 | } else |
| 1560 | Visit(E->getBase()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1561 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1562 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1563 | for (auto *C : S->clauses()) { |
| 1564 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1565 | // for task directives. |
| 1566 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1567 | for (auto *CC : C->children()) { |
| 1568 | if (CC) |
| 1569 | Visit(CC); |
| 1570 | } |
| 1571 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1572 | } |
| 1573 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1574 | for (auto *C : S->children()) { |
| 1575 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1576 | Visit(C); |
| 1577 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1578 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1579 | |
| 1580 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1581 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1582 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1583 | return VarsWithInheritedDSA; |
| 1584 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1585 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1586 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1587 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1588 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1589 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1590 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1591 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1592 | switch (DKind) { |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1593 | case OMPD_parallel: |
| 1594 | case OMPD_parallel_for: |
| 1595 | case OMPD_parallel_for_simd: |
| 1596 | case OMPD_parallel_sections: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1597 | case OMPD_teams: |
| 1598 | case OMPD_target_teams: { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1599 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1600 | QualType KmpInt32PtrTy = |
| 1601 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1602 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1603 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1604 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1605 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1606 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1607 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1608 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1609 | break; |
| 1610 | } |
Arpith Chacko Jacob | 6801957 | 2017-01-18 15:14:52 +0000 | [diff] [blame] | 1611 | case OMPD_target_parallel: { |
| 1612 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 1613 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1614 | }; |
| 1615 | // Start a captured region for 'target' with no implicit parameters. |
| 1616 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1617 | ParamsTarget); |
| 1618 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1619 | QualType KmpInt32PtrTy = |
| 1620 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1621 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 1622 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1623 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1624 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1625 | }; |
| 1626 | // Start a captured region for 'parallel'. |
| 1627 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1628 | ParamsParallel); |
| 1629 | break; |
| 1630 | } |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1631 | case OMPD_simd: |
| 1632 | case OMPD_for: |
| 1633 | case OMPD_for_simd: |
| 1634 | case OMPD_sections: |
| 1635 | case OMPD_section: |
| 1636 | case OMPD_single: |
| 1637 | case OMPD_master: |
| 1638 | case OMPD_critical: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1639 | case OMPD_taskgroup: |
| 1640 | case OMPD_distribute: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1641 | case OMPD_ordered: |
| 1642 | case OMPD_atomic: |
| 1643 | case OMPD_target_data: |
| 1644 | case OMPD_target: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1645 | case OMPD_target_parallel_for: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1646 | case OMPD_target_parallel_for_simd: |
| 1647 | case OMPD_target_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1648 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1649 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1650 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1651 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1652 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1653 | break; |
| 1654 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1655 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1656 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1657 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1658 | FunctionProtoType::ExtProtoInfo EPI; |
| 1659 | EPI.Variadic = true; |
| 1660 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1661 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1662 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1663 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1664 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1665 | std::make_pair(".copy_fn.", |
| 1666 | Context.getPointerType(CopyFnType).withConst()), |
| 1667 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1668 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1669 | }; |
| 1670 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1671 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1672 | // Mark this captured region as inlined, because we don't use outlined |
| 1673 | // function directly. |
| 1674 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1675 | AlwaysInlineAttr::CreateImplicit( |
| 1676 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1677 | break; |
| 1678 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1679 | case OMPD_taskloop: |
| 1680 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1681 | QualType KmpInt32Ty = |
| 1682 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1683 | QualType KmpUInt64Ty = |
| 1684 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1685 | QualType KmpInt64Ty = |
| 1686 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1687 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1688 | FunctionProtoType::ExtProtoInfo EPI; |
| 1689 | EPI.Variadic = true; |
| 1690 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1691 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1692 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1693 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1694 | std::make_pair(".privates.", |
| 1695 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1696 | std::make_pair( |
| 1697 | ".copy_fn.", |
| 1698 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1699 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1700 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1701 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1702 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1703 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1704 | }; |
| 1705 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1706 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1707 | // Mark this captured region as inlined, because we don't use outlined |
| 1708 | // function directly. |
| 1709 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1710 | AlwaysInlineAttr::CreateImplicit( |
| 1711 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1712 | break; |
| 1713 | } |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1714 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1715 | case OMPD_distribute_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1716 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1717 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1718 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1719 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1720 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1721 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1722 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1723 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 1724 | case OMPD_target_teams_distribute_simd: { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1725 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1726 | QualType KmpInt32PtrTy = |
| 1727 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1728 | Sema::CapturedParamNameType Params[] = { |
| 1729 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1730 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1731 | std::make_pair(".previous.lb.", Context.getSizeType()), |
| 1732 | std::make_pair(".previous.ub.", Context.getSizeType()), |
| 1733 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1734 | }; |
| 1735 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1736 | Params); |
| 1737 | break; |
| 1738 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1739 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1740 | case OMPD_taskyield: |
| 1741 | case OMPD_barrier: |
| 1742 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1743 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1744 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1745 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1746 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1747 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1748 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1749 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1750 | case OMPD_declare_target: |
| 1751 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1752 | case OMPD_target_update: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1753 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1754 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1755 | llvm_unreachable("Unknown OpenMP directive"); |
| 1756 | } |
| 1757 | } |
| 1758 | |
Arpith Chacko Jacob | 6801957 | 2017-01-18 15:14:52 +0000 | [diff] [blame] | 1759 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
| 1760 | return getOpenMPCaptureRegions(DKind).size(); |
| 1761 | } |
| 1762 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1763 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1764 | Expr *CaptureExpr, bool WithInit, |
| 1765 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1766 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1767 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1768 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1769 | QualType Ty = Init->getType(); |
| 1770 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1771 | if (S.getLangOpts().CPlusPlus) |
| 1772 | Ty = C.getLValueReferenceType(Ty); |
| 1773 | else { |
| 1774 | Ty = C.getPointerType(Ty); |
| 1775 | ExprResult Res = |
| 1776 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1777 | if (!Res.isUsable()) |
| 1778 | return nullptr; |
| 1779 | Init = Res.get(); |
| 1780 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1781 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1782 | } |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 1783 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
| 1784 | CaptureExpr->getLocStart()); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1785 | if (!WithInit) |
| 1786 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1787 | S.CurContext->addHiddenDecl(CED); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1788 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1789 | return CED; |
| 1790 | } |
| 1791 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1792 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1793 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1794 | OMPCapturedExprDecl *CD; |
| 1795 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1796 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1797 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1798 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1799 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1800 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1801 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1804 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1805 | if (!Ref) { |
| 1806 | auto *CD = |
| 1807 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1808 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1809 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1810 | CaptureExpr->getExprLoc()); |
| 1811 | } |
| 1812 | ExprResult Res = Ref; |
| 1813 | if (!S.getLangOpts().CPlusPlus && |
| 1814 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1815 | Ref->getType()->isPointerType()) |
| 1816 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1817 | if (!Res.isUsable()) |
| 1818 | return ExprError(); |
| 1819 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
Arpith Chacko Jacob | 6801957 | 2017-01-18 15:14:52 +0000 | [diff] [blame] | 1822 | namespace { |
| 1823 | // OpenMP directives parsed in this section are represented as a |
| 1824 | // CapturedStatement with an associated statement. If a syntax error |
| 1825 | // is detected during the parsing of the associated statement, the |
| 1826 | // compiler must abort processing and close the CapturedStatement. |
| 1827 | // |
| 1828 | // Combined directives such as 'target parallel' have more than one |
| 1829 | // nested CapturedStatements. This RAII ensures that we unwind out |
| 1830 | // of all the nested CapturedStatements when an error is found. |
| 1831 | class CaptureRegionUnwinderRAII { |
| 1832 | private: |
| 1833 | Sema &S; |
| 1834 | bool &ErrorFound; |
| 1835 | OpenMPDirectiveKind DKind; |
| 1836 | |
| 1837 | public: |
| 1838 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
| 1839 | OpenMPDirectiveKind DKind) |
| 1840 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
| 1841 | ~CaptureRegionUnwinderRAII() { |
| 1842 | if (ErrorFound) { |
| 1843 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
| 1844 | while (--ThisCaptureLevel >= 0) |
| 1845 | S.ActOnCapturedRegionError(); |
| 1846 | } |
| 1847 | } |
| 1848 | }; |
| 1849 | } // namespace |
| 1850 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1851 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1852 | ArrayRef<OMPClause *> Clauses) { |
Arpith Chacko Jacob | 6801957 | 2017-01-18 15:14:52 +0000 | [diff] [blame] | 1853 | bool ErrorFound = false; |
| 1854 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
| 1855 | *this, ErrorFound, DSAStack->getCurrentDirective()); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1856 | if (!S.isUsable()) { |
Arpith Chacko Jacob | 6801957 | 2017-01-18 15:14:52 +0000 | [diff] [blame] | 1857 | ErrorFound = true; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1858 | return StmtError(); |
| 1859 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1860 | |
| 1861 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1862 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1863 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1864 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1865 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1866 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1867 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1868 | (getLangOpts().OpenMPUseTLS && |
| 1869 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1870 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1871 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1872 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1873 | for (auto *VarRef : Clause->children()) { |
| 1874 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1875 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1876 | } |
| 1877 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1878 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1879 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1880 | // Mark all variables in private list clauses as used in inner region. |
| 1881 | // Required for proper codegen of combined directives. |
| 1882 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1883 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1884 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1885 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1886 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1887 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1888 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1889 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1890 | if (auto *E = C->getPostUpdateExpr()) |
| 1891 | MarkDeclarationsReferencedInExpr(E); |
| 1892 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1893 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1894 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1895 | SC = cast<OMPScheduleClause>(Clause); |
| 1896 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1897 | OC = cast<OMPOrderedClause>(Clause); |
| 1898 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1899 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1900 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1901 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1902 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1903 | // specified. |
| 1904 | if (SC && |
| 1905 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1906 | SC->getSecondScheduleModifier() == |
| 1907 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1908 | OC) { |
| 1909 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1910 | ? SC->getFirstScheduleModifierLoc() |
| 1911 | : SC->getSecondScheduleModifierLoc(), |
| 1912 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1913 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1914 | ErrorFound = true; |
| 1915 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1916 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1917 | for (auto *C : LCs) { |
| 1918 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1919 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1920 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1921 | ErrorFound = true; |
| 1922 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1923 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1924 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1925 | OC->getNumForLoops()) { |
| 1926 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1927 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1928 | ErrorFound = true; |
| 1929 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1930 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1931 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1932 | } |
Arpith Chacko Jacob | 6801957 | 2017-01-18 15:14:52 +0000 | [diff] [blame] | 1933 | StmtResult SR = S; |
| 1934 | int ThisCaptureLevel = |
| 1935 | getOpenMPCaptureLevels(DSAStack->getCurrentDirective()); |
| 1936 | while (--ThisCaptureLevel >= 0) |
| 1937 | SR = ActOnCapturedRegionEnd(SR.get()); |
| 1938 | return SR; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1941 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1942 | OpenMPDirectiveKind CurrentRegion, |
| 1943 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1944 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1945 | SourceLocation StartLoc) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1946 | if (Stack->getCurScope()) { |
| 1947 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1948 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1949 | bool NestingProhibited = false; |
| 1950 | bool CloseNesting = true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1951 | bool OrphanSeen = false; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1952 | enum { |
| 1953 | NoRecommend, |
| 1954 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1955 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1956 | ShouldBeInTargetRegion, |
| 1957 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1958 | } Recommend = NoRecommend; |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 1959 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1960 | // OpenMP [2.16, Nesting of Regions] |
| 1961 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1962 | // OpenMP [2.8.1,simd Construct, Restrictions] |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 1963 | // An ordered construct with the simd clause is the only OpenMP |
| 1964 | // construct that can appear in the simd region. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1965 | // Allowing a SIMD construct nested in another SIMD construct is an |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 1966 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 1967 | // message. |
| 1968 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 1969 | ? diag::err_omp_prohibited_region_simd |
| 1970 | : diag::warn_omp_nesting_simd); |
| 1971 | return CurrentRegion != OMPD_simd; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1972 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1973 | if (ParentRegion == OMPD_atomic) { |
| 1974 | // OpenMP [2.16, Nesting of Regions] |
| 1975 | // OpenMP constructs may not be nested inside an atomic region. |
| 1976 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1977 | return true; |
| 1978 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1979 | if (CurrentRegion == OMPD_section) { |
| 1980 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1981 | // Orphaned section directives are prohibited. That is, the section |
| 1982 | // directives must appear within the sections construct and must not be |
| 1983 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1984 | if (ParentRegion != OMPD_sections && |
| 1985 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1986 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1987 | << (ParentRegion != OMPD_unknown) |
| 1988 | << getOpenMPDirectiveName(ParentRegion); |
| 1989 | return true; |
| 1990 | } |
| 1991 | return false; |
| 1992 | } |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 1993 | // Allow some constructs (except teams) to be orphaned (they could be |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1994 | // used in functions, called from OpenMP regions with the required |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 1995 | // preconditions). |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1996 | if (ParentRegion == OMPD_unknown && |
| 1997 | !isOpenMPNestingTeamsDirective(CurrentRegion)) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1998 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1999 | if (CurrentRegion == OMPD_cancellation_point || |
| 2000 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2001 | // OpenMP [2.16, Nesting of Regions] |
| 2002 | // A cancellation point construct for which construct-type-clause is |
| 2003 | // taskgroup must be nested inside a task construct. A cancellation |
| 2004 | // point construct for which construct-type-clause is not taskgroup must |
| 2005 | // be closely nested inside an OpenMP construct that matches the type |
| 2006 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2007 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2008 | // nested inside a task construct. A cancel construct for which |
| 2009 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2010 | // OpenMP construct that matches the type specified in |
| 2011 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2012 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2013 | !((CancelRegion == OMPD_parallel && |
| 2014 | (ParentRegion == OMPD_parallel || |
| 2015 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2016 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2017 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2018 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2019 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2020 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2021 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2022 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2023 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2024 | // OpenMP [2.16, Nesting of Regions] |
| 2025 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2026 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2027 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2028 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2029 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2030 | // OpenMP [2.16, Nesting of Regions] |
| 2031 | // A critical region may not be nested (closely or otherwise) inside a |
| 2032 | // critical region with the same name. Note that this restriction is not |
| 2033 | // sufficient to prevent deadlock. |
| 2034 | SourceLocation PreviousCriticalLoc; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2035 | bool DeadLock = Stack->hasDirective( |
| 2036 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 2037 | const DeclarationNameInfo &DNI, |
| 2038 | SourceLocation Loc) -> bool { |
| 2039 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 2040 | PreviousCriticalLoc = Loc; |
| 2041 | return true; |
| 2042 | } else |
| 2043 | return false; |
| 2044 | }, |
| 2045 | false /* skip top directive */); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2046 | if (DeadLock) { |
| 2047 | SemaRef.Diag(StartLoc, |
| 2048 | diag::err_omp_prohibited_region_critical_same_name) |
| 2049 | << CurrentName.getName(); |
| 2050 | if (PreviousCriticalLoc.isValid()) |
| 2051 | SemaRef.Diag(PreviousCriticalLoc, |
| 2052 | diag::note_omp_previous_critical_region); |
| 2053 | return true; |
| 2054 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2055 | } else if (CurrentRegion == OMPD_barrier) { |
| 2056 | // OpenMP [2.16, Nesting of Regions] |
| 2057 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2058 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2059 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2060 | isOpenMPTaskingDirective(ParentRegion) || |
| 2061 | ParentRegion == OMPD_master || |
| 2062 | ParentRegion == OMPD_critical || |
| 2063 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2064 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2065 | !isOpenMPParallelDirective(CurrentRegion) && |
| 2066 | !isOpenMPTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2067 | // OpenMP [2.16, Nesting of Regions] |
| 2068 | // A worksharing region may not be closely nested inside a worksharing, |
| 2069 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2070 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2071 | isOpenMPTaskingDirective(ParentRegion) || |
| 2072 | ParentRegion == OMPD_master || |
| 2073 | ParentRegion == OMPD_critical || |
| 2074 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2075 | Recommend = ShouldBeInParallelRegion; |
| 2076 | } else if (CurrentRegion == OMPD_ordered) { |
| 2077 | // OpenMP [2.16, Nesting of Regions] |
| 2078 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2079 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2080 | // An ordered region must be closely nested inside a loop region (or |
| 2081 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2082 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2083 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2084 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2085 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2086 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2087 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2088 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2089 | Recommend = ShouldBeInOrderedRegion; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2090 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2091 | // OpenMP [2.16, Nesting of Regions] |
| 2092 | // If specified, a teams construct must be contained within a target |
| 2093 | // construct. |
| 2094 | NestingProhibited = ParentRegion != OMPD_target; |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2095 | OrphanSeen = ParentRegion == OMPD_unknown; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2096 | Recommend = ShouldBeInTargetRegion; |
| 2097 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2098 | } |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2099 | if (!NestingProhibited && |
| 2100 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
| 2101 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
| 2102 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2103 | // OpenMP [2.16, Nesting of Regions] |
| 2104 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2105 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2106 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2107 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2108 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2109 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2110 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2111 | if (!NestingProhibited && |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2112 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2113 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2114 | // The region associated with the distribute construct must be strictly |
| 2115 | // nested inside a teams region |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2116 | NestingProhibited = |
| 2117 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2118 | Recommend = ShouldBeInTeamsRegion; |
| 2119 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2120 | if (!NestingProhibited && |
| 2121 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2122 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2123 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2124 | // If a target, target update, target data, target enter data, or |
| 2125 | // target exit data construct is encountered during execution of a |
| 2126 | // target region, the behavior is unspecified. |
| 2127 | NestingProhibited = Stack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2128 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 2129 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2130 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2131 | OffendingRegion = K; |
| 2132 | return true; |
| 2133 | } else |
| 2134 | return false; |
| 2135 | }, |
| 2136 | false /* don't skip top directive */); |
| 2137 | CloseNesting = false; |
| 2138 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2139 | if (NestingProhibited) { |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2140 | if (OrphanSeen) { |
| 2141 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 2142 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 2143 | } else { |
| 2144 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 2145 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2146 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 2147 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2148 | return true; |
| 2149 | } |
| 2150 | } |
| 2151 | return false; |
| 2152 | } |
| 2153 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2154 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2155 | ArrayRef<OMPClause *> Clauses, |
| 2156 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2157 | bool ErrorFound = false; |
| 2158 | unsigned NamedModifiersNumber = 0; |
| 2159 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2160 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2161 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2162 | for (const auto *C : Clauses) { |
| 2163 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2164 | // At most one if clause without a directive-name-modifier can appear on |
| 2165 | // the directive. |
| 2166 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2167 | if (FoundNameModifiers[CurNM]) { |
| 2168 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2169 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2170 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2171 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2172 | } else if (CurNM != OMPD_unknown) { |
| 2173 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2174 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2175 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2176 | FoundNameModifiers[CurNM] = IC; |
| 2177 | if (CurNM == OMPD_unknown) |
| 2178 | continue; |
| 2179 | // Check if the specified name modifier is allowed for the current |
| 2180 | // directive. |
| 2181 | // At most one if clause with the particular directive-name-modifier can |
| 2182 | // appear on the directive. |
| 2183 | bool MatchFound = false; |
| 2184 | for (auto NM : AllowedNameModifiers) { |
| 2185 | if (CurNM == NM) { |
| 2186 | MatchFound = true; |
| 2187 | break; |
| 2188 | } |
| 2189 | } |
| 2190 | if (!MatchFound) { |
| 2191 | S.Diag(IC->getNameModifierLoc(), |
| 2192 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2193 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2194 | ErrorFound = true; |
| 2195 | } |
| 2196 | } |
| 2197 | } |
| 2198 | // If any if clause on the directive includes a directive-name-modifier then |
| 2199 | // all if clauses on the directive must include a directive-name-modifier. |
| 2200 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2201 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2202 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2203 | diag::err_omp_no_more_if_clause); |
| 2204 | } else { |
| 2205 | std::string Values; |
| 2206 | std::string Sep(", "); |
| 2207 | unsigned AllowedCnt = 0; |
| 2208 | unsigned TotalAllowedNum = |
| 2209 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2210 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2211 | ++Cnt) { |
| 2212 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2213 | if (!FoundNameModifiers[NM]) { |
| 2214 | Values += "'"; |
| 2215 | Values += getOpenMPDirectiveName(NM); |
| 2216 | Values += "'"; |
| 2217 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2218 | Values += " or "; |
| 2219 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2220 | Values += Sep; |
| 2221 | ++AllowedCnt; |
| 2222 | } |
| 2223 | } |
| 2224 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2225 | diag::err_omp_unnamed_if_clause) |
| 2226 | << (TotalAllowedNum > 1) << Values; |
| 2227 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2228 | for (auto Loc : NameModifierLoc) { |
| 2229 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2230 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2231 | ErrorFound = true; |
| 2232 | } |
| 2233 | return ErrorFound; |
| 2234 | } |
| 2235 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2236 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2237 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2238 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2239 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2240 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2241 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2242 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2243 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2244 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2245 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2246 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2247 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2248 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2249 | if (AStmt) { |
| 2250 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2251 | |
| 2252 | // Check default data sharing attributes for referenced variables. |
| 2253 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2254 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2255 | if (DSAChecker.isErrorFound()) |
| 2256 | return StmtError(); |
| 2257 | // Generate list of implicitly defined firstprivate variables. |
| 2258 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2259 | |
| 2260 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2261 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2262 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2263 | SourceLocation(), SourceLocation())) { |
| 2264 | ClausesWithImplicit.push_back(Implicit); |
| 2265 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2266 | DSAChecker.getImplicitFirstprivate().size(); |
| 2267 | } else |
| 2268 | ErrorFound = true; |
| 2269 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2270 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2271 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2272 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2273 | switch (Kind) { |
| 2274 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2275 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2276 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2277 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2278 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2279 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2280 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2281 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2282 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2283 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2284 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2285 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2286 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2287 | case OMPD_for_simd: |
| 2288 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2289 | EndLoc, VarsWithInheritedDSA); |
| 2290 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2291 | case OMPD_sections: |
| 2292 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2293 | EndLoc); |
| 2294 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2295 | case OMPD_section: |
| 2296 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2297 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2298 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2299 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2300 | case OMPD_single: |
| 2301 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2302 | EndLoc); |
| 2303 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2304 | case OMPD_master: |
| 2305 | assert(ClausesWithImplicit.empty() && |
| 2306 | "No clauses are allowed for 'omp master' directive"); |
| 2307 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2308 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2309 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2310 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2311 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2312 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2313 | case OMPD_parallel_for: |
| 2314 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2315 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2316 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2317 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2318 | case OMPD_parallel_for_simd: |
| 2319 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2320 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2321 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2322 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2323 | case OMPD_parallel_sections: |
| 2324 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2325 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2326 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2327 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2328 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2329 | Res = |
| 2330 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2331 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2332 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2333 | case OMPD_taskyield: |
| 2334 | assert(ClausesWithImplicit.empty() && |
| 2335 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2336 | assert(AStmt == nullptr && |
| 2337 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2338 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2339 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2340 | case OMPD_barrier: |
| 2341 | assert(ClausesWithImplicit.empty() && |
| 2342 | "No clauses are allowed for 'omp barrier' directive"); |
| 2343 | assert(AStmt == nullptr && |
| 2344 | "No associated statement allowed for 'omp barrier' directive"); |
| 2345 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2346 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2347 | case OMPD_taskwait: |
| 2348 | assert(ClausesWithImplicit.empty() && |
| 2349 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2350 | assert(AStmt == nullptr && |
| 2351 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2352 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2353 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2354 | case OMPD_taskgroup: |
| 2355 | assert(ClausesWithImplicit.empty() && |
| 2356 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2357 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2358 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2359 | case OMPD_flush: |
| 2360 | assert(AStmt == nullptr && |
| 2361 | "No associated statement allowed for 'omp flush' directive"); |
| 2362 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2363 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2364 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2365 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2366 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2367 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2368 | case OMPD_atomic: |
| 2369 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2370 | EndLoc); |
| 2371 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2372 | case OMPD_teams: |
| 2373 | Res = |
| 2374 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2375 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2376 | case OMPD_target: |
| 2377 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2378 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2379 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2380 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2381 | case OMPD_target_parallel: |
| 2382 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 2383 | StartLoc, EndLoc); |
| 2384 | AllowedNameModifiers.push_back(OMPD_target); |
| 2385 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2386 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2387 | case OMPD_target_parallel_for: |
| 2388 | Res = ActOnOpenMPTargetParallelForDirective( |
| 2389 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2390 | AllowedNameModifiers.push_back(OMPD_target); |
| 2391 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2392 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2393 | case OMPD_cancellation_point: |
| 2394 | assert(ClausesWithImplicit.empty() && |
| 2395 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2396 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2397 | "cancellation point' directive"); |
| 2398 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2399 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2400 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2401 | assert(AStmt == nullptr && |
| 2402 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2403 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2404 | CancelRegion); |
| 2405 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2406 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2407 | case OMPD_target_data: |
| 2408 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2409 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2410 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2411 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2412 | case OMPD_target_enter_data: |
| 2413 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2414 | EndLoc); |
| 2415 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2416 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2417 | case OMPD_target_exit_data: |
| 2418 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2419 | EndLoc); |
| 2420 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2421 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2422 | case OMPD_taskloop: |
| 2423 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2424 | EndLoc, VarsWithInheritedDSA); |
| 2425 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2426 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2427 | case OMPD_taskloop_simd: |
| 2428 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2429 | EndLoc, VarsWithInheritedDSA); |
| 2430 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2431 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2432 | case OMPD_distribute: |
| 2433 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2434 | EndLoc, VarsWithInheritedDSA); |
| 2435 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 2436 | case OMPD_target_update: |
| 2437 | assert(!AStmt && "Statement is not allowed for target update"); |
| 2438 | Res = |
| 2439 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2440 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 2441 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2442 | case OMPD_distribute_parallel_for: |
| 2443 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 2444 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2445 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2446 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2447 | case OMPD_distribute_parallel_for_simd: |
| 2448 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 2449 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2450 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2451 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2452 | case OMPD_distribute_simd: |
| 2453 | Res = ActOnOpenMPDistributeSimdDirective( |
| 2454 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2455 | break; |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2456 | case OMPD_target_parallel_for_simd: |
| 2457 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 2458 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2459 | AllowedNameModifiers.push_back(OMPD_target); |
| 2460 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2461 | break; |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2462 | case OMPD_target_simd: |
| 2463 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2464 | EndLoc, VarsWithInheritedDSA); |
| 2465 | AllowedNameModifiers.push_back(OMPD_target); |
| 2466 | break; |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2467 | case OMPD_teams_distribute: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2468 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 2469 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2470 | break; |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 2471 | case OMPD_teams_distribute_simd: |
| 2472 | Res = ActOnOpenMPTeamsDistributeSimdDirective( |
| 2473 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2474 | break; |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2475 | case OMPD_teams_distribute_parallel_for_simd: |
| 2476 | Res = ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 2477 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2478 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2479 | break; |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 2480 | case OMPD_teams_distribute_parallel_for: |
| 2481 | Res = ActOnOpenMPTeamsDistributeParallelForDirective( |
| 2482 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2483 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2484 | break; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2485 | case OMPD_target_teams: |
| 2486 | Res = ActOnOpenMPTargetTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2487 | EndLoc); |
| 2488 | AllowedNameModifiers.push_back(OMPD_target); |
| 2489 | break; |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 2490 | case OMPD_target_teams_distribute: |
| 2491 | Res = ActOnOpenMPTargetTeamsDistributeDirective( |
| 2492 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2493 | AllowedNameModifiers.push_back(OMPD_target); |
| 2494 | break; |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 2495 | case OMPD_target_teams_distribute_parallel_for: |
| 2496 | Res = ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 2497 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2498 | AllowedNameModifiers.push_back(OMPD_target); |
| 2499 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2500 | break; |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 2501 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 2502 | Res = ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 2503 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2504 | AllowedNameModifiers.push_back(OMPD_target); |
| 2505 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2506 | break; |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 2507 | case OMPD_target_teams_distribute_simd: |
| 2508 | Res = ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 2509 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2510 | AllowedNameModifiers.push_back(OMPD_target); |
| 2511 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 2512 | case OMPD_declare_target: |
| 2513 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2514 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2515 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2516 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2517 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2518 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2519 | llvm_unreachable("Unknown OpenMP directive"); |
| 2520 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2521 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2522 | for (auto P : VarsWithInheritedDSA) { |
| 2523 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2524 | << P.first << P.second->getSourceRange(); |
| 2525 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2526 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2527 | |
| 2528 | if (!AllowedNameModifiers.empty()) |
| 2529 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2530 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2531 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2532 | if (ErrorFound) |
| 2533 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2534 | return Res; |
| 2535 | } |
| 2536 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2537 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 2538 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2539 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2540 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 2541 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2542 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2543 | assert(Linears.size() == LinModifiers.size()); |
| 2544 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2545 | if (!DG || DG.get().isNull()) |
| 2546 | return DeclGroupPtrTy(); |
| 2547 | |
| 2548 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 2549 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2550 | return DG; |
| 2551 | } |
| 2552 | auto *ADecl = DG.get().getSingleDecl(); |
| 2553 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 2554 | ADecl = FTD->getTemplatedDecl(); |
| 2555 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2556 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 2557 | if (!FD) { |
| 2558 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2559 | return DeclGroupPtrTy(); |
| 2560 | } |
| 2561 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2562 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2563 | // The parameter of the simdlen clause must be a constant positive integer |
| 2564 | // expression. |
| 2565 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2566 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2567 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2568 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2569 | // The special this pointer can be used as if was one of the arguments to the |
| 2570 | // function in any of the linear, aligned, or uniform clauses. |
| 2571 | // The uniform clause declares one or more arguments to have an invariant |
| 2572 | // value for all concurrent invocations of the function in the execution of a |
| 2573 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2574 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 2575 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2576 | for (auto *E : Uniforms) { |
| 2577 | E = E->IgnoreParenImpCasts(); |
| 2578 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2579 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 2580 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2581 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2582 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 2583 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2584 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2585 | } |
| 2586 | if (isa<CXXThisExpr>(E)) { |
| 2587 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2588 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2589 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2590 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2591 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2592 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2593 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2594 | // The aligned clause declares that the object to which each list item points |
| 2595 | // is aligned to the number of bytes expressed in the optional parameter of |
| 2596 | // the aligned clause. |
| 2597 | // The special this pointer can be used as if was one of the arguments to the |
| 2598 | // function in any of the linear, aligned, or uniform clauses. |
| 2599 | // The type of list items appearing in the aligned clause must be array, |
| 2600 | // pointer, reference to array, or reference to pointer. |
| 2601 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 2602 | Expr *AlignedThis = nullptr; |
| 2603 | for (auto *E : Aligneds) { |
| 2604 | E = E->IgnoreParenImpCasts(); |
| 2605 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2606 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2607 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2608 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2609 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2610 | ->getCanonicalDecl() == CanonPVD) { |
| 2611 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2612 | // A list-item cannot appear in more than one aligned clause. |
| 2613 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 2614 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2615 | << 1 << E->getSourceRange(); |
| 2616 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 2617 | diag::note_omp_explicit_dsa) |
| 2618 | << getOpenMPClauseName(OMPC_aligned); |
| 2619 | continue; |
| 2620 | } |
| 2621 | AlignedArgs[CanonPVD] = E; |
| 2622 | QualType QTy = PVD->getType() |
| 2623 | .getNonReferenceType() |
| 2624 | .getUnqualifiedType() |
| 2625 | .getCanonicalType(); |
| 2626 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 2627 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 2628 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 2629 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 2630 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 2631 | } |
| 2632 | continue; |
| 2633 | } |
| 2634 | } |
| 2635 | if (isa<CXXThisExpr>(E)) { |
| 2636 | if (AlignedThis) { |
| 2637 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2638 | << 2 << E->getSourceRange(); |
| 2639 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2640 | << getOpenMPClauseName(OMPC_aligned); |
| 2641 | } |
| 2642 | AlignedThis = E; |
| 2643 | continue; |
| 2644 | } |
| 2645 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2646 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2647 | } |
| 2648 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 2649 | // positive integer expression. If no optional parameter is specified, |
| 2650 | // implementation-defined default alignments for SIMD instructions on the |
| 2651 | // target platforms are assumed. |
| 2652 | SmallVector<Expr *, 4> NewAligns; |
| 2653 | for (auto *E : Alignments) { |
| 2654 | ExprResult Align; |
| 2655 | if (E) |
| 2656 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 2657 | NewAligns.push_back(Align.get()); |
| 2658 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2659 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2660 | // The linear clause declares one or more list items to be private to a SIMD |
| 2661 | // lane and to have a linear relationship with respect to the iteration space |
| 2662 | // of a loop. |
| 2663 | // The special this pointer can be used as if was one of the arguments to the |
| 2664 | // function in any of the linear, aligned, or uniform clauses. |
| 2665 | // When a linear-step expression is specified in a linear clause it must be |
| 2666 | // either a constant integer expression or an integer-typed parameter that is |
| 2667 | // specified in a uniform clause on the directive. |
| 2668 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 2669 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 2670 | auto MI = LinModifiers.begin(); |
| 2671 | for (auto *E : Linears) { |
| 2672 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 2673 | ++MI; |
| 2674 | E = E->IgnoreParenImpCasts(); |
| 2675 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2676 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2677 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2678 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2679 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2680 | ->getCanonicalDecl() == CanonPVD) { |
| 2681 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 2682 | // A list-item cannot appear in more than one linear clause. |
| 2683 | if (LinearArgs.count(CanonPVD) > 0) { |
| 2684 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2685 | << getOpenMPClauseName(OMPC_linear) |
| 2686 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 2687 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 2688 | diag::note_omp_explicit_dsa) |
| 2689 | << getOpenMPClauseName(OMPC_linear); |
| 2690 | continue; |
| 2691 | } |
| 2692 | // Each argument can appear in at most one uniform or linear clause. |
| 2693 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 2694 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2695 | << getOpenMPClauseName(OMPC_linear) |
| 2696 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 2697 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 2698 | diag::note_omp_explicit_dsa) |
| 2699 | << getOpenMPClauseName(OMPC_uniform); |
| 2700 | continue; |
| 2701 | } |
| 2702 | LinearArgs[CanonPVD] = E; |
| 2703 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2704 | E->isInstantiationDependent() || |
| 2705 | E->containsUnexpandedParameterPack()) |
| 2706 | continue; |
| 2707 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 2708 | PVD->getOriginalType()); |
| 2709 | continue; |
| 2710 | } |
| 2711 | } |
| 2712 | if (isa<CXXThisExpr>(E)) { |
| 2713 | if (UniformedLinearThis) { |
| 2714 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2715 | << getOpenMPClauseName(OMPC_linear) |
| 2716 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 2717 | << E->getSourceRange(); |
| 2718 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2719 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 2720 | : OMPC_linear); |
| 2721 | continue; |
| 2722 | } |
| 2723 | UniformedLinearThis = E; |
| 2724 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2725 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 2726 | continue; |
| 2727 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 2728 | E->getType()); |
| 2729 | continue; |
| 2730 | } |
| 2731 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2732 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2733 | } |
| 2734 | Expr *Step = nullptr; |
| 2735 | Expr *NewStep = nullptr; |
| 2736 | SmallVector<Expr *, 4> NewSteps; |
| 2737 | for (auto *E : Steps) { |
| 2738 | // Skip the same step expression, it was checked already. |
| 2739 | if (Step == E || !E) { |
| 2740 | NewSteps.push_back(E ? NewStep : nullptr); |
| 2741 | continue; |
| 2742 | } |
| 2743 | Step = E; |
| 2744 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 2745 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2746 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2747 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 2748 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 2749 | << Step->getSourceRange(); |
| 2750 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 2751 | E->isInstantiationDependent() || |
| 2752 | E->containsUnexpandedParameterPack() || |
| 2753 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 2754 | NewSteps.push_back(Step); |
| 2755 | else { |
| 2756 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 2757 | << Step->getSourceRange(); |
| 2758 | } |
| 2759 | continue; |
| 2760 | } |
| 2761 | NewStep = Step; |
| 2762 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 2763 | !Step->isInstantiationDependent() && |
| 2764 | !Step->containsUnexpandedParameterPack()) { |
| 2765 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 2766 | .get(); |
| 2767 | if (NewStep) |
| 2768 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 2769 | } |
| 2770 | NewSteps.push_back(NewStep); |
| 2771 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2772 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 2773 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2774 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2775 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 2776 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 2777 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 2778 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2779 | ADecl->addAttr(NewAttr); |
| 2780 | return ConvertDeclToDeclGroup(ADecl); |
| 2781 | } |
| 2782 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2783 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2784 | Stmt *AStmt, |
| 2785 | SourceLocation StartLoc, |
| 2786 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2787 | if (!AStmt) |
| 2788 | return StmtError(); |
| 2789 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2790 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2791 | // 1.2.2 OpenMP Language Terminology |
| 2792 | // Structured block - An executable statement with a single entry at the |
| 2793 | // top and a single exit at the bottom. |
| 2794 | // The point of exit cannot be a branch out of the structured block. |
| 2795 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2796 | CS->getCapturedDecl()->setNothrow(); |
| 2797 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2798 | getCurFunction()->setHasBranchProtectedScope(); |
| 2799 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2800 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2801 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2804 | namespace { |
| 2805 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2806 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2807 | /// for IR generation. |
| 2808 | class OpenMPIterationSpaceChecker { |
| 2809 | /// \brief Reference to Sema. |
| 2810 | Sema &SemaRef; |
| 2811 | /// \brief A location for diagnostics (when there is no some better location). |
| 2812 | SourceLocation DefaultLoc; |
| 2813 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2814 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2815 | /// \brief A source location for referring to loop init later. |
| 2816 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2817 | /// \brief A source location for referring to condition later. |
| 2818 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2819 | /// \brief A source location for referring to increment later. |
| 2820 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2821 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2822 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2823 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2824 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2825 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2826 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2827 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2828 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2829 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2830 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2831 | /// \brief This flag is true when condition is one of: |
| 2832 | /// Var < UB |
| 2833 | /// Var <= UB |
| 2834 | /// UB > Var |
| 2835 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2836 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2837 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2838 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2839 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2840 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2841 | |
| 2842 | public: |
| 2843 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2844 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2845 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2846 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2847 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2848 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2849 | /// for less/greater and for strict/non-strict comparison. |
| 2850 | bool CheckCond(Expr *S); |
| 2851 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2852 | /// does not conform, otherwise save loop step (#Step). |
| 2853 | bool CheckInc(Expr *S); |
| 2854 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2855 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2856 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2857 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2858 | /// \brief Source range of the loop init. |
| 2859 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2860 | /// \brief Source range of the loop condition. |
| 2861 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2862 | /// \brief Source range of the loop increment. |
| 2863 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2864 | /// \brief True if the step should be subtracted. |
| 2865 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2866 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2867 | Expr * |
| 2868 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 2869 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2870 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2871 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 2872 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2873 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 2874 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 2875 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2876 | /// \brief Build reference expression to the private counter be used for |
| 2877 | /// codegen. |
| 2878 | Expr *BuildPrivateCounterVar() const; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2879 | /// \brief Build initialization of the counter be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2880 | Expr *BuildCounterInit() const; |
| 2881 | /// \brief Build step of the counter be used for codegen. |
| 2882 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2883 | /// \brief Return true if any expression is dependent. |
| 2884 | bool Dependent() const; |
| 2885 | |
| 2886 | private: |
| 2887 | /// \brief Check the right-hand side of an assignment in the increment |
| 2888 | /// expression. |
| 2889 | bool CheckIncRHS(Expr *RHS); |
| 2890 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2891 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2892 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2893 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2894 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2895 | /// \brief Helper to set loop increment. |
| 2896 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2897 | }; |
| 2898 | |
| 2899 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2900 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2901 | assert(!LB && !UB && !Step); |
| 2902 | return false; |
| 2903 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2904 | return LCDecl->getType()->isDependentType() || |
| 2905 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 2906 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2907 | } |
| 2908 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2909 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2910 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2911 | E = ExprTemp->getSubExpr(); |
| 2912 | |
| 2913 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2914 | E = MTE->GetTemporaryExpr(); |
| 2915 | |
| 2916 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2917 | E = Binder->getSubExpr(); |
| 2918 | |
| 2919 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2920 | E = ICE->getSubExprAsWritten(); |
| 2921 | return E->IgnoreParens(); |
| 2922 | } |
| 2923 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2924 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 2925 | Expr *NewLCRefExpr, |
| 2926 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2927 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2928 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2929 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2930 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2931 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2932 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 2933 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2934 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2935 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2936 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2937 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2938 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2939 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2940 | LB = NewLB; |
| 2941 | return false; |
| 2942 | } |
| 2943 | |
| 2944 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2945 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2946 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2947 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 2948 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2949 | if (!NewUB) |
| 2950 | return true; |
| 2951 | UB = NewUB; |
| 2952 | TestIsLessOp = LessOp; |
| 2953 | TestIsStrictOp = StrictOp; |
| 2954 | ConditionSrcRange = SR; |
| 2955 | ConditionLoc = SL; |
| 2956 | return false; |
| 2957 | } |
| 2958 | |
| 2959 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2960 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2961 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2962 | if (!NewStep) |
| 2963 | return true; |
| 2964 | if (!NewStep->isValueDependent()) { |
| 2965 | // Check that the step is integer expression. |
| 2966 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2967 | ExprResult Val = |
| 2968 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2969 | if (Val.isInvalid()) |
| 2970 | return true; |
| 2971 | NewStep = Val.get(); |
| 2972 | |
| 2973 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2974 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2975 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2976 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2977 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2978 | // the loop. |
| 2979 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2980 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2981 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2982 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2983 | // the loop. |
| 2984 | llvm::APSInt Result; |
| 2985 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2986 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2987 | bool IsConstNeg = |
| 2988 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2989 | bool IsConstPos = |
| 2990 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2991 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2992 | if (UB && (IsConstZero || |
| 2993 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2994 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2995 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2996 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2997 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2998 | SemaRef.Diag(ConditionLoc, |
| 2999 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3000 | << TestIsLessOp << ConditionSrcRange; |
| 3001 | return true; |
| 3002 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3003 | if (TestIsLessOp == Subtract) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3004 | NewStep = |
| 3005 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 3006 | .get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3007 | Subtract = !Subtract; |
| 3008 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | Step = NewStep; |
| 3012 | SubtractStep = Subtract; |
| 3013 | return false; |
| 3014 | } |
| 3015 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3016 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3017 | // Check init-expr for canonical loop form and save loop counter |
| 3018 | // variable - #Var and its initialization value - #LB. |
| 3019 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3020 | // var = lb |
| 3021 | // integer-type var = lb |
| 3022 | // random-access-iterator-type var = lb |
| 3023 | // pointer-type var = lb |
| 3024 | // |
| 3025 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3026 | if (EmitDiags) { |
| 3027 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3028 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3029 | return true; |
| 3030 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3031 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3032 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3033 | S = ExprTemp->getSubExpr(); |
| 3034 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3035 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3036 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3037 | S = E->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3038 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3039 | if (BO->getOpcode() == BO_Assign) { |
| 3040 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 3041 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3042 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3043 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3044 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3045 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 3046 | } |
| 3047 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3048 | if (ME->isArrow() && |
| 3049 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3050 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3051 | } |
| 3052 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3053 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3054 | if (DS->isSingleDecl()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3055 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3056 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3057 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3058 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3059 | SemaRef.Diag(S->getLocStart(), |
| 3060 | diag::ext_omp_loop_not_canonical_init) |
| 3061 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3062 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3063 | } |
| 3064 | } |
| 3065 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3066 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3067 | if (CE->getOperator() == OO_Equal) { |
| 3068 | auto *LHS = CE->getArg(0); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3069 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3070 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3071 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3072 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3073 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 3074 | } |
| 3075 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3076 | if (ME->isArrow() && |
| 3077 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3078 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3079 | } |
| 3080 | } |
| 3081 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3082 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3083 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3084 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3085 | if (EmitDiags) { |
| 3086 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3087 | << S->getSourceRange(); |
| 3088 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3089 | return true; |
| 3090 | } |
| 3091 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3092 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3093 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3094 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3095 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3096 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3097 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3098 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3099 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3100 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3101 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3102 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3103 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3104 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 3105 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 3106 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 3107 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3108 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3109 | return getCanonicalDecl(VD); |
| 3110 | } |
| 3111 | } |
| 3112 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 3113 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3114 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3115 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3119 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3120 | // less/greater and for strict/non-strict comparison. |
| 3121 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3122 | // var relational-op b |
| 3123 | // b relational-op var |
| 3124 | // |
| 3125 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3126 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3127 | return true; |
| 3128 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3129 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3130 | SourceLocation CondLoc = S->getLocStart(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3131 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3132 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3133 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3134 | return SetUB(BO->getRHS(), |
| 3135 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3136 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3137 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3138 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3139 | return SetUB(BO->getLHS(), |
| 3140 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3141 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3142 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3143 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3144 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3145 | if (CE->getNumArgs() == 2) { |
| 3146 | auto Op = CE->getOperator(); |
| 3147 | switch (Op) { |
| 3148 | case OO_Greater: |
| 3149 | case OO_GreaterEqual: |
| 3150 | case OO_Less: |
| 3151 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3152 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3153 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3154 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3155 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3156 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3157 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3158 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3159 | CE->getOperatorLoc()); |
| 3160 | break; |
| 3161 | default: |
| 3162 | break; |
| 3163 | } |
| 3164 | } |
| 3165 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3166 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3167 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3168 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3169 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3170 | return true; |
| 3171 | } |
| 3172 | |
| 3173 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3174 | // RHS of canonical loop form increment can be: |
| 3175 | // var + incr |
| 3176 | // incr + var |
| 3177 | // var - incr |
| 3178 | // |
| 3179 | RHS = RHS->IgnoreParenImpCasts(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3180 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3181 | if (BO->isAdditiveOp()) { |
| 3182 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3183 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3184 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3185 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3186 | return SetStep(BO->getLHS(), false); |
| 3187 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3188 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3189 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3190 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3191 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3192 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3193 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3194 | return SetStep(CE->getArg(0), false); |
| 3195 | } |
| 3196 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3197 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3198 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3199 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3200 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3201 | return true; |
| 3202 | } |
| 3203 | |
| 3204 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3205 | // Check incr-expr for canonical loop form and return true if it |
| 3206 | // does not conform. |
| 3207 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3208 | // ++var |
| 3209 | // var++ |
| 3210 | // --var |
| 3211 | // var-- |
| 3212 | // var += incr |
| 3213 | // var -= incr |
| 3214 | // var = var + incr |
| 3215 | // var = incr + var |
| 3216 | // var = var - incr |
| 3217 | // |
| 3218 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3219 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3220 | return true; |
| 3221 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3222 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3223 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3224 | S = ExprTemp->getSubExpr(); |
| 3225 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3226 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3227 | S = S->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3228 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3229 | if (UO->isIncrementDecrementOp() && |
| 3230 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3231 | return SetStep(SemaRef |
| 3232 | .ActOnIntegerConstant(UO->getLocStart(), |
| 3233 | (UO->isDecrementOp() ? -1 : 1)) |
| 3234 | .get(), |
| 3235 | false); |
| 3236 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3237 | switch (BO->getOpcode()) { |
| 3238 | case BO_AddAssign: |
| 3239 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3240 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3241 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3242 | break; |
| 3243 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3244 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3245 | return CheckIncRHS(BO->getRHS()); |
| 3246 | break; |
| 3247 | default: |
| 3248 | break; |
| 3249 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3250 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3251 | switch (CE->getOperator()) { |
| 3252 | case OO_PlusPlus: |
| 3253 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3254 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3255 | return SetStep(SemaRef |
| 3256 | .ActOnIntegerConstant( |
| 3257 | CE->getLocStart(), |
| 3258 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 3259 | .get(), |
| 3260 | false); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3261 | break; |
| 3262 | case OO_PlusEqual: |
| 3263 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3264 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3265 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3266 | break; |
| 3267 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3268 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3269 | return CheckIncRHS(CE->getArg(1)); |
| 3270 | break; |
| 3271 | default: |
| 3272 | break; |
| 3273 | } |
| 3274 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3275 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3276 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3277 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3278 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3279 | return true; |
| 3280 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3281 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3282 | static ExprResult |
| 3283 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 3284 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 3285 | if (SemaRef.CurContext->isDependentContext()) |
| 3286 | return ExprResult(Capture); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3287 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 3288 | return SemaRef.PerformImplicitConversion( |
| 3289 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 3290 | /*AllowExplicit=*/true); |
| 3291 | auto I = Captures.find(Capture); |
| 3292 | if (I != Captures.end()) |
| 3293 | return buildCapture(SemaRef, Capture, I->second); |
| 3294 | DeclRefExpr *Ref = nullptr; |
| 3295 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 3296 | Captures[Capture] = Ref; |
| 3297 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3298 | } |
| 3299 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3300 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3301 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 3302 | Scope *S, const bool LimitedType, |
| 3303 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3304 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3305 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3306 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3307 | SemaRef.getLangOpts().CPlusPlus) { |
| 3308 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3309 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3310 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3311 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 3312 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3313 | if (!Upper || !Lower) |
| 3314 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3315 | |
| 3316 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3317 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3318 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3319 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3320 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3321 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3322 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3323 | return nullptr; |
| 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | if (!Diff.isUsable()) |
| 3328 | return nullptr; |
| 3329 | |
| 3330 | // Upper - Lower [- 1] |
| 3331 | if (TestIsStrictOp) |
| 3332 | Diff = SemaRef.BuildBinOp( |
| 3333 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3334 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3335 | if (!Diff.isUsable()) |
| 3336 | return nullptr; |
| 3337 | |
| 3338 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3339 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 3340 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3341 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3342 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3343 | if (!Diff.isUsable()) |
| 3344 | return nullptr; |
| 3345 | |
| 3346 | // Parentheses (for dumping/debugging purposes only). |
| 3347 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3348 | if (!Diff.isUsable()) |
| 3349 | return nullptr; |
| 3350 | |
| 3351 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3352 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3353 | if (!Diff.isUsable()) |
| 3354 | return nullptr; |
| 3355 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3356 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3357 | QualType Type = Diff.get()->getType(); |
| 3358 | auto &C = SemaRef.Context; |
| 3359 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3360 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3361 | if (!Type->isIntegerType() || UseVarType) { |
| 3362 | unsigned NewSize = |
| 3363 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3364 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3365 | : Type->hasSignedIntegerRepresentation(); |
| 3366 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3367 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3368 | Diff = SemaRef.PerformImplicitConversion( |
| 3369 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3370 | if (!Diff.isUsable()) |
| 3371 | return nullptr; |
| 3372 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3373 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3374 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3375 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3376 | if (NewSize != C.getTypeSize(Type)) { |
| 3377 | if (NewSize < C.getTypeSize(Type)) { |
| 3378 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3379 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3380 | << InitSrcRange << ConditionSrcRange; |
| 3381 | } |
| 3382 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3383 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3384 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3385 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3386 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3387 | Sema::AA_Converting, true); |
| 3388 | if (!Diff.isUsable()) |
| 3389 | return nullptr; |
| 3390 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3391 | } |
| 3392 | } |
| 3393 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3394 | return Diff.get(); |
| 3395 | } |
| 3396 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3397 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 3398 | Scope *S, Expr *Cond, |
| 3399 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3400 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3401 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3402 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3403 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3404 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 3405 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 3406 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 3407 | return nullptr; |
| 3408 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3409 | auto CondExpr = SemaRef.BuildBinOp( |
| 3410 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3411 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3412 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3413 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3414 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 3415 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3416 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3417 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3418 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3419 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3420 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3421 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3422 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3423 | } |
| 3424 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3425 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3426 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3427 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3428 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 3429 | if (!VD) { |
| 3430 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 3431 | auto *Ref = buildDeclRefExpr( |
| 3432 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3433 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 3434 | // If the loop control decl is explicitly marked as private, do not mark it |
| 3435 | // as captured again. |
| 3436 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 3437 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3438 | return Ref; |
| 3439 | } |
| 3440 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3441 | DefaultLoc); |
| 3442 | } |
| 3443 | |
| 3444 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3445 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 3446 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3447 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3448 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 3449 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3450 | if (PrivateVar->isInvalidDecl()) |
| 3451 | return nullptr; |
| 3452 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3453 | } |
| 3454 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3455 | } |
| 3456 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 3457 | /// \brief Build initialization of the counter to be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3458 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3459 | |
| 3460 | /// \brief Build step of the counter be used for codegen. |
| 3461 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3462 | |
| 3463 | /// \brief Iteration space of a single for loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3464 | struct LoopIterationSpace final { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3465 | /// \brief Condition of the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3466 | Expr *PreCond = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3467 | /// \brief This expression calculates the number of iterations in the loop. |
| 3468 | /// It is always possible to calculate it before starting the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3469 | Expr *NumIterations = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3470 | /// \brief The loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3471 | Expr *CounterVar = nullptr; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3472 | /// \brief Private loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3473 | Expr *PrivateCounterVar = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3474 | /// \brief This is initializer for the initial value of #CounterVar. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3475 | Expr *CounterInit = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3476 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3477 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3478 | Expr *CounterStep = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3479 | /// \brief Should step be subtracted? |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3480 | bool Subtract = false; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3481 | /// \brief Source range of the loop init. |
| 3482 | SourceRange InitSrcRange; |
| 3483 | /// \brief Source range of the loop condition. |
| 3484 | SourceRange CondSrcRange; |
| 3485 | /// \brief Source range of the loop increment. |
| 3486 | SourceRange IncSrcRange; |
| 3487 | }; |
| 3488 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3489 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3490 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3491 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3492 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3493 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3494 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3495 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3496 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3497 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3498 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3499 | if (auto *D = ISC.GetLoopDecl()) { |
| 3500 | auto *VD = dyn_cast<VarDecl>(D); |
| 3501 | if (!VD) { |
| 3502 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 3503 | VD = Private; |
| 3504 | else { |
| 3505 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 3506 | /*WithInit=*/false); |
| 3507 | VD = cast<VarDecl>(Ref->getDecl()); |
| 3508 | } |
| 3509 | } |
| 3510 | DSAStack->addLoopControlVariable(D, VD); |
| 3511 | } |
| 3512 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3513 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3517 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3518 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3519 | static bool CheckOpenMPIterationSpace( |
| 3520 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3521 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3522 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3523 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3524 | LoopIterationSpace &ResultIterSpace, |
| 3525 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3526 | // OpenMP [2.6, Canonical Loop Form] |
| 3527 | // for (init-expr; test-expr; incr-expr) structured-block |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3528 | auto *For = dyn_cast_or_null<ForStmt>(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3529 | if (!For) { |
| 3530 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3531 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3532 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3533 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3534 | if (NestedLoopCount > 1) { |
| 3535 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3536 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3537 | diag::note_omp_collapse_ordered_expr) |
| 3538 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3539 | << OrderedLoopCountExpr->getSourceRange(); |
| 3540 | else if (CollapseLoopCountExpr) |
| 3541 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3542 | diag::note_omp_collapse_ordered_expr) |
| 3543 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3544 | else |
| 3545 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3546 | diag::note_omp_collapse_ordered_expr) |
| 3547 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3548 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3549 | return true; |
| 3550 | } |
| 3551 | assert(For->getBody()); |
| 3552 | |
| 3553 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3554 | |
| 3555 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3556 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3557 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3558 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3559 | |
| 3560 | bool HasErrors = false; |
| 3561 | |
| 3562 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3563 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 3564 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3565 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3566 | // OpenMP [2.6, Canonical Loop Form] |
| 3567 | // Var is one of the following: |
| 3568 | // A variable of signed or unsigned integer type. |
| 3569 | // For C++, a variable of a random access iterator type. |
| 3570 | // For C, a variable of a pointer type. |
| 3571 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 3572 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3573 | !VarType->isPointerType() && |
| 3574 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3575 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3576 | << SemaRef.getLangOpts().CPlusPlus; |
| 3577 | HasErrors = true; |
| 3578 | } |
| 3579 | |
| 3580 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 3581 | // a Construct |
| 3582 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3583 | // parallel for construct is (are) private. |
| 3584 | // The loop iteration variable in the associated for-loop of a simd |
| 3585 | // construct with just one associated for-loop is linear with a |
| 3586 | // constant-linear-step that is the increment of the associated for-loop. |
| 3587 | // Exclude loop var from the list of variables with implicitly defined data |
| 3588 | // sharing attributes. |
| 3589 | VarsWithImplicitDSA.erase(LCDecl); |
| 3590 | |
| 3591 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 3592 | // in a Construct, C/C++]. |
| 3593 | // The loop iteration variable in the associated for-loop of a simd |
| 3594 | // construct with just one associated for-loop may be listed in a linear |
| 3595 | // clause with a constant-linear-step that is the increment of the |
| 3596 | // associated for-loop. |
| 3597 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3598 | // parallel for construct may be listed in a private or lastprivate clause. |
| 3599 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 3600 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3601 | // declared in the loop and it is predetermined as a private. |
| 3602 | auto PredeterminedCKind = |
| 3603 | isOpenMPSimdDirective(DKind) |
| 3604 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3605 | : OMPC_private; |
| 3606 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3607 | DVar.CKind != PredeterminedCKind) || |
| 3608 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 3609 | isOpenMPDistributeDirective(DKind)) && |
| 3610 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3611 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3612 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 3613 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 3614 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3615 | << getOpenMPClauseName(PredeterminedCKind); |
| 3616 | if (DVar.RefExpr == nullptr) |
| 3617 | DVar.CKind = PredeterminedCKind; |
| 3618 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 3619 | HasErrors = true; |
| 3620 | } else if (LoopDeclRefExpr != nullptr) { |
| 3621 | // Make the loop iteration variable private (for worksharing constructs), |
| 3622 | // linear (for simd directives with the only one associated loop) or |
| 3623 | // lastprivate (for simd directives with several collapsed or ordered |
| 3624 | // loops). |
| 3625 | if (DVar.CKind == OMPC_unknown) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3626 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 3627 | [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3628 | /*FromParent=*/false); |
| 3629 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 3630 | } |
| 3631 | |
| 3632 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 3633 | |
| 3634 | // Check test-expr. |
| 3635 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3636 | |
| 3637 | // Check incr-expr. |
| 3638 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3639 | } |
| 3640 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3641 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3642 | return HasErrors; |
| 3643 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3644 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3645 | ResultIterSpace.PreCond = |
| 3646 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3647 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3648 | DSA.getCurScope(), |
| 3649 | (isOpenMPWorksharingDirective(DKind) || |
| 3650 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 3651 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3652 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3653 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3654 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3655 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3656 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3657 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3658 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3659 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3660 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3661 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3662 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3663 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3664 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3665 | ResultIterSpace.CounterInit == nullptr || |
| 3666 | ResultIterSpace.CounterStep == nullptr); |
| 3667 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3668 | return HasErrors; |
| 3669 | } |
| 3670 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3671 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3672 | static ExprResult |
| 3673 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 3674 | ExprResult Start, |
| 3675 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3676 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3677 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 3678 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3679 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3680 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3681 | VarRef.get()->getType())) { |
| 3682 | NewStart = SemaRef.PerformImplicitConversion( |
| 3683 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3684 | /*AllowExplicit=*/true); |
| 3685 | if (!NewStart.isUsable()) |
| 3686 | return ExprError(); |
| 3687 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3688 | |
| 3689 | auto Init = |
| 3690 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3691 | return Init; |
| 3692 | } |
| 3693 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3694 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3695 | static ExprResult |
| 3696 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3697 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 3698 | ExprResult Step, bool Subtract, |
| 3699 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3700 | // Add parentheses (for debugging purposes only). |
| 3701 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3702 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3703 | !Step.isUsable()) |
| 3704 | return ExprError(); |
| 3705 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3706 | ExprResult NewStep = Step; |
| 3707 | if (Captures) |
| 3708 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3709 | if (NewStep.isInvalid()) |
| 3710 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3711 | ExprResult Update = |
| 3712 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3713 | if (!Update.isUsable()) |
| 3714 | return ExprError(); |
| 3715 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3716 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 3717 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3718 | ExprResult NewStart = Start; |
| 3719 | if (Captures) |
| 3720 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3721 | if (NewStart.isInvalid()) |
| 3722 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3723 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3724 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 3725 | ExprResult SavedUpdate = Update; |
| 3726 | ExprResult UpdateVal; |
| 3727 | if (VarRef.get()->getType()->isOverloadableType() || |
| 3728 | NewStart.get()->getType()->isOverloadableType() || |
| 3729 | Update.get()->getType()->isOverloadableType()) { |
| 3730 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3731 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 3732 | Update = |
| 3733 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3734 | if (Update.isUsable()) { |
| 3735 | UpdateVal = |
| 3736 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 3737 | VarRef.get(), SavedUpdate.get()); |
| 3738 | if (UpdateVal.isUsable()) { |
| 3739 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 3740 | UpdateVal.get()); |
| 3741 | } |
| 3742 | } |
| 3743 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3744 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3745 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3746 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 3747 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 3748 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 3749 | NewStart.get(), SavedUpdate.get()); |
| 3750 | if (!Update.isUsable()) |
| 3751 | return ExprError(); |
| 3752 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3753 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 3754 | VarRef.get()->getType())) { |
| 3755 | Update = SemaRef.PerformImplicitConversion( |
| 3756 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3757 | if (!Update.isUsable()) |
| 3758 | return ExprError(); |
| 3759 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3760 | |
| 3761 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3762 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3763 | return Update; |
| 3764 | } |
| 3765 | |
| 3766 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3767 | /// bits. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3768 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3769 | if (E == nullptr) |
| 3770 | return ExprError(); |
| 3771 | auto &C = SemaRef.Context; |
| 3772 | QualType OldType = E->getType(); |
| 3773 | unsigned HasBits = C.getTypeSize(OldType); |
| 3774 | if (HasBits >= Bits) |
| 3775 | return ExprResult(E); |
| 3776 | // OK to convert to signed, because new type has more bits than old. |
| 3777 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3778 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3779 | true); |
| 3780 | } |
| 3781 | |
| 3782 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3783 | /// into \a Bits bits. |
| 3784 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3785 | if (E == nullptr) |
| 3786 | return false; |
| 3787 | llvm::APSInt Result; |
| 3788 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3789 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3790 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3791 | } |
| 3792 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3793 | /// Build preinits statement for the given declarations. |
| 3794 | static Stmt *buildPreInits(ASTContext &Context, |
| 3795 | SmallVectorImpl<Decl *> &PreInits) { |
| 3796 | if (!PreInits.empty()) { |
| 3797 | return new (Context) DeclStmt( |
| 3798 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 3799 | SourceLocation(), SourceLocation()); |
| 3800 | } |
| 3801 | return nullptr; |
| 3802 | } |
| 3803 | |
| 3804 | /// Build preinits statement for the given declarations. |
| 3805 | static Stmt *buildPreInits(ASTContext &Context, |
| 3806 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 3807 | if (!Captures.empty()) { |
| 3808 | SmallVector<Decl *, 16> PreInits; |
| 3809 | for (auto &Pair : Captures) |
| 3810 | PreInits.push_back(Pair.second->getDecl()); |
| 3811 | return buildPreInits(Context, PreInits); |
| 3812 | } |
| 3813 | return nullptr; |
| 3814 | } |
| 3815 | |
| 3816 | /// Build postupdate expression for the given list of postupdates expressions. |
| 3817 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 3818 | Expr *PostUpdate = nullptr; |
| 3819 | if (!PostUpdates.empty()) { |
| 3820 | for (auto *E : PostUpdates) { |
| 3821 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 3822 | E->getExprLoc(), |
| 3823 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 3824 | E->getExprLoc(), E) |
| 3825 | .get(); |
| 3826 | PostUpdate = PostUpdate |
| 3827 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 3828 | PostUpdate, ConvE) |
| 3829 | .get() |
| 3830 | : ConvE; |
| 3831 | } |
| 3832 | } |
| 3833 | return PostUpdate; |
| 3834 | } |
| 3835 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3836 | /// \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] | 3837 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3838 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3839 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3840 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3841 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3842 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3843 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3844 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3845 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3846 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3847 | // Found 'collapse' clause - calculate collapse number. |
| 3848 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3849 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3850 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3851 | } |
| 3852 | if (OrderedLoopCountExpr) { |
| 3853 | // Found 'ordered' clause - calculate collapse number. |
| 3854 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3855 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3856 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3857 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3858 | diag::err_omp_wrong_ordered_loop_count) |
| 3859 | << OrderedLoopCountExpr->getSourceRange(); |
| 3860 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3861 | diag::note_collapse_loop_count) |
| 3862 | << CollapseLoopCountExpr->getSourceRange(); |
| 3863 | } |
| 3864 | NestedLoopCount = Result.getLimitedValue(); |
| 3865 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3866 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3867 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3868 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3869 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3870 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3871 | IterSpaces.resize(NestedLoopCount); |
| 3872 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3873 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3874 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3875 | NestedLoopCount, CollapseLoopCountExpr, |
| 3876 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3877 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3878 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3879 | // 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] | 3880 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3881 | // All loops associated with the construct must be perfectly nested; that |
| 3882 | // is, there must be no intervening code nor any OpenMP directive between |
| 3883 | // any two loops. |
| 3884 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3885 | } |
| 3886 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3887 | Built.clear(/* size */ NestedLoopCount); |
| 3888 | |
| 3889 | if (SemaRef.CurContext->isDependentContext()) |
| 3890 | return NestedLoopCount; |
| 3891 | |
| 3892 | // An example of what is generated for the following code: |
| 3893 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3894 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3895 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3896 | // for (k = 0; k < NK; ++k) |
| 3897 | // for (j = J0; j < NJ; j+=2) { |
| 3898 | // <loop body> |
| 3899 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3900 | // |
| 3901 | // We generate the code below. |
| 3902 | // Note: the loop body may be outlined in CodeGen. |
| 3903 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3904 | // iterations and operator+= to calculate counter value. |
| 3905 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3906 | // or i64 is currently supported). |
| 3907 | // |
| 3908 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3909 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3910 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3911 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3912 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3913 | // <loop body (using local i and j)> |
| 3914 | // } |
| 3915 | // i = NI; // assign final values of counters |
| 3916 | // j = NJ; |
| 3917 | // |
| 3918 | |
| 3919 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3920 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3921 | // Precondition tests if there is at least one iteration (all conditions are |
| 3922 | // true). |
| 3923 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3924 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3925 | ExprResult LastIteration32 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3926 | 32 /* Bits */, SemaRef |
| 3927 | .PerformImplicitConversion( |
| 3928 | N0->IgnoreImpCasts(), N0->getType(), |
| 3929 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3930 | .get(), |
| 3931 | SemaRef); |
| 3932 | ExprResult LastIteration64 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3933 | 64 /* Bits */, SemaRef |
| 3934 | .PerformImplicitConversion( |
| 3935 | N0->IgnoreImpCasts(), N0->getType(), |
| 3936 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3937 | .get(), |
| 3938 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3939 | |
| 3940 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3941 | return NestedLoopCount; |
| 3942 | |
| 3943 | auto &C = SemaRef.Context; |
| 3944 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3945 | |
| 3946 | Scope *CurScope = DSA.getCurScope(); |
| 3947 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3948 | if (PreCond.isUsable()) { |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3949 | PreCond = |
| 3950 | SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, |
| 3951 | PreCond.get(), IterSpaces[Cnt].PreCond); |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3952 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3953 | auto N = IterSpaces[Cnt].NumIterations; |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3954 | SourceLocation Loc = N->getExprLoc(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3955 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3956 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3957 | LastIteration32 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3958 | CurScope, Loc, BO_Mul, LastIteration32.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3959 | SemaRef |
| 3960 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3961 | Sema::AA_Converting, |
| 3962 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3963 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3964 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3965 | LastIteration64 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3966 | CurScope, Loc, BO_Mul, LastIteration64.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3967 | SemaRef |
| 3968 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3969 | Sema::AA_Converting, |
| 3970 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3971 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3972 | } |
| 3973 | |
| 3974 | // Choose either the 32-bit or 64-bit version. |
| 3975 | ExprResult LastIteration = LastIteration64; |
| 3976 | if (LastIteration32.isUsable() && |
| 3977 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3978 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3979 | FitsInto( |
| 3980 | 32 /* Bits */, |
| 3981 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3982 | LastIteration64.get(), SemaRef))) |
| 3983 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3984 | QualType VType = LastIteration.get()->getType(); |
| 3985 | QualType RealVType = VType; |
| 3986 | QualType StrideVType = VType; |
| 3987 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 3988 | VType = |
| 3989 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 3990 | StrideVType = |
| 3991 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 3992 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3993 | |
| 3994 | if (!LastIteration.isUsable()) |
| 3995 | return 0; |
| 3996 | |
| 3997 | // Save the number of iterations. |
| 3998 | ExprResult NumIterations = LastIteration; |
| 3999 | { |
| 4000 | LastIteration = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4001 | CurScope, LastIteration.get()->getExprLoc(), BO_Sub, |
| 4002 | LastIteration.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4003 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4004 | if (!LastIteration.isUsable()) |
| 4005 | return 0; |
| 4006 | } |
| 4007 | |
| 4008 | // Calculate the last iteration number beforehand instead of doing this on |
| 4009 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4010 | llvm::APSInt Result; |
| 4011 | bool IsConstant = |
| 4012 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4013 | ExprResult CalcLastIteration; |
| 4014 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4015 | ExprResult SaveRef = |
| 4016 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4017 | LastIteration = SaveRef; |
| 4018 | |
| 4019 | // Prepare SaveRef + 1. |
| 4020 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4021 | CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4022 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4023 | if (!NumIterations.isUsable()) |
| 4024 | return 0; |
| 4025 | } |
| 4026 | |
| 4027 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4028 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4029 | // Build variables passed into runtime, necessary for worksharing directives. |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4030 | ExprResult LB, UB, IL, ST, EUB, PrevLB, PrevUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4031 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4032 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4033 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4034 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4035 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4036 | SemaRef.AddInitializerToDecl(LBDecl, |
| 4037 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4038 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4039 | |
| 4040 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4041 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4042 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4043 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4044 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4045 | |
| 4046 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4047 | // This will be used to implement clause 'lastprivate'. |
| 4048 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4049 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4050 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4051 | SemaRef.AddInitializerToDecl(ILDecl, |
| 4052 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4053 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4054 | |
| 4055 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4056 | VarDecl *STDecl = |
| 4057 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 4058 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4059 | SemaRef.AddInitializerToDecl(STDecl, |
| 4060 | SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4061 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4062 | |
| 4063 | // Build expression: UB = min(UB, LastIteration) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4064 | // It is necessary for CodeGen of directives with static scheduling. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4065 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4066 | UB.get(), LastIteration.get()); |
| 4067 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4068 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4069 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4070 | CondOp.get()); |
| 4071 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4072 | |
| 4073 | // If we have a combined directive that combines 'distribute', 'for' or |
| 4074 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 4075 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 4076 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 4077 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4078 | auto *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
| 4079 | |
| 4080 | // We expect to have at least 2 more parameters than the 'parallel' |
| 4081 | // directive does - the lower and upper bounds of the previous schedule. |
| 4082 | assert(CD->getNumParams() >= 4 && |
| 4083 | "Unexpected number of parameters in loop combined directive"); |
| 4084 | |
| 4085 | // Set the proper type for the bounds given what we learned from the |
| 4086 | // enclosed loops. |
| 4087 | auto *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 4088 | auto *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| 4089 | |
| 4090 | // Previous lower and upper bounds are obtained from the region |
| 4091 | // parameters. |
| 4092 | PrevLB = |
| 4093 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 4094 | PrevUB = |
| 4095 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 4096 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4097 | } |
| 4098 | |
| 4099 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4100 | ExprResult IV; |
| 4101 | ExprResult Init; |
| 4102 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4103 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 4104 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4105 | Expr *RHS = |
| 4106 | (isOpenMPWorksharingDirective(DKind) || |
| 4107 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 4108 | ? LB.get() |
| 4109 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4110 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4111 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4112 | } |
| 4113 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4114 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4115 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4116 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4117 | (isOpenMPWorksharingDirective(DKind) || |
| 4118 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4119 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4120 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4121 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4122 | |
| 4123 | // Loop increment (IV = IV + 1) |
| 4124 | SourceLocation IncLoc; |
| 4125 | ExprResult Inc = |
| 4126 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4127 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4128 | if (!Inc.isUsable()) |
| 4129 | return 0; |
| 4130 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4131 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4132 | if (!Inc.isUsable()) |
| 4133 | return 0; |
| 4134 | |
| 4135 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4136 | // Used for directives with static scheduling. |
| 4137 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4138 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4139 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4140 | // LB + ST |
| 4141 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4142 | if (!NextLB.isUsable()) |
| 4143 | return 0; |
| 4144 | // LB = LB + ST |
| 4145 | NextLB = |
| 4146 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4147 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4148 | if (!NextLB.isUsable()) |
| 4149 | return 0; |
| 4150 | // UB + ST |
| 4151 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4152 | if (!NextUB.isUsable()) |
| 4153 | return 0; |
| 4154 | // UB = UB + ST |
| 4155 | NextUB = |
| 4156 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4157 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4158 | if (!NextUB.isUsable()) |
| 4159 | return 0; |
| 4160 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4161 | |
| 4162 | // Build updates and final values of the loop counters. |
| 4163 | bool HasErrors = false; |
| 4164 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4165 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4166 | Built.Updates.resize(NestedLoopCount); |
| 4167 | Built.Finals.resize(NestedLoopCount); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4168 | SmallVector<Expr *, 4> LoopMultipliers; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4169 | { |
| 4170 | ExprResult Div; |
| 4171 | // Go from inner nested loop to outer. |
| 4172 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4173 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4174 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4175 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4176 | // where Div is product of previous iterations' IS.NumIters. |
| 4177 | ExprResult Iter; |
| 4178 | if (Div.isUsable()) { |
| 4179 | Iter = |
| 4180 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4181 | } else { |
| 4182 | Iter = IV; |
| 4183 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4184 | "unusable div expected on first iteration only"); |
| 4185 | } |
| 4186 | |
| 4187 | if (Cnt != 0 && Iter.isUsable()) |
| 4188 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4189 | IS.NumIterations); |
| 4190 | if (!Iter.isUsable()) { |
| 4191 | HasErrors = true; |
| 4192 | break; |
| 4193 | } |
| 4194 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4195 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4196 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 4197 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 4198 | IS.CounterVar->getExprLoc(), |
| 4199 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4200 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4201 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4202 | if (!Init.isUsable()) { |
| 4203 | HasErrors = true; |
| 4204 | break; |
| 4205 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4206 | ExprResult Update = BuildCounterUpdate( |
| 4207 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 4208 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4209 | if (!Update.isUsable()) { |
| 4210 | HasErrors = true; |
| 4211 | break; |
| 4212 | } |
| 4213 | |
| 4214 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4215 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4216 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4217 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4218 | if (!Final.isUsable()) { |
| 4219 | HasErrors = true; |
| 4220 | break; |
| 4221 | } |
| 4222 | |
| 4223 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4224 | if (Cnt != 0) { |
| 4225 | if (Div.isUnset()) |
| 4226 | Div = IS.NumIterations; |
| 4227 | else |
| 4228 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4229 | IS.NumIterations); |
| 4230 | |
| 4231 | // Add parentheses (for debugging purposes only). |
| 4232 | if (Div.isUsable()) |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4233 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4234 | if (!Div.isUsable()) { |
| 4235 | HasErrors = true; |
| 4236 | break; |
| 4237 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4238 | LoopMultipliers.push_back(Div.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4239 | } |
| 4240 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4241 | HasErrors = true; |
| 4242 | break; |
| 4243 | } |
| 4244 | // Save results |
| 4245 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4246 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4247 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4248 | Built.Updates[Cnt] = Update.get(); |
| 4249 | Built.Finals[Cnt] = Final.get(); |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | if (HasErrors) |
| 4254 | return 0; |
| 4255 | |
| 4256 | // Save results |
| 4257 | Built.IterationVarRef = IV.get(); |
| 4258 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4259 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4260 | Built.CalcLastIteration = |
| 4261 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4262 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4263 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4264 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4265 | Built.Init = Init.get(); |
| 4266 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4267 | Built.LB = LB.get(); |
| 4268 | Built.UB = UB.get(); |
| 4269 | Built.IL = IL.get(); |
| 4270 | Built.ST = ST.get(); |
| 4271 | Built.EUB = EUB.get(); |
| 4272 | Built.NLB = NextLB.get(); |
| 4273 | Built.NUB = NextUB.get(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4274 | Built.PrevLB = PrevLB.get(); |
| 4275 | Built.PrevUB = PrevUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4276 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4277 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); |
| 4278 | // Fill data for doacross depend clauses. |
| 4279 | for (auto Pair : DSA.getDoacrossDependClauses()) { |
| 4280 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 4281 | Pair.first->setCounterValue(CounterVal); |
| 4282 | else { |
| 4283 | if (NestedLoopCount != Pair.second.size() || |
| 4284 | NestedLoopCount != LoopMultipliers.size() + 1) { |
| 4285 | // Erroneous case - clause has some problems. |
| 4286 | Pair.first->setCounterValue(CounterVal); |
| 4287 | continue; |
| 4288 | } |
| 4289 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink); |
| 4290 | auto I = Pair.second.rbegin(); |
| 4291 | auto IS = IterSpaces.rbegin(); |
| 4292 | auto ILM = LoopMultipliers.rbegin(); |
| 4293 | Expr *UpCounterVal = CounterVal; |
| 4294 | Expr *Multiplier = nullptr; |
| 4295 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4296 | if (I->first) { |
| 4297 | assert(IS->CounterStep); |
| 4298 | Expr *NormalizedOffset = |
| 4299 | SemaRef |
| 4300 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, |
| 4301 | I->first, IS->CounterStep) |
| 4302 | .get(); |
| 4303 | if (Multiplier) { |
| 4304 | NormalizedOffset = |
| 4305 | SemaRef |
| 4306 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, |
| 4307 | NormalizedOffset, Multiplier) |
| 4308 | .get(); |
| 4309 | } |
| 4310 | assert(I->second == OO_Plus || I->second == OO_Minus); |
| 4311 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4312 | UpCounterVal = SemaRef |
| 4313 | .BuildBinOp(CurScope, I->first->getExprLoc(), BOK, |
| 4314 | UpCounterVal, NormalizedOffset) |
| 4315 | .get(); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4316 | } |
| 4317 | Multiplier = *ILM; |
| 4318 | ++I; |
| 4319 | ++IS; |
| 4320 | ++ILM; |
| 4321 | } |
| 4322 | Pair.first->setCounterValue(UpCounterVal); |
| 4323 | } |
| 4324 | } |
| 4325 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4326 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4327 | } |
| 4328 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4329 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4330 | auto CollapseClauses = |
| 4331 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4332 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4333 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4334 | return nullptr; |
| 4335 | } |
| 4336 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4337 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4338 | auto OrderedClauses = |
| 4339 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4340 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4341 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4342 | return nullptr; |
| 4343 | } |
| 4344 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4345 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 4346 | const ArrayRef<OMPClause *> Clauses) { |
| 4347 | OMPSafelenClause *Safelen = nullptr; |
| 4348 | OMPSimdlenClause *Simdlen = nullptr; |
| 4349 | |
| 4350 | for (auto *Clause : Clauses) { |
| 4351 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4352 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4353 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4354 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4355 | if (Safelen && Simdlen) |
| 4356 | break; |
| 4357 | } |
| 4358 | |
| 4359 | if (Simdlen && Safelen) { |
| 4360 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4361 | auto SimdlenLength = Simdlen->getSimdlen(); |
| 4362 | auto SafelenLength = Safelen->getSafelen(); |
| 4363 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 4364 | SimdlenLength->isInstantiationDependent() || |
| 4365 | SimdlenLength->containsUnexpandedParameterPack()) |
| 4366 | return false; |
| 4367 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 4368 | SafelenLength->isInstantiationDependent() || |
| 4369 | SafelenLength->containsUnexpandedParameterPack()) |
| 4370 | return false; |
| 4371 | SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context); |
| 4372 | SafelenLength->EvaluateAsInt(SafelenRes, S.Context); |
| 4373 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 4374 | // If both simdlen and safelen clauses are specified, the value of the |
| 4375 | // simdlen parameter must be less than or equal to the value of the safelen |
| 4376 | // parameter. |
| 4377 | if (SimdlenRes > SafelenRes) { |
| 4378 | S.Diag(SimdlenLength->getExprLoc(), |
| 4379 | diag::err_omp_wrong_simdlen_safelen_values) |
| 4380 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 4381 | return true; |
| 4382 | } |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4383 | } |
| 4384 | return false; |
| 4385 | } |
| 4386 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4387 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4388 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4389 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4390 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4391 | if (!AStmt) |
| 4392 | return StmtError(); |
| 4393 | |
| 4394 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4395 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4396 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4397 | // define the nested loops number. |
| 4398 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4399 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4400 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4401 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4402 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4403 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4404 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4405 | "omp simd loop exprs were not built"); |
| 4406 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4407 | if (!CurContext->isDependentContext()) { |
| 4408 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4409 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4410 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4411 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4412 | B.NumIterations, *this, CurScope, |
| 4413 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4414 | return StmtError(); |
| 4415 | } |
| 4416 | } |
| 4417 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4418 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4419 | return StmtError(); |
| 4420 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4421 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4422 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4423 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4424 | } |
| 4425 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4426 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4427 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4428 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4429 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4430 | if (!AStmt) |
| 4431 | return StmtError(); |
| 4432 | |
| 4433 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4434 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4435 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4436 | // define the nested loops number. |
| 4437 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4438 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4439 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4440 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4441 | return StmtError(); |
| 4442 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4443 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4444 | "omp for loop exprs were not built"); |
| 4445 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4446 | if (!CurContext->isDependentContext()) { |
| 4447 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4448 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4449 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4450 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4451 | B.NumIterations, *this, CurScope, |
| 4452 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4453 | return StmtError(); |
| 4454 | } |
| 4455 | } |
| 4456 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4457 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4458 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4459 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4460 | } |
| 4461 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4462 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4463 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4464 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4465 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4466 | if (!AStmt) |
| 4467 | return StmtError(); |
| 4468 | |
| 4469 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4470 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4471 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4472 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4473 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4474 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4475 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4476 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4477 | if (NestedLoopCount == 0) |
| 4478 | return StmtError(); |
| 4479 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4480 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4481 | "omp for simd loop exprs were not built"); |
| 4482 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4483 | if (!CurContext->isDependentContext()) { |
| 4484 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4485 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4486 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4487 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4488 | B.NumIterations, *this, CurScope, |
| 4489 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4490 | return StmtError(); |
| 4491 | } |
| 4492 | } |
| 4493 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4494 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4495 | return StmtError(); |
| 4496 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4497 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4498 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4499 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4500 | } |
| 4501 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4502 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4503 | Stmt *AStmt, |
| 4504 | SourceLocation StartLoc, |
| 4505 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4506 | if (!AStmt) |
| 4507 | return StmtError(); |
| 4508 | |
| 4509 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4510 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4511 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4512 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4513 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4514 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4515 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4516 | return StmtError(); |
| 4517 | // All associated statements must be '#pragma omp section' except for |
| 4518 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4519 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4520 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4521 | if (SectionStmt) |
| 4522 | Diag(SectionStmt->getLocStart(), |
| 4523 | diag::err_omp_sections_substmt_not_section); |
| 4524 | return StmtError(); |
| 4525 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4526 | cast<OMPSectionDirective>(SectionStmt) |
| 4527 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4528 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4529 | } else { |
| 4530 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4531 | return StmtError(); |
| 4532 | } |
| 4533 | |
| 4534 | getCurFunction()->setHasBranchProtectedScope(); |
| 4535 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4536 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4537 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4538 | } |
| 4539 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4540 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4541 | SourceLocation StartLoc, |
| 4542 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4543 | if (!AStmt) |
| 4544 | return StmtError(); |
| 4545 | |
| 4546 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4547 | |
| 4548 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4549 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4550 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4551 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4552 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4553 | } |
| 4554 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4555 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4556 | Stmt *AStmt, |
| 4557 | SourceLocation StartLoc, |
| 4558 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4559 | if (!AStmt) |
| 4560 | return StmtError(); |
| 4561 | |
| 4562 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4563 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4564 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4565 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4566 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4567 | // The copyprivate clause must not be used with the nowait clause. |
| 4568 | OMPClause *Nowait = nullptr; |
| 4569 | OMPClause *Copyprivate = nullptr; |
| 4570 | for (auto *Clause : Clauses) { |
| 4571 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4572 | Nowait = Clause; |
| 4573 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4574 | Copyprivate = Clause; |
| 4575 | if (Copyprivate && Nowait) { |
| 4576 | Diag(Copyprivate->getLocStart(), |
| 4577 | diag::err_omp_single_copyprivate_with_nowait); |
| 4578 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4579 | return StmtError(); |
| 4580 | } |
| 4581 | } |
| 4582 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4583 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4584 | } |
| 4585 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4586 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4587 | SourceLocation StartLoc, |
| 4588 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4589 | if (!AStmt) |
| 4590 | return StmtError(); |
| 4591 | |
| 4592 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4593 | |
| 4594 | getCurFunction()->setHasBranchProtectedScope(); |
| 4595 | |
| 4596 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4597 | } |
| 4598 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4599 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4600 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4601 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4602 | if (!AStmt) |
| 4603 | return StmtError(); |
| 4604 | |
| 4605 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4606 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4607 | bool ErrorFound = false; |
| 4608 | llvm::APSInt Hint; |
| 4609 | SourceLocation HintLoc; |
| 4610 | bool DependentHint = false; |
| 4611 | for (auto *C : Clauses) { |
| 4612 | if (C->getClauseKind() == OMPC_hint) { |
| 4613 | if (!DirName.getName()) { |
| 4614 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4615 | ErrorFound = true; |
| 4616 | } |
| 4617 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4618 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4619 | E->isInstantiationDependent()) |
| 4620 | DependentHint = true; |
| 4621 | else { |
| 4622 | Hint = E->EvaluateKnownConstInt(Context); |
| 4623 | HintLoc = C->getLocStart(); |
| 4624 | } |
| 4625 | } |
| 4626 | } |
| 4627 | if (ErrorFound) |
| 4628 | return StmtError(); |
| 4629 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4630 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4631 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4632 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4633 | if (HintLoc.isValid()) { |
| 4634 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4635 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4636 | } else |
| 4637 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4638 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4639 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4640 | << 1 |
| 4641 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4642 | /*Radix=*/10, /*Signed=*/false); |
| 4643 | } else |
| 4644 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4645 | } |
| 4646 | } |
| 4647 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4648 | getCurFunction()->setHasBranchProtectedScope(); |
| 4649 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4650 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4651 | Clauses, AStmt); |
| 4652 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4653 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4654 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4657 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4658 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4659 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4660 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4661 | if (!AStmt) |
| 4662 | return StmtError(); |
| 4663 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4664 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4665 | // 1.2.2 OpenMP Language Terminology |
| 4666 | // Structured block - An executable statement with a single entry at the |
| 4667 | // top and a single exit at the bottom. |
| 4668 | // The point of exit cannot be a branch out of the structured block. |
| 4669 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4670 | CS->getCapturedDecl()->setNothrow(); |
| 4671 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4672 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4673 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4674 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4675 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4676 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4677 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4678 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4679 | if (NestedLoopCount == 0) |
| 4680 | return StmtError(); |
| 4681 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4682 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4683 | "omp parallel for loop exprs were not built"); |
| 4684 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4685 | if (!CurContext->isDependentContext()) { |
| 4686 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4687 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4688 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4689 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4690 | B.NumIterations, *this, CurScope, |
| 4691 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4692 | return StmtError(); |
| 4693 | } |
| 4694 | } |
| 4695 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4696 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4697 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4698 | NestedLoopCount, Clauses, AStmt, B, |
| 4699 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4700 | } |
| 4701 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4702 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4703 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4704 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4705 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4706 | if (!AStmt) |
| 4707 | return StmtError(); |
| 4708 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4709 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4710 | // 1.2.2 OpenMP Language Terminology |
| 4711 | // Structured block - An executable statement with a single entry at the |
| 4712 | // top and a single exit at the bottom. |
| 4713 | // The point of exit cannot be a branch out of the structured block. |
| 4714 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4715 | CS->getCapturedDecl()->setNothrow(); |
| 4716 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4717 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4718 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4719 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4720 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4721 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4722 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4723 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4724 | if (NestedLoopCount == 0) |
| 4725 | return StmtError(); |
| 4726 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4727 | if (!CurContext->isDependentContext()) { |
| 4728 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4729 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4730 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4731 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4732 | B.NumIterations, *this, CurScope, |
| 4733 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4734 | return StmtError(); |
| 4735 | } |
| 4736 | } |
| 4737 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4738 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4739 | return StmtError(); |
| 4740 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4741 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4742 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4743 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4744 | } |
| 4745 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4746 | StmtResult |
| 4747 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4748 | Stmt *AStmt, SourceLocation StartLoc, |
| 4749 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4750 | if (!AStmt) |
| 4751 | return StmtError(); |
| 4752 | |
| 4753 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4754 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4755 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4756 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4757 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4758 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4759 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4760 | return StmtError(); |
| 4761 | // All associated statements must be '#pragma omp section' except for |
| 4762 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4763 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4764 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4765 | if (SectionStmt) |
| 4766 | Diag(SectionStmt->getLocStart(), |
| 4767 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4768 | return StmtError(); |
| 4769 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4770 | cast<OMPSectionDirective>(SectionStmt) |
| 4771 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4772 | } |
| 4773 | } else { |
| 4774 | Diag(AStmt->getLocStart(), |
| 4775 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4776 | return StmtError(); |
| 4777 | } |
| 4778 | |
| 4779 | getCurFunction()->setHasBranchProtectedScope(); |
| 4780 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4781 | return OMPParallelSectionsDirective::Create( |
| 4782 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4783 | } |
| 4784 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4785 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4786 | Stmt *AStmt, SourceLocation StartLoc, |
| 4787 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4788 | if (!AStmt) |
| 4789 | return StmtError(); |
| 4790 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4791 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4792 | // 1.2.2 OpenMP Language Terminology |
| 4793 | // Structured block - An executable statement with a single entry at the |
| 4794 | // top and a single exit at the bottom. |
| 4795 | // The point of exit cannot be a branch out of the structured block. |
| 4796 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4797 | CS->getCapturedDecl()->setNothrow(); |
| 4798 | |
| 4799 | getCurFunction()->setHasBranchProtectedScope(); |
| 4800 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4801 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4802 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4803 | } |
| 4804 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4805 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4806 | SourceLocation EndLoc) { |
| 4807 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4808 | } |
| 4809 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4810 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4811 | SourceLocation EndLoc) { |
| 4812 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4813 | } |
| 4814 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4815 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4816 | SourceLocation EndLoc) { |
| 4817 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4818 | } |
| 4819 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4820 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4821 | SourceLocation StartLoc, |
| 4822 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4823 | if (!AStmt) |
| 4824 | return StmtError(); |
| 4825 | |
| 4826 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4827 | |
| 4828 | getCurFunction()->setHasBranchProtectedScope(); |
| 4829 | |
| 4830 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4831 | } |
| 4832 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4833 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4834 | SourceLocation StartLoc, |
| 4835 | SourceLocation EndLoc) { |
| 4836 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4837 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4838 | } |
| 4839 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4840 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4841 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4842 | SourceLocation StartLoc, |
| 4843 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4844 | OMPClause *DependFound = nullptr; |
| 4845 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4846 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4847 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4848 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4849 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4850 | for (auto *C : Clauses) { |
| 4851 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4852 | DependFound = C; |
| 4853 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4854 | if (DependSourceClause) { |
| 4855 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 4856 | << getOpenMPDirectiveName(OMPD_ordered) |
| 4857 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 4858 | ErrorFound = true; |
| 4859 | } else |
| 4860 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4861 | if (DependSinkClause) { |
| 4862 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4863 | << 0; |
| 4864 | ErrorFound = true; |
| 4865 | } |
| 4866 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 4867 | if (DependSourceClause) { |
| 4868 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4869 | << 1; |
| 4870 | ErrorFound = true; |
| 4871 | } |
| 4872 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4873 | } |
| 4874 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4875 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4876 | else if (C->getClauseKind() == OMPC_simd) |
| 4877 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4878 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4879 | if (!ErrorFound && !SC && |
| 4880 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4881 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4882 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4883 | // that can appear in the simd region. |
| 4884 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4885 | ErrorFound = true; |
| 4886 | } else if (DependFound && (TC || SC)) { |
| 4887 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 4888 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 4889 | ErrorFound = true; |
| 4890 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 4891 | Diag(DependFound->getLocStart(), |
| 4892 | diag::err_omp_ordered_directive_without_param); |
| 4893 | ErrorFound = true; |
| 4894 | } else if (TC || Clauses.empty()) { |
| 4895 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4896 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4897 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 4898 | << (TC != nullptr); |
| 4899 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4900 | ErrorFound = true; |
| 4901 | } |
| 4902 | } |
| 4903 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4904 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4905 | |
| 4906 | if (AStmt) { |
| 4907 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4908 | |
| 4909 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4910 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4911 | |
| 4912 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4915 | namespace { |
| 4916 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4917 | /// construct. |
| 4918 | class OpenMPAtomicUpdateChecker { |
| 4919 | /// \brief Error results for atomic update expressions. |
| 4920 | enum ExprAnalysisErrorCode { |
| 4921 | /// \brief A statement is not an expression statement. |
| 4922 | NotAnExpression, |
| 4923 | /// \brief Expression is not builtin binary or unary operation. |
| 4924 | NotABinaryOrUnaryExpression, |
| 4925 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4926 | NotAnUnaryIncDecExpression, |
| 4927 | /// \brief An expression is not of scalar type. |
| 4928 | NotAScalarType, |
| 4929 | /// \brief A binary operation is not an assignment operation. |
| 4930 | NotAnAssignmentOp, |
| 4931 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4932 | NotABinaryExpression, |
| 4933 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4934 | /// expression. |
| 4935 | NotABinaryOperator, |
| 4936 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4937 | /// part. |
| 4938 | NotAnUpdateExpression, |
| 4939 | /// \brief No errors is found. |
| 4940 | NoError |
| 4941 | }; |
| 4942 | /// \brief Reference to Sema. |
| 4943 | Sema &SemaRef; |
| 4944 | /// \brief A location for note diagnostics (when error is found). |
| 4945 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4946 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4947 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4948 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4949 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4950 | /// \brief Helper expression of the form |
| 4951 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4952 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4953 | Expr *UpdateExpr; |
| 4954 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4955 | /// important for non-associative operations. |
| 4956 | bool IsXLHSInRHSPart; |
| 4957 | BinaryOperatorKind Op; |
| 4958 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4959 | /// \brief true if the source expression is a postfix unary operation, false |
| 4960 | /// if it is a prefix unary operation. |
| 4961 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4962 | |
| 4963 | public: |
| 4964 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4965 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4966 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4967 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4968 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4969 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4970 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4971 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4972 | /// \param NoteId Diagnostic note for the main error message. |
| 4973 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4974 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4975 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4976 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4977 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4978 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4979 | /// \brief Return the update expression used in calculation of the updated |
| 4980 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4981 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4982 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4983 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4984 | /// false otherwise. |
| 4985 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4986 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4987 | /// \brief true if the source expression is a postfix unary operation, false |
| 4988 | /// if it is a prefix unary operation. |
| 4989 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4990 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4991 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4992 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4993 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4994 | }; |
| 4995 | } // namespace |
| 4996 | |
| 4997 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4998 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4999 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5000 | SourceLocation ErrorLoc, NoteLoc; |
| 5001 | SourceRange ErrorRange, NoteRange; |
| 5002 | // Allowed constructs are: |
| 5003 | // x = x binop expr; |
| 5004 | // x = expr binop x; |
| 5005 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5006 | X = AtomicBinOp->getLHS(); |
| 5007 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5008 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5009 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5010 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5011 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5012 | Op = AtomicInnerBinOp->getOpcode(); |
| 5013 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5014 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5015 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5016 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5017 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5018 | /*Canonical=*/true); |
| 5019 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5020 | /*Canonical=*/true); |
| 5021 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5022 | /*Canonical=*/true); |
| 5023 | if (XId == LHSId) { |
| 5024 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5025 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5026 | } else if (XId == RHSId) { |
| 5027 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5028 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5029 | } else { |
| 5030 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5031 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5032 | NoteLoc = X->getExprLoc(); |
| 5033 | NoteRange = X->getSourceRange(); |
| 5034 | ErrorFound = NotAnUpdateExpression; |
| 5035 | } |
| 5036 | } else { |
| 5037 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5038 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5039 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5040 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5041 | ErrorFound = NotABinaryOperator; |
| 5042 | } |
| 5043 | } else { |
| 5044 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5045 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5046 | ErrorFound = NotABinaryExpression; |
| 5047 | } |
| 5048 | } else { |
| 5049 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5050 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5051 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5052 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5053 | ErrorFound = NotAnAssignmentOp; |
| 5054 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5055 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5056 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5057 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5058 | return true; |
| 5059 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5060 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5061 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5062 | } |
| 5063 | |
| 5064 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5065 | unsigned NoteId) { |
| 5066 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5067 | SourceLocation ErrorLoc, NoteLoc; |
| 5068 | SourceRange ErrorRange, NoteRange; |
| 5069 | // Allowed constructs are: |
| 5070 | // x++; |
| 5071 | // x--; |
| 5072 | // ++x; |
| 5073 | // --x; |
| 5074 | // x binop= expr; |
| 5075 | // x = x binop expr; |
| 5076 | // x = expr binop x; |
| 5077 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5078 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5079 | if (AtomicBody->getType()->isScalarType() || |
| 5080 | AtomicBody->isInstantiationDependent()) { |
| 5081 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5082 | AtomicBody->IgnoreParenImpCasts())) { |
| 5083 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5084 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5085 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5086 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5087 | E = AtomicCompAssignOp->getRHS(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5088 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5089 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5090 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5091 | AtomicBody->IgnoreParenImpCasts())) { |
| 5092 | // Check for Binary Operation |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5093 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5094 | return true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5095 | } else if (auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| 5096 | AtomicBody->IgnoreParenImpCasts())) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5097 | // Check for Unary Operation |
| 5098 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5099 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5100 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5101 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5102 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5103 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5104 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5105 | } else { |
| 5106 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5107 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5108 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5109 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5110 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5111 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5112 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5113 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5114 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5115 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5116 | } |
| 5117 | } else { |
| 5118 | ErrorFound = NotAScalarType; |
| 5119 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5120 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5121 | } |
| 5122 | } else { |
| 5123 | ErrorFound = NotAnExpression; |
| 5124 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5125 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5126 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5127 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5128 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5129 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5130 | return true; |
| 5131 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5132 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5133 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5134 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5135 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5136 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5137 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5138 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5139 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5140 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5141 | auto Update = |
| 5142 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5143 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5144 | if (Update.isInvalid()) |
| 5145 | return true; |
| 5146 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5147 | Sema::AA_Casting); |
| 5148 | if (Update.isInvalid()) |
| 5149 | return true; |
| 5150 | UpdateExpr = Update.get(); |
| 5151 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5152 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5153 | } |
| 5154 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5155 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5156 | Stmt *AStmt, |
| 5157 | SourceLocation StartLoc, |
| 5158 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5159 | if (!AStmt) |
| 5160 | return StmtError(); |
| 5161 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5162 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5163 | // 1.2.2 OpenMP Language Terminology |
| 5164 | // Structured block - An executable statement with a single entry at the |
| 5165 | // top and a single exit at the bottom. |
| 5166 | // The point of exit cannot be a branch out of the structured block. |
| 5167 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5168 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5169 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5170 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5171 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5172 | C->getClauseKind() == OMPC_update || |
| 5173 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5174 | if (AtomicKind != OMPC_unknown) { |
| 5175 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5176 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5177 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5178 | << getOpenMPClauseName(AtomicKind); |
| 5179 | } else { |
| 5180 | AtomicKind = C->getClauseKind(); |
| 5181 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5182 | } |
| 5183 | } |
| 5184 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5185 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5186 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5187 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5188 | Body = EWC->getSubExpr(); |
| 5189 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5190 | Expr *X = nullptr; |
| 5191 | Expr *V = nullptr; |
| 5192 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5193 | Expr *UE = nullptr; |
| 5194 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5195 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5196 | // OpenMP [2.12.6, atomic Construct] |
| 5197 | // In the next expressions: |
| 5198 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5199 | // * During the execution of an atomic region, multiple syntactic |
| 5200 | // occurrences of x must designate the same storage location. |
| 5201 | // * Neither of v and expr (as applicable) may access the storage location |
| 5202 | // designated by x. |
| 5203 | // * Neither of x and expr (as applicable) may access the storage location |
| 5204 | // designated by v. |
| 5205 | // * expr is an expression with scalar type. |
| 5206 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5207 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5208 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5209 | // (expr). This requirement is satisfied if the operators in expr have |
| 5210 | // precedence greater than binop, or by using parentheses around expr or |
| 5211 | // subexpressions of expr. |
| 5212 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5213 | // binop x. This requirement is satisfied if the operators in expr have |
| 5214 | // precedence equal to or greater than binop, or by using parentheses around |
| 5215 | // expr or subexpressions of expr. |
| 5216 | // * For forms that allow multiple occurrences of x, the number of times |
| 5217 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5218 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5219 | enum { |
| 5220 | NotAnExpression, |
| 5221 | NotAnAssignmentOp, |
| 5222 | NotAScalarType, |
| 5223 | NotAnLValue, |
| 5224 | NoError |
| 5225 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5226 | SourceLocation ErrorLoc, NoteLoc; |
| 5227 | SourceRange ErrorRange, NoteRange; |
| 5228 | // If clause is read: |
| 5229 | // v = x; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5230 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5231 | auto *AtomicBinOp = |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5232 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5233 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5234 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5235 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5236 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5237 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5238 | if (!X->isLValue() || !V->isLValue()) { |
| 5239 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5240 | ErrorFound = NotAnLValue; |
| 5241 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5242 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5243 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5244 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5245 | } |
| 5246 | } else if (!X->isInstantiationDependent() || |
| 5247 | !V->isInstantiationDependent()) { |
| 5248 | auto NotScalarExpr = |
| 5249 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5250 | ? V |
| 5251 | : X; |
| 5252 | ErrorFound = NotAScalarType; |
| 5253 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5254 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5255 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5256 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5257 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5258 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5259 | ErrorFound = NotAnAssignmentOp; |
| 5260 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5261 | ErrorRange = AtomicBody->getSourceRange(); |
| 5262 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5263 | : AtomicBody->getExprLoc(); |
| 5264 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5265 | : AtomicBody->getSourceRange(); |
| 5266 | } |
| 5267 | } else { |
| 5268 | ErrorFound = NotAnExpression; |
| 5269 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5270 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5271 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5272 | if (ErrorFound != NoError) { |
| 5273 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5274 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5275 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5276 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5277 | return StmtError(); |
| 5278 | } else if (CurContext->isDependentContext()) |
| 5279 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5280 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5281 | enum { |
| 5282 | NotAnExpression, |
| 5283 | NotAnAssignmentOp, |
| 5284 | NotAScalarType, |
| 5285 | NotAnLValue, |
| 5286 | NoError |
| 5287 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5288 | SourceLocation ErrorLoc, NoteLoc; |
| 5289 | SourceRange ErrorRange, NoteRange; |
| 5290 | // If clause is write: |
| 5291 | // x = expr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5292 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5293 | auto *AtomicBinOp = |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5294 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5295 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5296 | X = AtomicBinOp->getLHS(); |
| 5297 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5298 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5299 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5300 | if (!X->isLValue()) { |
| 5301 | ErrorFound = NotAnLValue; |
| 5302 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5303 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5304 | NoteLoc = X->getExprLoc(); |
| 5305 | NoteRange = X->getSourceRange(); |
| 5306 | } |
| 5307 | } else if (!X->isInstantiationDependent() || |
| 5308 | !E->isInstantiationDependent()) { |
| 5309 | auto NotScalarExpr = |
| 5310 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5311 | ? E |
| 5312 | : X; |
| 5313 | ErrorFound = NotAScalarType; |
| 5314 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5315 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5316 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5317 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5318 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5319 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5320 | ErrorFound = NotAnAssignmentOp; |
| 5321 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5322 | ErrorRange = AtomicBody->getSourceRange(); |
| 5323 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5324 | : AtomicBody->getExprLoc(); |
| 5325 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5326 | : AtomicBody->getSourceRange(); |
| 5327 | } |
| 5328 | } else { |
| 5329 | ErrorFound = NotAnExpression; |
| 5330 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5331 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5332 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5333 | if (ErrorFound != NoError) { |
| 5334 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5335 | << ErrorRange; |
| 5336 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5337 | << NoteRange; |
| 5338 | return StmtError(); |
| 5339 | } else if (CurContext->isDependentContext()) |
| 5340 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5341 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5342 | // If clause is update: |
| 5343 | // x++; |
| 5344 | // x--; |
| 5345 | // ++x; |
| 5346 | // --x; |
| 5347 | // x binop= expr; |
| 5348 | // x = x binop expr; |
| 5349 | // x = expr binop x; |
| 5350 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5351 | if (Checker.checkStatement( |
| 5352 | Body, (AtomicKind == OMPC_update) |
| 5353 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5354 | : diag::err_omp_atomic_not_expression_statement, |
| 5355 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5356 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5357 | if (!CurContext->isDependentContext()) { |
| 5358 | E = Checker.getExpr(); |
| 5359 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5360 | UE = Checker.getUpdateExpr(); |
| 5361 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5362 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5363 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5364 | enum { |
| 5365 | NotAnAssignmentOp, |
| 5366 | NotACompoundStatement, |
| 5367 | NotTwoSubstatements, |
| 5368 | NotASpecificExpression, |
| 5369 | NoError |
| 5370 | } ErrorFound = NoError; |
| 5371 | SourceLocation ErrorLoc, NoteLoc; |
| 5372 | SourceRange ErrorRange, NoteRange; |
| 5373 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5374 | // If clause is a capture: |
| 5375 | // v = x++; |
| 5376 | // v = x--; |
| 5377 | // v = ++x; |
| 5378 | // v = --x; |
| 5379 | // v = x binop= expr; |
| 5380 | // v = x = x binop expr; |
| 5381 | // v = x = expr binop x; |
| 5382 | auto *AtomicBinOp = |
| 5383 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5384 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5385 | V = AtomicBinOp->getLHS(); |
| 5386 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5387 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5388 | if (Checker.checkStatement( |
| 5389 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5390 | diag::note_omp_atomic_update)) |
| 5391 | return StmtError(); |
| 5392 | E = Checker.getExpr(); |
| 5393 | X = Checker.getX(); |
| 5394 | UE = Checker.getUpdateExpr(); |
| 5395 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5396 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5397 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5398 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5399 | ErrorRange = AtomicBody->getSourceRange(); |
| 5400 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5401 | : AtomicBody->getExprLoc(); |
| 5402 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5403 | : AtomicBody->getSourceRange(); |
| 5404 | ErrorFound = NotAnAssignmentOp; |
| 5405 | } |
| 5406 | if (ErrorFound != NoError) { |
| 5407 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5408 | << ErrorRange; |
| 5409 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5410 | return StmtError(); |
| 5411 | } else if (CurContext->isDependentContext()) { |
| 5412 | UE = V = E = X = nullptr; |
| 5413 | } |
| 5414 | } else { |
| 5415 | // If clause is a capture: |
| 5416 | // { v = x; x = expr; } |
| 5417 | // { v = x; x++; } |
| 5418 | // { v = x; x--; } |
| 5419 | // { v = x; ++x; } |
| 5420 | // { v = x; --x; } |
| 5421 | // { v = x; x binop= expr; } |
| 5422 | // { v = x; x = x binop expr; } |
| 5423 | // { v = x; x = expr binop x; } |
| 5424 | // { x++; v = x; } |
| 5425 | // { x--; v = x; } |
| 5426 | // { ++x; v = x; } |
| 5427 | // { --x; v = x; } |
| 5428 | // { x binop= expr; v = x; } |
| 5429 | // { x = x binop expr; v = x; } |
| 5430 | // { x = expr binop x; v = x; } |
| 5431 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5432 | // Check that this is { expr1; expr2; } |
| 5433 | if (CS->size() == 2) { |
| 5434 | auto *First = CS->body_front(); |
| 5435 | auto *Second = CS->body_back(); |
| 5436 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5437 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5438 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5439 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5440 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5441 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5442 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5443 | BinaryOperator *BinOp = nullptr; |
| 5444 | if (IsUpdateExprFound) { |
| 5445 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5446 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5447 | } |
| 5448 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5449 | // { v = x; x++; } |
| 5450 | // { v = x; x--; } |
| 5451 | // { v = x; ++x; } |
| 5452 | // { v = x; --x; } |
| 5453 | // { v = x; x binop= expr; } |
| 5454 | // { v = x; x = x binop expr; } |
| 5455 | // { v = x; x = expr binop x; } |
| 5456 | // Check that the first expression has form v = x. |
| 5457 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5458 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5459 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5460 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5461 | IsUpdateExprFound = XId == PossibleXId; |
| 5462 | if (IsUpdateExprFound) { |
| 5463 | V = BinOp->getLHS(); |
| 5464 | X = Checker.getX(); |
| 5465 | E = Checker.getExpr(); |
| 5466 | UE = Checker.getUpdateExpr(); |
| 5467 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5468 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5469 | } |
| 5470 | } |
| 5471 | if (!IsUpdateExprFound) { |
| 5472 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5473 | BinOp = nullptr; |
| 5474 | if (IsUpdateExprFound) { |
| 5475 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5476 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5477 | } |
| 5478 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5479 | // { x++; v = x; } |
| 5480 | // { x--; v = x; } |
| 5481 | // { ++x; v = x; } |
| 5482 | // { --x; v = x; } |
| 5483 | // { x binop= expr; v = x; } |
| 5484 | // { x = x binop expr; v = x; } |
| 5485 | // { x = expr binop x; v = x; } |
| 5486 | // Check that the second expression has form v = x. |
| 5487 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5488 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5489 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5490 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5491 | IsUpdateExprFound = XId == PossibleXId; |
| 5492 | if (IsUpdateExprFound) { |
| 5493 | V = BinOp->getLHS(); |
| 5494 | X = Checker.getX(); |
| 5495 | E = Checker.getExpr(); |
| 5496 | UE = Checker.getUpdateExpr(); |
| 5497 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5498 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5499 | } |
| 5500 | } |
| 5501 | } |
| 5502 | if (!IsUpdateExprFound) { |
| 5503 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5504 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5505 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5506 | if (!FirstExpr || !SecondExpr || |
| 5507 | !(FirstExpr->isInstantiationDependent() || |
| 5508 | SecondExpr->isInstantiationDependent())) { |
| 5509 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5510 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5511 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5512 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5513 | : First->getLocStart(); |
| 5514 | NoteRange = ErrorRange = FirstBinOp |
| 5515 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5516 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5517 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5518 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5519 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5520 | ErrorFound = NotAnAssignmentOp; |
| 5521 | NoteLoc = ErrorLoc = SecondBinOp |
| 5522 | ? SecondBinOp->getOperatorLoc() |
| 5523 | : Second->getLocStart(); |
| 5524 | NoteRange = ErrorRange = |
| 5525 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5526 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5527 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5528 | auto *PossibleXRHSInFirst = |
| 5529 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5530 | auto *PossibleXLHSInSecond = |
| 5531 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5532 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5533 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5534 | /*Canonical=*/true); |
| 5535 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5536 | /*Canonical=*/true); |
| 5537 | IsUpdateExprFound = X1Id == X2Id; |
| 5538 | if (IsUpdateExprFound) { |
| 5539 | V = FirstBinOp->getLHS(); |
| 5540 | X = SecondBinOp->getLHS(); |
| 5541 | E = SecondBinOp->getRHS(); |
| 5542 | UE = nullptr; |
| 5543 | IsXLHSInRHSPart = false; |
| 5544 | IsPostfixUpdate = true; |
| 5545 | } else { |
| 5546 | ErrorFound = NotASpecificExpression; |
| 5547 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5548 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5549 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5550 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5551 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5552 | } |
| 5553 | } |
| 5554 | } |
| 5555 | } |
| 5556 | } else { |
| 5557 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5558 | NoteRange = ErrorRange = |
| 5559 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5560 | ErrorFound = NotTwoSubstatements; |
| 5561 | } |
| 5562 | } else { |
| 5563 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5564 | NoteRange = ErrorRange = |
| 5565 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5566 | ErrorFound = NotACompoundStatement; |
| 5567 | } |
| 5568 | if (ErrorFound != NoError) { |
| 5569 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5570 | << ErrorRange; |
| 5571 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5572 | return StmtError(); |
| 5573 | } else if (CurContext->isDependentContext()) { |
| 5574 | UE = V = E = X = nullptr; |
| 5575 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5576 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5577 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5578 | |
| 5579 | getCurFunction()->setHasBranchProtectedScope(); |
| 5580 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5581 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5582 | X, V, E, UE, IsXLHSInRHSPart, |
| 5583 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5584 | } |
| 5585 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5586 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5587 | Stmt *AStmt, |
| 5588 | SourceLocation StartLoc, |
| 5589 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5590 | if (!AStmt) |
| 5591 | return StmtError(); |
| 5592 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5593 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5594 | // 1.2.2 OpenMP Language Terminology |
| 5595 | // Structured block - An executable statement with a single entry at the |
| 5596 | // top and a single exit at the bottom. |
| 5597 | // The point of exit cannot be a branch out of the structured block. |
| 5598 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5599 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5600 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5601 | // OpenMP [2.16, Nesting of Regions] |
| 5602 | // If specified, a teams construct must be contained within a target |
| 5603 | // construct. That target construct must contain no statements or directives |
| 5604 | // outside of the teams construct. |
| 5605 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5606 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5607 | bool OMPTeamsFound = true; |
| 5608 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5609 | auto I = CS->body_begin(); |
| 5610 | while (I != CS->body_end()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5611 | auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5612 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5613 | OMPTeamsFound = false; |
| 5614 | break; |
| 5615 | } |
| 5616 | ++I; |
| 5617 | } |
| 5618 | assert(I != CS->body_end() && "Not found statement"); |
| 5619 | S = *I; |
Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 5620 | } else { |
| 5621 | auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| 5622 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5623 | } |
| 5624 | if (!OMPTeamsFound) { |
| 5625 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5626 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5627 | diag::note_omp_nested_teams_construct_here); |
| 5628 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5629 | << isa<OMPExecutableDirective>(S); |
| 5630 | return StmtError(); |
| 5631 | } |
| 5632 | } |
| 5633 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5634 | getCurFunction()->setHasBranchProtectedScope(); |
| 5635 | |
| 5636 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5637 | } |
| 5638 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5639 | StmtResult |
| 5640 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5641 | Stmt *AStmt, SourceLocation StartLoc, |
| 5642 | SourceLocation EndLoc) { |
| 5643 | if (!AStmt) |
| 5644 | return StmtError(); |
| 5645 | |
| 5646 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5647 | // 1.2.2 OpenMP Language Terminology |
| 5648 | // Structured block - An executable statement with a single entry at the |
| 5649 | // top and a single exit at the bottom. |
| 5650 | // The point of exit cannot be a branch out of the structured block. |
| 5651 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5652 | CS->getCapturedDecl()->setNothrow(); |
| 5653 | |
| 5654 | getCurFunction()->setHasBranchProtectedScope(); |
| 5655 | |
| 5656 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5657 | AStmt); |
| 5658 | } |
| 5659 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5660 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5661 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5662 | SourceLocation EndLoc, |
| 5663 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5664 | if (!AStmt) |
| 5665 | return StmtError(); |
| 5666 | |
| 5667 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5668 | // 1.2.2 OpenMP Language Terminology |
| 5669 | // Structured block - An executable statement with a single entry at the |
| 5670 | // top and a single exit at the bottom. |
| 5671 | // The point of exit cannot be a branch out of the structured block. |
| 5672 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5673 | CS->getCapturedDecl()->setNothrow(); |
| 5674 | |
| 5675 | OMPLoopDirective::HelperExprs B; |
| 5676 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5677 | // define the nested loops number. |
| 5678 | unsigned NestedLoopCount = |
| 5679 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5680 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5681 | VarsWithImplicitDSA, B); |
| 5682 | if (NestedLoopCount == 0) |
| 5683 | return StmtError(); |
| 5684 | |
| 5685 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5686 | "omp target parallel for loop exprs were not built"); |
| 5687 | |
| 5688 | if (!CurContext->isDependentContext()) { |
| 5689 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5690 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5691 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5692 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5693 | B.NumIterations, *this, CurScope, |
| 5694 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5695 | return StmtError(); |
| 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | getCurFunction()->setHasBranchProtectedScope(); |
| 5700 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5701 | NestedLoopCount, Clauses, AStmt, |
| 5702 | B, DSAStack->isCancelRegion()); |
| 5703 | } |
| 5704 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5705 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5706 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5707 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5708 | I != E; ++I) { |
| 5709 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5710 | return true; |
| 5711 | } |
| 5712 | } |
| 5713 | |
| 5714 | return false; |
| 5715 | } |
| 5716 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5717 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5718 | Stmt *AStmt, |
| 5719 | SourceLocation StartLoc, |
| 5720 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5721 | if (!AStmt) |
| 5722 | return StmtError(); |
| 5723 | |
| 5724 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5725 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5726 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 5727 | // At least one map clause must appear on the directive. |
| 5728 | if (!HasMapClause(Clauses)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5729 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5730 | << getOpenMPDirectiveName(OMPD_target_data); |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5731 | return StmtError(); |
| 5732 | } |
| 5733 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5734 | getCurFunction()->setHasBranchProtectedScope(); |
| 5735 | |
| 5736 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5737 | AStmt); |
| 5738 | } |
| 5739 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5740 | StmtResult |
| 5741 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5742 | SourceLocation StartLoc, |
| 5743 | SourceLocation EndLoc) { |
| 5744 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5745 | // At least one map clause must appear on the directive. |
| 5746 | if (!HasMapClause(Clauses)) { |
| 5747 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5748 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5749 | return StmtError(); |
| 5750 | } |
| 5751 | |
| 5752 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5753 | Clauses); |
| 5754 | } |
| 5755 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5756 | StmtResult |
| 5757 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5758 | SourceLocation StartLoc, |
| 5759 | SourceLocation EndLoc) { |
| 5760 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5761 | // At least one map clause must appear on the directive. |
| 5762 | if (!HasMapClause(Clauses)) { |
| 5763 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5764 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5765 | return StmtError(); |
| 5766 | } |
| 5767 | |
| 5768 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5769 | } |
| 5770 | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5771 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 5772 | SourceLocation StartLoc, |
| 5773 | SourceLocation EndLoc) { |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5774 | bool seenMotionClause = false; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 5775 | for (auto *C : Clauses) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 5776 | if (C->getClauseKind() == OMPC_to || C->getClauseKind() == OMPC_from) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 5777 | seenMotionClause = true; |
| 5778 | } |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5779 | if (!seenMotionClause) { |
| 5780 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 5781 | return StmtError(); |
| 5782 | } |
| 5783 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5784 | } |
| 5785 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5786 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5787 | Stmt *AStmt, SourceLocation StartLoc, |
| 5788 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5789 | if (!AStmt) |
| 5790 | return StmtError(); |
| 5791 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5792 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5793 | // 1.2.2 OpenMP Language Terminology |
| 5794 | // Structured block - An executable statement with a single entry at the |
| 5795 | // top and a single exit at the bottom. |
| 5796 | // The point of exit cannot be a branch out of the structured block. |
| 5797 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5798 | CS->getCapturedDecl()->setNothrow(); |
| 5799 | |
| 5800 | getCurFunction()->setHasBranchProtectedScope(); |
| 5801 | |
| 5802 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5803 | } |
| 5804 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5805 | StmtResult |
| 5806 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5807 | SourceLocation EndLoc, |
| 5808 | OpenMPDirectiveKind CancelRegion) { |
| 5809 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5810 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5811 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5812 | << getOpenMPDirectiveName(CancelRegion); |
| 5813 | return StmtError(); |
| 5814 | } |
| 5815 | if (DSAStack->isParentNowaitRegion()) { |
| 5816 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5817 | return StmtError(); |
| 5818 | } |
| 5819 | if (DSAStack->isParentOrderedRegion()) { |
| 5820 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5821 | return StmtError(); |
| 5822 | } |
| 5823 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5824 | CancelRegion); |
| 5825 | } |
| 5826 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5827 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5828 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5829 | SourceLocation EndLoc, |
| 5830 | OpenMPDirectiveKind CancelRegion) { |
| 5831 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5832 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5833 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5834 | << getOpenMPDirectiveName(CancelRegion); |
| 5835 | return StmtError(); |
| 5836 | } |
| 5837 | if (DSAStack->isParentNowaitRegion()) { |
| 5838 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5839 | return StmtError(); |
| 5840 | } |
| 5841 | if (DSAStack->isParentOrderedRegion()) { |
| 5842 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5843 | return StmtError(); |
| 5844 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5845 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5846 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5847 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5848 | } |
| 5849 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5850 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5851 | ArrayRef<OMPClause *> Clauses) { |
| 5852 | OMPClause *PrevClause = nullptr; |
| 5853 | bool ErrorFound = false; |
| 5854 | for (auto *C : Clauses) { |
| 5855 | if (C->getClauseKind() == OMPC_grainsize || |
| 5856 | C->getClauseKind() == OMPC_num_tasks) { |
| 5857 | if (!PrevClause) |
| 5858 | PrevClause = C; |
| 5859 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5860 | S.Diag(C->getLocStart(), |
| 5861 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5862 | << getOpenMPClauseName(C->getClauseKind()) |
| 5863 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5864 | S.Diag(PrevClause->getLocStart(), |
| 5865 | diag::note_omp_previous_grainsize_num_tasks) |
| 5866 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5867 | ErrorFound = true; |
| 5868 | } |
| 5869 | } |
| 5870 | } |
| 5871 | return ErrorFound; |
| 5872 | } |
| 5873 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5874 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5875 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5876 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5877 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5878 | if (!AStmt) |
| 5879 | return StmtError(); |
| 5880 | |
| 5881 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5882 | OMPLoopDirective::HelperExprs B; |
| 5883 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5884 | // define the nested loops number. |
| 5885 | unsigned NestedLoopCount = |
| 5886 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5887 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5888 | VarsWithImplicitDSA, B); |
| 5889 | if (NestedLoopCount == 0) |
| 5890 | return StmtError(); |
| 5891 | |
| 5892 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5893 | "omp for loop exprs were not built"); |
| 5894 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5895 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5896 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5897 | // not appear on the same taskloop directive. |
| 5898 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5899 | return StmtError(); |
| 5900 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5901 | getCurFunction()->setHasBranchProtectedScope(); |
| 5902 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5903 | NestedLoopCount, Clauses, AStmt, B); |
| 5904 | } |
| 5905 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5906 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5907 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5908 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5909 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5910 | if (!AStmt) |
| 5911 | return StmtError(); |
| 5912 | |
| 5913 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5914 | OMPLoopDirective::HelperExprs B; |
| 5915 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5916 | // define the nested loops number. |
| 5917 | unsigned NestedLoopCount = |
| 5918 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5919 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5920 | VarsWithImplicitDSA, B); |
| 5921 | if (NestedLoopCount == 0) |
| 5922 | return StmtError(); |
| 5923 | |
| 5924 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5925 | "omp for loop exprs were not built"); |
| 5926 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5927 | if (!CurContext->isDependentContext()) { |
| 5928 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5929 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5930 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5931 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5932 | B.NumIterations, *this, CurScope, |
| 5933 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5934 | return StmtError(); |
| 5935 | } |
| 5936 | } |
| 5937 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5938 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5939 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5940 | // not appear on the same taskloop directive. |
| 5941 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5942 | return StmtError(); |
| 5943 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5944 | getCurFunction()->setHasBranchProtectedScope(); |
| 5945 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5946 | NestedLoopCount, Clauses, AStmt, B); |
| 5947 | } |
| 5948 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5949 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5950 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5951 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5952 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5953 | if (!AStmt) |
| 5954 | return StmtError(); |
| 5955 | |
| 5956 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5957 | OMPLoopDirective::HelperExprs B; |
| 5958 | // In presence of clause 'collapse' with number of loops, it will |
| 5959 | // define the nested loops number. |
| 5960 | unsigned NestedLoopCount = |
| 5961 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5962 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5963 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5964 | if (NestedLoopCount == 0) |
| 5965 | return StmtError(); |
| 5966 | |
| 5967 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5968 | "omp for loop exprs were not built"); |
| 5969 | |
| 5970 | getCurFunction()->setHasBranchProtectedScope(); |
| 5971 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5972 | NestedLoopCount, Clauses, AStmt, B); |
| 5973 | } |
| 5974 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5975 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 5976 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5977 | SourceLocation EndLoc, |
| 5978 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5979 | if (!AStmt) |
| 5980 | return StmtError(); |
| 5981 | |
| 5982 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5983 | // 1.2.2 OpenMP Language Terminology |
| 5984 | // Structured block - An executable statement with a single entry at the |
| 5985 | // top and a single exit at the bottom. |
| 5986 | // The point of exit cannot be a branch out of the structured block. |
| 5987 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5988 | CS->getCapturedDecl()->setNothrow(); |
| 5989 | |
| 5990 | OMPLoopDirective::HelperExprs B; |
| 5991 | // In presence of clause 'collapse' with number of loops, it will |
| 5992 | // define the nested loops number. |
| 5993 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5994 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 5995 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 5996 | VarsWithImplicitDSA, B); |
| 5997 | if (NestedLoopCount == 0) |
| 5998 | return StmtError(); |
| 5999 | |
| 6000 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6001 | "omp for loop exprs were not built"); |
| 6002 | |
| 6003 | getCurFunction()->setHasBranchProtectedScope(); |
| 6004 | return OMPDistributeParallelForDirective::Create( |
| 6005 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6006 | } |
| 6007 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6008 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 6009 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6010 | SourceLocation EndLoc, |
| 6011 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6012 | if (!AStmt) |
| 6013 | return StmtError(); |
| 6014 | |
| 6015 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6016 | // 1.2.2 OpenMP Language Terminology |
| 6017 | // Structured block - An executable statement with a single entry at the |
| 6018 | // top and a single exit at the bottom. |
| 6019 | // The point of exit cannot be a branch out of the structured block. |
| 6020 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6021 | CS->getCapturedDecl()->setNothrow(); |
| 6022 | |
| 6023 | OMPLoopDirective::HelperExprs B; |
| 6024 | // In presence of clause 'collapse' with number of loops, it will |
| 6025 | // define the nested loops number. |
| 6026 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6027 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6028 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6029 | VarsWithImplicitDSA, B); |
| 6030 | if (NestedLoopCount == 0) |
| 6031 | return StmtError(); |
| 6032 | |
| 6033 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6034 | "omp for loop exprs were not built"); |
| 6035 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6036 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6037 | return StmtError(); |
| 6038 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6039 | getCurFunction()->setHasBranchProtectedScope(); |
| 6040 | return OMPDistributeParallelForSimdDirective::Create( |
| 6041 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6042 | } |
| 6043 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6044 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 6045 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6046 | SourceLocation EndLoc, |
| 6047 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6048 | if (!AStmt) |
| 6049 | return StmtError(); |
| 6050 | |
| 6051 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6052 | // 1.2.2 OpenMP Language Terminology |
| 6053 | // Structured block - An executable statement with a single entry at the |
| 6054 | // top and a single exit at the bottom. |
| 6055 | // The point of exit cannot be a branch out of the structured block. |
| 6056 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6057 | CS->getCapturedDecl()->setNothrow(); |
| 6058 | |
| 6059 | OMPLoopDirective::HelperExprs B; |
| 6060 | // In presence of clause 'collapse' with number of loops, it will |
| 6061 | // define the nested loops number. |
| 6062 | unsigned NestedLoopCount = |
| 6063 | CheckOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6064 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6065 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6066 | if (NestedLoopCount == 0) |
| 6067 | return StmtError(); |
| 6068 | |
| 6069 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6070 | "omp for loop exprs were not built"); |
| 6071 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6072 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6073 | return StmtError(); |
| 6074 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6075 | getCurFunction()->setHasBranchProtectedScope(); |
| 6076 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6077 | NestedLoopCount, Clauses, AStmt, B); |
| 6078 | } |
| 6079 | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6080 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 6081 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6082 | SourceLocation EndLoc, |
| 6083 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6084 | if (!AStmt) |
| 6085 | return StmtError(); |
| 6086 | |
| 6087 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6088 | // 1.2.2 OpenMP Language Terminology |
| 6089 | // Structured block - An executable statement with a single entry at the |
| 6090 | // top and a single exit at the bottom. |
| 6091 | // The point of exit cannot be a branch out of the structured block. |
| 6092 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6093 | CS->getCapturedDecl()->setNothrow(); |
| 6094 | |
| 6095 | OMPLoopDirective::HelperExprs B; |
| 6096 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6097 | // define the nested loops number. |
| 6098 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6099 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6100 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6101 | VarsWithImplicitDSA, B); |
| 6102 | if (NestedLoopCount == 0) |
| 6103 | return StmtError(); |
| 6104 | |
| 6105 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6106 | "omp target parallel for simd loop exprs were not built"); |
| 6107 | |
| 6108 | if (!CurContext->isDependentContext()) { |
| 6109 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6110 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6111 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6112 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6113 | B.NumIterations, *this, CurScope, |
| 6114 | DSAStack)) |
| 6115 | return StmtError(); |
| 6116 | } |
| 6117 | } |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6118 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6119 | return StmtError(); |
| 6120 | |
| 6121 | getCurFunction()->setHasBranchProtectedScope(); |
| 6122 | return OMPTargetParallelForSimdDirective::Create( |
| 6123 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6124 | } |
| 6125 | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6126 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 6127 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6128 | SourceLocation EndLoc, |
| 6129 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6130 | if (!AStmt) |
| 6131 | return StmtError(); |
| 6132 | |
| 6133 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6134 | // 1.2.2 OpenMP Language Terminology |
| 6135 | // Structured block - An executable statement with a single entry at the |
| 6136 | // top and a single exit at the bottom. |
| 6137 | // The point of exit cannot be a branch out of the structured block. |
| 6138 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6139 | CS->getCapturedDecl()->setNothrow(); |
| 6140 | |
| 6141 | OMPLoopDirective::HelperExprs B; |
| 6142 | // In presence of clause 'collapse' with number of loops, it will define the |
| 6143 | // nested loops number. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6144 | unsigned NestedLoopCount = |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6145 | CheckOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| 6146 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6147 | VarsWithImplicitDSA, B); |
| 6148 | if (NestedLoopCount == 0) |
| 6149 | return StmtError(); |
| 6150 | |
| 6151 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6152 | "omp target simd loop exprs were not built"); |
| 6153 | |
| 6154 | if (!CurContext->isDependentContext()) { |
| 6155 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6156 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6157 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6158 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6159 | B.NumIterations, *this, CurScope, |
| 6160 | DSAStack)) |
| 6161 | return StmtError(); |
| 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6166 | return StmtError(); |
| 6167 | |
| 6168 | getCurFunction()->setHasBranchProtectedScope(); |
| 6169 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6170 | NestedLoopCount, Clauses, AStmt, B); |
| 6171 | } |
| 6172 | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6173 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 6174 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6175 | SourceLocation EndLoc, |
| 6176 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6177 | if (!AStmt) |
| 6178 | return StmtError(); |
| 6179 | |
| 6180 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6181 | // 1.2.2 OpenMP Language Terminology |
| 6182 | // Structured block - An executable statement with a single entry at the |
| 6183 | // top and a single exit at the bottom. |
| 6184 | // The point of exit cannot be a branch out of the structured block. |
| 6185 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6186 | CS->getCapturedDecl()->setNothrow(); |
| 6187 | |
| 6188 | OMPLoopDirective::HelperExprs B; |
| 6189 | // In presence of clause 'collapse' with number of loops, it will |
| 6190 | // define the nested loops number. |
| 6191 | unsigned NestedLoopCount = |
| 6192 | CheckOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| 6193 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6194 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6195 | if (NestedLoopCount == 0) |
| 6196 | return StmtError(); |
| 6197 | |
| 6198 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6199 | "omp teams distribute loop exprs were not built"); |
| 6200 | |
| 6201 | getCurFunction()->setHasBranchProtectedScope(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6202 | return OMPTeamsDistributeDirective::Create( |
| 6203 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6206 | StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective( |
| 6207 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6208 | SourceLocation EndLoc, |
| 6209 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6210 | if (!AStmt) |
| 6211 | return StmtError(); |
| 6212 | |
| 6213 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6214 | // 1.2.2 OpenMP Language Terminology |
| 6215 | // Structured block - An executable statement with a single entry at the |
| 6216 | // top and a single exit at the bottom. |
| 6217 | // The point of exit cannot be a branch out of the structured block. |
| 6218 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6219 | CS->getCapturedDecl()->setNothrow(); |
| 6220 | |
| 6221 | OMPLoopDirective::HelperExprs B; |
| 6222 | // In presence of clause 'collapse' with number of loops, it will |
| 6223 | // define the nested loops number. |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 6224 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6225 | OMPD_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6226 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6227 | VarsWithImplicitDSA, B); |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6228 | |
| 6229 | if (NestedLoopCount == 0) |
| 6230 | return StmtError(); |
| 6231 | |
| 6232 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6233 | "omp teams distribute simd loop exprs were not built"); |
| 6234 | |
| 6235 | if (!CurContext->isDependentContext()) { |
| 6236 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6237 | for (auto C : Clauses) { |
| 6238 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6239 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6240 | B.NumIterations, *this, CurScope, |
| 6241 | DSAStack)) |
| 6242 | return StmtError(); |
| 6243 | } |
| 6244 | } |
| 6245 | |
| 6246 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6247 | return StmtError(); |
| 6248 | |
| 6249 | getCurFunction()->setHasBranchProtectedScope(); |
| 6250 | return OMPTeamsDistributeSimdDirective::Create( |
| 6251 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6252 | } |
| 6253 | |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 6254 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 6255 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6256 | SourceLocation EndLoc, |
| 6257 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6258 | if (!AStmt) |
| 6259 | return StmtError(); |
| 6260 | |
| 6261 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6262 | // 1.2.2 OpenMP Language Terminology |
| 6263 | // Structured block - An executable statement with a single entry at the |
| 6264 | // top and a single exit at the bottom. |
| 6265 | // The point of exit cannot be a branch out of the structured block. |
| 6266 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6267 | CS->getCapturedDecl()->setNothrow(); |
| 6268 | |
| 6269 | OMPLoopDirective::HelperExprs B; |
| 6270 | // In presence of clause 'collapse' with number of loops, it will |
| 6271 | // define the nested loops number. |
| 6272 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6273 | OMPD_teams_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6274 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6275 | VarsWithImplicitDSA, B); |
| 6276 | |
| 6277 | if (NestedLoopCount == 0) |
| 6278 | return StmtError(); |
| 6279 | |
| 6280 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6281 | "omp for loop exprs were not built"); |
| 6282 | |
| 6283 | if (!CurContext->isDependentContext()) { |
| 6284 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6285 | for (auto C : Clauses) { |
| 6286 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6287 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6288 | B.NumIterations, *this, CurScope, |
| 6289 | DSAStack)) |
| 6290 | return StmtError(); |
| 6291 | } |
| 6292 | } |
| 6293 | |
| 6294 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6295 | return StmtError(); |
| 6296 | |
| 6297 | getCurFunction()->setHasBranchProtectedScope(); |
| 6298 | return OMPTeamsDistributeParallelForSimdDirective::Create( |
| 6299 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6300 | } |
| 6301 | |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 6302 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective( |
| 6303 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6304 | SourceLocation EndLoc, |
| 6305 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6306 | if (!AStmt) |
| 6307 | return StmtError(); |
| 6308 | |
| 6309 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6310 | // 1.2.2 OpenMP Language Terminology |
| 6311 | // Structured block - An executable statement with a single entry at the |
| 6312 | // top and a single exit at the bottom. |
| 6313 | // The point of exit cannot be a branch out of the structured block. |
| 6314 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6315 | CS->getCapturedDecl()->setNothrow(); |
| 6316 | |
| 6317 | OMPLoopDirective::HelperExprs B; |
| 6318 | // In presence of clause 'collapse' with number of loops, it will |
| 6319 | // define the nested loops number. |
| 6320 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6321 | OMPD_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 6322 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6323 | VarsWithImplicitDSA, B); |
| 6324 | |
| 6325 | if (NestedLoopCount == 0) |
| 6326 | return StmtError(); |
| 6327 | |
| 6328 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6329 | "omp for loop exprs were not built"); |
| 6330 | |
| 6331 | if (!CurContext->isDependentContext()) { |
| 6332 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6333 | for (auto C : Clauses) { |
| 6334 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6335 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6336 | B.NumIterations, *this, CurScope, |
| 6337 | DSAStack)) |
| 6338 | return StmtError(); |
| 6339 | } |
| 6340 | } |
| 6341 | |
| 6342 | getCurFunction()->setHasBranchProtectedScope(); |
| 6343 | return OMPTeamsDistributeParallelForDirective::Create( |
| 6344 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6345 | } |
| 6346 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 6347 | StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6348 | Stmt *AStmt, |
| 6349 | SourceLocation StartLoc, |
| 6350 | SourceLocation EndLoc) { |
| 6351 | if (!AStmt) |
| 6352 | return StmtError(); |
| 6353 | |
| 6354 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6355 | // 1.2.2 OpenMP Language Terminology |
| 6356 | // Structured block - An executable statement with a single entry at the |
| 6357 | // top and a single exit at the bottom. |
| 6358 | // The point of exit cannot be a branch out of the structured block. |
| 6359 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6360 | CS->getCapturedDecl()->setNothrow(); |
| 6361 | |
| 6362 | getCurFunction()->setHasBranchProtectedScope(); |
| 6363 | |
| 6364 | return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6365 | AStmt); |
| 6366 | } |
| 6367 | |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 6368 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeDirective( |
| 6369 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6370 | SourceLocation EndLoc, |
| 6371 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6372 | if (!AStmt) |
| 6373 | return StmtError(); |
| 6374 | |
| 6375 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6376 | // 1.2.2 OpenMP Language Terminology |
| 6377 | // Structured block - An executable statement with a single entry at the |
| 6378 | // top and a single exit at the bottom. |
| 6379 | // The point of exit cannot be a branch out of the structured block. |
| 6380 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6381 | CS->getCapturedDecl()->setNothrow(); |
| 6382 | |
| 6383 | OMPLoopDirective::HelperExprs B; |
| 6384 | // In presence of clause 'collapse' with number of loops, it will |
| 6385 | // define the nested loops number. |
| 6386 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6387 | OMPD_target_teams_distribute, |
| 6388 | getCollapseNumberExpr(Clauses), |
| 6389 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6390 | VarsWithImplicitDSA, B); |
| 6391 | if (NestedLoopCount == 0) |
| 6392 | return StmtError(); |
| 6393 | |
| 6394 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6395 | "omp target teams distribute loop exprs were not built"); |
| 6396 | |
| 6397 | getCurFunction()->setHasBranchProtectedScope(); |
| 6398 | return OMPTargetTeamsDistributeDirective::Create( |
| 6399 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6400 | } |
| 6401 | |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 6402 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 6403 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6404 | SourceLocation EndLoc, |
| 6405 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6406 | if (!AStmt) |
| 6407 | return StmtError(); |
| 6408 | |
| 6409 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6410 | // 1.2.2 OpenMP Language Terminology |
| 6411 | // Structured block - An executable statement with a single entry at the |
| 6412 | // top and a single exit at the bottom. |
| 6413 | // The point of exit cannot be a branch out of the structured block. |
| 6414 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6415 | CS->getCapturedDecl()->setNothrow(); |
| 6416 | |
| 6417 | OMPLoopDirective::HelperExprs B; |
| 6418 | // In presence of clause 'collapse' with number of loops, it will |
| 6419 | // define the nested loops number. |
| 6420 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6421 | OMPD_target_teams_distribute_parallel_for, |
| 6422 | getCollapseNumberExpr(Clauses), |
| 6423 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6424 | VarsWithImplicitDSA, B); |
| 6425 | if (NestedLoopCount == 0) |
| 6426 | return StmtError(); |
| 6427 | |
| 6428 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6429 | "omp target teams distribute parallel for loop exprs were not built"); |
| 6430 | |
| 6431 | if (!CurContext->isDependentContext()) { |
| 6432 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6433 | for (auto C : Clauses) { |
| 6434 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6435 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6436 | B.NumIterations, *this, CurScope, |
| 6437 | DSAStack)) |
| 6438 | return StmtError(); |
| 6439 | } |
| 6440 | } |
| 6441 | |
| 6442 | getCurFunction()->setHasBranchProtectedScope(); |
| 6443 | return OMPTargetTeamsDistributeParallelForDirective::Create( |
| 6444 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6445 | } |
| 6446 | |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 6447 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 6448 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6449 | SourceLocation EndLoc, |
| 6450 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6451 | if (!AStmt) |
| 6452 | return StmtError(); |
| 6453 | |
| 6454 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6455 | // 1.2.2 OpenMP Language Terminology |
| 6456 | // Structured block - An executable statement with a single entry at the |
| 6457 | // top and a single exit at the bottom. |
| 6458 | // The point of exit cannot be a branch out of the structured block. |
| 6459 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6460 | CS->getCapturedDecl()->setNothrow(); |
| 6461 | |
| 6462 | OMPLoopDirective::HelperExprs B; |
| 6463 | // In presence of clause 'collapse' with number of loops, it will |
| 6464 | // define the nested loops number. |
| 6465 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6466 | OMPD_target_teams_distribute_parallel_for_simd, |
| 6467 | getCollapseNumberExpr(Clauses), |
| 6468 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6469 | VarsWithImplicitDSA, B); |
| 6470 | if (NestedLoopCount == 0) |
| 6471 | return StmtError(); |
| 6472 | |
| 6473 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6474 | "omp target teams distribute parallel for simd loop exprs were not " |
| 6475 | "built"); |
| 6476 | |
| 6477 | if (!CurContext->isDependentContext()) { |
| 6478 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6479 | for (auto C : Clauses) { |
| 6480 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6481 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6482 | B.NumIterations, *this, CurScope, |
| 6483 | DSAStack)) |
| 6484 | return StmtError(); |
| 6485 | } |
| 6486 | } |
| 6487 | |
| 6488 | getCurFunction()->setHasBranchProtectedScope(); |
| 6489 | return OMPTargetTeamsDistributeParallelForSimdDirective::Create( |
| 6490 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6491 | } |
| 6492 | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 6493 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 6494 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6495 | SourceLocation EndLoc, |
| 6496 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6497 | if (!AStmt) |
| 6498 | return StmtError(); |
| 6499 | |
| 6500 | auto *CS = cast<CapturedStmt>(AStmt); |
| 6501 | // 1.2.2 OpenMP Language Terminology |
| 6502 | // Structured block - An executable statement with a single entry at the |
| 6503 | // top and a single exit at the bottom. |
| 6504 | // The point of exit cannot be a branch out of the structured block. |
| 6505 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6506 | CS->getCapturedDecl()->setNothrow(); |
| 6507 | |
| 6508 | OMPLoopDirective::HelperExprs B; |
| 6509 | // In presence of clause 'collapse' with number of loops, it will |
| 6510 | // define the nested loops number. |
| 6511 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6512 | OMPD_target_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6513 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6514 | VarsWithImplicitDSA, B); |
| 6515 | if (NestedLoopCount == 0) |
| 6516 | return StmtError(); |
| 6517 | |
| 6518 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6519 | "omp target teams distribute simd loop exprs were not built"); |
| 6520 | |
| 6521 | getCurFunction()->setHasBranchProtectedScope(); |
| 6522 | return OMPTargetTeamsDistributeSimdDirective::Create( |
| 6523 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6524 | } |
| 6525 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6526 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6527 | SourceLocation StartLoc, |
| 6528 | SourceLocation LParenLoc, |
| 6529 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6530 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6531 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6532 | case OMPC_final: |
| 6533 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6534 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6535 | case OMPC_num_threads: |
| 6536 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6537 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6538 | case OMPC_safelen: |
| 6539 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6540 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6541 | case OMPC_simdlen: |
| 6542 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6543 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6544 | case OMPC_collapse: |
| 6545 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6546 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6547 | case OMPC_ordered: |
| 6548 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6549 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6550 | case OMPC_device: |
| 6551 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6552 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6553 | case OMPC_num_teams: |
| 6554 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6555 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6556 | case OMPC_thread_limit: |
| 6557 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6558 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6559 | case OMPC_priority: |
| 6560 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6561 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6562 | case OMPC_grainsize: |
| 6563 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6564 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6565 | case OMPC_num_tasks: |
| 6566 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6567 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6568 | case OMPC_hint: |
| 6569 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6570 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6571 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6572 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6573 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6574 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6575 | case OMPC_private: |
| 6576 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6577 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6578 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6579 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6580 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6581 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6582 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6583 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6584 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6585 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6586 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6587 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6588 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6589 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6590 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6591 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6592 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6593 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6594 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6595 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6596 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6597 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6598 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6599 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6600 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6601 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6602 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6603 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6604 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 6605 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 6606 | case OMPC_is_device_ptr: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6607 | llvm_unreachable("Clause is not allowed."); |
| 6608 | } |
| 6609 | return Res; |
| 6610 | } |
| 6611 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6612 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6613 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6614 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6615 | SourceLocation NameModifierLoc, |
| 6616 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6617 | SourceLocation EndLoc) { |
| 6618 | Expr *ValExpr = Condition; |
| 6619 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6620 | !Condition->isInstantiationDependent() && |
| 6621 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6622 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6623 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6624 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6625 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6626 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6627 | } |
| 6628 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6629 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6630 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6631 | } |
| 6632 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6633 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6634 | SourceLocation StartLoc, |
| 6635 | SourceLocation LParenLoc, |
| 6636 | SourceLocation EndLoc) { |
| 6637 | Expr *ValExpr = Condition; |
| 6638 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6639 | !Condition->isInstantiationDependent() && |
| 6640 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6641 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6642 | if (Val.isInvalid()) |
| 6643 | return nullptr; |
| 6644 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6645 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6649 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6650 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6651 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6652 | if (!Op) |
| 6653 | return ExprError(); |
| 6654 | |
| 6655 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6656 | public: |
| 6657 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6658 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6659 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6660 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6661 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6662 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6663 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6664 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6665 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6666 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6667 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6668 | QualType T, |
| 6669 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6670 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6671 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6672 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6673 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6674 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6675 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6676 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6677 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6678 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6679 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6680 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6681 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6682 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6683 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6684 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6685 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6686 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6687 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6688 | llvm_unreachable("conversion functions are permitted"); |
| 6689 | } |
| 6690 | } ConvertDiagnoser; |
| 6691 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6692 | } |
| 6693 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6694 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6695 | OpenMPClauseKind CKind, |
| 6696 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6697 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6698 | !ValExpr->isInstantiationDependent()) { |
| 6699 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6700 | ExprResult Value = |
| 6701 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6702 | if (Value.isInvalid()) |
| 6703 | return false; |
| 6704 | |
| 6705 | ValExpr = Value.get(); |
| 6706 | // The expression must evaluate to a non-negative integer value. |
| 6707 | llvm::APSInt Result; |
| 6708 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6709 | Result.isSigned() && |
| 6710 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6711 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6712 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6713 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6714 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6715 | return false; |
| 6716 | } |
| 6717 | } |
| 6718 | return true; |
| 6719 | } |
| 6720 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6721 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6722 | SourceLocation StartLoc, |
| 6723 | SourceLocation LParenLoc, |
| 6724 | SourceLocation EndLoc) { |
| 6725 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6726 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6727 | // OpenMP [2.5, Restrictions] |
| 6728 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6729 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6730 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6731 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6732 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6733 | return new (Context) |
| 6734 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6735 | } |
| 6736 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6737 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6738 | OpenMPClauseKind CKind, |
| 6739 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6740 | if (!E) |
| 6741 | return ExprError(); |
| 6742 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6743 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6744 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6745 | llvm::APSInt Result; |
| 6746 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6747 | if (ICE.isInvalid()) |
| 6748 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6749 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6750 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6751 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6752 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6753 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6754 | return ExprError(); |
| 6755 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6756 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6757 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6758 | << E->getSourceRange(); |
| 6759 | return ExprError(); |
| 6760 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6761 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6762 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6763 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6764 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6765 | return ICE; |
| 6766 | } |
| 6767 | |
| 6768 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6769 | SourceLocation LParenLoc, |
| 6770 | SourceLocation EndLoc) { |
| 6771 | // OpenMP [2.8.1, simd construct, Description] |
| 6772 | // The parameter of the safelen clause must be a constant |
| 6773 | // positive integer expression. |
| 6774 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6775 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6776 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6777 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6778 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6781 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6782 | SourceLocation LParenLoc, |
| 6783 | SourceLocation EndLoc) { |
| 6784 | // OpenMP [2.8.1, simd construct, Description] |
| 6785 | // The parameter of the simdlen clause must be a constant |
| 6786 | // positive integer expression. |
| 6787 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6788 | if (Simdlen.isInvalid()) |
| 6789 | return nullptr; |
| 6790 | return new (Context) |
| 6791 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6792 | } |
| 6793 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6794 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6795 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6796 | SourceLocation LParenLoc, |
| 6797 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6798 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6799 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6800 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6801 | // The parameter of the collapse clause must be a constant |
| 6802 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6803 | ExprResult NumForLoopsResult = |
| 6804 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6805 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6806 | return nullptr; |
| 6807 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6808 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6809 | } |
| 6810 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6811 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6812 | SourceLocation EndLoc, |
| 6813 | SourceLocation LParenLoc, |
| 6814 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6815 | // OpenMP [2.7.1, loop construct, Description] |
| 6816 | // OpenMP [2.8.1, simd construct, Description] |
| 6817 | // OpenMP [2.9.6, distribute construct, Description] |
| 6818 | // The parameter of the ordered clause must be a constant |
| 6819 | // positive integer expression if any. |
| 6820 | if (NumForLoops && LParenLoc.isValid()) { |
| 6821 | ExprResult NumForLoopsResult = |
| 6822 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6823 | if (NumForLoopsResult.isInvalid()) |
| 6824 | return nullptr; |
| 6825 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6826 | } else |
| 6827 | NumForLoops = nullptr; |
| 6828 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6829 | return new (Context) |
| 6830 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6831 | } |
| 6832 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6833 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6834 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6835 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6836 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6837 | switch (Kind) { |
| 6838 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6839 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6840 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6841 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6842 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6843 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6844 | Res = ActOnOpenMPProcBindClause( |
| 6845 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6846 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6847 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6848 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6849 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6850 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6851 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6852 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6853 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6854 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6855 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6856 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6857 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6858 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6859 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6860 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6861 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6862 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6863 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6864 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6865 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6866 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6867 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6868 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6869 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6870 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6871 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6872 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6873 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6874 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6875 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6876 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6877 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6878 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6879 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6880 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6881 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6882 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6883 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6884 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6885 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6886 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6887 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6888 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6889 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6890 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6891 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6892 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 6893 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 6894 | case OMPC_is_device_ptr: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6895 | llvm_unreachable("Clause is not allowed."); |
| 6896 | } |
| 6897 | return Res; |
| 6898 | } |
| 6899 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6900 | static std::string |
| 6901 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6902 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6903 | std::string Values; |
| 6904 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6905 | unsigned Skipped = Exclude.size(); |
| 6906 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6907 | for (unsigned i = First; i < Last; ++i) { |
| 6908 | if (std::find(S, E, i) != E) { |
| 6909 | --Skipped; |
| 6910 | continue; |
| 6911 | } |
| 6912 | Values += "'"; |
| 6913 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6914 | Values += "'"; |
| 6915 | if (i == Bound - Skipped) |
| 6916 | Values += " or "; |
| 6917 | else if (i != Bound + 1 - Skipped) |
| 6918 | Values += ", "; |
| 6919 | } |
| 6920 | return Values; |
| 6921 | } |
| 6922 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6923 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6924 | SourceLocation KindKwLoc, |
| 6925 | SourceLocation StartLoc, |
| 6926 | SourceLocation LParenLoc, |
| 6927 | SourceLocation EndLoc) { |
| 6928 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6929 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6930 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6931 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6932 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6933 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6934 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6935 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6936 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6937 | switch (Kind) { |
| 6938 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6939 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6940 | break; |
| 6941 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6942 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6943 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6944 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6945 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6946 | break; |
| 6947 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6948 | return new (Context) |
| 6949 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6950 | } |
| 6951 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6952 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6953 | SourceLocation KindKwLoc, |
| 6954 | SourceLocation StartLoc, |
| 6955 | SourceLocation LParenLoc, |
| 6956 | SourceLocation EndLoc) { |
| 6957 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6958 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6959 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6960 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6961 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6962 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6963 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6964 | return new (Context) |
| 6965 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6966 | } |
| 6967 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6968 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6969 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6970 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6971 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6972 | SourceLocation EndLoc) { |
| 6973 | OMPClause *Res = nullptr; |
| 6974 | switch (Kind) { |
| 6975 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6976 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6977 | assert(Argument.size() == NumberOfElements && |
| 6978 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6979 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6980 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6981 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6982 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6983 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6984 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6985 | break; |
| 6986 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6987 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6988 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6989 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6990 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6991 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6992 | case OMPC_dist_schedule: |
| 6993 | Res = ActOnOpenMPDistScheduleClause( |
| 6994 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6995 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6996 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6997 | case OMPC_defaultmap: |
| 6998 | enum { Modifier, DefaultmapKind }; |
| 6999 | Res = ActOnOpenMPDefaultmapClause( |
| 7000 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7001 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7002 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 7003 | EndLoc); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7004 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7005 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7006 | case OMPC_num_threads: |
| 7007 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7008 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7009 | case OMPC_collapse: |
| 7010 | case OMPC_default: |
| 7011 | case OMPC_proc_bind: |
| 7012 | case OMPC_private: |
| 7013 | case OMPC_firstprivate: |
| 7014 | case OMPC_lastprivate: |
| 7015 | case OMPC_shared: |
| 7016 | case OMPC_reduction: |
| 7017 | case OMPC_linear: |
| 7018 | case OMPC_aligned: |
| 7019 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7020 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7021 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7022 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7023 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7024 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7025 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7026 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7027 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7028 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7029 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7030 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7031 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7032 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7033 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7034 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7035 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7036 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7037 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7038 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7039 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7040 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7041 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7042 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7043 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7044 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7045 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7046 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7047 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7048 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7049 | case OMPC_is_device_ptr: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7050 | llvm_unreachable("Clause is not allowed."); |
| 7051 | } |
| 7052 | return Res; |
| 7053 | } |
| 7054 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7055 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7056 | OpenMPScheduleClauseModifier M2, |
| 7057 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 7058 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 7059 | SmallVector<unsigned, 2> Excluded; |
| 7060 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 7061 | Excluded.push_back(M2); |
| 7062 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 7063 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 7064 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 7065 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 7066 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 7067 | << getListOfPossibleValues(OMPC_schedule, |
| 7068 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 7069 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7070 | Excluded) |
| 7071 | << getOpenMPClauseName(OMPC_schedule); |
| 7072 | return true; |
| 7073 | } |
| 7074 | return false; |
| 7075 | } |
| 7076 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7077 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7078 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7079 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7080 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 7081 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 7082 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 7083 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 7084 | return nullptr; |
| 7085 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7086 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 7087 | // but not both. |
| 7088 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 7089 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 7090 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 7091 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 7092 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 7093 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 7094 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 7095 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 7096 | return nullptr; |
| 7097 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7098 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 7099 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7100 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 7101 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 7102 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7103 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7104 | Exclude); |
| 7105 | } else { |
| 7106 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7107 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7108 | } |
| 7109 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 7110 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 7111 | return nullptr; |
| 7112 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7113 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7114 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 7115 | // schedule(guided). |
| 7116 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 7117 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 7118 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 7119 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 7120 | diag::err_omp_schedule_nonmonotonic_static); |
| 7121 | return nullptr; |
| 7122 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7123 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7124 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7125 | if (ChunkSize) { |
| 7126 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 7127 | !ChunkSize->isInstantiationDependent() && |
| 7128 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 7129 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 7130 | ExprResult Val = |
| 7131 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 7132 | if (Val.isInvalid()) |
| 7133 | return nullptr; |
| 7134 | |
| 7135 | ValExpr = Val.get(); |
| 7136 | |
| 7137 | // OpenMP [2.7.1, Restrictions] |
| 7138 | // chunk_size must be a loop invariant integer expression with a positive |
| 7139 | // value. |
| 7140 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7141 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 7142 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7143 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7144 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7145 | return nullptr; |
| 7146 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 7147 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 7148 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7149 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7150 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7151 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7152 | } |
| 7153 | } |
| 7154 | } |
| 7155 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7156 | return new (Context) |
| 7157 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7158 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7159 | } |
| 7160 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7161 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 7162 | SourceLocation StartLoc, |
| 7163 | SourceLocation EndLoc) { |
| 7164 | OMPClause *Res = nullptr; |
| 7165 | switch (Kind) { |
| 7166 | case OMPC_ordered: |
| 7167 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 7168 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7169 | case OMPC_nowait: |
| 7170 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 7171 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7172 | case OMPC_untied: |
| 7173 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 7174 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7175 | case OMPC_mergeable: |
| 7176 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 7177 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7178 | case OMPC_read: |
| 7179 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 7180 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7181 | case OMPC_write: |
| 7182 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 7183 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7184 | case OMPC_update: |
| 7185 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 7186 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7187 | case OMPC_capture: |
| 7188 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 7189 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7190 | case OMPC_seq_cst: |
| 7191 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 7192 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7193 | case OMPC_threads: |
| 7194 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 7195 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7196 | case OMPC_simd: |
| 7197 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 7198 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7199 | case OMPC_nogroup: |
| 7200 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 7201 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7202 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7203 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7204 | case OMPC_num_threads: |
| 7205 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7206 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7207 | case OMPC_collapse: |
| 7208 | case OMPC_schedule: |
| 7209 | case OMPC_private: |
| 7210 | case OMPC_firstprivate: |
| 7211 | case OMPC_lastprivate: |
| 7212 | case OMPC_shared: |
| 7213 | case OMPC_reduction: |
| 7214 | case OMPC_linear: |
| 7215 | case OMPC_aligned: |
| 7216 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7217 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7218 | case OMPC_default: |
| 7219 | case OMPC_proc_bind: |
| 7220 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7221 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7222 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7223 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7224 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7225 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7226 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7227 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7228 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7229 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7230 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7231 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7232 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7233 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7234 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7235 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7236 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7237 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7238 | case OMPC_is_device_ptr: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7239 | llvm_unreachable("Clause is not allowed."); |
| 7240 | } |
| 7241 | return Res; |
| 7242 | } |
| 7243 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7244 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 7245 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7246 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7247 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 7248 | } |
| 7249 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7250 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 7251 | SourceLocation EndLoc) { |
| 7252 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 7253 | } |
| 7254 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7255 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 7256 | SourceLocation EndLoc) { |
| 7257 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 7258 | } |
| 7259 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7260 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 7261 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7262 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 7263 | } |
| 7264 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7265 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 7266 | SourceLocation EndLoc) { |
| 7267 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 7268 | } |
| 7269 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7270 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 7271 | SourceLocation EndLoc) { |
| 7272 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 7273 | } |
| 7274 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7275 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 7276 | SourceLocation EndLoc) { |
| 7277 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 7278 | } |
| 7279 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7280 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 7281 | SourceLocation EndLoc) { |
| 7282 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 7283 | } |
| 7284 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7285 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 7286 | SourceLocation EndLoc) { |
| 7287 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 7288 | } |
| 7289 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7290 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 7291 | SourceLocation EndLoc) { |
| 7292 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 7293 | } |
| 7294 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7295 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 7296 | SourceLocation EndLoc) { |
| 7297 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 7298 | } |
| 7299 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7300 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7301 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7302 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7303 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7304 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7305 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7306 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7307 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7308 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7309 | switch (Kind) { |
| 7310 | case OMPC_private: |
| 7311 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7312 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7313 | case OMPC_firstprivate: |
| 7314 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7315 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7316 | case OMPC_lastprivate: |
| 7317 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7318 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7319 | case OMPC_shared: |
| 7320 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7321 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7322 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7323 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7324 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7325 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7326 | case OMPC_linear: |
| 7327 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7328 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7329 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7330 | case OMPC_aligned: |
| 7331 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7332 | ColonLoc, EndLoc); |
| 7333 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7334 | case OMPC_copyin: |
| 7335 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7336 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7337 | case OMPC_copyprivate: |
| 7338 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7339 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7340 | case OMPC_flush: |
| 7341 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7342 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7343 | case OMPC_depend: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7344 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7345 | StartLoc, LParenLoc, EndLoc); |
| 7346 | break; |
| 7347 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7348 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7349 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7350 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7351 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7352 | case OMPC_to: |
| 7353 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7354 | break; |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7355 | case OMPC_from: |
| 7356 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7357 | break; |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7358 | case OMPC_use_device_ptr: |
| 7359 | Res = ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7360 | break; |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7361 | case OMPC_is_device_ptr: |
| 7362 | Res = ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7363 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7364 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7365 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7366 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7367 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7368 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7369 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7370 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7371 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7372 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7373 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7374 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7375 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7376 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7377 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7378 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7379 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7380 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7381 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7382 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7383 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7384 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7385 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7386 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7387 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7388 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7389 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7390 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7391 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7392 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7393 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7394 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7395 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7396 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7397 | llvm_unreachable("Clause is not allowed."); |
| 7398 | } |
| 7399 | return Res; |
| 7400 | } |
| 7401 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7402 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7403 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7404 | ExprResult Res = BuildDeclRefExpr( |
| 7405 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7406 | if (!Res.isUsable()) |
| 7407 | return ExprError(); |
| 7408 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7409 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7410 | if (!Res.isUsable()) |
| 7411 | return ExprError(); |
| 7412 | } |
| 7413 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7414 | Res = DefaultLvalueConversion(Res.get()); |
| 7415 | if (!Res.isUsable()) |
| 7416 | return ExprError(); |
| 7417 | } |
| 7418 | return Res; |
| 7419 | } |
| 7420 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7421 | static std::pair<ValueDecl *, bool> |
| 7422 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7423 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7424 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7425 | RefExpr->containsUnexpandedParameterPack()) |
| 7426 | return std::make_pair(nullptr, true); |
| 7427 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7428 | // OpenMP [3.1, C/C++] |
| 7429 | // A list item is a variable name. |
| 7430 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7431 | // A variable that is part of another variable (as an array or |
| 7432 | // structure element) cannot appear in a private clause. |
| 7433 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7434 | enum { |
| 7435 | NoArrayExpr = -1, |
| 7436 | ArraySubscript = 0, |
| 7437 | OMPArraySection = 1 |
| 7438 | } IsArrayExpr = NoArrayExpr; |
| 7439 | if (AllowArraySection) { |
| 7440 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7441 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7442 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7443 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7444 | RefExpr = Base; |
| 7445 | IsArrayExpr = ArraySubscript; |
| 7446 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7447 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7448 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7449 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7450 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7451 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7452 | RefExpr = Base; |
| 7453 | IsArrayExpr = OMPArraySection; |
| 7454 | } |
| 7455 | } |
| 7456 | ELoc = RefExpr->getExprLoc(); |
| 7457 | ERange = RefExpr->getSourceRange(); |
| 7458 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7459 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7460 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7461 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7462 | (S.getCurrentThisType().isNull() || !ME || |
| 7463 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7464 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7465 | if (IsArrayExpr != NoArrayExpr) |
| 7466 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7467 | << ERange; |
| 7468 | else { |
| 7469 | S.Diag(ELoc, |
| 7470 | AllowArraySection |
| 7471 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7472 | : diag::err_omp_expected_var_name_member_expr) |
| 7473 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7474 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7475 | return std::make_pair(nullptr, false); |
| 7476 | } |
| 7477 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7478 | } |
| 7479 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7480 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7481 | SourceLocation StartLoc, |
| 7482 | SourceLocation LParenLoc, |
| 7483 | SourceLocation EndLoc) { |
| 7484 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7485 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7486 | for (auto &RefExpr : VarList) { |
| 7487 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7488 | SourceLocation ELoc; |
| 7489 | SourceRange ERange; |
| 7490 | Expr *SimpleRefExpr = RefExpr; |
| 7491 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7492 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7493 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7494 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7495 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7496 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7497 | ValueDecl *D = Res.first; |
| 7498 | if (!D) |
| 7499 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7500 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7501 | QualType Type = D->getType(); |
| 7502 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7503 | |
| 7504 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7505 | // A variable that appears in a private clause must not have an incomplete |
| 7506 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7507 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7508 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7509 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7510 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7511 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7512 | // in a Construct] |
| 7513 | // Variables with the predetermined data-sharing attributes may not be |
| 7514 | // listed in data-sharing attributes clauses, except for the cases |
| 7515 | // listed below. For these exceptions only, listing a predetermined |
| 7516 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7517 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7518 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7519 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7520 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7521 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7522 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7523 | continue; |
| 7524 | } |
| 7525 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7526 | auto CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7527 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7528 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7529 | isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7530 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7531 | << getOpenMPClauseName(OMPC_private) << Type |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7532 | << getOpenMPDirectiveName(CurrDir); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7533 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7534 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7535 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7536 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7537 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7538 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7539 | continue; |
| 7540 | } |
| 7541 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7542 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7543 | // A list item cannot appear in both a map clause and a data-sharing |
| 7544 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7545 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7546 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7547 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7548 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 7549 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7550 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 7551 | CurrDir == OMPD_target_parallel_for_simd || |
| 7552 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7553 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 7554 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7555 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7556 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 7557 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 7558 | ConflictKind = WhereFoundClauseKind; |
| 7559 | return true; |
| 7560 | })) { |
| 7561 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7562 | << getOpenMPClauseName(OMPC_private) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7563 | << getOpenMPClauseName(ConflictKind) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7564 | << getOpenMPDirectiveName(CurrDir); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7565 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7566 | continue; |
| 7567 | } |
| 7568 | } |
| 7569 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7570 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7571 | // A variable of class type (or array thereof) that appears in a private |
| 7572 | // clause requires an accessible, unambiguous default constructor for the |
| 7573 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7574 | // Generate helper private variable and initialize it with the default |
| 7575 | // value. The address of the original variable is replaced by the address of |
| 7576 | // the new private variable in CodeGen. This new variable is not added to |
| 7577 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7578 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7579 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7580 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7581 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 7582 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7583 | if (VDPrivate->isInvalidDecl()) |
| 7584 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7585 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7586 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7587 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7588 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 7589 | if (!VD && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7590 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7591 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 7592 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 7593 | ? RefExpr->IgnoreParens() |
| 7594 | : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7595 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7596 | } |
| 7597 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7598 | if (Vars.empty()) |
| 7599 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7600 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7601 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7602 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7603 | } |
| 7604 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7605 | namespace { |
| 7606 | class DiagsUninitializedSeveretyRAII { |
| 7607 | private: |
| 7608 | DiagnosticsEngine &Diags; |
| 7609 | SourceLocation SavedLoc; |
| 7610 | bool IsIgnored; |
| 7611 | |
| 7612 | public: |
| 7613 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7614 | bool IsIgnored) |
| 7615 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7616 | if (!IsIgnored) { |
| 7617 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7618 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7619 | } |
| 7620 | } |
| 7621 | ~DiagsUninitializedSeveretyRAII() { |
| 7622 | if (!IsIgnored) |
| 7623 | Diags.popMappings(SavedLoc); |
| 7624 | } |
| 7625 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7626 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7627 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7628 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7629 | SourceLocation StartLoc, |
| 7630 | SourceLocation LParenLoc, |
| 7631 | SourceLocation EndLoc) { |
| 7632 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7633 | SmallVector<Expr *, 8> PrivateCopies; |
| 7634 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7635 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7636 | bool IsImplicitClause = |
| 7637 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7638 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7639 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7640 | for (auto &RefExpr : VarList) { |
| 7641 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7642 | SourceLocation ELoc; |
| 7643 | SourceRange ERange; |
| 7644 | Expr *SimpleRefExpr = RefExpr; |
| 7645 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7646 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7647 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7648 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7649 | PrivateCopies.push_back(nullptr); |
| 7650 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7651 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7652 | ValueDecl *D = Res.first; |
| 7653 | if (!D) |
| 7654 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7655 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7656 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7657 | QualType Type = D->getType(); |
| 7658 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7659 | |
| 7660 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7661 | // A variable that appears in a private clause must not have an incomplete |
| 7662 | // type or a reference type. |
| 7663 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7664 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7665 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7666 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7667 | |
| 7668 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7669 | // 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] | 7670 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7671 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7672 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7673 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7674 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7675 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7676 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7677 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7678 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7679 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7680 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7681 | // A list item that specifies a given variable may not appear in more |
| 7682 | // than one clause on the same directive, except that a variable may be |
| 7683 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7684 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7685 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7686 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7687 | << getOpenMPClauseName(DVar.CKind) |
| 7688 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7689 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7690 | continue; |
| 7691 | } |
| 7692 | |
| 7693 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7694 | // in a Construct] |
| 7695 | // Variables with the predetermined data-sharing attributes may not be |
| 7696 | // listed in data-sharing attributes clauses, except for the cases |
| 7697 | // listed below. For these exceptions only, listing a predetermined |
| 7698 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7699 | // the variable's predetermined data-sharing attributes. |
| 7700 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7701 | // in a Construct, C/C++, p.2] |
| 7702 | // Variables with const-qualified type having no mutable member may be |
| 7703 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7704 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7705 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7706 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7707 | << getOpenMPClauseName(DVar.CKind) |
| 7708 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7709 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7710 | continue; |
| 7711 | } |
| 7712 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7713 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7714 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7715 | // A list item that is private within a parallel region must not appear |
| 7716 | // in a firstprivate clause on a worksharing construct if any of the |
| 7717 | // worksharing regions arising from the worksharing construct ever bind |
| 7718 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7719 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7720 | !isOpenMPParallelDirective(CurrDir) && |
| 7721 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7722 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7723 | if (DVar.CKind != OMPC_shared && |
| 7724 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7725 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7726 | Diag(ELoc, diag::err_omp_required_access) |
| 7727 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7728 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7729 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7730 | continue; |
| 7731 | } |
| 7732 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7733 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7734 | // A list item that appears in a reduction clause of a parallel construct |
| 7735 | // must not appear in a firstprivate clause on a worksharing or task |
| 7736 | // construct if any of the worksharing or task regions arising from the |
| 7737 | // worksharing or task construct ever bind to any of the parallel regions |
| 7738 | // arising from the parallel construct. |
| 7739 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7740 | // A list item that appears in a reduction clause in worksharing |
| 7741 | // construct must not appear in a firstprivate clause in a task construct |
| 7742 | // encountered during execution of any of the worksharing regions arising |
| 7743 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 7744 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 7745 | DVar = DSAStack->hasInnermostDSA( |
| 7746 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 7747 | [](OpenMPDirectiveKind K) -> bool { |
| 7748 | return isOpenMPParallelDirective(K) || |
| 7749 | isOpenMPWorksharingDirective(K); |
| 7750 | }, |
| 7751 | false); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7752 | if (DVar.CKind == OMPC_reduction && |
| 7753 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7754 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7755 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7756 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7757 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7758 | continue; |
| 7759 | } |
| 7760 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7761 | |
| 7762 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7763 | // A list item that is private within a teams region must not appear in a |
| 7764 | // firstprivate clause on a distribute construct if any of the distribute |
| 7765 | // regions arising from the distribute construct ever bind to any of the |
| 7766 | // teams regions arising from the teams construct. |
| 7767 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7768 | // A list item that appears in a reduction clause of a teams construct |
| 7769 | // must not appear in a firstprivate clause on a distribute construct if |
| 7770 | // any of the distribute regions arising from the distribute construct |
| 7771 | // ever bind to any of the teams regions arising from the teams construct. |
| 7772 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7773 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7774 | // both. |
| 7775 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 7776 | DVar = DSAStack->hasInnermostDSA( |
| 7777 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_private; }, |
| 7778 | [](OpenMPDirectiveKind K) -> bool { |
| 7779 | return isOpenMPTeamsDirective(K); |
| 7780 | }, |
| 7781 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7782 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7783 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7784 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7785 | continue; |
| 7786 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 7787 | DVar = DSAStack->hasInnermostDSA( |
| 7788 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 7789 | [](OpenMPDirectiveKind K) -> bool { |
| 7790 | return isOpenMPTeamsDirective(K); |
| 7791 | }, |
| 7792 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7793 | if (DVar.CKind == OMPC_reduction && |
| 7794 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7795 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7796 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7797 | continue; |
| 7798 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7799 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7800 | if (DVar.CKind == OMPC_lastprivate) { |
| 7801 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7802 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7803 | continue; |
| 7804 | } |
| 7805 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7806 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7807 | // A list item cannot appear in both a map clause and a data-sharing |
| 7808 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7809 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7810 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7811 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7812 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 7813 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7814 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 7815 | CurrDir == OMPD_target_parallel_for_simd || |
| 7816 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7817 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 7818 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7819 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7820 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 7821 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 7822 | ConflictKind = WhereFoundClauseKind; |
| 7823 | return true; |
| 7824 | })) { |
| 7825 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7826 | << getOpenMPClauseName(OMPC_firstprivate) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7827 | << getOpenMPClauseName(ConflictKind) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7828 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7829 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7830 | continue; |
| 7831 | } |
| 7832 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7833 | } |
| 7834 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7835 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7836 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 7837 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7838 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7839 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7840 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7841 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7842 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7843 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7844 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7845 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7846 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7847 | continue; |
| 7848 | } |
| 7849 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7850 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7851 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7852 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7853 | // Generate helper private variable and initialize it with the value of the |
| 7854 | // original variable. The address of the original variable is replaced by |
| 7855 | // the address of the new private variable in the CodeGen. This new variable |
| 7856 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7857 | // original variable for proper diagnostics and variable capturing. |
| 7858 | Expr *VDInitRefExpr = nullptr; |
| 7859 | // For arrays generate initializer for single element and replace it by the |
| 7860 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7861 | if (Type->isArrayType()) { |
| 7862 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7863 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7864 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7865 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7866 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7867 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7868 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7869 | InitializedEntity Entity = |
| 7870 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7871 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7872 | |
| 7873 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7874 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7875 | if (Result.isInvalid()) |
| 7876 | VDPrivate->setInvalidDecl(); |
| 7877 | else |
| 7878 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7879 | // Remove temp variable declaration. |
| 7880 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7881 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7882 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 7883 | ".firstprivate.temp"); |
| 7884 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 7885 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7886 | AddInitializerToDecl(VDPrivate, |
| 7887 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 7888 | /*DirectInit=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7889 | } |
| 7890 | if (VDPrivate->isInvalidDecl()) { |
| 7891 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7892 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7893 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7894 | } |
| 7895 | continue; |
| 7896 | } |
| 7897 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7898 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7899 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 7900 | RefExpr->getExprLoc()); |
| 7901 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 7902 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7903 | if (TopDVar.CKind == OMPC_lastprivate) |
| 7904 | Ref = TopDVar.PrivateCopy; |
| 7905 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7906 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7907 | if (!IsOpenMPCapturedDecl(D)) |
| 7908 | ExprCaptures.push_back(Ref->getDecl()); |
| 7909 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7910 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7911 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 7912 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 7913 | ? RefExpr->IgnoreParens() |
| 7914 | : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7915 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7916 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7917 | } |
| 7918 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7919 | if (Vars.empty()) |
| 7920 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7921 | |
| 7922 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7923 | Vars, PrivateCopies, Inits, |
| 7924 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7925 | } |
| 7926 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7927 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7928 | SourceLocation StartLoc, |
| 7929 | SourceLocation LParenLoc, |
| 7930 | SourceLocation EndLoc) { |
| 7931 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7932 | SmallVector<Expr *, 8> SrcExprs; |
| 7933 | SmallVector<Expr *, 8> DstExprs; |
| 7934 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7935 | SmallVector<Decl *, 4> ExprCaptures; |
| 7936 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7937 | for (auto &RefExpr : VarList) { |
| 7938 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7939 | SourceLocation ELoc; |
| 7940 | SourceRange ERange; |
| 7941 | Expr *SimpleRefExpr = RefExpr; |
| 7942 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7943 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7944 | // It will be analyzed later. |
| 7945 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7946 | SrcExprs.push_back(nullptr); |
| 7947 | DstExprs.push_back(nullptr); |
| 7948 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7949 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7950 | ValueDecl *D = Res.first; |
| 7951 | if (!D) |
| 7952 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7953 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7954 | QualType Type = D->getType(); |
| 7955 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7956 | |
| 7957 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7958 | // A variable that appears in a lastprivate clause must not have an |
| 7959 | // incomplete type or a reference type. |
| 7960 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7961 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7962 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7963 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7964 | |
| 7965 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7966 | // in a Construct] |
| 7967 | // Variables with the predetermined data-sharing attributes may not be |
| 7968 | // listed in data-sharing attributes clauses, except for the cases |
| 7969 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7970 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7971 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7972 | DVar.CKind != OMPC_firstprivate && |
| 7973 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7974 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7975 | << getOpenMPClauseName(DVar.CKind) |
| 7976 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7977 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7978 | continue; |
| 7979 | } |
| 7980 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7981 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7982 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7983 | // A list item that is private within a parallel region, or that appears in |
| 7984 | // the reduction clause of a parallel construct, must not appear in a |
| 7985 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7986 | // worksharing regions ever binds to any of the corresponding parallel |
| 7987 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7988 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7989 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7990 | !isOpenMPParallelDirective(CurrDir) && |
| 7991 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7992 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7993 | if (DVar.CKind != OMPC_shared) { |
| 7994 | Diag(ELoc, diag::err_omp_required_access) |
| 7995 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7996 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7997 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7998 | continue; |
| 7999 | } |
| 8000 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8001 | |
| 8002 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8003 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8004 | // both. |
| 8005 | if (CurrDir == OMPD_distribute) { |
| 8006 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 8007 | if (DVar.CKind == OMPC_firstprivate) { |
| 8008 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 8009 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8010 | continue; |
| 8011 | } |
| 8012 | } |
| 8013 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8014 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8015 | // A variable of class type (or array thereof) that appears in a |
| 8016 | // lastprivate clause requires an accessible, unambiguous default |
| 8017 | // constructor for the class type, unless the list item is also specified |
| 8018 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8019 | // A variable of class type (or array thereof) that appears in a |
| 8020 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8021 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8022 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8023 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8024 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8025 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8026 | auto *PseudoSrcExpr = |
| 8027 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8028 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8029 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8030 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8031 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8032 | // For arrays generate assignment operation for single element and replace |
| 8033 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8034 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8035 | PseudoDstExpr, PseudoSrcExpr); |
| 8036 | if (AssignmentOp.isInvalid()) |
| 8037 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8038 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8039 | /*DiscardedValue=*/true); |
| 8040 | if (AssignmentOp.isInvalid()) |
| 8041 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8042 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8043 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8044 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8045 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8046 | Ref = TopDVar.PrivateCopy; |
| 8047 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8048 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8049 | if (!IsOpenMPCapturedDecl(D)) |
| 8050 | ExprCaptures.push_back(Ref->getDecl()); |
| 8051 | } |
| 8052 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8053 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8054 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8055 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8056 | if (!RefRes.isUsable()) |
| 8057 | continue; |
| 8058 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8059 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8060 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8061 | if (!PostUpdateRes.isUsable()) |
| 8062 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8063 | ExprPostUpdates.push_back( |
| 8064 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8065 | } |
| 8066 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8067 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8068 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8069 | ? RefExpr->IgnoreParens() |
| 8070 | : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8071 | SrcExprs.push_back(PseudoSrcExpr); |
| 8072 | DstExprs.push_back(PseudoDstExpr); |
| 8073 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8074 | } |
| 8075 | |
| 8076 | if (Vars.empty()) |
| 8077 | return nullptr; |
| 8078 | |
| 8079 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8080 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8081 | buildPreInits(Context, ExprCaptures), |
| 8082 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8083 | } |
| 8084 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8085 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 8086 | SourceLocation StartLoc, |
| 8087 | SourceLocation LParenLoc, |
| 8088 | SourceLocation EndLoc) { |
| 8089 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8090 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8091 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8092 | SourceLocation ELoc; |
| 8093 | SourceRange ERange; |
| 8094 | Expr *SimpleRefExpr = RefExpr; |
| 8095 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8096 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8097 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8098 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8099 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8100 | ValueDecl *D = Res.first; |
| 8101 | if (!D) |
| 8102 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8103 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8104 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8105 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8106 | // in a Construct] |
| 8107 | // Variables with the predetermined data-sharing attributes may not be |
| 8108 | // listed in data-sharing attributes clauses, except for the cases |
| 8109 | // listed below. For these exceptions only, listing a predetermined |
| 8110 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8111 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8112 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8113 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 8114 | DVar.RefExpr) { |
| 8115 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8116 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8117 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8118 | continue; |
| 8119 | } |
| 8120 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8121 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8122 | if (!VD && IsOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8123 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8124 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8125 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 8126 | ? RefExpr->IgnoreParens() |
| 8127 | : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8128 | } |
| 8129 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8130 | if (Vars.empty()) |
| 8131 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8132 | |
| 8133 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 8134 | } |
| 8135 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8136 | namespace { |
| 8137 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 8138 | DSAStackTy *Stack; |
| 8139 | |
| 8140 | public: |
| 8141 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 8142 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8143 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8144 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 8145 | return false; |
| 8146 | if (DVar.CKind != OMPC_unknown) |
| 8147 | return true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8148 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| 8149 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 8150 | false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8151 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8152 | return true; |
| 8153 | return false; |
| 8154 | } |
| 8155 | return false; |
| 8156 | } |
| 8157 | bool VisitStmt(Stmt *S) { |
| 8158 | for (auto Child : S->children()) { |
| 8159 | if (Child && Visit(Child)) |
| 8160 | return true; |
| 8161 | } |
| 8162 | return false; |
| 8163 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8164 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8165 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8166 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8167 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8168 | namespace { |
| 8169 | // Transform MemberExpression for specified FieldDecl of current class to |
| 8170 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 8171 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 8172 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 8173 | ValueDecl *Field; |
| 8174 | DeclRefExpr *CapturedExpr; |
| 8175 | |
| 8176 | public: |
| 8177 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 8178 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 8179 | |
| 8180 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 8181 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 8182 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8183 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8184 | return CapturedExpr; |
| 8185 | } |
| 8186 | return BaseTransform::TransformMemberExpr(E); |
| 8187 | } |
| 8188 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 8189 | }; |
| 8190 | } // namespace |
| 8191 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8192 | template <typename T> |
| 8193 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 8194 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 8195 | for (auto &Set : Lookups) { |
| 8196 | for (auto *D : Set) { |
| 8197 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 8198 | return Res; |
| 8199 | } |
| 8200 | } |
| 8201 | return T(); |
| 8202 | } |
| 8203 | |
| 8204 | static ExprResult |
| 8205 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 8206 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 8207 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 8208 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 8209 | if (ReductionIdScopeSpec.isInvalid()) |
| 8210 | return ExprError(); |
| 8211 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 8212 | if (S) { |
| 8213 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 8214 | Lookup.suppressDiagnostics(); |
| 8215 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 8216 | auto *D = Lookup.getRepresentativeDecl(); |
| 8217 | do { |
| 8218 | S = S->getParent(); |
| 8219 | } while (S && !S->isDeclScope(D)); |
| 8220 | if (S) |
| 8221 | S = S->getParent(); |
| 8222 | Lookups.push_back(UnresolvedSet<8>()); |
| 8223 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 8224 | Lookup.clear(); |
| 8225 | } |
| 8226 | } else if (auto *ULE = |
| 8227 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 8228 | Lookups.push_back(UnresolvedSet<8>()); |
| 8229 | Decl *PrevD = nullptr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8230 | for (auto *D : ULE->decls()) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8231 | if (D == PrevD) |
| 8232 | Lookups.push_back(UnresolvedSet<8>()); |
| 8233 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 8234 | Lookups.back().addDecl(DRD); |
| 8235 | PrevD = D; |
| 8236 | } |
| 8237 | } |
| 8238 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 8239 | Ty->containsUnexpandedParameterPack() || |
| 8240 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 8241 | return !D->isInvalidDecl() && |
| 8242 | (D->getType()->isDependentType() || |
| 8243 | D->getType()->isInstantiationDependentType() || |
| 8244 | D->getType()->containsUnexpandedParameterPack()); |
| 8245 | })) { |
| 8246 | UnresolvedSet<8> ResSet; |
| 8247 | for (auto &Set : Lookups) { |
| 8248 | ResSet.append(Set.begin(), Set.end()); |
| 8249 | // The last item marks the end of all declarations at the specified scope. |
| 8250 | ResSet.addDecl(Set[Set.size() - 1]); |
| 8251 | } |
| 8252 | return UnresolvedLookupExpr::Create( |
| 8253 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8254 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 8255 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 8256 | } |
| 8257 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8258 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 8259 | if (!D->isInvalidDecl() && |
| 8260 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 8261 | return D; |
| 8262 | return nullptr; |
| 8263 | })) |
| 8264 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8265 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8266 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 8267 | if (!D->isInvalidDecl() && |
| 8268 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 8269 | !Ty.isMoreQualifiedThan(D->getType())) |
| 8270 | return D; |
| 8271 | return nullptr; |
| 8272 | })) { |
| 8273 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 8274 | /*DetectVirtual=*/false); |
| 8275 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 8276 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 8277 | VD->getType().getUnqualifiedType()))) { |
| 8278 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 8279 | /*DiagID=*/0) != |
| 8280 | Sema::AR_inaccessible) { |
| 8281 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 8282 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8283 | } |
| 8284 | } |
| 8285 | } |
| 8286 | } |
| 8287 | if (ReductionIdScopeSpec.isSet()) { |
| 8288 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 8289 | return ExprError(); |
| 8290 | } |
| 8291 | return ExprEmpty(); |
| 8292 | } |
| 8293 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8294 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 8295 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 8296 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8297 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 8298 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8299 | auto DN = ReductionId.getName(); |
| 8300 | auto OOK = DN.getCXXOverloadedOperator(); |
| 8301 | BinaryOperatorKind BOK = BO_Comma; |
| 8302 | |
| 8303 | // OpenMP [2.14.3.6, reduction clause] |
| 8304 | // C |
| 8305 | // reduction-identifier is either an identifier or one of the following |
| 8306 | // operators: +, -, *, &, |, ^, && and || |
| 8307 | // C++ |
| 8308 | // reduction-identifier is either an id-expression or one of the following |
| 8309 | // operators: +, -, *, &, |, ^, && and || |
| 8310 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 8311 | switch (OOK) { |
| 8312 | case OO_Plus: |
| 8313 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8314 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8315 | break; |
| 8316 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8317 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8318 | break; |
| 8319 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8320 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8321 | break; |
| 8322 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8323 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8324 | break; |
| 8325 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8326 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8327 | break; |
| 8328 | case OO_AmpAmp: |
| 8329 | BOK = BO_LAnd; |
| 8330 | break; |
| 8331 | case OO_PipePipe: |
| 8332 | BOK = BO_LOr; |
| 8333 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8334 | case OO_New: |
| 8335 | case OO_Delete: |
| 8336 | case OO_Array_New: |
| 8337 | case OO_Array_Delete: |
| 8338 | case OO_Slash: |
| 8339 | case OO_Percent: |
| 8340 | case OO_Tilde: |
| 8341 | case OO_Exclaim: |
| 8342 | case OO_Equal: |
| 8343 | case OO_Less: |
| 8344 | case OO_Greater: |
| 8345 | case OO_LessEqual: |
| 8346 | case OO_GreaterEqual: |
| 8347 | case OO_PlusEqual: |
| 8348 | case OO_MinusEqual: |
| 8349 | case OO_StarEqual: |
| 8350 | case OO_SlashEqual: |
| 8351 | case OO_PercentEqual: |
| 8352 | case OO_CaretEqual: |
| 8353 | case OO_AmpEqual: |
| 8354 | case OO_PipeEqual: |
| 8355 | case OO_LessLess: |
| 8356 | case OO_GreaterGreater: |
| 8357 | case OO_LessLessEqual: |
| 8358 | case OO_GreaterGreaterEqual: |
| 8359 | case OO_EqualEqual: |
| 8360 | case OO_ExclaimEqual: |
| 8361 | case OO_PlusPlus: |
| 8362 | case OO_MinusMinus: |
| 8363 | case OO_Comma: |
| 8364 | case OO_ArrowStar: |
| 8365 | case OO_Arrow: |
| 8366 | case OO_Call: |
| 8367 | case OO_Subscript: |
| 8368 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 8369 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8370 | case NUM_OVERLOADED_OPERATORS: |
| 8371 | llvm_unreachable("Unexpected reduction identifier"); |
| 8372 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8373 | if (auto II = DN.getAsIdentifierInfo()) { |
| 8374 | if (II->isStr("max")) |
| 8375 | BOK = BO_GT; |
| 8376 | else if (II->isStr("min")) |
| 8377 | BOK = BO_LT; |
| 8378 | } |
| 8379 | break; |
| 8380 | } |
| 8381 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8382 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8383 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8384 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8385 | |
| 8386 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8387 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8388 | SmallVector<Expr *, 8> LHSs; |
| 8389 | SmallVector<Expr *, 8> RHSs; |
| 8390 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8391 | SmallVector<Decl *, 4> ExprCaptures; |
| 8392 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8393 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 8394 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8395 | for (auto RefExpr : VarList) { |
| 8396 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8397 | // OpenMP [2.1, C/C++] |
| 8398 | // A list item is a variable or array section, subject to the restrictions |
| 8399 | // specified in Section 2.4 on page 42 and in each of the sections |
| 8400 | // describing clauses and directives for which a list appears. |
| 8401 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8402 | // A variable that is part of another variable (as an array or |
| 8403 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8404 | if (!FirstIter && IR != ER) |
| 8405 | ++IR; |
| 8406 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8407 | SourceLocation ELoc; |
| 8408 | SourceRange ERange; |
| 8409 | Expr *SimpleRefExpr = RefExpr; |
| 8410 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8411 | /*AllowArraySection=*/true); |
| 8412 | if (Res.second) { |
| 8413 | // It will be analyzed later. |
| 8414 | Vars.push_back(RefExpr); |
| 8415 | Privates.push_back(nullptr); |
| 8416 | LHSs.push_back(nullptr); |
| 8417 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8418 | // Try to find 'declare reduction' corresponding construct before using |
| 8419 | // builtin/overloaded operators. |
| 8420 | QualType Type = Context.DependentTy; |
| 8421 | CXXCastPath BasePath; |
| 8422 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8423 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8424 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8425 | if (CurContext->isDependentContext() && |
| 8426 | (DeclareReductionRef.isUnset() || |
| 8427 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 8428 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8429 | else |
| 8430 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8431 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8432 | ValueDecl *D = Res.first; |
| 8433 | if (!D) |
| 8434 | continue; |
| 8435 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8436 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8437 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 8438 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 8439 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8440 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8441 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8442 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 8443 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 8444 | Type = ATy->getElementType(); |
| 8445 | else |
| 8446 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8447 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8448 | } else |
| 8449 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 8450 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8451 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8452 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8453 | // A variable that appears in a private clause must not have an incomplete |
| 8454 | // type or a reference type. |
| 8455 | if (RequireCompleteType(ELoc, Type, |
| 8456 | diag::err_omp_reduction_incomplete_type)) |
| 8457 | continue; |
| 8458 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8459 | // A list item that appears in a reduction clause must not be |
| 8460 | // const-qualified. |
| 8461 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8462 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8463 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8464 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8465 | bool IsDecl = !VD || |
| 8466 | VD->isThisDeclarationADefinition(Context) == |
| 8467 | VarDecl::DeclarationOnly; |
| 8468 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8469 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8470 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8471 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8472 | continue; |
| 8473 | } |
| 8474 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8475 | // If a list-item is a reference type then it must bind to the same object |
| 8476 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8477 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8478 | VarDecl *VDDef = VD->getDefinition(); |
David Sheinkman | 9258999 | 2016-10-04 14:41:36 +0000 | [diff] [blame] | 8479 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8480 | DSARefChecker Check(DSAStack); |
| 8481 | if (Check.Visit(VDDef->getInit())) { |
| 8482 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8483 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8484 | continue; |
| 8485 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8486 | } |
| 8487 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8488 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8489 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8490 | // in a Construct] |
| 8491 | // Variables with the predetermined data-sharing attributes may not be |
| 8492 | // listed in data-sharing attributes clauses, except for the cases |
| 8493 | // listed below. For these exceptions only, listing a predetermined |
| 8494 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8495 | // the variable's predetermined data-sharing attributes. |
| 8496 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8497 | // Any number of reduction clauses can be specified on the directive, |
| 8498 | // but a list item can appear only once in the reduction clauses for that |
| 8499 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8500 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8501 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8502 | if (DVar.CKind == OMPC_reduction) { |
| 8503 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8504 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8505 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8506 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8507 | } else if (DVar.CKind != OMPC_unknown) { |
| 8508 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8509 | << getOpenMPClauseName(DVar.CKind) |
| 8510 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8511 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8512 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8513 | } |
| 8514 | |
| 8515 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8516 | // A list item that appears in a reduction clause of a worksharing |
| 8517 | // construct must be shared in the parallel regions to which any of the |
| 8518 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8519 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8520 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8521 | !isOpenMPParallelDirective(CurrDir) && |
| 8522 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8523 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8524 | if (DVar.CKind != OMPC_shared) { |
| 8525 | Diag(ELoc, diag::err_omp_required_access) |
| 8526 | << getOpenMPClauseName(OMPC_reduction) |
| 8527 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8528 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8529 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8530 | } |
| 8531 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8532 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8533 | // Try to find 'declare reduction' corresponding construct before using |
| 8534 | // builtin/overloaded operators. |
| 8535 | CXXCastPath BasePath; |
| 8536 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8537 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8538 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8539 | if (DeclareReductionRef.isInvalid()) |
| 8540 | continue; |
| 8541 | if (CurContext->isDependentContext() && |
| 8542 | (DeclareReductionRef.isUnset() || |
| 8543 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 8544 | Vars.push_back(RefExpr); |
| 8545 | Privates.push_back(nullptr); |
| 8546 | LHSs.push_back(nullptr); |
| 8547 | RHSs.push_back(nullptr); |
| 8548 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8549 | continue; |
| 8550 | } |
| 8551 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 8552 | // Not allowed reduction identifier is found. |
| 8553 | Diag(ReductionId.getLocStart(), |
| 8554 | diag::err_omp_unknown_reduction_identifier) |
| 8555 | << Type << ReductionIdRange; |
| 8556 | continue; |
| 8557 | } |
| 8558 | |
| 8559 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 8560 | // The type of a list item that appears in a reduction clause must be valid |
| 8561 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 8562 | // of the list item must be an allowed arithmetic data type: char, int, |
| 8563 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 8564 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 8565 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 8566 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 8567 | if (DeclareReductionRef.isUnset()) { |
| 8568 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 8569 | !(Type->isScalarType() || |
| 8570 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 8571 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 8572 | << getLangOpts().CPlusPlus; |
| 8573 | if (!ASE && !OASE) { |
| 8574 | bool IsDecl = !VD || |
| 8575 | VD->isThisDeclarationADefinition(Context) == |
| 8576 | VarDecl::DeclarationOnly; |
| 8577 | Diag(D->getLocation(), |
| 8578 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8579 | << D; |
| 8580 | } |
| 8581 | continue; |
| 8582 | } |
| 8583 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 8584 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 8585 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 8586 | if (!ASE && !OASE) { |
| 8587 | bool IsDecl = !VD || |
| 8588 | VD->isThisDeclarationADefinition(Context) == |
| 8589 | VarDecl::DeclarationOnly; |
| 8590 | Diag(D->getLocation(), |
| 8591 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8592 | << D; |
| 8593 | } |
| 8594 | continue; |
| 8595 | } |
| 8596 | } |
| 8597 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8598 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8599 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8600 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8601 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8602 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8603 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8604 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8605 | (!ASE && |
| 8606 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8607 | // For arrays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8608 | // Create pseudo array type for private copy. The size for this array will |
| 8609 | // be generated during codegen. |
| 8610 | // For array subscripts or single variables Private Ty is the same as Type |
| 8611 | // (type of the variable or single array element). |
| 8612 | PrivateTy = Context.getVariableArrayType( |
| 8613 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 8614 | Context.getSizeType(), VK_RValue), |
| 8615 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8616 | } else if (!ASE && !OASE && |
| 8617 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 8618 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8619 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8620 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 8621 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8622 | // Add initializer for private variable. |
| 8623 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8624 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8625 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 8626 | if (DeclareReductionRef.isUsable()) { |
| 8627 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 8628 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 8629 | if (DRD->getInitializer()) { |
| 8630 | Init = DRDRef; |
| 8631 | RHSVD->setInit(DRDRef); |
| 8632 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8633 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8634 | } else { |
| 8635 | switch (BOK) { |
| 8636 | case BO_Add: |
| 8637 | case BO_Xor: |
| 8638 | case BO_Or: |
| 8639 | case BO_LOr: |
| 8640 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 8641 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 8642 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 8643 | break; |
| 8644 | case BO_Mul: |
| 8645 | case BO_LAnd: |
| 8646 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8647 | // '*' and '&&' reduction ops - initializer is '1'. |
| 8648 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8649 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8650 | break; |
| 8651 | case BO_And: { |
| 8652 | // '&' reduction op - initializer is '~0'. |
| 8653 | QualType OrigType = Type; |
| 8654 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 8655 | Type = ComplexTy->getElementType(); |
| 8656 | if (Type->isRealFloatingType()) { |
| 8657 | llvm::APFloat InitValue = |
| 8658 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8659 | /*isIEEE=*/true); |
| 8660 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8661 | Type, ELoc); |
| 8662 | } else if (Type->isScalarType()) { |
| 8663 | auto Size = Context.getTypeSize(Type); |
| 8664 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8665 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8666 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8667 | } |
| 8668 | if (Init && OrigType->isAnyComplexType()) { |
| 8669 | // Init = 0xFFFF + 0xFFFFi; |
| 8670 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8671 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8672 | } |
| 8673 | Type = OrigType; |
| 8674 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8675 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8676 | case BO_LT: |
| 8677 | case BO_GT: { |
| 8678 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8679 | // the reduction list item type'. |
| 8680 | // 'max' reduction op - initializer is 'Least representable number in |
| 8681 | // the reduction list item type'. |
| 8682 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8683 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8684 | auto Size = Context.getTypeSize(Type); |
| 8685 | QualType IntTy = |
| 8686 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8687 | llvm::APInt InitValue = |
| 8688 | (BOK != BO_LT) |
| 8689 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8690 | : llvm::APInt::getMinValue(Size) |
| 8691 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8692 | : llvm::APInt::getMaxValue(Size); |
| 8693 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8694 | if (Type->isPointerType()) { |
| 8695 | // Cast to pointer type. |
| 8696 | auto CastExpr = BuildCStyleCastExpr( |
| 8697 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8698 | SourceLocation(), Init); |
| 8699 | if (CastExpr.isInvalid()) |
| 8700 | continue; |
| 8701 | Init = CastExpr.get(); |
| 8702 | } |
| 8703 | } else if (Type->isRealFloatingType()) { |
| 8704 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8705 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8706 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8707 | Type, ELoc); |
| 8708 | } |
| 8709 | break; |
| 8710 | } |
| 8711 | case BO_PtrMemD: |
| 8712 | case BO_PtrMemI: |
| 8713 | case BO_MulAssign: |
| 8714 | case BO_Div: |
| 8715 | case BO_Rem: |
| 8716 | case BO_Sub: |
| 8717 | case BO_Shl: |
| 8718 | case BO_Shr: |
| 8719 | case BO_LE: |
| 8720 | case BO_GE: |
| 8721 | case BO_EQ: |
| 8722 | case BO_NE: |
| 8723 | case BO_AndAssign: |
| 8724 | case BO_XorAssign: |
| 8725 | case BO_OrAssign: |
| 8726 | case BO_Assign: |
| 8727 | case BO_AddAssign: |
| 8728 | case BO_SubAssign: |
| 8729 | case BO_DivAssign: |
| 8730 | case BO_RemAssign: |
| 8731 | case BO_ShlAssign: |
| 8732 | case BO_ShrAssign: |
| 8733 | case BO_Comma: |
| 8734 | llvm_unreachable("Unexpected reduction operation"); |
| 8735 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8736 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8737 | if (Init && DeclareReductionRef.isUnset()) { |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8738 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8739 | } else if (!Init) |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8740 | ActOnUninitializedDecl(RHSVD); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8741 | if (RHSVD->isInvalidDecl()) |
| 8742 | continue; |
| 8743 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8744 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8745 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8746 | bool IsDecl = |
| 8747 | !VD || |
| 8748 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8749 | Diag(D->getLocation(), |
| 8750 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8751 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8752 | continue; |
| 8753 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8754 | // Store initializer for single element in private copy. Will be used during |
| 8755 | // codegen. |
| 8756 | PrivateVD->setInit(RHSVD->getInit()); |
| 8757 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8758 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8759 | ExprResult ReductionOp; |
| 8760 | if (DeclareReductionRef.isUsable()) { |
| 8761 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 8762 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 8763 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 8764 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 8765 | if (!BasePath.empty()) { |
| 8766 | LHS = DefaultLvalueConversion(LHS.get()); |
| 8767 | RHS = DefaultLvalueConversion(RHS.get()); |
| 8768 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8769 | CK_UncheckedDerivedToBase, LHS.get(), |
| 8770 | &BasePath, LHS.get()->getValueKind()); |
| 8771 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8772 | CK_UncheckedDerivedToBase, RHS.get(), |
| 8773 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8774 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8775 | FunctionProtoType::ExtProtoInfo EPI; |
| 8776 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 8777 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 8778 | auto *OVE = new (Context) OpaqueValueExpr( |
| 8779 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 8780 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 8781 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 8782 | ReductionOp = new (Context) |
| 8783 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 8784 | } else { |
| 8785 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 8786 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 8787 | if (ReductionOp.isUsable()) { |
| 8788 | if (BOK != BO_LT && BOK != BO_GT) { |
| 8789 | ReductionOp = |
| 8790 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8791 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8792 | } else { |
| 8793 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8794 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8795 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8796 | ReductionOp = |
| 8797 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8798 | BO_Assign, LHSDRE, ConditionalOp); |
| 8799 | } |
| 8800 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 8801 | } |
| 8802 | if (ReductionOp.isInvalid()) |
| 8803 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8804 | } |
| 8805 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8806 | DeclRefExpr *Ref = nullptr; |
| 8807 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8808 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8809 | if (ASE || OASE) { |
| 8810 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 8811 | VarsExpr = |
| 8812 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 8813 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8814 | } else { |
| 8815 | VarsExpr = Ref = |
| 8816 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8817 | } |
| 8818 | if (!IsOpenMPCapturedDecl(D)) { |
| 8819 | ExprCaptures.push_back(Ref->getDecl()); |
| 8820 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8821 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8822 | if (!RefRes.isUsable()) |
| 8823 | continue; |
| 8824 | ExprResult PostUpdateRes = |
| 8825 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8826 | SimpleRefExpr, RefRes.get()); |
| 8827 | if (!PostUpdateRes.isUsable()) |
| 8828 | continue; |
| 8829 | ExprPostUpdates.push_back( |
| 8830 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8831 | } |
| 8832 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8833 | } |
| 8834 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 8835 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8836 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8837 | LHSs.push_back(LHSDRE); |
| 8838 | RHSs.push_back(RHSDRE); |
| 8839 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8840 | } |
| 8841 | |
| 8842 | if (Vars.empty()) |
| 8843 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8844 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8845 | return OMPReductionClause::Create( |
| 8846 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8847 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8848 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 8849 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8850 | } |
| 8851 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8852 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 8853 | SourceLocation LinLoc) { |
| 8854 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8855 | LinKind == OMPC_LINEAR_unknown) { |
| 8856 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8857 | return true; |
| 8858 | } |
| 8859 | return false; |
| 8860 | } |
| 8861 | |
| 8862 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 8863 | OpenMPLinearClauseKind LinKind, |
| 8864 | QualType Type) { |
| 8865 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 8866 | // A variable must not have an incomplete type or a reference type. |
| 8867 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 8868 | return true; |
| 8869 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 8870 | !Type->isReferenceType()) { |
| 8871 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 8872 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 8873 | return true; |
| 8874 | } |
| 8875 | Type = Type.getNonReferenceType(); |
| 8876 | |
| 8877 | // A list item must not be const-qualified. |
| 8878 | if (Type.isConstant(Context)) { |
| 8879 | Diag(ELoc, diag::err_omp_const_variable) |
| 8880 | << getOpenMPClauseName(OMPC_linear); |
| 8881 | if (D) { |
| 8882 | bool IsDecl = |
| 8883 | !VD || |
| 8884 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8885 | Diag(D->getLocation(), |
| 8886 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8887 | << D; |
| 8888 | } |
| 8889 | return true; |
| 8890 | } |
| 8891 | |
| 8892 | // A list item must be of integral or pointer type. |
| 8893 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 8894 | const auto *Ty = Type.getTypePtrOrNull(); |
| 8895 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8896 | !Ty->isPointerType())) { |
| 8897 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 8898 | if (D) { |
| 8899 | bool IsDecl = |
| 8900 | !VD || |
| 8901 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8902 | Diag(D->getLocation(), |
| 8903 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8904 | << D; |
| 8905 | } |
| 8906 | return true; |
| 8907 | } |
| 8908 | return false; |
| 8909 | } |
| 8910 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8911 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8912 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8913 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8914 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8915 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8916 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8917 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8918 | SmallVector<Decl *, 4> ExprCaptures; |
| 8919 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8920 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8921 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8922 | for (auto &RefExpr : VarList) { |
| 8923 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8924 | SourceLocation ELoc; |
| 8925 | SourceRange ERange; |
| 8926 | Expr *SimpleRefExpr = RefExpr; |
| 8927 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8928 | /*AllowArraySection=*/false); |
| 8929 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8930 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8931 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8932 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8933 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8934 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8935 | ValueDecl *D = Res.first; |
| 8936 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8937 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8938 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8939 | QualType Type = D->getType(); |
| 8940 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8941 | |
| 8942 | // OpenMP [2.14.3.7, linear clause] |
| 8943 | // A list-item cannot appear in more than one linear clause. |
| 8944 | // A list-item that appears in a linear clause cannot appear in any |
| 8945 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8946 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8947 | if (DVar.RefExpr) { |
| 8948 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8949 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8950 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8951 | continue; |
| 8952 | } |
| 8953 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8954 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8955 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8956 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8957 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8958 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8959 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8960 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8961 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8962 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8963 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8964 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8965 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8966 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8967 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8968 | if (!IsOpenMPCapturedDecl(D)) { |
| 8969 | ExprCaptures.push_back(Ref->getDecl()); |
| 8970 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8971 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8972 | if (!RefRes.isUsable()) |
| 8973 | continue; |
| 8974 | ExprResult PostUpdateRes = |
| 8975 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8976 | SimpleRefExpr, RefRes.get()); |
| 8977 | if (!PostUpdateRes.isUsable()) |
| 8978 | continue; |
| 8979 | ExprPostUpdates.push_back( |
| 8980 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 8981 | } |
| 8982 | } |
| 8983 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8984 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8985 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8986 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8987 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8988 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8989 | /*DirectInit=*/false); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8990 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 8991 | |
| 8992 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8993 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8994 | ? RefExpr->IgnoreParens() |
| 8995 | : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8996 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8997 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8998 | } |
| 8999 | |
| 9000 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9001 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9002 | |
| 9003 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9004 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9005 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9006 | !Step->isInstantiationDependent() && |
| 9007 | !Step->containsUnexpandedParameterPack()) { |
| 9008 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9009 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9010 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9011 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9012 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9013 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9014 | // Build var to save the step value. |
| 9015 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9016 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9017 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9018 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9019 | ExprResult CalcStep = |
| 9020 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9021 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9022 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9023 | // Warn about zero linear step (it would be probably better specified as |
| 9024 | // making corresponding variables 'const'). |
| 9025 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9026 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9027 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9028 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9029 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9030 | if (!IsConstant && CalcStep.isUsable()) { |
| 9031 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9032 | // (This is not used if the number of iterations may be kfold-ed). |
| 9033 | CalcStepExpr = CalcStep.get(); |
| 9034 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9035 | } |
| 9036 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9037 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9038 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9039 | StepExpr, CalcStepExpr, |
| 9040 | buildPreInits(Context, ExprCaptures), |
| 9041 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9042 | } |
| 9043 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9044 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9045 | Expr *NumIterations, Sema &SemaRef, |
| 9046 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9047 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9048 | SmallVector<Expr *, 8> Updates; |
| 9049 | SmallVector<Expr *, 8> Finals; |
| 9050 | Expr *Step = Clause.getStep(); |
| 9051 | Expr *CalcStep = Clause.getCalcStep(); |
| 9052 | // OpenMP [2.14.3.7, linear clause] |
| 9053 | // If linear-step is not specified it is assumed to be 1. |
| 9054 | if (Step == nullptr) |
| 9055 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9056 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9057 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9058 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9059 | bool HasErrors = false; |
| 9060 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9061 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9062 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9063 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9064 | SourceLocation ELoc; |
| 9065 | SourceRange ERange; |
| 9066 | Expr *SimpleRefExpr = RefExpr; |
| 9067 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9068 | /*AllowArraySection=*/false); |
| 9069 | ValueDecl *D = Res.first; |
| 9070 | if (Res.second || !D) { |
| 9071 | Updates.push_back(nullptr); |
| 9072 | Finals.push_back(nullptr); |
| 9073 | HasErrors = true; |
| 9074 | continue; |
| 9075 | } |
| 9076 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { |
| 9077 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) |
| 9078 | ->getMemberDecl(); |
| 9079 | } |
| 9080 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9081 | Expr *InitExpr = *CurInit; |
| 9082 | |
| 9083 | // Build privatized reference to the current linear var. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9084 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9085 | Expr *CapturedRef; |
| 9086 | if (LinKind == OMPC_LINEAR_uval) |
| 9087 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 9088 | else |
| 9089 | CapturedRef = |
| 9090 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 9091 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 9092 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9093 | |
| 9094 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9095 | ExprResult Update; |
| 9096 | if (!Info.first) { |
| 9097 | Update = |
| 9098 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 9099 | InitExpr, IV, Step, /* Subtract */ false); |
| 9100 | } else |
| 9101 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9102 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 9103 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9104 | |
| 9105 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9106 | ExprResult Final; |
| 9107 | if (!Info.first) { |
| 9108 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 9109 | InitExpr, NumIterations, Step, |
| 9110 | /* Subtract */ false); |
| 9111 | } else |
| 9112 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9113 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 9114 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9115 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9116 | if (!Update.isUsable() || !Final.isUsable()) { |
| 9117 | Updates.push_back(nullptr); |
| 9118 | Finals.push_back(nullptr); |
| 9119 | HasErrors = true; |
| 9120 | } else { |
| 9121 | Updates.push_back(Update.get()); |
| 9122 | Finals.push_back(Final.get()); |
| 9123 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 9124 | ++CurInit; |
| 9125 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9126 | } |
| 9127 | Clause.setUpdates(Updates); |
| 9128 | Clause.setFinals(Finals); |
| 9129 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9130 | } |
| 9131 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9132 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 9133 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 9134 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 9135 | |
| 9136 | SmallVector<Expr *, 8> Vars; |
| 9137 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9138 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9139 | SourceLocation ELoc; |
| 9140 | SourceRange ERange; |
| 9141 | Expr *SimpleRefExpr = RefExpr; |
| 9142 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9143 | /*AllowArraySection=*/false); |
| 9144 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9145 | // It will be analyzed later. |
| 9146 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9147 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9148 | ValueDecl *D = Res.first; |
| 9149 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9150 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9151 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9152 | QualType QType = D->getType(); |
| 9153 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9154 | |
| 9155 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9156 | // The type of list items appearing in the aligned clause must be |
| 9157 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9158 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9159 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9160 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9161 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9162 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9163 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9164 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9165 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9166 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9167 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9168 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9169 | continue; |
| 9170 | } |
| 9171 | |
| 9172 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9173 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9174 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 9175 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9176 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 9177 | << getOpenMPClauseName(OMPC_aligned); |
| 9178 | continue; |
| 9179 | } |
| 9180 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9181 | DeclRefExpr *Ref = nullptr; |
| 9182 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 9183 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 9184 | Vars.push_back(DefaultFunctionArrayConversion( |
| 9185 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 9186 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9187 | } |
| 9188 | |
| 9189 | // OpenMP [2.8.1, simd construct, Description] |
| 9190 | // The parameter of the aligned clause, alignment, must be a constant |
| 9191 | // positive integer expression. |
| 9192 | // If no optional parameter is specified, implementation-defined default |
| 9193 | // alignments for SIMD instructions on the target platforms are assumed. |
| 9194 | if (Alignment != nullptr) { |
| 9195 | ExprResult AlignResult = |
| 9196 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 9197 | if (AlignResult.isInvalid()) |
| 9198 | return nullptr; |
| 9199 | Alignment = AlignResult.get(); |
| 9200 | } |
| 9201 | if (Vars.empty()) |
| 9202 | return nullptr; |
| 9203 | |
| 9204 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 9205 | EndLoc, Vars, Alignment); |
| 9206 | } |
| 9207 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9208 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 9209 | SourceLocation StartLoc, |
| 9210 | SourceLocation LParenLoc, |
| 9211 | SourceLocation EndLoc) { |
| 9212 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9213 | SmallVector<Expr *, 8> SrcExprs; |
| 9214 | SmallVector<Expr *, 8> DstExprs; |
| 9215 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9216 | for (auto &RefExpr : VarList) { |
| 9217 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 9218 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9219 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9220 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9221 | SrcExprs.push_back(nullptr); |
| 9222 | DstExprs.push_back(nullptr); |
| 9223 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9224 | continue; |
| 9225 | } |
| 9226 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9227 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9228 | // OpenMP [2.1, C/C++] |
| 9229 | // A list item is a variable name. |
| 9230 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 9231 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9232 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9233 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9234 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 9235 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9236 | continue; |
| 9237 | } |
| 9238 | |
| 9239 | Decl *D = DE->getDecl(); |
| 9240 | VarDecl *VD = cast<VarDecl>(D); |
| 9241 | |
| 9242 | QualType Type = VD->getType(); |
| 9243 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 9244 | // It will be analyzed later. |
| 9245 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9246 | SrcExprs.push_back(nullptr); |
| 9247 | DstExprs.push_back(nullptr); |
| 9248 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9249 | continue; |
| 9250 | } |
| 9251 | |
| 9252 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 9253 | // A list item that appears in a copyin clause must be threadprivate. |
| 9254 | if (!DSAStack->isThreadPrivate(VD)) { |
| 9255 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9256 | << getOpenMPClauseName(OMPC_copyin) |
| 9257 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9258 | continue; |
| 9259 | } |
| 9260 | |
| 9261 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9262 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9263 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9264 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9265 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9266 | auto *SrcVD = |
| 9267 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 9268 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9269 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9270 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 9271 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9272 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 9273 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9274 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9275 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9276 | // For arrays generate assignment operation for single element and replace |
| 9277 | // it by the original array element in CodeGen. |
| 9278 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 9279 | PseudoDstExpr, PseudoSrcExpr); |
| 9280 | if (AssignmentOp.isInvalid()) |
| 9281 | continue; |
| 9282 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 9283 | /*DiscardedValue=*/true); |
| 9284 | if (AssignmentOp.isInvalid()) |
| 9285 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9286 | |
| 9287 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 9288 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9289 | SrcExprs.push_back(PseudoSrcExpr); |
| 9290 | DstExprs.push_back(PseudoDstExpr); |
| 9291 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9292 | } |
| 9293 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9294 | if (Vars.empty()) |
| 9295 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9296 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9297 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 9298 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9299 | } |
| 9300 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9301 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 9302 | SourceLocation StartLoc, |
| 9303 | SourceLocation LParenLoc, |
| 9304 | SourceLocation EndLoc) { |
| 9305 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9306 | SmallVector<Expr *, 8> SrcExprs; |
| 9307 | SmallVector<Expr *, 8> DstExprs; |
| 9308 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9309 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9310 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9311 | SourceLocation ELoc; |
| 9312 | SourceRange ERange; |
| 9313 | Expr *SimpleRefExpr = RefExpr; |
| 9314 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9315 | /*AllowArraySection=*/false); |
| 9316 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9317 | // It will be analyzed later. |
| 9318 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9319 | SrcExprs.push_back(nullptr); |
| 9320 | DstExprs.push_back(nullptr); |
| 9321 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9322 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9323 | ValueDecl *D = Res.first; |
| 9324 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9325 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9326 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9327 | QualType Type = D->getType(); |
| 9328 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9329 | |
| 9330 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 9331 | // A list item that appears in a copyprivate clause may not appear in a |
| 9332 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9333 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 9334 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9335 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 9336 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9337 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9338 | << getOpenMPClauseName(DVar.CKind) |
| 9339 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9340 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9341 | continue; |
| 9342 | } |
| 9343 | |
| 9344 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 9345 | // All list items that appear in a copyprivate clause must be either |
| 9346 | // threadprivate or private in the enclosing context. |
| 9347 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9348 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9349 | if (DVar.CKind == OMPC_shared) { |
| 9350 | Diag(ELoc, diag::err_omp_required_access) |
| 9351 | << getOpenMPClauseName(OMPC_copyprivate) |
| 9352 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9353 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9354 | continue; |
| 9355 | } |
| 9356 | } |
| 9357 | } |
| 9358 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9359 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9360 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9361 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9362 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 9363 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9364 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9365 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9366 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9367 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9368 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9369 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9370 | continue; |
| 9371 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9372 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9373 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9374 | // A variable of class type (or array thereof) that appears in a |
| 9375 | // copyin clause requires an accessible, unambiguous copy assignment |
| 9376 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9377 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 9378 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9379 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9380 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 9381 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9382 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9383 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9384 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 9385 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9386 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9387 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9388 | PseudoDstExpr, PseudoSrcExpr); |
| 9389 | if (AssignmentOp.isInvalid()) |
| 9390 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9391 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9392 | /*DiscardedValue=*/true); |
| 9393 | if (AssignmentOp.isInvalid()) |
| 9394 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9395 | |
| 9396 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 9397 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9398 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 9399 | Vars.push_back( |
| 9400 | VD ? RefExpr->IgnoreParens() |
| 9401 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9402 | SrcExprs.push_back(PseudoSrcExpr); |
| 9403 | DstExprs.push_back(PseudoDstExpr); |
| 9404 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9405 | } |
| 9406 | |
| 9407 | if (Vars.empty()) |
| 9408 | return nullptr; |
| 9409 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9410 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9411 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9412 | } |
| 9413 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9414 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 9415 | SourceLocation StartLoc, |
| 9416 | SourceLocation LParenLoc, |
| 9417 | SourceLocation EndLoc) { |
| 9418 | if (VarList.empty()) |
| 9419 | return nullptr; |
| 9420 | |
| 9421 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 9422 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9423 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9424 | OMPClause * |
| 9425 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 9426 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 9427 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9428 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9429 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9430 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9431 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9432 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9433 | return nullptr; |
| 9434 | } |
| 9435 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9436 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 9437 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9438 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9439 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9440 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 9441 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 9442 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9443 | return nullptr; |
| 9444 | } |
| 9445 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9446 | DSAStackTy::OperatorOffsetTy OpsOffs; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9447 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 9448 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 9449 | if (DepKind == OMPC_DEPEND_sink) { |
| 9450 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 9451 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 9452 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9453 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9454 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9455 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 9456 | DSAStack->getParentOrderedRegionParam()) { |
| 9457 | for (auto &RefExpr : VarList) { |
| 9458 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9459 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9460 | // It will be analyzed later. |
| 9461 | Vars.push_back(RefExpr); |
| 9462 | continue; |
| 9463 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9464 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9465 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 9466 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 9467 | if (DepKind == OMPC_DEPEND_sink) { |
| 9468 | if (DepCounter >= TotalDepCount) { |
| 9469 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 9470 | continue; |
| 9471 | } |
| 9472 | ++DepCounter; |
| 9473 | // OpenMP [2.13.9, Summary] |
| 9474 | // depend(dependence-type : vec), where dependence-type is: |
| 9475 | // 'sink' and where vec is the iteration vector, which has the form: |
| 9476 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 9477 | // where n is the value specified by the ordered clause in the loop |
| 9478 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 9479 | // loop associated with the loop directive, and di is a constant |
| 9480 | // non-negative integer. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9481 | if (CurContext->isDependentContext()) { |
| 9482 | // It will be analyzed later. |
| 9483 | Vars.push_back(RefExpr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9484 | continue; |
| 9485 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9486 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 9487 | OverloadedOperatorKind OOK = OO_None; |
| 9488 | SourceLocation OOLoc; |
| 9489 | Expr *LHS = SimpleExpr; |
| 9490 | Expr *RHS = nullptr; |
| 9491 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 9492 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 9493 | OOLoc = BO->getOperatorLoc(); |
| 9494 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 9495 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 9496 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 9497 | OOK = OCE->getOperator(); |
| 9498 | OOLoc = OCE->getOperatorLoc(); |
| 9499 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9500 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 9501 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 9502 | OOK = MCE->getMethodDecl() |
| 9503 | ->getNameInfo() |
| 9504 | .getName() |
| 9505 | .getCXXOverloadedOperator(); |
| 9506 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 9507 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 9508 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9509 | } |
| 9510 | SourceLocation ELoc; |
| 9511 | SourceRange ERange; |
| 9512 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 9513 | /*AllowArraySection=*/false); |
| 9514 | if (Res.second) { |
| 9515 | // It will be analyzed later. |
| 9516 | Vars.push_back(RefExpr); |
| 9517 | } |
| 9518 | ValueDecl *D = Res.first; |
| 9519 | if (!D) |
| 9520 | continue; |
| 9521 | |
| 9522 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 9523 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 9524 | continue; |
| 9525 | } |
| 9526 | if (RHS) { |
| 9527 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 9528 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 9529 | if (RHSRes.isInvalid()) |
| 9530 | continue; |
| 9531 | } |
| 9532 | if (!CurContext->isDependentContext() && |
| 9533 | DSAStack->getParentOrderedRegionParam() && |
| 9534 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| 9535 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9536 | << DSAStack->getParentLoopControlVariable( |
| 9537 | DepCounter.getZExtValue()); |
| 9538 | continue; |
| 9539 | } |
| 9540 | OpsOffs.push_back({RHS, OOK}); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9541 | } else { |
| 9542 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 9543 | // A variable that is part of another variable (such as a field of a |
| 9544 | // structure) but is not an array element or an array section cannot |
| 9545 | // appear in a depend clause. |
| 9546 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9547 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 9548 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 9549 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 9550 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9551 | (ASE && |
| 9552 | !ASE->getBase() |
| 9553 | ->getType() |
| 9554 | .getNonReferenceType() |
| 9555 | ->isPointerType() && |
| 9556 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9557 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 9558 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9559 | continue; |
| 9560 | } |
| 9561 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9562 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 9563 | } |
| 9564 | |
| 9565 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 9566 | TotalDepCount > VarList.size() && |
| 9567 | DSAStack->getParentOrderedRegionParam()) { |
| 9568 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9569 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 9570 | } |
| 9571 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 9572 | Vars.empty()) |
| 9573 | return nullptr; |
| 9574 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9575 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9576 | DepKind, DepLoc, ColonLoc, Vars); |
| 9577 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) |
| 9578 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 9579 | return C; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9580 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9581 | |
| 9582 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 9583 | SourceLocation LParenLoc, |
| 9584 | SourceLocation EndLoc) { |
| 9585 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9586 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9587 | // OpenMP [2.9.1, Restrictions] |
| 9588 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9589 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 9590 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9591 | return nullptr; |
| 9592 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9593 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9594 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9595 | |
| 9596 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 9597 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 9598 | if (!RD || RD->isInvalidDecl()) |
| 9599 | return true; |
| 9600 | |
| 9601 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 9602 | if (RD->isDynamicClass()) { |
| 9603 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9604 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 9605 | return false; |
| 9606 | } |
| 9607 | auto *DC = RD; |
| 9608 | bool IsCorrect = true; |
| 9609 | for (auto *I : DC->decls()) { |
| 9610 | if (I) { |
| 9611 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 9612 | if (MD->isStatic()) { |
| 9613 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9614 | SemaRef.Diag(MD->getLocation(), |
| 9615 | diag::note_omp_static_member_in_target); |
| 9616 | IsCorrect = false; |
| 9617 | } |
| 9618 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 9619 | if (VD->isStaticDataMember()) { |
| 9620 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9621 | SemaRef.Diag(VD->getLocation(), |
| 9622 | diag::note_omp_static_member_in_target); |
| 9623 | IsCorrect = false; |
| 9624 | } |
| 9625 | } |
| 9626 | } |
| 9627 | } |
| 9628 | |
| 9629 | for (auto &I : RD->bases()) { |
| 9630 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 9631 | I.getType()->getAsCXXRecordDecl())) |
| 9632 | IsCorrect = false; |
| 9633 | } |
| 9634 | return IsCorrect; |
| 9635 | } |
| 9636 | |
| 9637 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 9638 | DSAStackTy *Stack, QualType QTy) { |
| 9639 | NamedDecl *ND; |
| 9640 | if (QTy->isIncompleteType(&ND)) { |
| 9641 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 9642 | return false; |
| 9643 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9644 | if (!RD->isInvalidDecl() && !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9645 | return false; |
| 9646 | } |
| 9647 | return true; |
| 9648 | } |
| 9649 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9650 | /// \brief Return true if it can be proven that the provided array expression |
| 9651 | /// (array section or array subscript) does NOT specify the whole size of the |
| 9652 | /// array whose base type is \a BaseQTy. |
| 9653 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 9654 | const Expr *E, |
| 9655 | QualType BaseQTy) { |
| 9656 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9657 | |
| 9658 | // If this is an array subscript, it refers to the whole size if the size of |
| 9659 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 9660 | // format of an array subscript if no colon is used. |
| 9661 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 9662 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9663 | return ATy->getSize().getSExtValue() != 1; |
| 9664 | // Size can't be evaluated statically. |
| 9665 | return false; |
| 9666 | } |
| 9667 | |
| 9668 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9669 | auto *LowerBound = OASE->getLowerBound(); |
| 9670 | auto *Length = OASE->getLength(); |
| 9671 | |
| 9672 | // 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] | 9673 | // covering the whole dimension. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9674 | if (LowerBound) { |
| 9675 | llvm::APSInt ConstLowerBound; |
| 9676 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 9677 | return false; // Can't get the integer value as a constant. |
| 9678 | if (ConstLowerBound.getSExtValue()) |
| 9679 | return true; |
| 9680 | } |
| 9681 | |
| 9682 | // If we don't have a length we covering the whole dimension. |
| 9683 | if (!Length) |
| 9684 | return false; |
| 9685 | |
| 9686 | // If the base is a pointer, we don't have a way to get the size of the |
| 9687 | // pointee. |
| 9688 | if (BaseQTy->isPointerType()) |
| 9689 | return false; |
| 9690 | |
| 9691 | // We can only check if the length is the same as the size of the dimension |
| 9692 | // if we have a constant array. |
| 9693 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 9694 | if (!CATy) |
| 9695 | return false; |
| 9696 | |
| 9697 | llvm::APSInt ConstLength; |
| 9698 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9699 | return false; // Can't get the integer value as a constant. |
| 9700 | |
| 9701 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 9702 | } |
| 9703 | |
| 9704 | // Return true if it can be proven that the provided array expression (array |
| 9705 | // section or array subscript) does NOT specify a single element of the array |
| 9706 | // whose base type is \a BaseQTy. |
| 9707 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9708 | const Expr *E, |
| 9709 | QualType BaseQTy) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9710 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9711 | |
| 9712 | // An array subscript always refer to a single element. Also, an array section |
| 9713 | // assumes the format of an array subscript if no colon is used. |
| 9714 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 9715 | return false; |
| 9716 | |
| 9717 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9718 | auto *Length = OASE->getLength(); |
| 9719 | |
| 9720 | // If we don't have a length we have to check if the array has unitary size |
| 9721 | // for this dimension. Also, we should always expect a length if the base type |
| 9722 | // is pointer. |
| 9723 | if (!Length) { |
| 9724 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9725 | return ATy->getSize().getSExtValue() != 1; |
| 9726 | // We cannot assume anything. |
| 9727 | return false; |
| 9728 | } |
| 9729 | |
| 9730 | // Check if the length evaluates to 1. |
| 9731 | llvm::APSInt ConstLength; |
| 9732 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9733 | return false; // Can't get the integer value as a constant. |
| 9734 | |
| 9735 | return ConstLength.getSExtValue() != 1; |
| 9736 | } |
| 9737 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9738 | // Return the expression of the base of the mappable expression or null if it |
| 9739 | // cannot be determined and do all the necessary checks to see if the expression |
| 9740 | // 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] | 9741 | // components of the expression. |
| 9742 | static Expr *CheckMapClauseExpressionBase( |
| 9743 | Sema &SemaRef, Expr *E, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9744 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| 9745 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9746 | SourceLocation ELoc = E->getExprLoc(); |
| 9747 | SourceRange ERange = E->getSourceRange(); |
| 9748 | |
| 9749 | // The base of elements of list in a map clause have to be either: |
| 9750 | // - a reference to variable or field. |
| 9751 | // - a member expression. |
| 9752 | // - an array expression. |
| 9753 | // |
| 9754 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 9755 | // reference to 'r'. |
| 9756 | // |
| 9757 | // If we have: |
| 9758 | // |
| 9759 | // struct SS { |
| 9760 | // Bla S; |
| 9761 | // foo() { |
| 9762 | // #pragma omp target map (S.Arr[:12]); |
| 9763 | // } |
| 9764 | // } |
| 9765 | // |
| 9766 | // We want to retrieve the member expression 'this->S'; |
| 9767 | |
| 9768 | Expr *RelevantExpr = nullptr; |
| 9769 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9770 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 9771 | // If a list item is an array section, it must specify contiguous storage. |
| 9772 | // |
| 9773 | // For this restriction it is sufficient that we make sure only references |
| 9774 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9775 | // exist except in the rightmost expression (unless they cover the whole |
| 9776 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9777 | // |
| 9778 | // r.ArrS[3:5].Arr[6:7] |
| 9779 | // |
| 9780 | // r.ArrS[3:5].x |
| 9781 | // |
| 9782 | // but these would be valid: |
| 9783 | // r.ArrS[3].Arr[6:7] |
| 9784 | // |
| 9785 | // r.ArrS[3].x |
| 9786 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9787 | bool AllowUnitySizeArraySection = true; |
| 9788 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9789 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 9790 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9791 | E = E->IgnoreParenImpCasts(); |
| 9792 | |
| 9793 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 9794 | if (!isa<VarDecl>(CurE->getDecl())) |
| 9795 | break; |
| 9796 | |
| 9797 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9798 | |
| 9799 | // If we got a reference to a declaration, we should not expect any array |
| 9800 | // section before that. |
| 9801 | AllowUnitySizeArraySection = false; |
| 9802 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9803 | |
| 9804 | // Record the component. |
| 9805 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 9806 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9807 | continue; |
| 9808 | } |
| 9809 | |
| 9810 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 9811 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9812 | |
| 9813 | if (isa<CXXThisExpr>(BaseE)) |
| 9814 | // We found a base expression: this->Val. |
| 9815 | RelevantExpr = CurE; |
| 9816 | else |
| 9817 | E = BaseE; |
| 9818 | |
| 9819 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 9820 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 9821 | << CurE->getSourceRange(); |
| 9822 | break; |
| 9823 | } |
| 9824 | |
| 9825 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 9826 | |
| 9827 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 9828 | // A bit-field cannot appear in a map clause. |
| 9829 | // |
| 9830 | if (FD->isBitField()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9831 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 9832 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9833 | break; |
| 9834 | } |
| 9835 | |
| 9836 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9837 | // If the type of a list item is a reference to a type T then the type |
| 9838 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9839 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9840 | |
| 9841 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9842 | // A list item cannot be a variable that is a member of a structure with |
| 9843 | // a union type. |
| 9844 | // |
| 9845 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9846 | if (RT->isUnionType()) { |
| 9847 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9848 | << CurE->getSourceRange(); |
| 9849 | break; |
| 9850 | } |
| 9851 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9852 | // If we got a member expression, we should not expect any array section |
| 9853 | // before that: |
| 9854 | // |
| 9855 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9856 | // If a list item is an element of a structure, only the rightmost symbol |
| 9857 | // of the variable reference can be an array section. |
| 9858 | // |
| 9859 | AllowUnitySizeArraySection = false; |
| 9860 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9861 | |
| 9862 | // Record the component. |
| 9863 | CurComponents.push_back( |
| 9864 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9865 | continue; |
| 9866 | } |
| 9867 | |
| 9868 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9869 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9870 | |
| 9871 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9872 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9873 | << 0 << CurE->getSourceRange(); |
| 9874 | break; |
| 9875 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9876 | |
| 9877 | // If we got an array subscript that express the whole dimension we |
| 9878 | // can have any array expressions before. If it only expressing part of |
| 9879 | // the dimension, we can only have unitary-size array expressions. |
| 9880 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 9881 | E->getType())) |
| 9882 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9883 | |
| 9884 | // Record the component - we don't have any declaration associated. |
| 9885 | CurComponents.push_back( |
| 9886 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9887 | continue; |
| 9888 | } |
| 9889 | |
| 9890 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9891 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9892 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9893 | auto CurType = |
| 9894 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 9895 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9896 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9897 | // If the type of a list item is a reference to a type T then the type |
| 9898 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9899 | if (CurType->isReferenceType()) |
| 9900 | CurType = CurType->getPointeeType(); |
| 9901 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9902 | bool IsPointer = CurType->isAnyPointerType(); |
| 9903 | |
| 9904 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9905 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9906 | << 0 << CurE->getSourceRange(); |
| 9907 | break; |
| 9908 | } |
| 9909 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9910 | bool NotWhole = |
| 9911 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 9912 | bool NotUnity = |
| 9913 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 9914 | |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 9915 | if (AllowWholeSizeArraySection) { |
| 9916 | // Any array section is currently allowed. Allowing a whole size array |
| 9917 | // section implies allowing a unity array section as well. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9918 | // |
| 9919 | // If this array section refers to the whole dimension we can still |
| 9920 | // accept other array sections before this one, except if the base is a |
| 9921 | // pointer. Otherwise, only unitary sections are accepted. |
| 9922 | if (NotWhole || IsPointer) |
| 9923 | AllowWholeSizeArraySection = false; |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 9924 | } else if (AllowUnitySizeArraySection && NotUnity) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9925 | // A unity or whole array section is not allowed and that is not |
| 9926 | // compatible with the properties of the current array section. |
| 9927 | SemaRef.Diag( |
| 9928 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 9929 | << CurE->getSourceRange(); |
| 9930 | break; |
| 9931 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9932 | |
| 9933 | // Record the component - we don't have any declaration associated. |
| 9934 | CurComponents.push_back( |
| 9935 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9936 | continue; |
| 9937 | } |
| 9938 | |
| 9939 | // If nothing else worked, this is not a valid map clause expression. |
| 9940 | SemaRef.Diag(ELoc, |
| 9941 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9942 | << ERange; |
| 9943 | break; |
| 9944 | } |
| 9945 | |
| 9946 | return RelevantExpr; |
| 9947 | } |
| 9948 | |
| 9949 | // Return true if expression E associated with value VD has conflicts with other |
| 9950 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9951 | static bool CheckMapConflicts( |
| 9952 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 9953 | bool CurrentRegionOnly, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9954 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 9955 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9956 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9957 | SourceLocation ELoc = E->getExprLoc(); |
| 9958 | SourceRange ERange = E->getSourceRange(); |
| 9959 | |
| 9960 | // In order to easily check the conflicts we need to match each component of |
| 9961 | // the expression under test with the components of the expressions that are |
| 9962 | // already in the stack. |
| 9963 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9964 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9965 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9966 | "Map clause expression with unexpected base!"); |
| 9967 | |
| 9968 | // Variables to help detecting enclosing problems in data environment nests. |
| 9969 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9970 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9971 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9972 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 9973 | VD, CurrentRegionOnly, |
| 9974 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 9975 | StackComponents, |
| 9976 | OpenMPClauseKind) -> bool { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9977 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9978 | assert(!StackComponents.empty() && |
| 9979 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9980 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9981 | "Map clause expression with unexpected base!"); |
| 9982 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9983 | // The whole expression in the stack. |
| 9984 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 9985 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9986 | // Expressions must start from the same base. Here we detect at which |
| 9987 | // point both expressions diverge from each other and see if we can |
| 9988 | // detect if the memory referred to both expressions is contiguous and |
| 9989 | // do not overlap. |
| 9990 | auto CI = CurComponents.rbegin(); |
| 9991 | auto CE = CurComponents.rend(); |
| 9992 | auto SI = StackComponents.rbegin(); |
| 9993 | auto SE = StackComponents.rend(); |
| 9994 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 9995 | |
| 9996 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 9997 | // At most one list item can be an array item derived from a given |
| 9998 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9999 | if (CurrentRegionOnly && |
| 10000 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10001 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10002 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10003 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10004 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10005 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10006 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10007 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10008 | diag::note_used_here) |
| 10009 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10010 | return true; |
| 10011 | } |
| 10012 | |
| 10013 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10014 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10015 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10016 | break; |
| 10017 | |
| 10018 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10019 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10020 | break; |
| 10021 | } |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10022 | // Check if the extra components of the expressions in the enclosing |
| 10023 | // data environment are redundant for the current base declaration. |
| 10024 | // If they are, the maps completely overlap, which is legal. |
| 10025 | for (; SI != SE; ++SI) { |
| 10026 | QualType Type; |
| 10027 | if (auto *ASE = |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10028 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10029 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10030 | } else if (auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| 10031 | SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10032 | auto *E = OASE->getBase()->IgnoreParenImpCasts(); |
| 10033 | Type = |
| 10034 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10035 | } |
| 10036 | if (Type.isNull() || Type->isAnyPointerType() || |
| 10037 | CheckArrayExpressionDoesNotReferToWholeSize( |
| 10038 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 10039 | break; |
| 10040 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10041 | |
| 10042 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10043 | // List items of map clauses in the same construct must not share |
| 10044 | // original storage. |
| 10045 | // |
| 10046 | // If the expressions are exactly the same or one is a subset of the |
| 10047 | // other, it means they are sharing storage. |
| 10048 | if (CI == CE && SI == SE) { |
| 10049 | if (CurrentRegionOnly) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10050 | if (CKind == OMPC_map) |
| 10051 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10052 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10053 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10054 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10055 | << ERange; |
| 10056 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10057 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10058 | << RE->getSourceRange(); |
| 10059 | return true; |
| 10060 | } else { |
| 10061 | // If we find the same expression in the enclosing data environment, |
| 10062 | // that is legal. |
| 10063 | IsEnclosedByDataEnvironmentExpr = true; |
| 10064 | return false; |
| 10065 | } |
| 10066 | } |
| 10067 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10068 | QualType DerivedType = |
| 10069 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10070 | SourceLocation DerivedLoc = |
| 10071 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10072 | |
| 10073 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10074 | // If the type of a list item is a reference to a type T then the type |
| 10075 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10076 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10077 | |
| 10078 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 10079 | // A variable for which the type is pointer and an array section |
| 10080 | // derived from that variable must not appear as list items of map |
| 10081 | // clauses of the same construct. |
| 10082 | // |
| 10083 | // Also, cover one of the cases in: |
| 10084 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10085 | // If any part of the original storage of a list item has corresponding |
| 10086 | // storage in the device data environment, all of the original storage |
| 10087 | // must have corresponding storage in the device data environment. |
| 10088 | // |
| 10089 | if (DerivedType->isAnyPointerType()) { |
| 10090 | if (CI == CE || SI == SE) { |
| 10091 | SemaRef.Diag( |
| 10092 | DerivedLoc, |
| 10093 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 10094 | << DerivedLoc; |
| 10095 | } else { |
| 10096 | assert(CI != CE && SI != SE); |
| 10097 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 10098 | << DerivedLoc; |
| 10099 | } |
| 10100 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10101 | << RE->getSourceRange(); |
| 10102 | return true; |
| 10103 | } |
| 10104 | |
| 10105 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10106 | // List items of map clauses in the same construct must not share |
| 10107 | // original storage. |
| 10108 | // |
| 10109 | // An expression is a subset of the other. |
| 10110 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10111 | if (CKind == OMPC_map) |
| 10112 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10113 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10114 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10115 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10116 | << ERange; |
| 10117 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10118 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10119 | << RE->getSourceRange(); |
| 10120 | return true; |
| 10121 | } |
| 10122 | |
| 10123 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10124 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10125 | if (!CurrentRegionOnly && SI != SE) |
| 10126 | EnclosingExpr = RE; |
| 10127 | |
| 10128 | // The current expression is a subset of the expression in the data |
| 10129 | // environment. |
| 10130 | IsEnclosedByDataEnvironmentExpr |= |
| 10131 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 10132 | |
| 10133 | return false; |
| 10134 | }); |
| 10135 | |
| 10136 | if (CurrentRegionOnly) |
| 10137 | return FoundError; |
| 10138 | |
| 10139 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10140 | // If any part of the original storage of a list item has corresponding |
| 10141 | // storage in the device data environment, all of the original storage must |
| 10142 | // have corresponding storage in the device data environment. |
| 10143 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 10144 | // If a list item is an element of a structure, and a different element of |
| 10145 | // the structure has a corresponding list item in the device data environment |
| 10146 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10147 | // 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] | 10148 | // data environment prior to the task encountering the construct. |
| 10149 | // |
| 10150 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 10151 | SemaRef.Diag(ELoc, |
| 10152 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 10153 | << ERange; |
| 10154 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 10155 | << EnclosingExpr->getSourceRange(); |
| 10156 | return true; |
| 10157 | } |
| 10158 | |
| 10159 | return FoundError; |
| 10160 | } |
| 10161 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10162 | namespace { |
| 10163 | // Utility struct that gathers all the related lists associated with a mappable |
| 10164 | // expression. |
| 10165 | struct MappableVarListInfo final { |
| 10166 | // The list of expressions. |
| 10167 | ArrayRef<Expr *> VarList; |
| 10168 | // The list of processed expressions. |
| 10169 | SmallVector<Expr *, 16> ProcessedVarList; |
| 10170 | // The mappble components for each expression. |
| 10171 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 10172 | // The base declaration of the variable. |
| 10173 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 10174 | |
| 10175 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 10176 | // We have a list of components and base declarations for each entry in the |
| 10177 | // variable list. |
| 10178 | VarComponents.reserve(VarList.size()); |
| 10179 | VarBaseDeclarations.reserve(VarList.size()); |
| 10180 | } |
| 10181 | }; |
| 10182 | } |
| 10183 | |
| 10184 | // Check the validity of the provided variable list for the provided clause kind |
| 10185 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 10186 | // components and variables are extracted and used to fill \a Vars, |
| 10187 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 10188 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 10189 | static void |
| 10190 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 10191 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 10192 | SourceLocation StartLoc, |
| 10193 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 10194 | bool IsMapTypeImplicit = false) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10195 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 10196 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10197 | "Unexpected clause kind with mappable expressions!"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10198 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10199 | // Keep track of the mappable components and base declarations in this clause. |
| 10200 | // Each entry in the list is going to have a list of components associated. We |
| 10201 | // record each set of the components so that we can build the clause later on. |
| 10202 | // In the end we should have the same amount of declarations and component |
| 10203 | // lists. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10204 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10205 | for (auto &RE : MVLI.VarList) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10206 | assert(RE && "Null expr in omp to/from/map clause"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10207 | SourceLocation ELoc = RE->getExprLoc(); |
| 10208 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10209 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 10210 | |
| 10211 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 10212 | VE->isInstantiationDependent() || |
| 10213 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10214 | // We can only analyze this information once the missing information is |
| 10215 | // resolved. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10216 | MVLI.ProcessedVarList.push_back(RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10217 | continue; |
| 10218 | } |
| 10219 | |
| 10220 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10221 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10222 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10223 | SemaRef.Diag(ELoc, |
| 10224 | diag::err_omp_expected_named_var_member_or_array_expression) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10225 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10226 | continue; |
| 10227 | } |
| 10228 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10229 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 10230 | ValueDecl *CurDeclaration = nullptr; |
| 10231 | |
| 10232 | // Obtain the array or member expression bases if required. Also, fill the |
| 10233 | // components array with all the components identified in the process. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10234 | auto *BE = |
| 10235 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10236 | if (!BE) |
| 10237 | continue; |
| 10238 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10239 | assert(!CurComponents.empty() && |
| 10240 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10241 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10242 | // For the following checks, we rely on the base declaration which is |
| 10243 | // expected to be associated with the last component. The declaration is |
| 10244 | // expected to be a variable or a field (if 'this' is being mapped). |
| 10245 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 10246 | assert(CurDeclaration && "Null decl on map clause."); |
| 10247 | assert( |
| 10248 | CurDeclaration->isCanonicalDecl() && |
| 10249 | "Expecting components to have associated only canonical declarations."); |
| 10250 | |
| 10251 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 10252 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10253 | |
| 10254 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 10255 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10256 | |
| 10257 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10258 | // threadprivate variables cannot appear in a map clause. |
| 10259 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 10260 | // threadprivate variables cannot appear in a from clause. |
| 10261 | if (VD && DSAS->isThreadPrivate(VD)) { |
| 10262 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10263 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 10264 | << getOpenMPClauseName(CKind); |
| 10265 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10266 | continue; |
| 10267 | } |
| 10268 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10269 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 10270 | // A list item cannot appear in both a map clause and a data-sharing |
| 10271 | // attribute clause on the same construct. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10272 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10273 | // Check conflicts with other map clause expressions. We check the conflicts |
| 10274 | // with the current construct separately from the enclosing data |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10275 | // environment, because the restrictions are different. We only have to |
| 10276 | // check conflicts across regions for the map clauses. |
| 10277 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10278 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10279 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10280 | if (CKind == OMPC_map && |
| 10281 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10282 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10283 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10284 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10285 | // OpenMP 4.5 [2.10.5, target update Construct] |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10286 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10287 | // If the type of a list item is a reference to a type T then the type will |
| 10288 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10289 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10290 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10291 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 10292 | // 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] | 10293 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10294 | // A list item must have a mappable type. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10295 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| 10296 | DSAS, Type)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10297 | continue; |
| 10298 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10299 | if (CKind == OMPC_map) { |
| 10300 | // target enter data |
| 10301 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 10302 | // A map-type must be specified in all map clauses and must be either |
| 10303 | // to or alloc. |
| 10304 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 10305 | if (DKind == OMPD_target_enter_data && |
| 10306 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 10307 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10308 | << (IsMapTypeImplicit ? 1 : 0) |
| 10309 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10310 | << getOpenMPDirectiveName(DKind); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10311 | continue; |
| 10312 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10313 | |
| 10314 | // target exit_data |
| 10315 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 10316 | // A map-type must be specified in all map clauses and must be either |
| 10317 | // from, release, or delete. |
| 10318 | if (DKind == OMPD_target_exit_data && |
| 10319 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 10320 | MapType == OMPC_MAP_delete)) { |
| 10321 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10322 | << (IsMapTypeImplicit ? 1 : 0) |
| 10323 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10324 | << getOpenMPDirectiveName(DKind); |
| 10325 | continue; |
| 10326 | } |
| 10327 | |
| 10328 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 10329 | // A list item cannot appear in both a map clause and a data-sharing |
| 10330 | // attribute clause on the same construct |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10331 | if ((DKind == OMPD_target || DKind == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10332 | DKind == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10333 | DKind == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10334 | DKind == OMPD_target_teams_distribute_parallel_for_simd || |
| 10335 | DKind == OMPD_target_teams_distribute_simd) && VD) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10336 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10337 | if (isOpenMPPrivate(DVar.CKind)) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10338 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10339 | << getOpenMPClauseName(DVar.CKind) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10340 | << getOpenMPClauseName(OMPC_map) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10341 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| 10342 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); |
| 10343 | continue; |
| 10344 | } |
| 10345 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10346 | } |
| 10347 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10348 | // Save the current expression. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10349 | MVLI.ProcessedVarList.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10350 | |
| 10351 | // Store the components in the stack so that they can be used to check |
| 10352 | // against other clauses later on. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10353 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 10354 | /*WhereFoundClauseKind=*/OMPC_map); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10355 | |
| 10356 | // Save the components and declaration to create the clause. For purposes of |
| 10357 | // the clause creation, any component list that has has base 'this' uses |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 10358 | // null as base declaration. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10359 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 10360 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 10361 | CurComponents.end()); |
| 10362 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 10363 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10364 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10365 | } |
| 10366 | |
| 10367 | OMPClause * |
| 10368 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 10369 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 10370 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 10371 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10372 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 10373 | MappableVarListInfo MVLI(VarList); |
| 10374 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 10375 | MapType, IsMapTypeImplicit); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10376 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10377 | // We need to produce a map clause even if we don't have variables so that |
| 10378 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10379 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10380 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 10381 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 10382 | IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10383 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10384 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10385 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 10386 | TypeResult ParsedType) { |
| 10387 | assert(ParsedType.isUsable()); |
| 10388 | |
| 10389 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 10390 | if (ReductionType.isNull()) |
| 10391 | return QualType(); |
| 10392 | |
| 10393 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 10394 | // A type name in a declare reduction directive cannot be a function type, an |
| 10395 | // array type, a reference type, or a type qualified with const, volatile or |
| 10396 | // restrict. |
| 10397 | if (ReductionType.hasQualifiers()) { |
| 10398 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 10399 | return QualType(); |
| 10400 | } |
| 10401 | |
| 10402 | if (ReductionType->isFunctionType()) { |
| 10403 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 10404 | return QualType(); |
| 10405 | } |
| 10406 | if (ReductionType->isReferenceType()) { |
| 10407 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 10408 | return QualType(); |
| 10409 | } |
| 10410 | if (ReductionType->isArrayType()) { |
| 10411 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 10412 | return QualType(); |
| 10413 | } |
| 10414 | return ReductionType; |
| 10415 | } |
| 10416 | |
| 10417 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 10418 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 10419 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 10420 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 10421 | SmallVector<Decl *, 8> Decls; |
| 10422 | Decls.reserve(ReductionTypes.size()); |
| 10423 | |
| 10424 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 10425 | ForRedeclaration); |
| 10426 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 10427 | // A reduction-identifier may not be re-declared in the current scope for the |
| 10428 | // same type or for a type that is compatible according to the base language |
| 10429 | // rules. |
| 10430 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 10431 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 10432 | bool InCompoundScope = true; |
| 10433 | if (S != nullptr) { |
| 10434 | // Find previous declaration with the same name not referenced in other |
| 10435 | // declarations. |
| 10436 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 10437 | InCompoundScope = |
| 10438 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 10439 | LookupName(Lookup, S); |
| 10440 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 10441 | /*AllowInlineNamespace=*/false); |
| 10442 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 10443 | auto Filter = Lookup.makeFilter(); |
| 10444 | while (Filter.hasNext()) { |
| 10445 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 10446 | if (InCompoundScope) { |
| 10447 | auto I = UsedAsPrevious.find(PrevDecl); |
| 10448 | if (I == UsedAsPrevious.end()) |
| 10449 | UsedAsPrevious[PrevDecl] = false; |
| 10450 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 10451 | UsedAsPrevious[D] = true; |
| 10452 | } |
| 10453 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 10454 | PrevDecl->getLocation(); |
| 10455 | } |
| 10456 | Filter.done(); |
| 10457 | if (InCompoundScope) { |
| 10458 | for (auto &PrevData : UsedAsPrevious) { |
| 10459 | if (!PrevData.second) { |
| 10460 | PrevDRD = PrevData.first; |
| 10461 | break; |
| 10462 | } |
| 10463 | } |
| 10464 | } |
| 10465 | } else if (PrevDeclInScope != nullptr) { |
| 10466 | auto *PrevDRDInScope = PrevDRD = |
| 10467 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 10468 | do { |
| 10469 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 10470 | PrevDRDInScope->getLocation(); |
| 10471 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 10472 | } while (PrevDRDInScope != nullptr); |
| 10473 | } |
| 10474 | for (auto &TyData : ReductionTypes) { |
| 10475 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 10476 | bool Invalid = false; |
| 10477 | if (I != PreviousRedeclTypes.end()) { |
| 10478 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 10479 | << TyData.first; |
| 10480 | Diag(I->second, diag::note_previous_definition); |
| 10481 | Invalid = true; |
| 10482 | } |
| 10483 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 10484 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 10485 | Name, TyData.first, PrevDRD); |
| 10486 | DC->addDecl(DRD); |
| 10487 | DRD->setAccess(AS); |
| 10488 | Decls.push_back(DRD); |
| 10489 | if (Invalid) |
| 10490 | DRD->setInvalidDecl(); |
| 10491 | else |
| 10492 | PrevDRD = DRD; |
| 10493 | } |
| 10494 | |
| 10495 | return DeclGroupPtrTy::make( |
| 10496 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 10497 | } |
| 10498 | |
| 10499 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 10500 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10501 | |
| 10502 | // Enter new function scope. |
| 10503 | PushFunctionScope(); |
| 10504 | getCurFunction()->setHasBranchProtectedScope(); |
| 10505 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 10506 | |
| 10507 | if (S != nullptr) |
| 10508 | PushDeclContext(S, DRD); |
| 10509 | else |
| 10510 | CurContext = DRD; |
| 10511 | |
| 10512 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10513 | |
| 10514 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10515 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 10516 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 10517 | // uses semantics of argument handles by value, but it should be passed by |
| 10518 | // reference. C lang does not support references, so pass all parameters as |
| 10519 | // pointers. |
| 10520 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10521 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10522 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10523 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 10524 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 10525 | // uses semantics of argument handles by value, but it should be passed by |
| 10526 | // reference. C lang does not support references, so pass all parameters as |
| 10527 | // pointers. |
| 10528 | // Create 'T omp_out;' variable. |
| 10529 | auto *OmpOutParm = |
| 10530 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 10531 | if (S != nullptr) { |
| 10532 | PushOnScopeChains(OmpInParm, S); |
| 10533 | PushOnScopeChains(OmpOutParm, S); |
| 10534 | } else { |
| 10535 | DRD->addDecl(OmpInParm); |
| 10536 | DRD->addDecl(OmpOutParm); |
| 10537 | } |
| 10538 | } |
| 10539 | |
| 10540 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 10541 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10542 | DiscardCleanupsInEvaluationContext(); |
| 10543 | PopExpressionEvaluationContext(); |
| 10544 | |
| 10545 | PopDeclContext(); |
| 10546 | PopFunctionScopeInfo(); |
| 10547 | |
| 10548 | if (Combiner != nullptr) |
| 10549 | DRD->setCombiner(Combiner); |
| 10550 | else |
| 10551 | DRD->setInvalidDecl(); |
| 10552 | } |
| 10553 | |
| 10554 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 10555 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10556 | |
| 10557 | // Enter new function scope. |
| 10558 | PushFunctionScope(); |
| 10559 | getCurFunction()->setHasBranchProtectedScope(); |
| 10560 | |
| 10561 | if (S != nullptr) |
| 10562 | PushDeclContext(S, DRD); |
| 10563 | else |
| 10564 | CurContext = DRD; |
| 10565 | |
| 10566 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10567 | |
| 10568 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10569 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 10570 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 10571 | // uses semantics of argument handles by value, but it should be passed by |
| 10572 | // reference. C lang does not support references, so pass all parameters as |
| 10573 | // pointers. |
| 10574 | // Create 'T omp_priv;' variable. |
| 10575 | auto *OmpPrivParm = |
| 10576 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10577 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 10578 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 10579 | // uses semantics of argument handles by value, but it should be passed by |
| 10580 | // reference. C lang does not support references, so pass all parameters as |
| 10581 | // pointers. |
| 10582 | // Create 'T omp_orig;' variable. |
| 10583 | auto *OmpOrigParm = |
| 10584 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10585 | if (S != nullptr) { |
| 10586 | PushOnScopeChains(OmpPrivParm, S); |
| 10587 | PushOnScopeChains(OmpOrigParm, S); |
| 10588 | } else { |
| 10589 | DRD->addDecl(OmpPrivParm); |
| 10590 | DRD->addDecl(OmpOrigParm); |
| 10591 | } |
| 10592 | } |
| 10593 | |
| 10594 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 10595 | Expr *Initializer) { |
| 10596 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10597 | DiscardCleanupsInEvaluationContext(); |
| 10598 | PopExpressionEvaluationContext(); |
| 10599 | |
| 10600 | PopDeclContext(); |
| 10601 | PopFunctionScopeInfo(); |
| 10602 | |
| 10603 | if (Initializer != nullptr) |
| 10604 | DRD->setInitializer(Initializer); |
| 10605 | else |
| 10606 | DRD->setInvalidDecl(); |
| 10607 | } |
| 10608 | |
| 10609 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 10610 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 10611 | for (auto *D : DeclReductions.get()) { |
| 10612 | if (IsValid) { |
| 10613 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10614 | if (S != nullptr) |
| 10615 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 10616 | } else |
| 10617 | D->setInvalidDecl(); |
| 10618 | } |
| 10619 | return DeclReductions; |
| 10620 | } |
| 10621 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10622 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10623 | SourceLocation StartLoc, |
| 10624 | SourceLocation LParenLoc, |
| 10625 | SourceLocation EndLoc) { |
| 10626 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10627 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10628 | // OpenMP [teams Constrcut, Restrictions] |
| 10629 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10630 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 10631 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10632 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10633 | |
| 10634 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10635 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10636 | |
| 10637 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 10638 | SourceLocation StartLoc, |
| 10639 | SourceLocation LParenLoc, |
| 10640 | SourceLocation EndLoc) { |
| 10641 | Expr *ValExpr = ThreadLimit; |
| 10642 | |
| 10643 | // OpenMP [teams Constrcut, Restrictions] |
| 10644 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10645 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 10646 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10647 | return nullptr; |
| 10648 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10649 | return new (Context) |
| 10650 | OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10651 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10652 | |
| 10653 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 10654 | SourceLocation StartLoc, |
| 10655 | SourceLocation LParenLoc, |
| 10656 | SourceLocation EndLoc) { |
| 10657 | Expr *ValExpr = Priority; |
| 10658 | |
| 10659 | // OpenMP [2.9.1, task Constrcut] |
| 10660 | // The priority-value is a non-negative numerical scalar expression. |
| 10661 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 10662 | /*StrictlyPositive=*/false)) |
| 10663 | return nullptr; |
| 10664 | |
| 10665 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10666 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 10667 | |
| 10668 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 10669 | SourceLocation StartLoc, |
| 10670 | SourceLocation LParenLoc, |
| 10671 | SourceLocation EndLoc) { |
| 10672 | Expr *ValExpr = Grainsize; |
| 10673 | |
| 10674 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10675 | // The parameter of the grainsize clause must be a positive integer |
| 10676 | // expression. |
| 10677 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 10678 | /*StrictlyPositive=*/true)) |
| 10679 | return nullptr; |
| 10680 | |
| 10681 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10682 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 10683 | |
| 10684 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 10685 | SourceLocation StartLoc, |
| 10686 | SourceLocation LParenLoc, |
| 10687 | SourceLocation EndLoc) { |
| 10688 | Expr *ValExpr = NumTasks; |
| 10689 | |
| 10690 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10691 | // The parameter of the num_tasks clause must be a positive integer |
| 10692 | // expression. |
| 10693 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 10694 | /*StrictlyPositive=*/true)) |
| 10695 | return nullptr; |
| 10696 | |
| 10697 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10698 | } |
| 10699 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 10700 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 10701 | SourceLocation LParenLoc, |
| 10702 | SourceLocation EndLoc) { |
| 10703 | // OpenMP [2.13.2, critical construct, Description] |
| 10704 | // ... where hint-expression is an integer constant expression that evaluates |
| 10705 | // to a valid lock hint. |
| 10706 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 10707 | if (HintExpr.isInvalid()) |
| 10708 | return nullptr; |
| 10709 | return new (Context) |
| 10710 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 10711 | } |
| 10712 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10713 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 10714 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 10715 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 10716 | SourceLocation EndLoc) { |
| 10717 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 10718 | std::string Values; |
| 10719 | Values += "'"; |
| 10720 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 10721 | Values += "'"; |
| 10722 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 10723 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 10724 | return nullptr; |
| 10725 | } |
| 10726 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10727 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10728 | if (ChunkSize) { |
| 10729 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 10730 | !ChunkSize->isInstantiationDependent() && |
| 10731 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 10732 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 10733 | ExprResult Val = |
| 10734 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 10735 | if (Val.isInvalid()) |
| 10736 | return nullptr; |
| 10737 | |
| 10738 | ValExpr = Val.get(); |
| 10739 | |
| 10740 | // OpenMP [2.7.1, Restrictions] |
| 10741 | // chunk_size must be a loop invariant integer expression with a positive |
| 10742 | // value. |
| 10743 | llvm::APSInt Result; |
| 10744 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 10745 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 10746 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 10747 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 10748 | return nullptr; |
| 10749 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 10750 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 10751 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10752 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 10753 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 10754 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10755 | } |
| 10756 | } |
| 10757 | } |
| 10758 | |
| 10759 | return new (Context) |
| 10760 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10761 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10762 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10763 | |
| 10764 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 10765 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 10766 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 10767 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 10768 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10769 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || Kind != OMPC_DEFAULTMAP_scalar) { |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10770 | std::string Value; |
| 10771 | SourceLocation Loc; |
| 10772 | Value += "'"; |
| 10773 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 10774 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10775 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10776 | Loc = MLoc; |
| 10777 | } else { |
| 10778 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10779 | OMPC_DEFAULTMAP_scalar); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10780 | Loc = KindLoc; |
| 10781 | } |
| 10782 | Value += "'"; |
| 10783 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 10784 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 10785 | return nullptr; |
| 10786 | } |
| 10787 | |
| 10788 | return new (Context) |
| 10789 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 10790 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10791 | |
| 10792 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 10793 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 10794 | if (!CurLexicalContext->isFileContext() && |
| 10795 | !CurLexicalContext->isExternCContext() && |
| 10796 | !CurLexicalContext->isExternCXXContext()) { |
| 10797 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 10798 | return false; |
| 10799 | } |
| 10800 | if (IsInOpenMPDeclareTargetContext) { |
| 10801 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 10802 | return false; |
| 10803 | } |
| 10804 | |
| 10805 | IsInOpenMPDeclareTargetContext = true; |
| 10806 | return true; |
| 10807 | } |
| 10808 | |
| 10809 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 10810 | assert(IsInOpenMPDeclareTargetContext && |
| 10811 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 10812 | |
| 10813 | IsInOpenMPDeclareTargetContext = false; |
| 10814 | } |
| 10815 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10816 | void Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, |
| 10817 | CXXScopeSpec &ScopeSpec, |
| 10818 | const DeclarationNameInfo &Id, |
| 10819 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 10820 | NamedDeclSetType &SameDirectiveDecls) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10821 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 10822 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 10823 | |
| 10824 | if (Lookup.isAmbiguous()) |
| 10825 | return; |
| 10826 | Lookup.suppressDiagnostics(); |
| 10827 | |
| 10828 | if (!Lookup.isSingleResult()) { |
| 10829 | if (TypoCorrection Corrected = |
| 10830 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 10831 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 10832 | CTK_ErrorRecovery)) { |
| 10833 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 10834 | << Id.getName()); |
| 10835 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 10836 | return; |
| 10837 | } |
| 10838 | |
| 10839 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 10840 | return; |
| 10841 | } |
| 10842 | |
| 10843 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| 10844 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 10845 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 10846 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 10847 | |
| 10848 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { |
| 10849 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| 10850 | ND->addAttr(A); |
| 10851 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 10852 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 10853 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); |
| 10854 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { |
| 10855 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 10856 | << Id.getName(); |
| 10857 | } |
| 10858 | } else |
| 10859 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| 10860 | } |
| 10861 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10862 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 10863 | Sema &SemaRef, Decl *D) { |
| 10864 | if (!D) |
| 10865 | return; |
| 10866 | Decl *LD = nullptr; |
| 10867 | if (isa<TagDecl>(D)) { |
| 10868 | LD = cast<TagDecl>(D)->getDefinition(); |
| 10869 | } else if (isa<VarDecl>(D)) { |
| 10870 | LD = cast<VarDecl>(D)->getDefinition(); |
| 10871 | |
| 10872 | // If this is an implicit variable that is legal and we do not need to do |
| 10873 | // anything. |
| 10874 | if (cast<VarDecl>(D)->isImplicit()) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10875 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10876 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10877 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10878 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10879 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10880 | return; |
| 10881 | } |
| 10882 | |
| 10883 | } else if (isa<FunctionDecl>(D)) { |
| 10884 | const FunctionDecl *FD = nullptr; |
| 10885 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 10886 | LD = const_cast<FunctionDecl *>(FD); |
| 10887 | |
| 10888 | // If the definition is associated with the current declaration in the |
| 10889 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 10890 | // to do anything else. |
| 10891 | if (LD == D) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10892 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10893 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10894 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10895 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10896 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10897 | return; |
| 10898 | } |
| 10899 | } |
| 10900 | if (!LD) |
| 10901 | LD = D; |
| 10902 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 10903 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 10904 | // Outlined declaration is not declared target. |
| 10905 | if (LD->isOutOfLine()) { |
| 10906 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 10907 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 10908 | } else { |
| 10909 | DeclContext *DC = LD->getDeclContext(); |
| 10910 | while (DC) { |
| 10911 | if (isa<FunctionDecl>(DC) && |
| 10912 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 10913 | break; |
| 10914 | DC = DC->getParent(); |
| 10915 | } |
| 10916 | if (DC) |
| 10917 | return; |
| 10918 | |
| 10919 | // Is not declared in target context. |
| 10920 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 10921 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 10922 | } |
| 10923 | // Mark decl as declared target to prevent further diagnostic. |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10924 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10925 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10926 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10927 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10928 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10929 | } |
| 10930 | } |
| 10931 | |
| 10932 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 10933 | Sema &SemaRef, DSAStackTy *Stack, |
| 10934 | ValueDecl *VD) { |
| 10935 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 10936 | return true; |
| 10937 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 10938 | return false; |
| 10939 | return true; |
| 10940 | } |
| 10941 | |
| 10942 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 10943 | if (!D || D->isInvalidDecl()) |
| 10944 | return; |
| 10945 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 10946 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 10947 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 10948 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 10949 | if (DSAStack->isThreadPrivate(VD)) { |
| 10950 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 10951 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 10952 | return; |
| 10953 | } |
| 10954 | } |
| 10955 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 10956 | // Problem if any with var declared with incomplete type will be reported |
| 10957 | // as normal, so no need to check it here. |
| 10958 | if ((E || !VD->getType()->isIncompleteType()) && |
| 10959 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 10960 | // Mark decl as declared target to prevent further diagnostic. |
| 10961 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10962 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10963 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10964 | VD->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10965 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10966 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10967 | } |
| 10968 | return; |
| 10969 | } |
| 10970 | } |
| 10971 | if (!E) { |
| 10972 | // Checking declaration inside declare target region. |
| 10973 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 10974 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10975 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10976 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10977 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10978 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10979 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10980 | } |
| 10981 | return; |
| 10982 | } |
| 10983 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 10984 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10985 | |
| 10986 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 10987 | SourceLocation StartLoc, |
| 10988 | SourceLocation LParenLoc, |
| 10989 | SourceLocation EndLoc) { |
| 10990 | MappableVarListInfo MVLI(VarList); |
| 10991 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 10992 | if (MVLI.ProcessedVarList.empty()) |
| 10993 | return nullptr; |
| 10994 | |
| 10995 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10996 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 10997 | MVLI.VarComponents); |
| 10998 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10999 | |
| 11000 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 11001 | SourceLocation StartLoc, |
| 11002 | SourceLocation LParenLoc, |
| 11003 | SourceLocation EndLoc) { |
| 11004 | MappableVarListInfo MVLI(VarList); |
| 11005 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 11006 | if (MVLI.ProcessedVarList.empty()) |
| 11007 | return nullptr; |
| 11008 | |
| 11009 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11010 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11011 | MVLI.VarComponents); |
| 11012 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11013 | |
| 11014 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11015 | SourceLocation StartLoc, |
| 11016 | SourceLocation LParenLoc, |
| 11017 | SourceLocation EndLoc) { |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11018 | MappableVarListInfo MVLI(VarList); |
| 11019 | SmallVector<Expr *, 8> PrivateCopies; |
| 11020 | SmallVector<Expr *, 8> Inits; |
| 11021 | |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11022 | for (auto &RefExpr : VarList) { |
| 11023 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 11024 | SourceLocation ELoc; |
| 11025 | SourceRange ERange; |
| 11026 | Expr *SimpleRefExpr = RefExpr; |
| 11027 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11028 | if (Res.second) { |
| 11029 | // It will be analyzed later. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11030 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 11031 | PrivateCopies.push_back(nullptr); |
| 11032 | Inits.push_back(nullptr); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11033 | } |
| 11034 | ValueDecl *D = Res.first; |
| 11035 | if (!D) |
| 11036 | continue; |
| 11037 | |
| 11038 | QualType Type = D->getType(); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11039 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 11040 | |
| 11041 | auto *VD = dyn_cast<VarDecl>(D); |
| 11042 | |
| 11043 | // Item should be a pointer or reference to pointer. |
| 11044 | if (!Type->isPointerType()) { |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11045 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 11046 | << 0 << RefExpr->getSourceRange(); |
| 11047 | continue; |
| 11048 | } |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11049 | |
| 11050 | // Build the private variable and the expression that refers to it. |
| 11051 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11052 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11053 | if (VDPrivate->isInvalidDecl()) |
| 11054 | continue; |
| 11055 | |
| 11056 | CurContext->addDecl(VDPrivate); |
| 11057 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 11058 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 11059 | |
| 11060 | // Add temporary variable to initialize the private copy of the pointer. |
| 11061 | auto *VDInit = |
| 11062 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| 11063 | auto *VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 11064 | RefExpr->getExprLoc()); |
| 11065 | AddInitializerToDecl(VDPrivate, |
| 11066 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 11067 | /*DirectInit=*/false); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11068 | |
| 11069 | // If required, build a capture to implement the privatization initialized |
| 11070 | // with the current list item value. |
| 11071 | DeclRefExpr *Ref = nullptr; |
| 11072 | if (!VD) |
| 11073 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11074 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 11075 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 11076 | Inits.push_back(VDInitRefExpr); |
| 11077 | |
| 11078 | // We need to add a data sharing attribute for this variable to make sure it |
| 11079 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 11080 | // similar properties of a first private variable. |
| 11081 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 11082 | |
| 11083 | // Create a mappable component for the list item. List items in this clause |
| 11084 | // only need a component. |
| 11085 | MVLI.VarBaseDeclarations.push_back(D); |
| 11086 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11087 | MVLI.VarComponents.back().push_back( |
| 11088 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11089 | } |
| 11090 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11091 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11092 | return nullptr; |
| 11093 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11094 | return OMPUseDevicePtrClause::Create( |
| 11095 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11096 | PrivateCopies, Inits, MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11097 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11098 | |
| 11099 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11100 | SourceLocation StartLoc, |
| 11101 | SourceLocation LParenLoc, |
| 11102 | SourceLocation EndLoc) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11103 | MappableVarListInfo MVLI(VarList); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11104 | for (auto &RefExpr : VarList) { |
Kelvin Li | 8437625 | 2016-12-14 15:39:58 +0000 | [diff] [blame] | 11105 | assert(RefExpr && "NULL expr in OpenMP is_device_ptr clause."); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11106 | SourceLocation ELoc; |
| 11107 | SourceRange ERange; |
| 11108 | Expr *SimpleRefExpr = RefExpr; |
| 11109 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11110 | if (Res.second) { |
| 11111 | // It will be analyzed later. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11112 | MVLI.ProcessedVarList.push_back(RefExpr); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11113 | } |
| 11114 | ValueDecl *D = Res.first; |
| 11115 | if (!D) |
| 11116 | continue; |
| 11117 | |
| 11118 | QualType Type = D->getType(); |
| 11119 | // item should be a pointer or array or reference to pointer or array |
| 11120 | if (!Type.getNonReferenceType()->isPointerType() && |
| 11121 | !Type.getNonReferenceType()->isArrayType()) { |
| 11122 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 11123 | << 0 << RefExpr->getSourceRange(); |
| 11124 | continue; |
| 11125 | } |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11126 | |
| 11127 | // Check if the declaration in the clause does not show up in any data |
| 11128 | // sharing attribute. |
| 11129 | auto DVar = DSAStack->getTopDSA(D, false); |
| 11130 | if (isOpenMPPrivate(DVar.CKind)) { |
| 11131 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 11132 | << getOpenMPClauseName(DVar.CKind) |
| 11133 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 11134 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 11135 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 11136 | continue; |
| 11137 | } |
| 11138 | |
| 11139 | Expr *ConflictExpr; |
| 11140 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11141 | D, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11142 | [&ConflictExpr]( |
| 11143 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 11144 | OpenMPClauseKind) -> bool { |
| 11145 | ConflictExpr = R.front().getAssociatedExpression(); |
| 11146 | return true; |
| 11147 | })) { |
| 11148 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 11149 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 11150 | << ConflictExpr->getSourceRange(); |
| 11151 | continue; |
| 11152 | } |
| 11153 | |
| 11154 | // Store the components in the stack so that they can be used to check |
| 11155 | // against other clauses later on. |
| 11156 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 11157 | DSAStack->addMappableExpressionComponents( |
| 11158 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 11159 | |
| 11160 | // Record the expression we've just processed. |
| 11161 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 11162 | |
| 11163 | // Create a mappable component for the list item. List items in this clause |
| 11164 | // only need a component. We use a null declaration to signal fields in |
| 11165 | // 'this'. |
| 11166 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 11167 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 11168 | "Unexpected device pointer expression!"); |
| 11169 | MVLI.VarBaseDeclarations.push_back( |
| 11170 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 11171 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11172 | MVLI.VarComponents.back().push_back(MC); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11173 | } |
| 11174 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11175 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11176 | return nullptr; |
| 11177 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11178 | return OMPIsDevicePtrClause::Create( |
| 11179 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11180 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11181 | } |