| 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 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9 | /// This file implements semantic analysis for OpenMP directives and |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 10 | /// clauses. |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 14 | #include "TreeTransform.h" |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTMutationListener.h" |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 17 | #include "clang/AST/CXXInheritance.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclOpenMP.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtCXX.h" |
| 22 | #include "clang/AST/StmtOpenMP.h" |
| 23 | #include "clang/AST/StmtVisitor.h" |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 24 | #include "clang/AST/TypeOrdering.h" |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 25 | #include "clang/Basic/OpenMPKinds.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 26 | #include "clang/Sema/Initialization.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Lookup.h" |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Scope.h" |
| 29 | #include "clang/Sema/ScopeInfo.h" |
| Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 30 | #include "clang/Sema/SemaInternal.h" |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/PointerEmbeddedInt.h" |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Stack of data-sharing attributes for variables |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 38 | static const Expr *checkMapClauseExpressionBase( |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 39 | Sema &SemaRef, Expr *E, |
| 40 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 41 | OpenMPClauseKind CKind, bool NoDiagnose); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 42 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 43 | namespace { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 44 | /// Default data sharing attributes, which can be applied to directive. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 45 | enum DefaultDataSharingAttributes { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 46 | DSA_unspecified = 0, /// Data sharing attribute not specified. |
| 47 | DSA_none = 1 << 0, /// Default data sharing attribute 'none'. |
| 48 | DSA_shared = 1 << 1, /// Default data sharing attribute 'shared'. |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /// Attributes of the defaultmap clause. |
| 52 | enum DefaultMapAttributes { |
| 53 | DMA_unspecified, /// Default mapping is not specified. |
| 54 | DMA_tofrom_scalar, /// Default mapping is 'tofrom:scalar'. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 55 | }; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 56 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 57 | /// Stack for tracking declarations used in OpenMP directives and |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 58 | /// clauses and their data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 59 | class DSAStackTy { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 60 | public: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 61 | struct DSAVarData { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 62 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| 63 | OpenMPClauseKind CKind = OMPC_unknown; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 64 | const Expr *RefExpr = nullptr; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 65 | DeclRefExpr *PrivateCopy = nullptr; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 66 | SourceLocation ImplicitDSALoc; |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 67 | DSAVarData() = default; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 68 | DSAVarData(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
| 69 | const Expr *RefExpr, DeclRefExpr *PrivateCopy, |
| 70 | SourceLocation ImplicitDSALoc) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 71 | : DKind(DKind), CKind(CKind), RefExpr(RefExpr), |
| 72 | PrivateCopy(PrivateCopy), ImplicitDSALoc(ImplicitDSALoc) {} |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 73 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 74 | using OperatorOffsetTy = |
| 75 | llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4>; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 76 | using DoacrossDependMapTy = |
| 77 | llvm::DenseMap<OMPDependClause *, OperatorOffsetTy>; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 78 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 79 | private: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 80 | struct DSAInfo { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 81 | OpenMPClauseKind Attributes = OMPC_unknown; |
| 82 | /// Pointer to a reference expression and a flag which shows that the |
| 83 | /// variable is marked as lastprivate(true) or not (false). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 84 | llvm::PointerIntPair<const Expr *, 1, bool> RefExpr; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 85 | DeclRefExpr *PrivateCopy = nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 86 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 87 | using DeclSAMapTy = llvm::SmallDenseMap<const ValueDecl *, DSAInfo, 8>; |
| 88 | using AlignedMapTy = llvm::SmallDenseMap<const ValueDecl *, const Expr *, 8>; |
| 89 | using LCDeclInfo = std::pair<unsigned, VarDecl *>; |
| 90 | using LoopControlVariablesMapTy = |
| 91 | llvm::SmallDenseMap<const ValueDecl *, LCDeclInfo, 8>; |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 92 | /// Struct that associates a component with the clause kind where they are |
| 93 | /// found. |
| 94 | struct MappedExprComponentTy { |
| 95 | OMPClauseMappableExprCommon::MappableExprComponentLists Components; |
| 96 | OpenMPClauseKind Kind = OMPC_unknown; |
| 97 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 98 | using MappedExprComponentsTy = |
| 99 | llvm::DenseMap<const ValueDecl *, MappedExprComponentTy>; |
| 100 | using CriticalsWithHintsTy = |
| 101 | llvm::StringMap<std::pair<const OMPCriticalDirective *, llvm::APSInt>>; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 102 | struct ReductionData { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 103 | using BOKPtrType = llvm::PointerEmbeddedInt<BinaryOperatorKind, 16>; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 104 | SourceRange ReductionRange; |
| Alexey Bataev | f87fa88 | 2017-07-21 19:26:22 +0000 | [diff] [blame] | 105 | llvm::PointerUnion<const Expr *, BOKPtrType> ReductionOp; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 106 | ReductionData() = default; |
| 107 | void set(BinaryOperatorKind BO, SourceRange RR) { |
| 108 | ReductionRange = RR; |
| 109 | ReductionOp = BO; |
| 110 | } |
| 111 | void set(const Expr *RefExpr, SourceRange RR) { |
| 112 | ReductionRange = RR; |
| 113 | ReductionOp = RefExpr; |
| 114 | } |
| 115 | }; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 116 | using DeclReductionMapTy = |
| 117 | llvm::SmallDenseMap<const ValueDecl *, ReductionData, 4>; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 118 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 119 | struct SharingMapTy { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 120 | DeclSAMapTy SharingMap; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 121 | DeclReductionMapTy ReductionMap; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 122 | AlignedMapTy AlignedMap; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 123 | MappedExprComponentsTy MappedExprComponents; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 124 | LoopControlVariablesMapTy LCVMap; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 125 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 126 | SourceLocation DefaultAttrLoc; |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 127 | DefaultMapAttributes DefaultMapAttr = DMA_unspecified; |
| 128 | SourceLocation DefaultMapAttrLoc; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 129 | OpenMPDirectiveKind Directive = OMPD_unknown; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 130 | DeclarationNameInfo DirectiveName; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 131 | Scope *CurScope = nullptr; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 132 | SourceLocation ConstructLoc; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 133 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
| 134 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
| 135 | /// This data is required during codegen. |
| 136 | DoacrossDependMapTy DoacrossDepends; |
| Patrick Lyster | 1647194 | 2019-02-06 18:18:02 +0000 | [diff] [blame] | 137 | /// First argument (Expr *) contains optional argument of the |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 138 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 139 | /// clause, false otherwise. |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 140 | llvm::Optional<std::pair<const Expr *, OMPOrderedClause *>> OrderedRegion; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 141 | unsigned AssociatedLoops = 1; |
| 142 | const Decl *PossiblyLoopCounter = nullptr; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 143 | bool NowaitRegion = false; |
| 144 | bool CancelRegion = false; |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 145 | bool LoopStart = false; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 146 | SourceLocation InnerTeamsRegionLoc; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 147 | /// Reference to the taskgroup task_reduction reference expression. |
| 148 | Expr *TaskgroupReductionRef = nullptr; |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 149 | llvm::DenseSet<QualType> MappedClassesQualTypes; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 150 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 151 | Scope *CurScope, SourceLocation Loc) |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 152 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
| 153 | ConstructLoc(Loc) {} |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 154 | SharingMapTy() = default; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 155 | }; |
| 156 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 157 | using StackTy = SmallVector<SharingMapTy, 4>; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 158 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 159 | /// Stack of used declaration and their data-sharing attributes. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 160 | DeclSAMapTy Threadprivates; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 161 | const FunctionScopeInfo *CurrentNonCapturingFunctionScope = nullptr; |
| 162 | SmallVector<std::pair<StackTy, const FunctionScopeInfo *>, 4> Stack; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 163 | /// true, if check for DSA must be from parent directive, false, if |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 164 | /// from current directive. |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 165 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 166 | Sema &SemaRef; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 167 | bool ForceCapturing = false; |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 168 | /// true if all the vaiables in the target executable directives must be |
| 169 | /// captured by reference. |
| 170 | bool ForceCaptureByReferenceInTargetExecutable = false; |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 171 | CriticalsWithHintsTy Criticals; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 172 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 173 | using iterator = StackTy::const_reverse_iterator; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 174 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 175 | DSAVarData getDSA(iterator &Iter, ValueDecl *D) const; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 176 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 177 | /// Checks if the variable is a local for OpenMP region. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 178 | bool isOpenMPLocal(VarDecl *D, iterator Iter) const; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 179 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 180 | bool isStackEmpty() const { |
| 181 | return Stack.empty() || |
| 182 | Stack.back().second != CurrentNonCapturingFunctionScope || |
| 183 | Stack.back().first.empty(); |
| 184 | } |
| 185 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 186 | /// Vector of previously declared requires directives |
| 187 | SmallVector<const OMPRequiresDecl *, 2> RequiresDecls; |
| 188 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 189 | public: |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 190 | explicit DSAStackTy(Sema &S) : SemaRef(S) {} |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 191 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 192 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| Alexey Bataev | 3f82cfc | 2017-12-13 15:28:44 +0000 | [diff] [blame] | 193 | OpenMPClauseKind getClauseParsingMode() const { |
| 194 | assert(isClauseParsingMode() && "Must be in clause parsing mode."); |
| 195 | return ClauseKindMode; |
| 196 | } |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 197 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 198 | |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 199 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 200 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 201 | |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 202 | void setForceCaptureByReferenceInTargetExecutable(bool V) { |
| 203 | ForceCaptureByReferenceInTargetExecutable = V; |
| 204 | } |
| 205 | bool isForceCaptureByReferenceInTargetExecutable() const { |
| 206 | return ForceCaptureByReferenceInTargetExecutable; |
| 207 | } |
| 208 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 209 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 210 | Scope *CurScope, SourceLocation Loc) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 211 | if (Stack.empty() || |
| 212 | Stack.back().second != CurrentNonCapturingFunctionScope) |
| 213 | Stack.emplace_back(StackTy(), CurrentNonCapturingFunctionScope); |
| 214 | Stack.back().first.emplace_back(DKind, DirName, CurScope, Loc); |
| 215 | Stack.back().first.back().DefaultAttrLoc = Loc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void pop() { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 219 | assert(!Stack.back().first.empty() && |
| 220 | "Data-sharing attributes stack is empty!"); |
| 221 | Stack.back().first.pop_back(); |
| 222 | } |
| 223 | |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 224 | /// Marks that we're started loop parsing. |
| 225 | void loopInit() { |
| 226 | assert(isOpenMPLoopDirective(getCurrentDirective()) && |
| 227 | "Expected loop-based directive."); |
| 228 | Stack.back().first.back().LoopStart = true; |
| 229 | } |
| 230 | /// Start capturing of the variables in the loop context. |
| 231 | void loopStart() { |
| 232 | assert(isOpenMPLoopDirective(getCurrentDirective()) && |
| 233 | "Expected loop-based directive."); |
| 234 | Stack.back().first.back().LoopStart = false; |
| 235 | } |
| 236 | /// true, if variables are captured, false otherwise. |
| 237 | bool isLoopStarted() const { |
| 238 | assert(isOpenMPLoopDirective(getCurrentDirective()) && |
| 239 | "Expected loop-based directive."); |
| 240 | return !Stack.back().first.back().LoopStart; |
| 241 | } |
| 242 | /// Marks (or clears) declaration as possibly loop counter. |
| 243 | void resetPossibleLoopCounter(const Decl *D = nullptr) { |
| 244 | Stack.back().first.back().PossiblyLoopCounter = |
| 245 | D ? D->getCanonicalDecl() : D; |
| 246 | } |
| 247 | /// Gets the possible loop counter decl. |
| 248 | const Decl *getPossiblyLoopCunter() const { |
| 249 | return Stack.back().first.back().PossiblyLoopCounter; |
| 250 | } |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 251 | /// Start new OpenMP region stack in new non-capturing function. |
| 252 | void pushFunction() { |
| 253 | const FunctionScopeInfo *CurFnScope = SemaRef.getCurFunction(); |
| 254 | assert(!isa<CapturingScopeInfo>(CurFnScope)); |
| 255 | CurrentNonCapturingFunctionScope = CurFnScope; |
| 256 | } |
| 257 | /// Pop region stack for non-capturing function. |
| 258 | void popFunction(const FunctionScopeInfo *OldFSI) { |
| 259 | if (!Stack.empty() && Stack.back().second == OldFSI) { |
| 260 | assert(Stack.back().first.empty()); |
| 261 | Stack.pop_back(); |
| 262 | } |
| 263 | CurrentNonCapturingFunctionScope = nullptr; |
| 264 | for (const FunctionScopeInfo *FSI : llvm::reverse(SemaRef.FunctionScopes)) { |
| 265 | if (!isa<CapturingScopeInfo>(FSI)) { |
| 266 | CurrentNonCapturingFunctionScope = FSI; |
| 267 | break; |
| 268 | } |
| 269 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 272 | void addCriticalWithHint(const OMPCriticalDirective *D, llvm::APSInt Hint) { |
| Alexey Bataev | 43a919f | 2018-04-13 17:48:43 +0000 | [diff] [blame] | 273 | Criticals.try_emplace(D->getDirectiveName().getAsString(), D, Hint); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 274 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 275 | const std::pair<const OMPCriticalDirective *, llvm::APSInt> |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 276 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 277 | auto I = Criticals.find(Name.getAsString()); |
| 278 | if (I != Criticals.end()) |
| 279 | return I->second; |
| 280 | return std::make_pair(nullptr, llvm::APSInt()); |
| 281 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 282 | /// If 'aligned' declaration for given variable \a D was not seen yet, |
| Alp Toker | 15e62a3 | 2014-06-06 12:02:07 +0000 | [diff] [blame] | 283 | /// add it and return NULL; otherwise return previous occurrence's expression |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 284 | /// for diagnostics. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 285 | const Expr *addUniqueAligned(const ValueDecl *D, const Expr *NewDE); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 286 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 287 | /// Register specified variable as loop control variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 288 | void addLoopControlVariable(const ValueDecl *D, VarDecl *Capture); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 289 | /// Check if the specified variable is a loop control variable for |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 290 | /// current region. |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 291 | /// \return The index of the loop control variable in the list of associated |
| 292 | /// for-loops (from outer to inner). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 293 | const LCDeclInfo isLoopControlVariable(const ValueDecl *D) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 294 | /// Check if the specified variable is a loop control variable for |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 295 | /// parent region. |
| 296 | /// \return The index of the loop control variable in the list of associated |
| 297 | /// for-loops (from outer to inner). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 298 | const LCDeclInfo isParentLoopControlVariable(const ValueDecl *D) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 299 | /// Get the loop control variable for the I-th loop (or nullptr) in |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 300 | /// parent directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 301 | const ValueDecl *getParentLoopControlVariable(unsigned I) const; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 302 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 303 | /// Adds explicit data sharing attribute to the specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 304 | void addDSA(const ValueDecl *D, const Expr *E, OpenMPClauseKind A, |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 305 | DeclRefExpr *PrivateCopy = nullptr); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 306 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 307 | /// Adds additional information for the reduction items with the reduction id |
| 308 | /// represented as an operator. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 309 | void addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 310 | BinaryOperatorKind BOK); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 311 | /// Adds additional information for the reduction items with the reduction id |
| 312 | /// represented as reduction identifier. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 313 | void addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 314 | const Expr *ReductionRef); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 315 | /// Returns the location and reduction operation from the innermost parent |
| 316 | /// region for the given \p D. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 317 | const DSAVarData |
| 318 | getTopMostTaskgroupReductionData(const ValueDecl *D, SourceRange &SR, |
| 319 | BinaryOperatorKind &BOK, |
| 320 | Expr *&TaskgroupDescriptor) const; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 321 | /// Returns the location and reduction operation from the innermost parent |
| 322 | /// region for the given \p D. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 323 | const DSAVarData |
| 324 | getTopMostTaskgroupReductionData(const ValueDecl *D, SourceRange &SR, |
| 325 | const Expr *&ReductionRef, |
| 326 | Expr *&TaskgroupDescriptor) const; |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 327 | /// Return reduction reference expression for the current taskgroup. |
| 328 | Expr *getTaskgroupReductionRef() const { |
| 329 | assert(Stack.back().first.back().Directive == OMPD_taskgroup && |
| 330 | "taskgroup reference expression requested for non taskgroup " |
| 331 | "directive."); |
| 332 | return Stack.back().first.back().TaskgroupReductionRef; |
| 333 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 334 | /// Checks if the given \p VD declaration is actually a taskgroup reduction |
| 335 | /// descriptor variable at the \p Level of OpenMP regions. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 336 | bool isTaskgroupReductionRef(const ValueDecl *VD, unsigned Level) const { |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 337 | return Stack.back().first[Level].TaskgroupReductionRef && |
| 338 | cast<DeclRefExpr>(Stack.back().first[Level].TaskgroupReductionRef) |
| 339 | ->getDecl() == VD; |
| 340 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 341 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 342 | /// Returns data sharing attributes from top of the stack for the |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 343 | /// specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 344 | const DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 345 | /// Returns data-sharing attributes for the specified declaration. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 346 | const DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 347 | /// Checks if the specified variables has data-sharing attributes which |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 348 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 349 | /// predicate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 350 | const DSAVarData |
| 351 | hasDSA(ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 352 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| 353 | bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 354 | /// Checks if the specified variables has data-sharing attributes which |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 355 | /// match specified \a CPred predicate in any innermost directive which |
| 356 | /// matches \a DPred predicate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 357 | const DSAVarData |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 358 | hasInnermostDSA(ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 359 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 360 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 361 | bool FromParent) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 362 | /// Checks if the specified variables has explicit data-sharing |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 363 | /// attributes which match specified \a CPred predicate at the specified |
| 364 | /// OpenMP region. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 365 | bool hasExplicitDSA(const ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 366 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 367 | unsigned Level, bool NotLastprivate = false) const; |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 368 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 369 | /// Returns true if the directive at level \Level matches in the |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 370 | /// specified \a DPred predicate. |
| 371 | bool hasExplicitDirective( |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 372 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 373 | unsigned Level) const; |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 374 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 375 | /// Finds a directive which matches specified \a DPred predicate. |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 376 | bool hasDirective( |
| 377 | const llvm::function_ref<bool( |
| 378 | OpenMPDirectiveKind, const DeclarationNameInfo &, SourceLocation)> |
| 379 | DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 380 | bool FromParent) const; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 381 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 382 | /// Returns currently analyzed directive. |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 383 | OpenMPDirectiveKind getCurrentDirective() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 384 | return isStackEmpty() ? OMPD_unknown : Stack.back().first.back().Directive; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 385 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 386 | /// Returns directive kind at specified level. |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 387 | OpenMPDirectiveKind getDirective(unsigned Level) const { |
| 388 | assert(!isStackEmpty() && "No directive at specified level."); |
| 389 | return Stack.back().first[Level].Directive; |
| 390 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 391 | /// Returns parent directive. |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 392 | OpenMPDirectiveKind getParentDirective() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 393 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 394 | return OMPD_unknown; |
| 395 | return std::next(Stack.back().first.rbegin())->Directive; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 396 | } |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 397 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 398 | /// Add requires decl to internal vector |
| 399 | void addRequiresDecl(OMPRequiresDecl *RD) { |
| 400 | RequiresDecls.push_back(RD); |
| 401 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 402 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 403 | /// Checks for a duplicate clause amongst previously declared requires |
| 404 | /// directives |
| 405 | bool hasDuplicateRequiresClause(ArrayRef<OMPClause *> ClauseList) const { |
| 406 | bool IsDuplicate = false; |
| 407 | for (OMPClause *CNew : ClauseList) { |
| 408 | for (const OMPRequiresDecl *D : RequiresDecls) { |
| 409 | for (const OMPClause *CPrev : D->clauselists()) { |
| 410 | if (CNew->getClauseKind() == CPrev->getClauseKind()) { |
| 411 | SemaRef.Diag(CNew->getBeginLoc(), |
| 412 | diag::err_omp_requires_clause_redeclaration) |
| 413 | << getOpenMPClauseName(CNew->getClauseKind()); |
| 414 | SemaRef.Diag(CPrev->getBeginLoc(), |
| 415 | diag::note_omp_requires_previous_clause) |
| 416 | << getOpenMPClauseName(CPrev->getClauseKind()); |
| 417 | IsDuplicate = true; |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | return IsDuplicate; |
| 423 | } |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 424 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 425 | /// Set default data sharing attribute to none. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 426 | void setDefaultDSANone(SourceLocation Loc) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 427 | assert(!isStackEmpty()); |
| 428 | Stack.back().first.back().DefaultAttr = DSA_none; |
| 429 | Stack.back().first.back().DefaultAttrLoc = Loc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 430 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 431 | /// Set default data sharing attribute to shared. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 432 | void setDefaultDSAShared(SourceLocation Loc) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 433 | assert(!isStackEmpty()); |
| 434 | Stack.back().first.back().DefaultAttr = DSA_shared; |
| 435 | Stack.back().first.back().DefaultAttrLoc = Loc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 436 | } |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 437 | /// Set default data mapping attribute to 'tofrom:scalar'. |
| 438 | void setDefaultDMAToFromScalar(SourceLocation Loc) { |
| 439 | assert(!isStackEmpty()); |
| 440 | Stack.back().first.back().DefaultMapAttr = DMA_tofrom_scalar; |
| 441 | Stack.back().first.back().DefaultMapAttrLoc = Loc; |
| 442 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 443 | |
| 444 | DefaultDataSharingAttributes getDefaultDSA() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 445 | return isStackEmpty() ? DSA_unspecified |
| 446 | : Stack.back().first.back().DefaultAttr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 447 | } |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 448 | SourceLocation getDefaultDSALocation() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 449 | return isStackEmpty() ? SourceLocation() |
| 450 | : Stack.back().first.back().DefaultAttrLoc; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 451 | } |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 452 | DefaultMapAttributes getDefaultDMA() const { |
| 453 | return isStackEmpty() ? DMA_unspecified |
| 454 | : Stack.back().first.back().DefaultMapAttr; |
| 455 | } |
| 456 | DefaultMapAttributes getDefaultDMAAtLevel(unsigned Level) const { |
| 457 | return Stack.back().first[Level].DefaultMapAttr; |
| 458 | } |
| 459 | SourceLocation getDefaultDMALocation() const { |
| 460 | return isStackEmpty() ? SourceLocation() |
| 461 | : Stack.back().first.back().DefaultMapAttrLoc; |
| 462 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 463 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 464 | /// Checks if the specified variable is a threadprivate. |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 465 | bool isThreadPrivate(VarDecl *D) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 466 | const DSAVarData DVar = getTopDSA(D, false); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 467 | return isOpenMPThreadPrivate(DVar.CKind); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 468 | } |
| 469 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 470 | /// Marks current region as ordered (it has an 'ordered' clause). |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 471 | void setOrderedRegion(bool IsOrdered, const Expr *Param, |
| 472 | OMPOrderedClause *Clause) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 473 | assert(!isStackEmpty()); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 474 | if (IsOrdered) |
| 475 | Stack.back().first.back().OrderedRegion.emplace(Param, Clause); |
| 476 | else |
| 477 | Stack.back().first.back().OrderedRegion.reset(); |
| 478 | } |
| 479 | /// Returns true, if region is ordered (has associated 'ordered' clause), |
| 480 | /// false - otherwise. |
| 481 | bool isOrderedRegion() const { |
| 482 | if (isStackEmpty()) |
| 483 | return false; |
| 484 | return Stack.back().first.rbegin()->OrderedRegion.hasValue(); |
| 485 | } |
| 486 | /// Returns optional parameter for the ordered region. |
| 487 | std::pair<const Expr *, OMPOrderedClause *> getOrderedRegionParam() const { |
| 488 | if (isStackEmpty() || |
| 489 | !Stack.back().first.rbegin()->OrderedRegion.hasValue()) |
| 490 | return std::make_pair(nullptr, nullptr); |
| 491 | return Stack.back().first.rbegin()->OrderedRegion.getValue(); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 492 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 493 | /// Returns true, if parent region is ordered (has associated |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 494 | /// 'ordered' clause), false - otherwise. |
| 495 | bool isParentOrderedRegion() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 496 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 497 | return false; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 498 | return std::next(Stack.back().first.rbegin())->OrderedRegion.hasValue(); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 499 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 500 | /// Returns optional parameter for the ordered region. |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 501 | std::pair<const Expr *, OMPOrderedClause *> |
| 502 | getParentOrderedRegionParam() const { |
| 503 | if (isStackEmpty() || Stack.back().first.size() == 1 || |
| 504 | !std::next(Stack.back().first.rbegin())->OrderedRegion.hasValue()) |
| 505 | return std::make_pair(nullptr, nullptr); |
| 506 | return std::next(Stack.back().first.rbegin())->OrderedRegion.getValue(); |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 507 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 508 | /// Marks current region as nowait (it has a 'nowait' clause). |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 509 | void setNowaitRegion(bool IsNowait = true) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 510 | assert(!isStackEmpty()); |
| 511 | Stack.back().first.back().NowaitRegion = IsNowait; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 512 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 513 | /// Returns true, if parent region is nowait (has associated |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 514 | /// 'nowait' clause), false - otherwise. |
| 515 | bool isParentNowaitRegion() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 516 | if (isStackEmpty() || Stack.back().first.size() == 1) |
| 517 | return false; |
| 518 | return std::next(Stack.back().first.rbegin())->NowaitRegion; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 519 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 520 | /// Marks parent region as cancel region. |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 521 | void setParentCancelRegion(bool Cancel = true) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 522 | if (!isStackEmpty() && Stack.back().first.size() > 1) { |
| 523 | auto &StackElemRef = *std::next(Stack.back().first.rbegin()); |
| 524 | StackElemRef.CancelRegion |= StackElemRef.CancelRegion || Cancel; |
| 525 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 526 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 527 | /// Return true if current region has inner cancel construct. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 528 | bool isCancelRegion() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 529 | return isStackEmpty() ? false : Stack.back().first.back().CancelRegion; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 530 | } |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 531 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 532 | /// Set collapse value for the region. |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 533 | void setAssociatedLoops(unsigned Val) { |
| 534 | assert(!isStackEmpty()); |
| 535 | Stack.back().first.back().AssociatedLoops = Val; |
| 536 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 537 | /// Return collapse value for region. |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 538 | unsigned getAssociatedLoops() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 539 | return isStackEmpty() ? 0 : Stack.back().first.back().AssociatedLoops; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 540 | } |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 541 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 542 | /// Marks current target region as one with closely nested teams |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 543 | /// region. |
| 544 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 545 | if (!isStackEmpty() && Stack.back().first.size() > 1) { |
| 546 | std::next(Stack.back().first.rbegin())->InnerTeamsRegionLoc = |
| 547 | TeamsRegionLoc; |
| 548 | } |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 549 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 550 | /// Returns true, if current region has closely nested teams region. |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 551 | bool hasInnerTeamsRegion() const { |
| 552 | return getInnerTeamsRegionLoc().isValid(); |
| 553 | } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 554 | /// Returns location of the nested teams region (if any). |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 555 | SourceLocation getInnerTeamsRegionLoc() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 556 | return isStackEmpty() ? SourceLocation() |
| 557 | : Stack.back().first.back().InnerTeamsRegionLoc; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 560 | Scope *getCurScope() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 561 | return isStackEmpty() ? nullptr : Stack.back().first.back().CurScope; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 562 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 563 | SourceLocation getConstructLoc() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 564 | return isStackEmpty() ? SourceLocation() |
| 565 | : Stack.back().first.back().ConstructLoc; |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 566 | } |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 567 | |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 568 | /// Do the check specified in \a Check to all component lists and return true |
| 569 | /// if any issue is found. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 570 | bool checkMappableExprComponentListsForDecl( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 571 | const ValueDecl *VD, bool CurrentRegionOnly, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 572 | const llvm::function_ref< |
| 573 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 574 | OpenMPClauseKind)> |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 575 | Check) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 576 | if (isStackEmpty()) |
| 577 | return false; |
| 578 | auto SI = Stack.back().first.rbegin(); |
| 579 | auto SE = Stack.back().first.rend(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 580 | |
| 581 | if (SI == SE) |
| 582 | return false; |
| 583 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 584 | if (CurrentRegionOnly) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 585 | SE = std::next(SI); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 586 | else |
| 587 | std::advance(SI, 1); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 588 | |
| 589 | for (; SI != SE; ++SI) { |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 590 | auto MI = SI->MappedExprComponents.find(VD); |
| 591 | if (MI != SI->MappedExprComponents.end()) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 592 | for (OMPClauseMappableExprCommon::MappableExprComponentListRef L : |
| 593 | MI->second.Components) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 594 | if (Check(L, MI->second.Kind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 595 | return true; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 596 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 597 | return false; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 600 | /// Do the check specified in \a Check to all component lists at a given level |
| 601 | /// and return true if any issue is found. |
| 602 | bool checkMappableExprComponentListsForDeclAtLevel( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 603 | const ValueDecl *VD, unsigned Level, |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 604 | const llvm::function_ref< |
| 605 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 606 | OpenMPClauseKind)> |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 607 | Check) const { |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 608 | if (isStackEmpty()) |
| 609 | return false; |
| 610 | |
| 611 | auto StartI = Stack.back().first.begin(); |
| 612 | auto EndI = Stack.back().first.end(); |
| 613 | if (std::distance(StartI, EndI) <= (int)Level) |
| 614 | return false; |
| 615 | std::advance(StartI, Level); |
| 616 | |
| 617 | auto MI = StartI->MappedExprComponents.find(VD); |
| 618 | if (MI != StartI->MappedExprComponents.end()) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 619 | for (OMPClauseMappableExprCommon::MappableExprComponentListRef L : |
| 620 | MI->second.Components) |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 621 | if (Check(L, MI->second.Kind)) |
| 622 | return true; |
| 623 | return false; |
| 624 | } |
| 625 | |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 626 | /// Create a new mappable expression component list associated with a given |
| 627 | /// declaration and initialize it with the provided list of components. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 628 | void addMappableExpressionComponents( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 629 | const ValueDecl *VD, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 630 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components, |
| 631 | OpenMPClauseKind WhereFoundClauseKind) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 632 | assert(!isStackEmpty() && |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 633 | "Not expecting to retrieve components from a empty stack!"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 634 | MappedExprComponentTy &MEC = |
| 635 | Stack.back().first.back().MappedExprComponents[VD]; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 636 | // Create new entry and append the new components there. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 637 | MEC.Components.resize(MEC.Components.size() + 1); |
| 638 | MEC.Components.back().append(Components.begin(), Components.end()); |
| 639 | MEC.Kind = WhereFoundClauseKind; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 640 | } |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 641 | |
| 642 | unsigned getNestingLevel() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 643 | assert(!isStackEmpty()); |
| 644 | return Stack.back().first.size() - 1; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 645 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 646 | void addDoacrossDependClause(OMPDependClause *C, |
| 647 | const OperatorOffsetTy &OpsOffs) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 648 | assert(!isStackEmpty() && Stack.back().first.size() > 1); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 649 | SharingMapTy &StackElem = *std::next(Stack.back().first.rbegin()); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 650 | assert(isOpenMPWorksharingDirective(StackElem.Directive)); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 651 | StackElem.DoacrossDepends.try_emplace(C, OpsOffs); |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 652 | } |
| 653 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 654 | getDoacrossDependClauses() const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 655 | assert(!isStackEmpty()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 656 | const SharingMapTy &StackElem = Stack.back().first.back(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 657 | if (isOpenMPWorksharingDirective(StackElem.Directive)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 658 | const DoacrossDependMapTy &Ref = StackElem.DoacrossDepends; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 659 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 660 | } |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 661 | return llvm::make_range(StackElem.DoacrossDepends.end(), |
| 662 | StackElem.DoacrossDepends.end()); |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 663 | } |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 664 | |
| 665 | // Store types of classes which have been explicitly mapped |
| 666 | void addMappedClassesQualTypes(QualType QT) { |
| 667 | SharingMapTy &StackElem = Stack.back().first.back(); |
| 668 | StackElem.MappedClassesQualTypes.insert(QT); |
| 669 | } |
| 670 | |
| 671 | // Return set of mapped classes types |
| 672 | bool isClassPreviouslyMapped(QualType QT) const { |
| 673 | const SharingMapTy &StackElem = Stack.back().first.back(); |
| 674 | return StackElem.MappedClassesQualTypes.count(QT) != 0; |
| 675 | } |
| 676 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 677 | }; |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 678 | |
| 679 | bool isImplicitTaskingRegion(OpenMPDirectiveKind DKind) { |
| 680 | return isOpenMPParallelDirective(DKind) || isOpenMPTeamsDirective(DKind); |
| 681 | } |
| 682 | |
| 683 | bool isImplicitOrExplicitTaskingRegion(OpenMPDirectiveKind DKind) { |
| 684 | return isImplicitTaskingRegion(DKind) || isOpenMPTaskingDirective(DKind) || DKind == OMPD_unknown; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 685 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 686 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 687 | } // namespace |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 688 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 689 | static const Expr *getExprAsWritten(const Expr *E) { |
| Bill Wendling | 7c44da2 | 2018-10-31 03:48:47 +0000 | [diff] [blame] | 690 | if (const auto *FE = dyn_cast<FullExpr>(E)) |
| 691 | E = FE->getSubExpr(); |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 692 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 693 | if (const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 694 | E = MTE->GetTemporaryExpr(); |
| 695 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 696 | while (const auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 697 | E = Binder->getSubExpr(); |
| 698 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 699 | if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 700 | E = ICE->getSubExprAsWritten(); |
| 701 | return E->IgnoreParens(); |
| 702 | } |
| 703 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 704 | static Expr *getExprAsWritten(Expr *E) { |
| 705 | return const_cast<Expr *>(getExprAsWritten(const_cast<const Expr *>(E))); |
| 706 | } |
| 707 | |
| 708 | static const ValueDecl *getCanonicalDecl(const ValueDecl *D) { |
| 709 | if (const auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) |
| 710 | if (const auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 711 | D = ME->getMemberDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 712 | const auto *VD = dyn_cast<VarDecl>(D); |
| 713 | const auto *FD = dyn_cast<FieldDecl>(D); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 714 | if (VD != nullptr) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 715 | VD = VD->getCanonicalDecl(); |
| 716 | D = VD; |
| 717 | } else { |
| 718 | assert(FD); |
| 719 | FD = FD->getCanonicalDecl(); |
| 720 | D = FD; |
| 721 | } |
| 722 | return D; |
| 723 | } |
| 724 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 725 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 726 | return const_cast<ValueDecl *>( |
| 727 | getCanonicalDecl(const_cast<const ValueDecl *>(D))); |
| 728 | } |
| 729 | |
| 730 | DSAStackTy::DSAVarData DSAStackTy::getDSA(iterator &Iter, |
| 731 | ValueDecl *D) const { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 732 | D = getCanonicalDecl(D); |
| 733 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 734 | const auto *FD = dyn_cast<FieldDecl>(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 735 | DSAVarData DVar; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 736 | if (isStackEmpty() || Iter == Stack.back().first.rend()) { |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 737 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 738 | // in a region but not in construct] |
| 739 | // File-scope or namespace-scope variables referenced in called routines |
| 740 | // in the region are shared unless they appear in a threadprivate |
| 741 | // directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 742 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(VD)) |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 743 | DVar.CKind = OMPC_shared; |
| 744 | |
| 745 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 746 | // in a region but not in construct] |
| 747 | // Variables with static storage duration that are declared in called |
| 748 | // routines in the region are shared. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 749 | if (VD && VD->hasGlobalStorage()) |
| 750 | DVar.CKind = OMPC_shared; |
| 751 | |
| 752 | // Non-static data members are shared by default. |
| 753 | if (FD) |
| Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 754 | DVar.CKind = OMPC_shared; |
| 755 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 756 | return DVar; |
| 757 | } |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 758 | |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 759 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 760 | // in a Construct, C/C++, predetermined, p.1] |
| 761 | // Variables with automatic storage duration that are declared in a scope |
| 762 | // inside the construct are private. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 763 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 764 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 765 | DVar.CKind = OMPC_private; |
| 766 | return DVar; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 767 | } |
| 768 | |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 769 | DVar.DKind = Iter->Directive; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 770 | // Explicitly specified attributes and local variables with predetermined |
| 771 | // attributes. |
| 772 | if (Iter->SharingMap.count(D)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 773 | const DSAInfo &Data = Iter->SharingMap.lookup(D); |
| 774 | DVar.RefExpr = Data.RefExpr.getPointer(); |
| 775 | DVar.PrivateCopy = Data.PrivateCopy; |
| 776 | DVar.CKind = Data.Attributes; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 777 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 778 | return DVar; |
| 779 | } |
| 780 | |
| 781 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 782 | // in a Construct, C/C++, implicitly determined, p.1] |
| 783 | // In a parallel or task construct, the data-sharing attributes of these |
| 784 | // variables are determined by the default clause, if present. |
| 785 | switch (Iter->DefaultAttr) { |
| 786 | case DSA_shared: |
| 787 | DVar.CKind = OMPC_shared; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 788 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 789 | return DVar; |
| 790 | case DSA_none: |
| 791 | return DVar; |
| 792 | case DSA_unspecified: |
| 793 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 794 | // in a Construct, implicitly determined, p.2] |
| 795 | // In a parallel construct, if no default clause is present, these |
| 796 | // variables are shared. |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 797 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 798 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 799 | isOpenMPTeamsDirective(DVar.DKind)) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 800 | DVar.CKind = OMPC_shared; |
| 801 | return DVar; |
| 802 | } |
| 803 | |
| 804 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 805 | // in a Construct, implicitly determined, p.4] |
| 806 | // In a task construct, if no default clause is present, a variable that in |
| 807 | // the enclosing context is determined to be shared by all implicit tasks |
| 808 | // bound to the current team is shared. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 809 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 810 | DSAVarData DVarTemp; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 811 | iterator I = Iter, E = Stack.back().first.rend(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 812 | do { |
| 813 | ++I; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 814 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 815 | // Referenced in a Construct, implicitly determined, p.6] |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 816 | // In a task construct, if no default clause is present, a variable |
| 817 | // whose data-sharing attribute is not determined by the rules above is |
| 818 | // firstprivate. |
| 819 | DVarTemp = getDSA(I, D); |
| 820 | if (DVarTemp.CKind != OMPC_shared) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 821 | DVar.RefExpr = nullptr; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 822 | DVar.CKind = OMPC_firstprivate; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 823 | return DVar; |
| 824 | } |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 825 | } while (I != E && !isImplicitTaskingRegion(I->Directive)); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 826 | DVar.CKind = |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 827 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 828 | return DVar; |
| 829 | } |
| 830 | } |
| 831 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 832 | // in a Construct, implicitly determined, p.3] |
| 833 | // For constructs other than task, if no default clause is present, these |
| 834 | // variables inherit their data-sharing attributes from the enclosing |
| 835 | // context. |
| Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 836 | return getDSA(++Iter, D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 837 | } |
| 838 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 839 | const Expr *DSAStackTy::addUniqueAligned(const ValueDecl *D, |
| 840 | const Expr *NewDE) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 841 | assert(!isStackEmpty() && "Data sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 842 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 843 | SharingMapTy &StackElem = Stack.back().first.back(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 844 | auto It = StackElem.AlignedMap.find(D); |
| 845 | if (It == StackElem.AlignedMap.end()) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 846 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 847 | StackElem.AlignedMap[D] = NewDE; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 848 | return nullptr; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 849 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 850 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 851 | return It->second; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 852 | } |
| 853 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 854 | void DSAStackTy::addLoopControlVariable(const ValueDecl *D, VarDecl *Capture) { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 855 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 856 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 857 | SharingMapTy &StackElem = Stack.back().first.back(); |
| 858 | StackElem.LCVMap.try_emplace( |
| 859 | D, LCDeclInfo(StackElem.LCVMap.size() + 1, Capture)); |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 862 | const DSAStackTy::LCDeclInfo |
| 863 | DSAStackTy::isLoopControlVariable(const ValueDecl *D) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 864 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 865 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 866 | const SharingMapTy &StackElem = Stack.back().first.back(); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 867 | auto It = StackElem.LCVMap.find(D); |
| 868 | if (It != StackElem.LCVMap.end()) |
| 869 | return It->second; |
| 870 | return {0, nullptr}; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 871 | } |
| 872 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 873 | const DSAStackTy::LCDeclInfo |
| 874 | DSAStackTy::isParentLoopControlVariable(const ValueDecl *D) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 875 | assert(!isStackEmpty() && Stack.back().first.size() > 1 && |
| 876 | "Data-sharing attributes stack is empty"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 877 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 878 | const SharingMapTy &StackElem = *std::next(Stack.back().first.rbegin()); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 879 | auto It = StackElem.LCVMap.find(D); |
| 880 | if (It != StackElem.LCVMap.end()) |
| 881 | return It->second; |
| 882 | return {0, nullptr}; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 885 | const ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 886 | assert(!isStackEmpty() && Stack.back().first.size() > 1 && |
| 887 | "Data-sharing attributes stack is empty"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 888 | const SharingMapTy &StackElem = *std::next(Stack.back().first.rbegin()); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 889 | if (StackElem.LCVMap.size() < I) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 890 | return nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 891 | for (const auto &Pair : StackElem.LCVMap) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 892 | if (Pair.second.first == I) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 893 | return Pair.first; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 894 | return nullptr; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 897 | void DSAStackTy::addDSA(const ValueDecl *D, const Expr *E, OpenMPClauseKind A, |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 898 | DeclRefExpr *PrivateCopy) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 899 | D = getCanonicalDecl(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 900 | if (A == OMPC_threadprivate) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 901 | DSAInfo &Data = Threadprivates[D]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 902 | Data.Attributes = A; |
| 903 | Data.RefExpr.setPointer(E); |
| 904 | Data.PrivateCopy = nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 905 | } else { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 906 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 907 | DSAInfo &Data = Stack.back().first.back().SharingMap[D]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 908 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 909 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 910 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 911 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 912 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 913 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 914 | return; |
| 915 | } |
| 916 | const bool IsLastprivate = |
| 917 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 918 | Data.Attributes = A; |
| 919 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 920 | Data.PrivateCopy = PrivateCopy; |
| 921 | if (PrivateCopy) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 922 | DSAInfo &Data = |
| 923 | Stack.back().first.back().SharingMap[PrivateCopy->getDecl()]; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 924 | Data.Attributes = A; |
| 925 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 926 | Data.PrivateCopy = nullptr; |
| 927 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 931 | /// Build a variable declaration for OpenMP loop iteration variable. |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 932 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 933 | StringRef Name, const AttrVec *Attrs = nullptr, |
| 934 | DeclRefExpr *OrigRef = nullptr) { |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 935 | DeclContext *DC = SemaRef.CurContext; |
| 936 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 937 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 938 | auto *Decl = |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 939 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
| 940 | if (Attrs) { |
| 941 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 942 | I != E; ++I) |
| 943 | Decl->addAttr(*I); |
| 944 | } |
| 945 | Decl->setImplicit(); |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 946 | if (OrigRef) { |
| 947 | Decl->addAttr( |
| 948 | OMPReferencedVarAttr::CreateImplicit(SemaRef.Context, OrigRef)); |
| 949 | } |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 950 | return Decl; |
| 951 | } |
| 952 | |
| 953 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 954 | SourceLocation Loc, |
| 955 | bool RefersToCapture = false) { |
| 956 | D->setReferenced(); |
| 957 | D->markUsed(S.Context); |
| 958 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 959 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 960 | VK_LValue); |
| 961 | } |
| 962 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 963 | void DSAStackTy::addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 964 | BinaryOperatorKind BOK) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 965 | D = getCanonicalDecl(D); |
| 966 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 967 | assert( |
| Richard Trieu | 09f1411 | 2017-07-21 21:29:35 +0000 | [diff] [blame] | 968 | Stack.back().first.back().SharingMap[D].Attributes == OMPC_reduction && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 969 | "Additional reduction info may be specified only for reduction items."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 970 | ReductionData &ReductionData = Stack.back().first.back().ReductionMap[D]; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 971 | assert(ReductionData.ReductionRange.isInvalid() && |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 972 | Stack.back().first.back().Directive == OMPD_taskgroup && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 973 | "Additional reduction info may be specified only once for reduction " |
| 974 | "items."); |
| 975 | ReductionData.set(BOK, SR); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 976 | Expr *&TaskgroupReductionRef = |
| 977 | Stack.back().first.back().TaskgroupReductionRef; |
| 978 | if (!TaskgroupReductionRef) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 979 | VarDecl *VD = buildVarDecl(SemaRef, SR.getBegin(), |
| 980 | SemaRef.Context.VoidPtrTy, ".task_red."); |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 981 | TaskgroupReductionRef = |
| 982 | buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, SR.getBegin()); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 983 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 986 | void DSAStackTy::addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 987 | const Expr *ReductionRef) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 988 | D = getCanonicalDecl(D); |
| 989 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty"); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 990 | assert( |
| Richard Trieu | 09f1411 | 2017-07-21 21:29:35 +0000 | [diff] [blame] | 991 | Stack.back().first.back().SharingMap[D].Attributes == OMPC_reduction && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 992 | "Additional reduction info may be specified only for reduction items."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 993 | ReductionData &ReductionData = Stack.back().first.back().ReductionMap[D]; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 994 | assert(ReductionData.ReductionRange.isInvalid() && |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 995 | Stack.back().first.back().Directive == OMPD_taskgroup && |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 996 | "Additional reduction info may be specified only once for reduction " |
| 997 | "items."); |
| 998 | ReductionData.set(ReductionRef, SR); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 999 | Expr *&TaskgroupReductionRef = |
| 1000 | Stack.back().first.back().TaskgroupReductionRef; |
| 1001 | if (!TaskgroupReductionRef) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1002 | VarDecl *VD = buildVarDecl(SemaRef, SR.getBegin(), |
| 1003 | SemaRef.Context.VoidPtrTy, ".task_red."); |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 1004 | TaskgroupReductionRef = |
| 1005 | buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, SR.getBegin()); |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 1006 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1009 | const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData( |
| 1010 | const ValueDecl *D, SourceRange &SR, BinaryOperatorKind &BOK, |
| 1011 | Expr *&TaskgroupDescriptor) const { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1012 | D = getCanonicalDecl(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1013 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty."); |
| 1014 | if (Stack.back().first.empty()) |
| 1015 | return DSAVarData(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1016 | for (iterator I = std::next(Stack.back().first.rbegin(), 1), |
| 1017 | E = Stack.back().first.rend(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1018 | I != E; std::advance(I, 1)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1019 | const DSAInfo &Data = I->SharingMap.lookup(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1020 | if (Data.Attributes != OMPC_reduction || I->Directive != OMPD_taskgroup) |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1021 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1022 | const ReductionData &ReductionData = I->ReductionMap.lookup(D); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1023 | if (!ReductionData.ReductionOp || |
| 1024 | ReductionData.ReductionOp.is<const Expr *>()) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1025 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1026 | SR = ReductionData.ReductionRange; |
| Alexey Bataev | f87fa88 | 2017-07-21 19:26:22 +0000 | [diff] [blame] | 1027 | BOK = ReductionData.ReductionOp.get<ReductionData::BOKPtrType>(); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 1028 | assert(I->TaskgroupReductionRef && "taskgroup reduction reference " |
| 1029 | "expression for the descriptor is not " |
| 1030 | "set."); |
| 1031 | TaskgroupDescriptor = I->TaskgroupReductionRef; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1032 | return DSAVarData(OMPD_taskgroup, OMPC_reduction, Data.RefExpr.getPointer(), |
| 1033 | Data.PrivateCopy, I->DefaultAttrLoc); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1034 | } |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1035 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1038 | const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData( |
| 1039 | const ValueDecl *D, SourceRange &SR, const Expr *&ReductionRef, |
| 1040 | Expr *&TaskgroupDescriptor) const { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1041 | D = getCanonicalDecl(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1042 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty."); |
| 1043 | if (Stack.back().first.empty()) |
| 1044 | return DSAVarData(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1045 | for (iterator I = std::next(Stack.back().first.rbegin(), 1), |
| 1046 | E = Stack.back().first.rend(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1047 | I != E; std::advance(I, 1)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1048 | const DSAInfo &Data = I->SharingMap.lookup(D); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1049 | if (Data.Attributes != OMPC_reduction || I->Directive != OMPD_taskgroup) |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1050 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1051 | const ReductionData &ReductionData = I->ReductionMap.lookup(D); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1052 | if (!ReductionData.ReductionOp || |
| 1053 | !ReductionData.ReductionOp.is<const Expr *>()) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1054 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1055 | SR = ReductionData.ReductionRange; |
| 1056 | ReductionRef = ReductionData.ReductionOp.get<const Expr *>(); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 1057 | assert(I->TaskgroupReductionRef && "taskgroup reduction reference " |
| 1058 | "expression for the descriptor is not " |
| 1059 | "set."); |
| 1060 | TaskgroupDescriptor = I->TaskgroupReductionRef; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1061 | return DSAVarData(OMPD_taskgroup, OMPC_reduction, Data.RefExpr.getPointer(), |
| 1062 | Data.PrivateCopy, I->DefaultAttrLoc); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1063 | } |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 1064 | return DSAVarData(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 1065 | } |
| 1066 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1067 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, iterator Iter) const { |
| Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1068 | D = D->getCanonicalDecl(); |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1069 | if (!isStackEmpty()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1070 | iterator I = Iter, E = Stack.back().first.rend(); |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1071 | Scope *TopScope = nullptr; |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 1072 | while (I != E && !isImplicitOrExplicitTaskingRegion(I->Directive) && |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1073 | !isOpenMPTargetExecutionDirective(I->Directive)) |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1074 | ++I; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1075 | if (I == E) |
| 1076 | return false; |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1077 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1078 | Scope *CurScope = getCurScope(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1079 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1080 | CurScope = CurScope->getParent(); |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1081 | return CurScope != TopScope; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1082 | } |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1083 | return false; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1086 | static bool isConstNotMutableType(Sema &SemaRef, QualType Type, |
| 1087 | bool AcceptIfMutable = true, |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1088 | bool *IsClassType = nullptr) { |
| 1089 | ASTContext &Context = SemaRef.getASTContext(); |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1090 | Type = Type.getNonReferenceType().getCanonicalType(); |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1091 | bool IsConstant = Type.isConstant(Context); |
| 1092 | Type = Context.getBaseElementType(Type); |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1093 | const CXXRecordDecl *RD = AcceptIfMutable && SemaRef.getLangOpts().CPlusPlus |
| 1094 | ? Type->getAsCXXRecordDecl() |
| 1095 | : nullptr; |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1096 | if (const auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 1097 | if (const ClassTemplateDecl *CTD = CTSD->getSpecializedTemplate()) |
| 1098 | RD = CTD->getTemplatedDecl(); |
| 1099 | if (IsClassType) |
| 1100 | *IsClassType = RD; |
| 1101 | return IsConstant && !(SemaRef.getLangOpts().CPlusPlus && RD && |
| 1102 | RD->hasDefinition() && RD->hasMutableFields()); |
| 1103 | } |
| 1104 | |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1105 | static bool rejectConstNotMutableType(Sema &SemaRef, const ValueDecl *D, |
| 1106 | QualType Type, OpenMPClauseKind CKind, |
| 1107 | SourceLocation ELoc, |
| 1108 | bool AcceptIfMutable = true, |
| 1109 | bool ListItemNotVar = false) { |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1110 | ASTContext &Context = SemaRef.getASTContext(); |
| 1111 | bool IsClassType; |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1112 | if (isConstNotMutableType(SemaRef, Type, AcceptIfMutable, &IsClassType)) { |
| 1113 | unsigned Diag = ListItemNotVar |
| 1114 | ? diag::err_omp_const_list_item |
| 1115 | : IsClassType ? diag::err_omp_const_not_mutable_variable |
| 1116 | : diag::err_omp_const_variable; |
| 1117 | SemaRef.Diag(ELoc, Diag) << getOpenMPClauseName(CKind); |
| 1118 | if (!ListItemNotVar && D) { |
| 1119 | const VarDecl *VD = dyn_cast<VarDecl>(D); |
| 1120 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 1121 | VarDecl::DeclarationOnly; |
| 1122 | SemaRef.Diag(D->getLocation(), |
| 1123 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1124 | << D; |
| 1125 | } |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1126 | return true; |
| 1127 | } |
| 1128 | return false; |
| 1129 | } |
| 1130 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1131 | const DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, |
| 1132 | bool FromParent) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1133 | D = getCanonicalDecl(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1134 | DSAVarData DVar; |
| 1135 | |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1136 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1137 | auto TI = Threadprivates.find(D); |
| 1138 | if (TI != Threadprivates.end()) { |
| 1139 | DVar.RefExpr = TI->getSecond().RefExpr.getPointer(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1140 | DVar.CKind = OMPC_threadprivate; |
| 1141 | return DVar; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1142 | } |
| 1143 | if (VD && VD->hasAttr<OMPThreadPrivateDeclAttr>()) { |
| Alexey Bataev | 817d7f3 | 2017-11-14 21:01:01 +0000 | [diff] [blame] | 1144 | DVar.RefExpr = buildDeclRefExpr( |
| 1145 | SemaRef, VD, D->getType().getNonReferenceType(), |
| 1146 | VD->getAttr<OMPThreadPrivateDeclAttr>()->getLocation()); |
| 1147 | DVar.CKind = OMPC_threadprivate; |
| 1148 | addDSA(D, DVar.RefExpr, OMPC_threadprivate); |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1149 | return DVar; |
| 1150 | } |
| 1151 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1152 | // in a Construct, C/C++, predetermined, p.1] |
| 1153 | // Variables appearing in threadprivate directives are threadprivate. |
| 1154 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 1155 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1156 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 1157 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
| 1158 | (VD && VD->getStorageClass() == SC_Register && |
| 1159 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 1160 | DVar.RefExpr = buildDeclRefExpr( |
| 1161 | SemaRef, VD, D->getType().getNonReferenceType(), D->getLocation()); |
| 1162 | DVar.CKind = OMPC_threadprivate; |
| 1163 | addDSA(D, DVar.RefExpr, OMPC_threadprivate); |
| 1164 | return DVar; |
| 1165 | } |
| 1166 | if (SemaRef.getLangOpts().OpenMPCUDAMode && VD && |
| 1167 | VD->isLocalVarDeclOrParm() && !isStackEmpty() && |
| 1168 | !isLoopControlVariable(D).first) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1169 | iterator IterTarget = |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1170 | std::find_if(Stack.back().first.rbegin(), Stack.back().first.rend(), |
| 1171 | [](const SharingMapTy &Data) { |
| 1172 | return isOpenMPTargetExecutionDirective(Data.Directive); |
| 1173 | }); |
| 1174 | if (IterTarget != Stack.back().first.rend()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1175 | iterator ParentIterTarget = std::next(IterTarget, 1); |
| 1176 | for (iterator Iter = Stack.back().first.rbegin(); |
| 1177 | Iter != ParentIterTarget; std::advance(Iter, 1)) { |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1178 | if (isOpenMPLocal(VD, Iter)) { |
| 1179 | DVar.RefExpr = |
| 1180 | buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
| 1181 | D->getLocation()); |
| 1182 | DVar.CKind = OMPC_threadprivate; |
| 1183 | return DVar; |
| 1184 | } |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1185 | } |
| 1186 | if (!isClauseParsingMode() || IterTarget != Stack.back().first.rbegin()) { |
| 1187 | auto DSAIter = IterTarget->SharingMap.find(D); |
| 1188 | if (DSAIter != IterTarget->SharingMap.end() && |
| 1189 | isOpenMPPrivate(DSAIter->getSecond().Attributes)) { |
| 1190 | DVar.RefExpr = DSAIter->getSecond().RefExpr.getPointer(); |
| 1191 | DVar.CKind = OMPC_threadprivate; |
| 1192 | return DVar; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1193 | } |
| 1194 | iterator End = Stack.back().first.rend(); |
| 1195 | if (!SemaRef.isOpenMPCapturedByRef( |
| 1196 | D, std::distance(ParentIterTarget, End))) { |
| Alexey Bataev | 852525d | 2018-03-02 17:17:12 +0000 | [diff] [blame] | 1197 | DVar.RefExpr = |
| 1198 | buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
| 1199 | IterTarget->ConstructLoc); |
| 1200 | DVar.CKind = OMPC_threadprivate; |
| 1201 | return DVar; |
| 1202 | } |
| 1203 | } |
| 1204 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1205 | } |
| 1206 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1207 | if (isStackEmpty()) |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1208 | // Not in OpenMP execution region and top scope was already checked. |
| 1209 | return DVar; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1210 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1211 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 1212 | // in a Construct, C/C++, predetermined, p.4] |
| 1213 | // Static data members are shared. |
| 1214 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1215 | // in a Construct, C/C++, predetermined, p.7] |
| 1216 | // Variables with static storage duration that are declared in a scope |
| 1217 | // inside the construct are shared. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1218 | auto &&MatchesAlways = [](OpenMPDirectiveKind) { return true; }; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1219 | if (VD && VD->isStaticDataMember()) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1220 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); |
| Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 1221 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1222 | return DVar; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1223 | |
| Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 1224 | DVar.CKind = OMPC_shared; |
| 1225 | return DVar; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1226 | } |
| 1227 | |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1228 | // The predetermined shared attribute for const-qualified types having no |
| 1229 | // mutable members was removed after OpenMP 3.1. |
| 1230 | if (SemaRef.LangOpts.OpenMP <= 31) { |
| 1231 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 1232 | // in a Construct, C/C++, predetermined, p.6] |
| 1233 | // Variables with const qualified type having no mutable member are |
| 1234 | // shared. |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 1235 | if (isConstNotMutableType(SemaRef, D->getType())) { |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1236 | // Variables with const-qualified type having no mutable member may be |
| 1237 | // listed in a firstprivate clause, even if they are static data members. |
| 1238 | DSAVarData DVarTemp = hasInnermostDSA( |
| 1239 | D, |
| 1240 | [](OpenMPClauseKind C) { |
| 1241 | return C == OMPC_firstprivate || C == OMPC_shared; |
| 1242 | }, |
| 1243 | MatchesAlways, FromParent); |
| 1244 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 1245 | return DVarTemp; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1246 | |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 1247 | DVar.CKind = OMPC_shared; |
| 1248 | return DVar; |
| 1249 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1252 | // Explicitly specified attributes and local variables with predetermined |
| 1253 | // attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1254 | iterator I = Stack.back().first.rbegin(); |
| 1255 | iterator EndI = Stack.back().first.rend(); |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1256 | if (FromParent && I != EndI) |
| 1257 | std::advance(I, 1); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1258 | auto It = I->SharingMap.find(D); |
| 1259 | if (It != I->SharingMap.end()) { |
| 1260 | const DSAInfo &Data = It->getSecond(); |
| 1261 | DVar.RefExpr = Data.RefExpr.getPointer(); |
| 1262 | DVar.PrivateCopy = Data.PrivateCopy; |
| 1263 | DVar.CKind = Data.Attributes; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1264 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 1265 | DVar.DKind = I->Directive; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | return DVar; |
| 1269 | } |
| 1270 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1271 | const DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 1272 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1273 | if (isStackEmpty()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1274 | iterator I; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1275 | return getDSA(I, D); |
| 1276 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1277 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1278 | iterator StartI = Stack.back().first.rbegin(); |
| 1279 | iterator EndI = Stack.back().first.rend(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1280 | if (FromParent && StartI != EndI) |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1281 | std::advance(StartI, 1); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1282 | return getDSA(StartI, D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1285 | const DSAStackTy::DSAVarData |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1286 | DSAStackTy::hasDSA(ValueDecl *D, |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1287 | const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1288 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1289 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1290 | if (isStackEmpty()) |
| 1291 | return {}; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1292 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1293 | iterator I = Stack.back().first.rbegin(); |
| 1294 | iterator EndI = Stack.back().first.rend(); |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1295 | if (FromParent && I != EndI) |
| Alexey Bataev | 0e6fc1c | 2017-04-27 14:46:26 +0000 | [diff] [blame] | 1296 | std::advance(I, 1); |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1297 | for (; I != EndI; std::advance(I, 1)) { |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 1298 | if (!DPred(I->Directive) && !isImplicitOrExplicitTaskingRegion(I->Directive)) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1299 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1300 | iterator NewI = I; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1301 | DSAVarData DVar = getDSA(NewI, D); |
| 1302 | if (I == NewI && CPred(DVar.CKind)) |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1303 | return DVar; |
| Alexey Bataev | 60859c0 | 2017-04-27 15:10:33 +0000 | [diff] [blame] | 1304 | } |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1305 | return {}; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1308 | const DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1309 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1310 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1311 | bool FromParent) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1312 | if (isStackEmpty()) |
| 1313 | return {}; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1314 | D = getCanonicalDecl(D); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1315 | iterator StartI = Stack.back().first.rbegin(); |
| 1316 | iterator EndI = Stack.back().first.rend(); |
| Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 1317 | if (FromParent && StartI != EndI) |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1318 | std::advance(StartI, 1); |
| Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 1319 | if (StartI == EndI || !DPred(StartI->Directive)) |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1320 | return {}; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1321 | iterator NewI = StartI; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 1322 | DSAVarData DVar = getDSA(NewI, D); |
| 1323 | return (NewI == StartI && CPred(DVar.CKind)) ? DVar : DSAVarData(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1326 | bool DSAStackTy::hasExplicitDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1327 | const ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> CPred, |
| 1328 | unsigned Level, bool NotLastprivate) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1329 | if (isStackEmpty()) |
| 1330 | return false; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1331 | D = getCanonicalDecl(D); |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1332 | auto StartI = Stack.back().first.begin(); |
| 1333 | auto EndI = Stack.back().first.end(); |
| NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 1334 | if (std::distance(StartI, EndI) <= (int)Level) |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1335 | return false; |
| 1336 | std::advance(StartI, Level); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1337 | auto I = StartI->SharingMap.find(D); |
| Alexey Bataev | 92b3365 | 2018-11-21 19:41:10 +0000 | [diff] [blame] | 1338 | if ((I != StartI->SharingMap.end()) && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1339 | I->getSecond().RefExpr.getPointer() && |
| 1340 | CPred(I->getSecond().Attributes) && |
| Alexey Bataev | 92b3365 | 2018-11-21 19:41:10 +0000 | [diff] [blame] | 1341 | (!NotLastprivate || !I->getSecond().RefExpr.getInt())) |
| 1342 | return true; |
| 1343 | // Check predetermined rules for the loop control variables. |
| 1344 | auto LI = StartI->LCVMap.find(D); |
| 1345 | if (LI != StartI->LCVMap.end()) |
| 1346 | return CPred(OMPC_private); |
| 1347 | return false; |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1350 | bool DSAStackTy::hasExplicitDirective( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1351 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
| 1352 | unsigned Level) const { |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1353 | if (isStackEmpty()) |
| 1354 | return false; |
| 1355 | auto StartI = Stack.back().first.begin(); |
| 1356 | auto EndI = Stack.back().first.end(); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1357 | if (std::distance(StartI, EndI) <= (int)Level) |
| 1358 | return false; |
| 1359 | std::advance(StartI, Level); |
| 1360 | return DPred(StartI->Directive); |
| 1361 | } |
| 1362 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1363 | bool DSAStackTy::hasDirective( |
| 1364 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 1365 | const DeclarationNameInfo &, SourceLocation)> |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 1366 | DPred, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1367 | bool FromParent) const { |
| Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1368 | // We look only in the enclosing region. |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1369 | if (isStackEmpty()) |
| Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1370 | return false; |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1371 | auto StartI = std::next(Stack.back().first.rbegin()); |
| 1372 | auto EndI = Stack.back().first.rend(); |
| Alexey Bataev | ccaddfb | 2017-04-26 14:24:21 +0000 | [diff] [blame] | 1373 | if (FromParent && StartI != EndI) |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1374 | StartI = std::next(StartI); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1375 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 1376 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 1377 | return true; |
| 1378 | } |
| 1379 | return false; |
| 1380 | } |
| 1381 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1382 | void Sema::InitDataSharingAttributesStack() { |
| 1383 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 1384 | } |
| 1385 | |
| 1386 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 1387 | |
| Alexey Bataev | 4b46539 | 2017-04-26 15:06:24 +0000 | [diff] [blame] | 1388 | void Sema::pushOpenMPFunctionRegion() { |
| 1389 | DSAStack->pushFunction(); |
| 1390 | } |
| 1391 | |
| 1392 | void Sema::popOpenMPFunctionRegion(const FunctionScopeInfo *OldFSI) { |
| 1393 | DSAStack->popFunction(OldFSI); |
| 1394 | } |
| 1395 | |
| Alexey Bataev | c416e64 | 2019-02-08 18:02:25 +0000 | [diff] [blame] | 1396 | static bool isOpenMPDeviceDelayedContext(Sema &S) { |
| 1397 | assert(S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice && |
| 1398 | "Expected OpenMP device compilation."); |
| 1399 | return !S.isInOpenMPTargetExecutionDirective() && |
| 1400 | !S.isInOpenMPDeclareTargetContext(); |
| 1401 | } |
| 1402 | |
| 1403 | /// Do we know that we will eventually codegen the given function? |
| 1404 | static bool isKnownEmitted(Sema &S, FunctionDecl *FD) { |
| 1405 | assert(S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice && |
| 1406 | "Expected OpenMP device compilation."); |
| 1407 | // Templates are emitted when they're instantiated. |
| 1408 | if (FD->isDependentContext()) |
| 1409 | return false; |
| 1410 | |
| 1411 | if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( |
| 1412 | FD->getCanonicalDecl())) |
| 1413 | return true; |
| 1414 | |
| 1415 | // Otherwise, the function is known-emitted if it's in our set of |
| 1416 | // known-emitted functions. |
| 1417 | return S.DeviceKnownEmittedFns.count(FD) > 0; |
| 1418 | } |
| 1419 | |
| 1420 | Sema::DeviceDiagBuilder Sema::diagIfOpenMPDeviceCode(SourceLocation Loc, |
| 1421 | unsigned DiagID) { |
| 1422 | assert(LangOpts.OpenMP && LangOpts.OpenMPIsDevice && |
| 1423 | "Expected OpenMP device compilation."); |
| 1424 | return DeviceDiagBuilder((isOpenMPDeviceDelayedContext(*this) && |
| 1425 | !isKnownEmitted(*this, getCurFunctionDecl())) |
| 1426 | ? DeviceDiagBuilder::K_Deferred |
| 1427 | : DeviceDiagBuilder::K_Immediate, |
| 1428 | Loc, DiagID, getCurFunctionDecl(), *this); |
| 1429 | } |
| 1430 | |
| 1431 | void Sema::checkOpenMPDeviceFunction(SourceLocation Loc, FunctionDecl *Callee) { |
| 1432 | assert(LangOpts.OpenMP && LangOpts.OpenMPIsDevice && |
| 1433 | "Expected OpenMP device compilation."); |
| 1434 | assert(Callee && "Callee may not be null."); |
| 1435 | FunctionDecl *Caller = getCurFunctionDecl(); |
| 1436 | |
| 1437 | // If the caller is known-emitted, mark the callee as known-emitted. |
| 1438 | // Otherwise, mark the call in our call graph so we can traverse it later. |
| 1439 | if (!isOpenMPDeviceDelayedContext(*this) || |
| 1440 | (Caller && isKnownEmitted(*this, Caller))) |
| 1441 | markKnownEmitted(*this, Caller, Callee, Loc, isKnownEmitted); |
| 1442 | else if (Caller) |
| 1443 | DeviceCallGraph[Caller].insert({Callee, Loc}); |
| 1444 | } |
| 1445 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1446 | bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level) const { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1447 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1448 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1449 | ASTContext &Ctx = getASTContext(); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1450 | bool IsByRef = true; |
| 1451 | |
| 1452 | // Find the directive that is associated with the provided scope. |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 1453 | D = cast<ValueDecl>(D->getCanonicalDecl()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1454 | QualType Ty = D->getType(); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1455 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1456 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1457 | // This table summarizes how a given variable should be passed to the device |
| 1458 | // given its type and the clauses where it appears. This table is based on |
| 1459 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 1460 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 1461 | // |
| 1462 | // ========================================================================= |
| 1463 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 1464 | // | |(tofrom:scalar)| | pvt | | | | |
| 1465 | // ========================================================================= |
| 1466 | // | scl | | | | - | | bycopy| |
| 1467 | // | scl | | - | x | - | - | bycopy| |
| 1468 | // | scl | | x | - | - | - | null | |
| 1469 | // | scl | x | | | - | | byref | |
| 1470 | // | scl | x | - | x | - | - | bycopy| |
| 1471 | // | scl | x | x | - | - | - | null | |
| 1472 | // | scl | | - | - | - | x | byref | |
| 1473 | // | scl | x | - | - | - | x | byref | |
| 1474 | // |
| 1475 | // | agg | n.a. | | | - | | byref | |
| 1476 | // | agg | n.a. | - | x | - | - | byref | |
| 1477 | // | agg | n.a. | x | - | - | - | null | |
| 1478 | // | agg | n.a. | - | - | - | x | byref | |
| 1479 | // | agg | n.a. | - | - | - | x[] | byref | |
| 1480 | // |
| 1481 | // | ptr | n.a. | | | - | | bycopy| |
| 1482 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 1483 | // | ptr | n.a. | x | - | - | - | null | |
| 1484 | // | ptr | n.a. | - | - | - | x | byref | |
| 1485 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 1486 | // | ptr | n.a. | - | - | x | | bycopy| |
| 1487 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 1488 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 1489 | // ========================================================================= |
| 1490 | // Legend: |
| 1491 | // scl - scalar |
| 1492 | // ptr - pointer |
| 1493 | // agg - aggregate |
| 1494 | // x - applies |
| 1495 | // - - invalid in this combination |
| 1496 | // [] - mapped with an array section |
| 1497 | // byref - should be mapped by reference |
| 1498 | // byval - should be mapped by value |
| 1499 | // null - initialize a local variable to null on the device |
| 1500 | // |
| 1501 | // Observations: |
| 1502 | // - All scalar declarations that show up in a map clause have to be passed |
| 1503 | // by reference, because they may have been mapped in the enclosing data |
| 1504 | // environment. |
| 1505 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 1506 | // passed by reference, regardless the result in the table above. |
| 1507 | // - For pointers mapped by value that have either an implicit map or an |
| 1508 | // array section, the runtime library may pass the NULL value to the |
| 1509 | // device instead of the value passed to it by the compiler. |
| 1510 | |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1511 | if (Ty->isReferenceType()) |
| 1512 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1513 | |
| 1514 | // Locate map clauses and see if the variable being captured is referred to |
| 1515 | // in any of those clauses. Here we only care about variables, not fields, |
| 1516 | // because fields are part of aggregates. |
| 1517 | bool IsVariableUsedInMapClause = false; |
| 1518 | bool IsVariableAssociatedWithSection = false; |
| 1519 | |
| Jonas Hahnfeld | f7c4d7b | 2017-07-01 10:40:50 +0000 | [diff] [blame] | 1520 | DSAStack->checkMappableExprComponentListsForDeclAtLevel( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1521 | D, Level, |
| 1522 | [&IsVariableUsedInMapClause, &IsVariableAssociatedWithSection, D]( |
| 1523 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1524 | MapExprComponents, |
| 1525 | OpenMPClauseKind WhereFoundClauseKind) { |
| 1526 | // Only the map clause information influences how a variable is |
| 1527 | // captured. E.g. is_device_ptr does not require changing the default |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 1528 | // behavior. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 1529 | if (WhereFoundClauseKind != OMPC_map) |
| 1530 | return false; |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1531 | |
| 1532 | auto EI = MapExprComponents.rbegin(); |
| 1533 | auto EE = MapExprComponents.rend(); |
| 1534 | |
| 1535 | assert(EI != EE && "Invalid map expression!"); |
| 1536 | |
| 1537 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 1538 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 1539 | |
| 1540 | ++EI; |
| 1541 | if (EI == EE) |
| 1542 | return false; |
| 1543 | |
| 1544 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 1545 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 1546 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 1547 | IsVariableAssociatedWithSection = true; |
| 1548 | // There is nothing more we need to know about this variable. |
| 1549 | return true; |
| 1550 | } |
| 1551 | |
| 1552 | // Keep looking for more map info. |
| 1553 | return false; |
| 1554 | }); |
| 1555 | |
| 1556 | if (IsVariableUsedInMapClause) { |
| 1557 | // If variable is identified in a map clause it is always captured by |
| 1558 | // reference except if it is a pointer that is dereferenced somehow. |
| 1559 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 1560 | } else { |
| Alexey Bataev | 3f96fe6 | 2017-12-13 17:31:39 +0000 | [diff] [blame] | 1561 | // By default, all the data that has a scalar type is mapped by copy |
| 1562 | // (except for reduction variables). |
| 1563 | IsByRef = |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 1564 | (DSAStack->isForceCaptureByReferenceInTargetExecutable() && |
| 1565 | !Ty->isAnyPointerType()) || |
| Alexey Bataev | 3f96fe6 | 2017-12-13 17:31:39 +0000 | [diff] [blame] | 1566 | !Ty->isScalarType() || |
| 1567 | DSAStack->getDefaultDMAAtLevel(Level) == DMA_tofrom_scalar || |
| 1568 | DSAStack->hasExplicitDSA( |
| 1569 | D, [](OpenMPClauseKind K) { return K == OMPC_reduction; }, Level); |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1570 | } |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1573 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 1574 | IsByRef = |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 1575 | ((DSAStack->isForceCaptureByReferenceInTargetExecutable() && |
| 1576 | !Ty->isAnyPointerType()) || |
| 1577 | !DSAStack->hasExplicitDSA( |
| 1578 | D, |
| 1579 | [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 1580 | Level, /*NotLastprivate=*/true)) && |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 1581 | // If the variable is artificial and must be captured by value - try to |
| 1582 | // capture by value. |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 1583 | !(isa<OMPCapturedExprDecl>(D) && !D->hasAttr<OMPCaptureNoInitAttr>() && |
| 1584 | !cast<OMPCapturedExprDecl>(D)->getInit()->isGLValue()); |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 1587 | // 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] | 1588 | // and alignment, because the runtime library only deals with uintptr types. |
| 1589 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 1590 | // instead. |
| 1591 | if (!IsByRef && |
| 1592 | (Ctx.getTypeSizeInChars(Ty) > |
| 1593 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1594 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1595 | IsByRef = true; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1596 | } |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 1597 | |
| 1598 | return IsByRef; |
| 1599 | } |
| 1600 | |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1601 | unsigned Sema::getOpenMPNestingLevel() const { |
| 1602 | assert(getLangOpts().OpenMP); |
| 1603 | return DSAStack->getNestingLevel(); |
| 1604 | } |
| 1605 | |
| Jonas Hahnfeld | 87d4426 | 2017-11-18 21:00:46 +0000 | [diff] [blame] | 1606 | bool Sema::isInOpenMPTargetExecutionDirective() const { |
| 1607 | return (isOpenMPTargetExecutionDirective(DSAStack->getCurrentDirective()) && |
| 1608 | !DSAStack->isClauseParsingMode()) || |
| 1609 | DSAStack->hasDirective( |
| 1610 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 1611 | SourceLocation) -> bool { |
| 1612 | return isOpenMPTargetExecutionDirective(K); |
| 1613 | }, |
| 1614 | false); |
| 1615 | } |
| 1616 | |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1617 | VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D) { |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1618 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1619 | D = getCanonicalDecl(D); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1620 | |
| 1621 | // If we are attempting to capture a global variable in a directive with |
| 1622 | // 'target' we return true so that this global is also mapped to the device. |
| 1623 | // |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1624 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1625 | if (VD && !VD->hasLocalStorage()) { |
| 1626 | if (isInOpenMPDeclareTargetContext() && |
| 1627 | (getCurCapturedRegion() || getCurBlock() || getCurLambda())) { |
| 1628 | // Try to mark variable as declare target if it is used in capturing |
| 1629 | // regions. |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 1630 | if (!OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1631 | checkDeclIsAllowedInOpenMPTarget(nullptr, VD); |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 1632 | return nullptr; |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1633 | } else if (isInOpenMPTargetExecutionDirective()) { |
| 1634 | // If the declaration is enclosed in a 'declare target' directive, |
| 1635 | // then it should not be captured. |
| 1636 | // |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 1637 | if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
| Alexey Bataev | bf8fe71 | 2018-08-07 16:14:36 +0000 | [diff] [blame] | 1638 | return nullptr; |
| 1639 | return VD; |
| 1640 | } |
| Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1641 | } |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 1642 | // Capture variables captured by reference in lambdas for target-based |
| 1643 | // directives. |
| 1644 | if (VD && !DSAStack->isClauseParsingMode()) { |
| 1645 | if (const auto *RD = VD->getType() |
| 1646 | .getCanonicalType() |
| 1647 | .getNonReferenceType() |
| 1648 | ->getAsCXXRecordDecl()) { |
| 1649 | bool SavedForceCaptureByReferenceInTargetExecutable = |
| 1650 | DSAStack->isForceCaptureByReferenceInTargetExecutable(); |
| 1651 | DSAStack->setForceCaptureByReferenceInTargetExecutable(/*V=*/true); |
| Alexey Bataev | d1840e5 | 2018-11-16 21:13:33 +0000 | [diff] [blame] | 1652 | if (RD->isLambda()) { |
| 1653 | llvm::DenseMap<const VarDecl *, FieldDecl *> Captures; |
| 1654 | FieldDecl *ThisCapture; |
| 1655 | RD->getCaptureFields(Captures, ThisCapture); |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 1656 | for (const LambdaCapture &LC : RD->captures()) { |
| 1657 | if (LC.getCaptureKind() == LCK_ByRef) { |
| 1658 | VarDecl *VD = LC.getCapturedVar(); |
| 1659 | DeclContext *VDC = VD->getDeclContext(); |
| 1660 | if (!VDC->Encloses(CurContext)) |
| 1661 | continue; |
| 1662 | DSAStackTy::DSAVarData DVarPrivate = |
| 1663 | DSAStack->getTopDSA(VD, /*FromParent=*/false); |
| 1664 | // Do not capture already captured variables. |
| 1665 | if (!OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD) && |
| 1666 | DVarPrivate.CKind == OMPC_unknown && |
| 1667 | !DSAStack->checkMappableExprComponentListsForDecl( |
| 1668 | D, /*CurrentRegionOnly=*/true, |
| 1669 | [](OMPClauseMappableExprCommon:: |
| 1670 | MappableExprComponentListRef, |
| 1671 | OpenMPClauseKind) { return true; })) |
| 1672 | MarkVariableReferenced(LC.getLocation(), LC.getCapturedVar()); |
| 1673 | } else if (LC.getCaptureKind() == LCK_This) { |
| Alexey Bataev | d1840e5 | 2018-11-16 21:13:33 +0000 | [diff] [blame] | 1674 | QualType ThisTy = getCurrentThisType(); |
| 1675 | if (!ThisTy.isNull() && |
| 1676 | Context.typesAreCompatible(ThisTy, ThisCapture->getType())) |
| 1677 | CheckCXXThisCapture(LC.getLocation()); |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 1678 | } |
| 1679 | } |
| Alexey Bataev | d1840e5 | 2018-11-16 21:13:33 +0000 | [diff] [blame] | 1680 | } |
| Alexey Bataev | 6070542 | 2018-10-30 15:50:12 +0000 | [diff] [blame] | 1681 | DSAStack->setForceCaptureByReferenceInTargetExecutable( |
| 1682 | SavedForceCaptureByReferenceInTargetExecutable); |
| 1683 | } |
| 1684 | } |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1685 | |
| Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 1686 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 1687 | (!DSAStack->isClauseParsingMode() || |
| 1688 | DSAStack->getParentDirective() != OMPD_unknown)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1689 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 1690 | if (Info.first || |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1691 | (VD && VD->hasLocalStorage() && |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 1692 | isImplicitOrExplicitTaskingRegion(DSAStack->getCurrentDirective())) || |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1693 | (VD && DSAStack->isForceVarCapturing())) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1694 | return VD ? VD : Info.second; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1695 | DSAStackTy::DSAVarData DVarPrivate = |
| 1696 | DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1697 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1698 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1699 | DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate, |
| 1700 | [](OpenMPDirectiveKind) { return true; }, |
| 1701 | DSAStack->isClauseParsingMode()); |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1702 | if (DVarPrivate.CKind != OMPC_unknown) |
| 1703 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1704 | } |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1705 | return nullptr; |
| Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 1708 | void Sema::adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
| 1709 | unsigned Level) const { |
| 1710 | SmallVector<OpenMPDirectiveKind, 4> Regions; |
| 1711 | getOpenMPCaptureRegions(Regions, DSAStack->getDirective(Level)); |
| 1712 | FunctionScopesIndex -= Regions.size(); |
| 1713 | } |
| 1714 | |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 1715 | void Sema::startOpenMPLoop() { |
| 1716 | assert(LangOpts.OpenMP && "OpenMP must be enabled."); |
| 1717 | if (isOpenMPLoopDirective(DSAStack->getCurrentDirective())) |
| 1718 | DSAStack->loopInit(); |
| 1719 | } |
| 1720 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1721 | bool Sema::isOpenMPPrivateDecl(const ValueDecl *D, unsigned Level) const { |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1722 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 1723 | if (isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 1724 | if (DSAStack->getAssociatedLoops() > 0 && |
| 1725 | !DSAStack->isLoopStarted()) { |
| 1726 | DSAStack->resetPossibleLoopCounter(D); |
| 1727 | DSAStack->loopStart(); |
| 1728 | return true; |
| 1729 | } |
| 1730 | if ((DSAStack->getPossiblyLoopCunter() == D->getCanonicalDecl() || |
| 1731 | DSAStack->isLoopControlVariable(D).first) && |
| 1732 | !DSAStack->hasExplicitDSA( |
| 1733 | D, [](OpenMPClauseKind K) { return K != OMPC_private; }, Level) && |
| 1734 | !isOpenMPSimdDirective(DSAStack->getCurrentDirective())) |
| 1735 | return true; |
| 1736 | } |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1737 | return DSAStack->hasExplicitDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1738 | D, [](OpenMPClauseKind K) { return K == OMPC_private; }, Level) || |
| Alexey Bataev | 3f82cfc | 2017-12-13 15:28:44 +0000 | [diff] [blame] | 1739 | (DSAStack->isClauseParsingMode() && |
| 1740 | DSAStack->getClauseParsingMode() == OMPC_private) || |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 1741 | // Consider taskgroup reduction descriptor variable a private to avoid |
| 1742 | // possible capture in the region. |
| 1743 | (DSAStack->hasExplicitDirective( |
| 1744 | [](OpenMPDirectiveKind K) { return K == OMPD_taskgroup; }, |
| 1745 | Level) && |
| 1746 | DSAStack->isTaskgroupReductionRef(D, Level)); |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1747 | } |
| 1748 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1749 | void Sema::setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, |
| 1750 | unsigned Level) { |
| Alexey Bataev | 3b8d558 | 2017-08-08 18:04:06 +0000 | [diff] [blame] | 1751 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1752 | D = getCanonicalDecl(D); |
| 1753 | OpenMPClauseKind OMPC = OMPC_unknown; |
| 1754 | for (unsigned I = DSAStack->getNestingLevel() + 1; I > Level; --I) { |
| 1755 | const unsigned NewLevel = I - 1; |
| 1756 | if (DSAStack->hasExplicitDSA(D, |
| 1757 | [&OMPC](const OpenMPClauseKind K) { |
| 1758 | if (isOpenMPPrivate(K)) { |
| 1759 | OMPC = K; |
| 1760 | return true; |
| 1761 | } |
| 1762 | return false; |
| 1763 | }, |
| 1764 | NewLevel)) |
| 1765 | break; |
| 1766 | if (DSAStack->checkMappableExprComponentListsForDeclAtLevel( |
| 1767 | D, NewLevel, |
| 1768 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 1769 | OpenMPClauseKind) { return true; })) { |
| 1770 | OMPC = OMPC_map; |
| 1771 | break; |
| 1772 | } |
| 1773 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1774 | NewLevel)) { |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 1775 | OMPC = OMPC_map; |
| 1776 | if (D->getType()->isScalarType() && |
| 1777 | DSAStack->getDefaultDMAAtLevel(NewLevel) != |
| 1778 | DefaultMapAttributes::DMA_tofrom_scalar) |
| 1779 | OMPC = OMPC_firstprivate; |
| Alexey Bataev | 3b8d558 | 2017-08-08 18:04:06 +0000 | [diff] [blame] | 1780 | break; |
| 1781 | } |
| 1782 | } |
| 1783 | if (OMPC != OMPC_unknown) |
| 1784 | FD->addAttr(OMPCaptureKindAttr::CreateImplicit(Context, OMPC)); |
| 1785 | } |
| 1786 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1787 | bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, |
| 1788 | unsigned Level) const { |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1789 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1790 | // Return true if the current level is no longer enclosed in a target region. |
| 1791 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1792 | const auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1793 | return VD && !VD->hasLocalStorage() && |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1794 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1795 | Level); |
| Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1798 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1799 | |
| 1800 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1801 | const DeclarationNameInfo &DirName, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1802 | Scope *CurScope, SourceLocation Loc) { |
| 1803 | DSAStack->push(DKind, DirName, CurScope, Loc); |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 1804 | PushExpressionEvaluationContext( |
| 1805 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1808 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1809 | DSAStack->setClauseParsingMode(K); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1810 | } |
| 1811 | |
| Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1812 | void Sema::EndOpenMPClause() { |
| 1813 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1816 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1817 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1818 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1819 | // clause requires an accessible, unambiguous default constructor for the |
| 1820 | // class type, unless the list item is also specified in a firstprivate |
| 1821 | // clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1822 | if (const auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
| 1823 | for (OMPClause *C : D->clauses()) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1824 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1825 | SmallVector<Expr *, 8> PrivateCopies; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1826 | for (Expr *DE : Clause->varlists()) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1827 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1828 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1829 | continue; |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1830 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1831 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1832 | auto *VD = cast<VarDecl>(DRE->getDecl()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1833 | QualType Type = VD->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1834 | const DSAStackTy::DSAVarData DVar = |
| 1835 | DSAStack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1836 | if (DVar.CKind == OMPC_lastprivate) { |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1837 | // Generate helper private variable and initialize it with the |
| 1838 | // default value. The address of the original variable is replaced |
| 1839 | // by the address of the new private variable in CodeGen. This new |
| 1840 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1841 | // region uses original variable for proper diagnostics. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1842 | VarDecl *VDPrivate = buildVarDecl( |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1843 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 1844 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr, DRE); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1845 | ActOnUninitializedDecl(VDPrivate); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1846 | if (VDPrivate->isInvalidDecl()) |
| 1847 | continue; |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1848 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1849 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1850 | } else { |
| 1851 | // The variable is also a firstprivate, so initialization sequence |
| 1852 | // for private copy is generated already. |
| 1853 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1854 | } |
| 1855 | } |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1856 | // Set initializers to private copies if no errors were found. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1857 | if (PrivateCopies.size() == Clause->varlist_size()) |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1858 | Clause->setPrivateCopies(PrivateCopies); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1863 | DSAStack->pop(); |
| 1864 | DiscardCleanupsInEvaluationContext(); |
| 1865 | PopExpressionEvaluationContext(); |
| 1866 | } |
| 1867 | |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1868 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1869 | Expr *NumIterations, Sema &SemaRef, |
| 1870 | Scope *S, DSAStackTy *Stack); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1871 | |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1872 | namespace { |
| 1873 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1874 | class VarDeclFilterCCC final : public CorrectionCandidateCallback { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1875 | private: |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1876 | Sema &SemaRef; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1877 | |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1878 | public: |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1879 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1880 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1881 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1882 | if (const auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1883 | return VD->hasGlobalStorage() && |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1884 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1885 | SemaRef.getCurScope()); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1886 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1887 | return false; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1888 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1889 | }; |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1890 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1891 | class VarOrFuncDeclFilterCCC final : public CorrectionCandidateCallback { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1892 | private: |
| 1893 | Sema &SemaRef; |
| 1894 | |
| 1895 | public: |
| 1896 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1897 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1898 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| Kelvin Li | 59e3d19 | 2017-11-30 18:52:06 +0000 | [diff] [blame] | 1899 | if (ND && (isa<VarDecl>(ND) || isa<FunctionDecl>(ND))) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1900 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1901 | SemaRef.getCurScope()); |
| 1902 | } |
| 1903 | return false; |
| 1904 | } |
| 1905 | }; |
| 1906 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1907 | } // namespace |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1908 | |
| 1909 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1910 | CXXScopeSpec &ScopeSpec, |
| 1911 | const DeclarationNameInfo &Id) { |
| 1912 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1913 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1914 | |
| 1915 | if (Lookup.isAmbiguous()) |
| 1916 | return ExprError(); |
| 1917 | |
| 1918 | VarDecl *VD; |
| 1919 | if (!Lookup.isSingleResult()) { |
| Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1920 | if (TypoCorrection Corrected = CorrectTypo( |
| 1921 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1922 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1923 | diagnoseTypo(Corrected, |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1924 | PDiag(Lookup.empty() |
| 1925 | ? diag::err_undeclared_var_use_suggest |
| 1926 | : diag::err_omp_expected_var_arg_suggest) |
| 1927 | << Id.getName()); |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1928 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1929 | } else { |
| Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1930 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1931 | : diag::err_omp_expected_var_arg) |
| 1932 | << Id.getName(); |
| 1933 | return ExprError(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1934 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 1935 | } else if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
| 1936 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
| 1937 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1938 | return ExprError(); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1939 | } |
| 1940 | Lookup.suppressDiagnostics(); |
| 1941 | |
| 1942 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1943 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1944 | if (!VD->hasGlobalStorage()) { |
| 1945 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1946 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1947 | bool IsDecl = |
| 1948 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1949 | Diag(VD->getLocation(), |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1950 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1951 | << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1952 | return ExprError(); |
| 1953 | } |
| 1954 | |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1955 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 1956 | NamedDecl *ND = CanonicalVD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1957 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1958 | // A threadprivate directive for file-scope variables must appear outside |
| 1959 | // any definition or declaration. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1960 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1961 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1962 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1963 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1964 | bool IsDecl = |
| 1965 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1966 | Diag(VD->getLocation(), |
| 1967 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1968 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1969 | return ExprError(); |
| 1970 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1971 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1972 | // A threadprivate directive for static class member variables must appear |
| 1973 | // in the class definition, in the same scope in which the member |
| 1974 | // variables are declared. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1975 | if (CanonicalVD->isStaticDataMember() && |
| 1976 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1977 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1978 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1979 | bool IsDecl = |
| 1980 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1981 | Diag(VD->getLocation(), |
| 1982 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1983 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1984 | return ExprError(); |
| 1985 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1986 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1987 | // A threadprivate directive for namespace-scope variables must appear |
| 1988 | // outside any definition or declaration other than the namespace |
| 1989 | // definition itself. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1990 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1991 | (!getCurLexicalContext()->isFileContext() || |
| 1992 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1993 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1994 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1995 | bool IsDecl = |
| 1996 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1997 | Diag(VD->getLocation(), |
| 1998 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1999 | << VD; |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2000 | return ExprError(); |
| 2001 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2002 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 2003 | // A threadprivate directive for static block-scope variables must appear |
| 2004 | // in the scope of the variable and not in a nested scope. |
| Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 2005 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 2006 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2007 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2008 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 2009 | bool IsDecl = |
| 2010 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2011 | Diag(VD->getLocation(), |
| 2012 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2013 | << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2014 | return ExprError(); |
| 2015 | } |
| 2016 | |
| 2017 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 2018 | // A threadprivate directive must lexically precede all references to any |
| 2019 | // of the variables in its list. |
| Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 2020 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2021 | Diag(Id.getLoc(), diag::err_omp_var_used) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2022 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2023 | return ExprError(); |
| 2024 | } |
| 2025 | |
| 2026 | QualType ExprType = VD->getType().getNonReferenceType(); |
| Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 2027 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 2028 | SourceLocation(), VD, |
| 2029 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 2030 | Id.getLoc(), ExprType, VK_LValue); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2031 | } |
| 2032 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2033 | Sema::DeclGroupPtrTy |
| 2034 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 2035 | ArrayRef<Expr *> VarList) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2036 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2037 | CurContext->addDecl(D); |
| 2038 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 2039 | } |
| David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 2040 | return nullptr; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2043 | namespace { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2044 | class LocalVarRefChecker final |
| 2045 | : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2046 | Sema &SemaRef; |
| 2047 | |
| 2048 | public: |
| 2049 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2050 | if (const auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2051 | if (VD->hasLocalStorage()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2052 | SemaRef.Diag(E->getBeginLoc(), |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2053 | diag::err_omp_local_var_in_threadprivate_init) |
| 2054 | << E->getSourceRange(); |
| 2055 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 2056 | << VD << VD->getSourceRange(); |
| 2057 | return true; |
| 2058 | } |
| 2059 | } |
| 2060 | return false; |
| 2061 | } |
| 2062 | bool VisitStmt(const Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2063 | for (const Stmt *Child : S->children()) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2064 | if (Child && Visit(Child)) |
| 2065 | return true; |
| 2066 | } |
| 2067 | return false; |
| 2068 | } |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2069 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2070 | }; |
| 2071 | } // namespace |
| 2072 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2073 | OMPThreadPrivateDecl * |
| 2074 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2075 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2076 | for (Expr *RefExpr : VarList) { |
| 2077 | auto *DE = cast<DeclRefExpr>(RefExpr); |
| 2078 | auto *VD = cast<VarDecl>(DE->getDecl()); |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2079 | SourceLocation ILoc = DE->getExprLoc(); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2080 | |
| Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 2081 | // Mark variable as used. |
| 2082 | VD->setReferenced(); |
| 2083 | VD->markUsed(Context); |
| 2084 | |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 2085 | QualType QType = VD->getType(); |
| 2086 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 2087 | // It will be analyzed later. |
| 2088 | Vars.push_back(DE); |
| 2089 | continue; |
| 2090 | } |
| 2091 | |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2092 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 2093 | // A threadprivate variable must not have an incomplete type. |
| 2094 | if (RequireCompleteType(ILoc, VD->getType(), |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2095 | diag::err_omp_threadprivate_incomplete_type)) { |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2096 | continue; |
| 2097 | } |
| 2098 | |
| 2099 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 2100 | // A threadprivate variable must not have a reference type. |
| 2101 | if (VD->getType()->isReferenceType()) { |
| 2102 | Diag(ILoc, diag::err_omp_ref_type_arg) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2103 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 2104 | bool IsDecl = |
| 2105 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2106 | Diag(VD->getLocation(), |
| 2107 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2108 | << VD; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2109 | continue; |
| 2110 | } |
| 2111 | |
| Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 2112 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 2113 | // the corresponding diagnostic. |
| 2114 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 2115 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 2116 | getLangOpts().OpenMPUseTLS && |
| 2117 | getASTContext().getTargetInfo().isTLSSupported())) || |
| Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 2118 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 2119 | !VD->isLocalVarDecl())) { |
| Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 2120 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 2121 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2122 | bool IsDecl = |
| 2123 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 2124 | Diag(VD->getLocation(), |
| 2125 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 2126 | << VD; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2127 | continue; |
| 2128 | } |
| 2129 | |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2130 | // Check if initial value of threadprivate variable reference variable with |
| 2131 | // local storage (it is not supported by runtime). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2132 | if (const Expr *Init = VD->getAnyInitializer()) { |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2133 | LocalVarRefChecker Checker(*this); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2134 | if (Checker.Visit(Init)) |
| 2135 | continue; |
| Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2138 | Vars.push_back(RefExpr); |
| Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 2139 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 2140 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 2141 | Context, SourceRange(Loc, Loc))); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2142 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 2143 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2144 | } |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 2145 | OMPThreadPrivateDecl *D = nullptr; |
| Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 2146 | if (!Vars.empty()) { |
| 2147 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 2148 | Vars); |
| 2149 | D->setAccess(AS_public); |
| 2150 | } |
| 2151 | return D; |
| Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2152 | } |
| Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2153 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2154 | Sema::DeclGroupPtrTy |
| 2155 | Sema::ActOnOpenMPRequiresDirective(SourceLocation Loc, |
| 2156 | ArrayRef<OMPClause *> ClauseList) { |
| 2157 | OMPRequiresDecl *D = nullptr; |
| 2158 | if (!CurContext->isFileContext()) { |
| 2159 | Diag(Loc, diag::err_omp_invalid_scope) << "requires"; |
| 2160 | } else { |
| 2161 | D = CheckOMPRequiresDecl(Loc, ClauseList); |
| 2162 | if (D) { |
| 2163 | CurContext->addDecl(D); |
| 2164 | DSAStack->addRequiresDecl(D); |
| 2165 | } |
| 2166 | } |
| 2167 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 2168 | } |
| 2169 | |
| 2170 | OMPRequiresDecl *Sema::CheckOMPRequiresDecl(SourceLocation Loc, |
| 2171 | ArrayRef<OMPClause *> ClauseList) { |
| 2172 | if (!DSAStack->hasDuplicateRequiresClause(ClauseList)) |
| 2173 | return OMPRequiresDecl::Create(Context, getCurLexicalContext(), Loc, |
| 2174 | ClauseList); |
| 2175 | return nullptr; |
| 2176 | } |
| 2177 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2178 | static void reportOriginalDsa(Sema &SemaRef, const DSAStackTy *Stack, |
| 2179 | const ValueDecl *D, |
| 2180 | const DSAStackTy::DSAVarData &DVar, |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2181 | bool IsLoopIterVar = false) { |
| 2182 | if (DVar.RefExpr) { |
| 2183 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2184 | << getOpenMPClauseName(DVar.CKind); |
| 2185 | return; |
| 2186 | } |
| 2187 | enum { |
| 2188 | PDSA_StaticMemberShared, |
| 2189 | PDSA_StaticLocalVarShared, |
| 2190 | PDSA_LoopIterVarPrivate, |
| 2191 | PDSA_LoopIterVarLinear, |
| 2192 | PDSA_LoopIterVarLastprivate, |
| 2193 | PDSA_ConstVarShared, |
| 2194 | PDSA_GlobalVarShared, |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2195 | PDSA_TaskVarFirstprivate, |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2196 | PDSA_LocalVarPrivate, |
| 2197 | PDSA_Implicit |
| 2198 | } Reason = PDSA_Implicit; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2199 | bool ReportHint = false; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2200 | auto ReportLoc = D->getLocation(); |
| 2201 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2202 | if (IsLoopIterVar) { |
| 2203 | if (DVar.CKind == OMPC_private) |
| 2204 | Reason = PDSA_LoopIterVarPrivate; |
| 2205 | else if (DVar.CKind == OMPC_lastprivate) |
| 2206 | Reason = PDSA_LoopIterVarLastprivate; |
| 2207 | else |
| 2208 | Reason = PDSA_LoopIterVarLinear; |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2209 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 2210 | DVar.CKind == OMPC_firstprivate) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2211 | Reason = PDSA_TaskVarFirstprivate; |
| 2212 | ReportLoc = DVar.ImplicitDSALoc; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2213 | } else if (VD && VD->isStaticLocal()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2214 | Reason = PDSA_StaticLocalVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2215 | else if (VD && VD->isStaticDataMember()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2216 | Reason = PDSA_StaticMemberShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2217 | else if (VD && VD->isFileVarDecl()) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2218 | Reason = PDSA_GlobalVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2219 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2220 | Reason = PDSA_ConstVarShared; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2221 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2222 | ReportHint = true; |
| 2223 | Reason = PDSA_LocalVarPrivate; |
| 2224 | } |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2225 | if (Reason != PDSA_Implicit) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2226 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2227 | << Reason << ReportHint |
| 2228 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 2229 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 2230 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 2231 | << getOpenMPClauseName(DVar.CKind); |
| 2232 | } |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2235 | namespace { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2236 | class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2237 | DSAStackTy *Stack; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2238 | Sema &SemaRef; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2239 | bool ErrorFound = false; |
| 2240 | CapturedStmt *CS = nullptr; |
| 2241 | llvm::SmallVector<Expr *, 4> ImplicitFirstprivate; |
| 2242 | llvm::SmallVector<Expr *, 4> ImplicitMap; |
| 2243 | Sema::VarsWithInheritedDSAType VarsWithInheritedDSA; |
| 2244 | llvm::SmallDenseSet<const ValueDecl *, 4> ImplicitDeclarations; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2245 | |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 2246 | void VisitSubCaptures(OMPExecutableDirective *S) { |
| 2247 | // Check implicitly captured variables. |
| 2248 | if (!S->hasAssociatedStmt() || !S->getAssociatedStmt()) |
| 2249 | return; |
| 2250 | for (const CapturedStmt::Capture &Cap : |
| 2251 | S->getInnermostCapturedStmt()->captures()) { |
| 2252 | if (!Cap.capturesVariable()) |
| 2253 | continue; |
| 2254 | VarDecl *VD = Cap.getCapturedVar(); |
| 2255 | // Do not try to map the variable if it or its sub-component was mapped |
| 2256 | // already. |
| 2257 | if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) && |
| 2258 | Stack->checkMappableExprComponentListsForDecl( |
| 2259 | VD, /*CurrentRegionOnly=*/true, |
| 2260 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 2261 | OpenMPClauseKind) { return true; })) |
| 2262 | continue; |
| 2263 | DeclRefExpr *DRE = buildDeclRefExpr( |
| 2264 | SemaRef, VD, VD->getType().getNonLValueExprType(SemaRef.Context), |
| 2265 | Cap.getLocation(), /*RefersToCapture=*/true); |
| 2266 | Visit(DRE); |
| 2267 | } |
| 2268 | } |
| 2269 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2270 | public: |
| 2271 | void VisitDeclRefExpr(DeclRefExpr *E) { |
| Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 2272 | if (E->isTypeDependent() || E->isValueDependent() || |
| 2273 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 2274 | return; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2275 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 2276 | VD = VD->getCanonicalDecl(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2277 | // Skip internally declared variables. |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 2278 | if (VD->hasLocalStorage() && !CS->capturesVariable(VD)) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2279 | return; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2280 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2281 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2282 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 2283 | if (DVar.RefExpr || !ImplicitDeclarations.insert(VD).second) |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2284 | return; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2285 | |
| Alexey Bataev | afe5057 | 2017-10-06 17:00:28 +0000 | [diff] [blame] | 2286 | // Skip internally declared static variables. |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 2287 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 2288 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD); |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 2289 | if (VD->hasGlobalStorage() && !CS->capturesVariable(VD) && |
| 2290 | (!Res || *Res != OMPDeclareTargetDeclAttr::MT_Link)) |
| Alexey Bataev | afe5057 | 2017-10-06 17:00:28 +0000 | [diff] [blame] | 2291 | return; |
| 2292 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2293 | SourceLocation ELoc = E->getExprLoc(); |
| 2294 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2295 | // The default(none) clause requires that each variable that is referenced |
| 2296 | // in the construct, and does not have a predetermined data-sharing |
| 2297 | // attribute, must have its data-sharing attribute explicitly determined |
| 2298 | // by being listed in a data-sharing attribute clause. |
| 2299 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
| Alexey Bataev | 7e6803e | 2019-01-09 15:58:05 +0000 | [diff] [blame] | 2300 | isImplicitOrExplicitTaskingRegion(DKind) && |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2301 | VarsWithInheritedDSA.count(VD) == 0) { |
| 2302 | VarsWithInheritedDSA[VD] = E; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2303 | return; |
| 2304 | } |
| 2305 | |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2306 | if (isOpenMPTargetExecutionDirective(DKind) && |
| 2307 | !Stack->isLoopControlVariable(VD).first) { |
| 2308 | if (!Stack->checkMappableExprComponentListsForDecl( |
| 2309 | VD, /*CurrentRegionOnly=*/true, |
| 2310 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 2311 | StackComponents, |
| 2312 | OpenMPClauseKind) { |
| 2313 | // Variable is used if it has been marked as an array, array |
| 2314 | // section or the variable iself. |
| 2315 | return StackComponents.size() == 1 || |
| 2316 | std::all_of( |
| 2317 | std::next(StackComponents.rbegin()), |
| 2318 | StackComponents.rend(), |
| 2319 | [](const OMPClauseMappableExprCommon:: |
| 2320 | MappableComponent &MC) { |
| 2321 | return MC.getAssociatedDeclaration() == |
| 2322 | nullptr && |
| 2323 | (isa<OMPArraySectionExpr>( |
| 2324 | MC.getAssociatedExpression()) || |
| 2325 | isa<ArraySubscriptExpr>( |
| 2326 | MC.getAssociatedExpression())); |
| 2327 | }); |
| 2328 | })) { |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 2329 | bool IsFirstprivate = false; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2330 | // By default lambdas are captured as firstprivates. |
| 2331 | if (const auto *RD = |
| 2332 | VD->getType().getNonReferenceType()->getAsCXXRecordDecl()) |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 2333 | IsFirstprivate = RD->isLambda(); |
| 2334 | IsFirstprivate = |
| 2335 | IsFirstprivate || |
| 2336 | (VD->getType().getNonReferenceType()->isScalarType() && |
| Alexey Bataev | 92327c5 | 2018-03-26 16:40:55 +0000 | [diff] [blame] | 2337 | Stack->getDefaultDMA() != DMA_tofrom_scalar && !Res); |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 2338 | if (IsFirstprivate) |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2339 | ImplicitFirstprivate.emplace_back(E); |
| 2340 | else |
| 2341 | ImplicitMap.emplace_back(E); |
| 2342 | return; |
| 2343 | } |
| 2344 | } |
| 2345 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2346 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 2347 | // A list item that appears in a reduction clause of the innermost |
| 2348 | // enclosing worksharing or parallel construct may not be accessed in an |
| 2349 | // explicit task. |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2350 | DVar = Stack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2351 | VD, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 2352 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2353 | return isOpenMPParallelDirective(K) || |
| 2354 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 2355 | }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 2356 | /*FromParent=*/true); |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2357 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2358 | ErrorFound = true; |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2359 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2360 | reportOriginalDsa(SemaRef, Stack, VD, DVar); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2361 | return; |
| 2362 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2363 | |
| 2364 | // Define implicit data-sharing attributes for task. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2365 | DVar = Stack->getImplicitDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2366 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 2367 | !Stack->isLoopControlVariable(VD).first) |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2368 | ImplicitFirstprivate.push_back(E); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2369 | } |
| 2370 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2371 | void VisitMemberExpr(MemberExpr *E) { |
| Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 2372 | if (E->isTypeDependent() || E->isValueDependent() || |
| 2373 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 2374 | return; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2375 | auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl()); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2376 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 2377 | if (auto *TE = dyn_cast<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 2378 | if (!FD) |
| 2379 | return; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2380 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(FD, /*FromParent=*/false); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2381 | // Check if the variable has explicit DSA set and stop analysis if it |
| 2382 | // so. |
| 2383 | if (DVar.RefExpr || !ImplicitDeclarations.insert(FD).second) |
| 2384 | return; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2385 | |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2386 | if (isOpenMPTargetExecutionDirective(DKind) && |
| 2387 | !Stack->isLoopControlVariable(FD).first && |
| 2388 | !Stack->checkMappableExprComponentListsForDecl( |
| 2389 | FD, /*CurrentRegionOnly=*/true, |
| 2390 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 2391 | StackComponents, |
| 2392 | OpenMPClauseKind) { |
| 2393 | return isa<CXXThisExpr>( |
| 2394 | cast<MemberExpr>( |
| 2395 | StackComponents.back().getAssociatedExpression()) |
| 2396 | ->getBase() |
| 2397 | ->IgnoreParens()); |
| 2398 | })) { |
| 2399 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 2400 | // A bit-field cannot appear in a map clause. |
| 2401 | // |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 2402 | if (FD->isBitField()) |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2403 | return; |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 2404 | |
| 2405 | // Check to see if the member expression is referencing a class that |
| 2406 | // has already been explicitly mapped |
| 2407 | if (Stack->isClassPreviouslyMapped(TE->getType())) |
| 2408 | return; |
| 2409 | |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2410 | ImplicitMap.emplace_back(E); |
| 2411 | return; |
| 2412 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2413 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2414 | SourceLocation ELoc = E->getExprLoc(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2415 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 2416 | // A list item that appears in a reduction clause of the innermost |
| 2417 | // enclosing worksharing or parallel construct may not be accessed in |
| 2418 | // an explicit task. |
| 2419 | DVar = Stack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2420 | FD, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 2421 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2422 | return isOpenMPParallelDirective(K) || |
| 2423 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 2424 | }, |
| 2425 | /*FromParent=*/true); |
| 2426 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
| 2427 | ErrorFound = true; |
| 2428 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2429 | reportOriginalDsa(SemaRef, Stack, FD, DVar); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2430 | return; |
| 2431 | } |
| 2432 | |
| 2433 | // Define implicit data-sharing attributes for task. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2434 | DVar = Stack->getImplicitDSA(FD, /*FromParent=*/false); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2435 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| Alexey Bataev | b40e0520 | 2018-10-24 18:53:12 +0000 | [diff] [blame] | 2436 | !Stack->isLoopControlVariable(FD).first) { |
| 2437 | // Check if there is a captured expression for the current field in the |
| 2438 | // region. Do not mark it as firstprivate unless there is no captured |
| 2439 | // expression. |
| 2440 | // TODO: try to make it firstprivate. |
| 2441 | if (DVar.CKind != OMPC_unknown) |
| 2442 | ImplicitFirstprivate.push_back(E); |
| 2443 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2444 | return; |
| 2445 | } |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 2446 | if (isOpenMPTargetExecutionDirective(DKind)) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2447 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2448 | if (!checkMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map, |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 2449 | /*NoDiagnose=*/true)) |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 2450 | return; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2451 | const auto *VD = cast<ValueDecl>( |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2452 | CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl()); |
| 2453 | if (!Stack->checkMappableExprComponentListsForDecl( |
| 2454 | VD, /*CurrentRegionOnly=*/true, |
| 2455 | [&CurComponents]( |
| 2456 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 2457 | StackComponents, |
| 2458 | OpenMPClauseKind) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2459 | auto CCI = CurComponents.rbegin(); |
| Alexey Bataev | 5ec3893 | 2017-09-26 16:19:04 +0000 | [diff] [blame] | 2460 | auto CCE = CurComponents.rend(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2461 | for (const auto &SC : llvm::reverse(StackComponents)) { |
| 2462 | // Do both expressions have the same kind? |
| 2463 | if (CCI->getAssociatedExpression()->getStmtClass() != |
| 2464 | SC.getAssociatedExpression()->getStmtClass()) |
| 2465 | if (!(isa<OMPArraySectionExpr>( |
| 2466 | SC.getAssociatedExpression()) && |
| 2467 | isa<ArraySubscriptExpr>( |
| 2468 | CCI->getAssociatedExpression()))) |
| 2469 | return false; |
| 2470 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2471 | const Decl *CCD = CCI->getAssociatedDeclaration(); |
| 2472 | const Decl *SCD = SC.getAssociatedDeclaration(); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2473 | CCD = CCD ? CCD->getCanonicalDecl() : nullptr; |
| 2474 | SCD = SCD ? SCD->getCanonicalDecl() : nullptr; |
| 2475 | if (SCD != CCD) |
| 2476 | return false; |
| 2477 | std::advance(CCI, 1); |
| Alexey Bataev | 5ec3893 | 2017-09-26 16:19:04 +0000 | [diff] [blame] | 2478 | if (CCI == CCE) |
| 2479 | break; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2480 | } |
| 2481 | return true; |
| 2482 | })) { |
| 2483 | Visit(E->getBase()); |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2484 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2485 | } else { |
| Alexey Bataev | 7fcacd8 | 2016-11-28 15:55:15 +0000 | [diff] [blame] | 2486 | Visit(E->getBase()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2487 | } |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2488 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2489 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2490 | for (OMPClause *C : S->clauses()) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2491 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2492 | // for task|target directives. |
| 2493 | // Skip analysis of arguments of implicitly defined map clause for target |
| 2494 | // directives. |
| 2495 | if (C && !((isa<OMPFirstprivateClause>(C) || isa<OMPMapClause>(C)) && |
| 2496 | C->isImplicit())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2497 | for (Stmt *CC : C->children()) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2498 | if (CC) |
| 2499 | Visit(CC); |
| 2500 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2501 | } |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2502 | } |
| Alexey Bataev | f07946e | 2018-10-29 20:17:42 +0000 | [diff] [blame] | 2503 | // Check implicitly captured variables. |
| 2504 | VisitSubCaptures(S); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2505 | } |
| 2506 | void VisitStmt(Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2507 | for (Stmt *C : S->children()) { |
| Alexey Bataev | 8fc7b5f | 2018-10-25 15:35:27 +0000 | [diff] [blame] | 2508 | if (C) { |
| Joel E. Denny | 0fdf5a9 | 2018-12-19 15:59:47 +0000 | [diff] [blame] | 2509 | // Check implicitly captured variables in the task-based directives to |
| 2510 | // check if they must be firstprivatized. |
| 2511 | Visit(C); |
| Alexey Bataev | 8fc7b5f | 2018-10-25 15:35:27 +0000 | [diff] [blame] | 2512 | } |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2513 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2514 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2515 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2516 | bool isErrorFound() const { return ErrorFound; } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 2517 | ArrayRef<Expr *> getImplicitFirstprivate() const { |
| 2518 | return ImplicitFirstprivate; |
| 2519 | } |
| 2520 | ArrayRef<Expr *> getImplicitMap() const { return ImplicitMap; } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2521 | const Sema::VarsWithInheritedDSAType &getVarsWithInheritedDSA() const { |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2522 | return VarsWithInheritedDSA; |
| 2523 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2524 | |
| Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2525 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 2526 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2527 | }; |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2528 | } // namespace |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2529 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2530 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2531 | switch (DKind) { |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 2532 | case OMPD_parallel: |
| 2533 | case OMPD_parallel_for: |
| 2534 | case OMPD_parallel_for_simd: |
| 2535 | case OMPD_parallel_sections: |
| Carlo Bertolli | ba1487b | 2017-10-04 14:12:09 +0000 | [diff] [blame] | 2536 | case OMPD_teams: |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 2537 | case OMPD_teams_distribute: |
| 2538 | case OMPD_teams_distribute_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2539 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 2540 | QualType KmpInt32PtrTy = |
| 2541 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2542 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2543 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2544 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 2545 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2546 | }; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2547 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2548 | Params); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | } |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 2551 | case OMPD_target_teams: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 2552 | case OMPD_target_parallel: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 2553 | case OMPD_target_parallel_for: |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 2554 | case OMPD_target_parallel_for_simd: |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 2555 | case OMPD_target_teams_distribute: |
| 2556 | case OMPD_target_teams_distribute_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2557 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 2558 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2559 | QualType KmpInt32PtrTy = |
| 2560 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2561 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2562 | FunctionProtoType::ExtProtoInfo EPI; |
| 2563 | EPI.Variadic = true; |
| 2564 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 2565 | Sema::CapturedParamNameType Params[] = { |
| 2566 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2567 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2568 | std::make_pair(".privates.", VoidPtrTy), |
| 2569 | std::make_pair( |
| 2570 | ".copy_fn.", |
| 2571 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2572 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2573 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2574 | }; |
| 2575 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2576 | Params); |
| Alexey Bataev | 0c869ef | 2018-01-16 15:57:07 +0000 | [diff] [blame] | 2577 | // Mark this captured region as inlined, because we don't use outlined |
| 2578 | // function directly. |
| 2579 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2580 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2581 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2582 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 2583 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2584 | }; |
| 2585 | // Start a captured region for 'target' with no implicit parameters. |
| 2586 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2587 | ParamsTarget); |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 2588 | Sema::CapturedParamNameType ParamsTeamsOrParallel[] = { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2589 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2590 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 2591 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2592 | }; |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 2593 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 2594 | // the same implicit parameters. |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2595 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 2596 | ParamsTeamsOrParallel); |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2597 | break; |
| 2598 | } |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2599 | case OMPD_target: |
| 2600 | case OMPD_target_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2601 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 2602 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2603 | QualType KmpInt32PtrTy = |
| 2604 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2605 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2606 | FunctionProtoType::ExtProtoInfo EPI; |
| 2607 | EPI.Variadic = true; |
| 2608 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 2609 | Sema::CapturedParamNameType Params[] = { |
| 2610 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2611 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2612 | std::make_pair(".privates.", VoidPtrTy), |
| 2613 | std::make_pair( |
| 2614 | ".copy_fn.", |
| 2615 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2616 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2617 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2618 | }; |
| 2619 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2620 | Params); |
| 2621 | // Mark this captured region as inlined, because we don't use outlined |
| 2622 | // function directly. |
| 2623 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2624 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2625 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2626 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2627 | std::make_pair(StringRef(), QualType())); |
| 2628 | break; |
| 2629 | } |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 2630 | case OMPD_simd: |
| 2631 | case OMPD_for: |
| 2632 | case OMPD_for_simd: |
| 2633 | case OMPD_sections: |
| 2634 | case OMPD_section: |
| 2635 | case OMPD_single: |
| 2636 | case OMPD_master: |
| 2637 | case OMPD_critical: |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2638 | case OMPD_taskgroup: |
| 2639 | case OMPD_distribute: |
| Alexey Bataev | 4650627 | 2017-12-05 17:41:34 +0000 | [diff] [blame] | 2640 | case OMPD_distribute_simd: |
| Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 2641 | case OMPD_ordered: |
| 2642 | case OMPD_atomic: |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2643 | case OMPD_target_data: { |
| Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2644 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2645 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2646 | }; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2647 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2648 | Params); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2649 | break; |
| 2650 | } |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2651 | case OMPD_task: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2652 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 2653 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2654 | QualType KmpInt32PtrTy = |
| 2655 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2656 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 2657 | FunctionProtoType::ExtProtoInfo EPI; |
| 2658 | EPI.Variadic = true; |
| 2659 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2660 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 2661 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2662 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2663 | std::make_pair(".privates.", VoidPtrTy), |
| 2664 | std::make_pair( |
| 2665 | ".copy_fn.", |
| 2666 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 2667 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2668 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2669 | }; |
| 2670 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2671 | Params); |
| Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 2672 | // Mark this captured region as inlined, because we don't use outlined |
| 2673 | // function directly. |
| 2674 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2675 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2676 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2677 | break; |
| 2678 | } |
| Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 2679 | case OMPD_taskloop: |
| 2680 | case OMPD_taskloop_simd: { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2681 | QualType KmpInt32Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2682 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1) |
| 2683 | .withConst(); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2684 | QualType KmpUInt64Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2685 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0) |
| 2686 | .withConst(); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2687 | QualType KmpInt64Ty = |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2688 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1) |
| 2689 | .withConst(); |
| 2690 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2691 | QualType KmpInt32PtrTy = |
| 2692 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2693 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2694 | FunctionProtoType::ExtProtoInfo EPI; |
| 2695 | EPI.Variadic = true; |
| 2696 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2697 | Sema::CapturedParamNameType Params[] = { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2698 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2699 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2700 | std::make_pair(".privates.", VoidPtrTy), |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2701 | std::make_pair( |
| 2702 | ".copy_fn.", |
| 2703 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 2704 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2705 | std::make_pair(".lb.", KmpUInt64Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2706 | std::make_pair(".ub.", KmpUInt64Ty), |
| 2707 | std::make_pair(".st.", KmpInt64Ty), |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2708 | std::make_pair(".liter.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2709 | std::make_pair(".reductions.", VoidPtrTy), |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2710 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2711 | }; |
| 2712 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2713 | Params); |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 2714 | // Mark this captured region as inlined, because we don't use outlined |
| 2715 | // function directly. |
| 2716 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2717 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2718 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2719 | break; |
| 2720 | } |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2721 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 2722 | case OMPD_distribute_parallel_for: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2723 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2724 | QualType KmpInt32PtrTy = |
| 2725 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2726 | Sema::CapturedParamNameType Params[] = { |
| 2727 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2728 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2729 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 2730 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2731 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2732 | }; |
| 2733 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2734 | Params); |
| 2735 | break; |
| 2736 | } |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 2737 | case OMPD_target_teams_distribute_parallel_for: |
| 2738 | case OMPD_target_teams_distribute_parallel_for_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2739 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 2740 | QualType KmpInt32PtrTy = |
| 2741 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2742 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 2743 | |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2744 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2745 | FunctionProtoType::ExtProtoInfo EPI; |
| 2746 | EPI.Variadic = true; |
| 2747 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 2748 | Sema::CapturedParamNameType Params[] = { |
| 2749 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2750 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2751 | std::make_pair(".privates.", VoidPtrTy), |
| 2752 | std::make_pair( |
| 2753 | ".copy_fn.", |
| 2754 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 2755 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2756 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2757 | }; |
| 2758 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2759 | Params); |
| Alexey Bataev | 9f9fb0b | 2018-01-16 19:02:33 +0000 | [diff] [blame] | 2760 | // Mark this captured region as inlined, because we don't use outlined |
| 2761 | // function directly. |
| 2762 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2763 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2764 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 2765 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 2766 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2767 | }; |
| 2768 | // Start a captured region for 'target' with no implicit parameters. |
| 2769 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2770 | ParamsTarget); |
| 2771 | |
| 2772 | Sema::CapturedParamNameType ParamsTeams[] = { |
| 2773 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2774 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 2775 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2776 | }; |
| 2777 | // Start a captured region for 'target' with no implicit parameters. |
| 2778 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2779 | ParamsTeams); |
| 2780 | |
| 2781 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 2782 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2783 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2784 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 2785 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 2786 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2787 | }; |
| 2788 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 2789 | // the same implicit parameters. |
| 2790 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2791 | ParamsParallel); |
| 2792 | break; |
| 2793 | } |
| 2794 | |
| Alexey Bataev | 4650627 | 2017-12-05 17:41:34 +0000 | [diff] [blame] | 2795 | case OMPD_teams_distribute_parallel_for: |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 2796 | case OMPD_teams_distribute_parallel_for_simd: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2797 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 2798 | QualType KmpInt32PtrTy = |
| 2799 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2800 | |
| 2801 | Sema::CapturedParamNameType ParamsTeams[] = { |
| 2802 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2803 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 2804 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2805 | }; |
| 2806 | // Start a captured region for 'target' with no implicit parameters. |
| 2807 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2808 | ParamsTeams); |
| 2809 | |
| 2810 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 2811 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 2812 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2813 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
| 2814 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 2815 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2816 | }; |
| 2817 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 2818 | // the same implicit parameters. |
| 2819 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2820 | ParamsParallel); |
| 2821 | break; |
| 2822 | } |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 2823 | case OMPD_target_update: |
| 2824 | case OMPD_target_enter_data: |
| 2825 | case OMPD_target_exit_data: { |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2826 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
| 2827 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
| 2828 | QualType KmpInt32PtrTy = |
| 2829 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 2830 | QualType Args[] = {VoidPtrTy}; |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 2831 | FunctionProtoType::ExtProtoInfo EPI; |
| 2832 | EPI.Variadic = true; |
| 2833 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
| 2834 | Sema::CapturedParamNameType Params[] = { |
| 2835 | std::make_pair(".global_tid.", KmpInt32Ty), |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2836 | std::make_pair(".part_id.", KmpInt32PtrTy), |
| 2837 | std::make_pair(".privates.", VoidPtrTy), |
| 2838 | std::make_pair( |
| 2839 | ".copy_fn.", |
| 2840 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 2841 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 2842 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 2843 | }; |
| 2844 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 2845 | Params); |
| 2846 | // Mark this captured region as inlined, because we don't use outlined |
| 2847 | // function directly. |
| 2848 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 2849 | AlwaysInlineAttr::CreateImplicit( |
| Alexey Bataev | c0f879b | 2018-04-10 20:10:53 +0000 | [diff] [blame] | 2850 | Context, AlwaysInlineAttr::Keyword_forceinline)); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 2851 | break; |
| 2852 | } |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2853 | case OMPD_threadprivate: |
| Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 2854 | case OMPD_taskyield: |
| 2855 | case OMPD_barrier: |
| 2856 | case OMPD_taskwait: |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2857 | case OMPD_cancellation_point: |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2858 | case OMPD_cancel: |
| Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 2859 | case OMPD_flush: |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2860 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 2861 | case OMPD_declare_mapper: |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2862 | case OMPD_declare_simd: |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 2863 | case OMPD_declare_target: |
| 2864 | case OMPD_end_declare_target: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2865 | case OMPD_requires: |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2866 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2867 | case OMPD_unknown: |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2868 | llvm_unreachable("Unknown OpenMP directive"); |
| 2869 | } |
| 2870 | } |
| 2871 | |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2872 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
| 2873 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 2874 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
| 2875 | return CaptureRegions.size(); |
| 2876 | } |
| 2877 | |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2878 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2879 | Expr *CaptureExpr, bool WithInit, |
| 2880 | bool AsExpression) { |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 2881 | assert(CaptureExpr); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2882 | ASTContext &C = S.getASTContext(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2883 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2884 | QualType Ty = Init->getType(); |
| 2885 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2886 | if (S.getLangOpts().CPlusPlus) { |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2887 | Ty = C.getLValueReferenceType(Ty); |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2888 | } else { |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2889 | Ty = C.getPointerType(Ty); |
| 2890 | ExprResult Res = |
| 2891 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 2892 | if (!Res.isUsable()) |
| 2893 | return nullptr; |
| 2894 | Init = Res.get(); |
| 2895 | } |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 2896 | WithInit = true; |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2897 | } |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 2898 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 2899 | CaptureExpr->getBeginLoc()); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 2900 | if (!WithInit) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2901 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C)); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2902 | S.CurContext->addHiddenDecl(CED); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 2903 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2904 | return CED; |
| 2905 | } |
| 2906 | |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 2907 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 2908 | bool WithInit) { |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 2909 | OMPCapturedExprDecl *CD; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2910 | if (VarDecl *VD = S.isOpenMPCapturedDecl(D)) |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 2911 | CD = cast<OMPCapturedExprDecl>(VD); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2912 | else |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2913 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 2914 | /*AsExpression=*/false); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2915 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 2916 | CaptureExpr->getExprLoc()); |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 2917 | } |
| 2918 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2919 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2920 | CaptureExpr = S.DefaultLvalueConversion(CaptureExpr).get(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2921 | if (!Ref) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2922 | OMPCapturedExprDecl *CD = buildCaptureDecl( |
| 2923 | S, &S.getASTContext().Idents.get(".capture_expr."), CaptureExpr, |
| 2924 | /*WithInit=*/true, /*AsExpression=*/true); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2925 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 2926 | CaptureExpr->getExprLoc()); |
| 2927 | } |
| 2928 | ExprResult Res = Ref; |
| 2929 | if (!S.getLangOpts().CPlusPlus && |
| 2930 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2931 | Ref->getType()->isPointerType()) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2932 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 2933 | if (!Res.isUsable()) |
| 2934 | return ExprError(); |
| 2935 | } |
| 2936 | return S.DefaultLvalueConversion(Res.get()); |
| Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2937 | } |
| 2938 | |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2939 | namespace { |
| 2940 | // OpenMP directives parsed in this section are represented as a |
| 2941 | // CapturedStatement with an associated statement. If a syntax error |
| 2942 | // is detected during the parsing of the associated statement, the |
| 2943 | // compiler must abort processing and close the CapturedStatement. |
| 2944 | // |
| 2945 | // Combined directives such as 'target parallel' have more than one |
| 2946 | // nested CapturedStatements. This RAII ensures that we unwind out |
| 2947 | // of all the nested CapturedStatements when an error is found. |
| 2948 | class CaptureRegionUnwinderRAII { |
| 2949 | private: |
| 2950 | Sema &S; |
| 2951 | bool &ErrorFound; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2952 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2953 | |
| 2954 | public: |
| 2955 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
| 2956 | OpenMPDirectiveKind DKind) |
| 2957 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
| 2958 | ~CaptureRegionUnwinderRAII() { |
| 2959 | if (ErrorFound) { |
| 2960 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
| 2961 | while (--ThisCaptureLevel >= 0) |
| 2962 | S.ActOnCapturedRegionError(); |
| 2963 | } |
| 2964 | } |
| 2965 | }; |
| 2966 | } // namespace |
| 2967 | |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2968 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 2969 | ArrayRef<OMPClause *> Clauses) { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2970 | bool ErrorFound = false; |
| 2971 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
| 2972 | *this, ErrorFound, DSAStack->getCurrentDirective()); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2973 | if (!S.isUsable()) { |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 2974 | ErrorFound = true; |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 2975 | return StmtError(); |
| 2976 | } |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2977 | |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 2978 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 2979 | getOpenMPCaptureRegions(CaptureRegions, DSAStack->getCurrentDirective()); |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 2980 | OMPOrderedClause *OC = nullptr; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2981 | OMPScheduleClause *SC = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2982 | SmallVector<const OMPLinearClause *, 4> LCs; |
| 2983 | SmallVector<const OMPClauseWithPreInit *, 4> PICs; |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 2984 | // This is required for proper codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2985 | for (OMPClause *Clause : Clauses) { |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 2986 | if (isOpenMPTaskingDirective(DSAStack->getCurrentDirective()) && |
| 2987 | Clause->getClauseKind() == OMPC_in_reduction) { |
| 2988 | // Capture taskgroup task_reduction descriptors inside the tasking regions |
| 2989 | // with the corresponding in_reduction items. |
| 2990 | auto *IRC = cast<OMPInReductionClause>(Clause); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 2991 | for (Expr *E : IRC->taskgroup_descriptors()) |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 2992 | if (E) |
| 2993 | MarkDeclarationsReferencedInExpr(E); |
| 2994 | } |
| Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 2995 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 2996 | Clause->getClauseKind() == OMPC_copyprivate || |
| 2997 | (getLangOpts().OpenMPUseTLS && |
| 2998 | getASTContext().getTargetInfo().isTLSSupported() && |
| 2999 | Clause->getClauseKind() == OMPC_copyin)) { |
| 3000 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 3001 | // Mark all variables in private list clauses as used in inner region. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3002 | for (Stmt *VarRef : Clause->children()) { |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3003 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
| Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 3004 | MarkDeclarationsReferencedInExpr(E); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3005 | } |
| 3006 | } |
| Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 3007 | DSAStack->setForceVarCapturing(/*V=*/false); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 3008 | } else if (CaptureRegions.size() > 1 || |
| 3009 | CaptureRegions.back() != OMPD_unknown) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3010 | if (auto *C = OMPClauseWithPreInit::get(Clause)) |
| 3011 | PICs.push_back(C); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 3012 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3013 | if (Expr *E = C->getPostUpdateExpr()) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 3014 | MarkDeclarationsReferencedInExpr(E); |
| 3015 | } |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3016 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3017 | if (Clause->getClauseKind() == OMPC_schedule) |
| 3018 | SC = cast<OMPScheduleClause>(Clause); |
| 3019 | else if (Clause->getClauseKind() == OMPC_ordered) |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3020 | OC = cast<OMPOrderedClause>(Clause); |
| 3021 | else if (Clause->getClauseKind() == OMPC_linear) |
| 3022 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 3023 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3024 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 3025 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 3026 | // specified. |
| 3027 | if (SC && |
| 3028 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 3029 | SC->getSecondScheduleModifier() == |
| 3030 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 3031 | OC) { |
| 3032 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 3033 | ? SC->getFirstScheduleModifierLoc() |
| 3034 | : SC->getSecondScheduleModifierLoc(), |
| 3035 | diag::err_omp_schedule_nonmonotonic_ordered) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 3036 | << SourceRange(OC->getBeginLoc(), OC->getEndLoc()); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3037 | ErrorFound = true; |
| 3038 | } |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3039 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3040 | for (const OMPLinearClause *C : LCs) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3041 | Diag(C->getBeginLoc(), diag::err_omp_linear_ordered) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 3042 | << SourceRange(OC->getBeginLoc(), OC->getEndLoc()); |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3043 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3044 | ErrorFound = true; |
| 3045 | } |
| Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 3046 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 3047 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 3048 | OC->getNumForLoops()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3049 | Diag(OC->getBeginLoc(), diag::err_omp_ordered_simd) |
| Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 3050 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 3051 | ErrorFound = true; |
| 3052 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 3053 | if (ErrorFound) { |
| Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 3054 | return StmtError(); |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3055 | } |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3056 | StmtResult SR = S; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 3057 | for (OpenMPDirectiveKind ThisCaptureRegion : llvm::reverse(CaptureRegions)) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3058 | // Mark all variables in private list clauses as used in inner region. |
| 3059 | // Required for proper codegen of combined directives. |
| 3060 | // TODO: add processing for other clauses. |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 3061 | if (ThisCaptureRegion != OMPD_unknown) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3062 | for (const clang::OMPClauseWithPreInit *C : PICs) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3063 | OpenMPDirectiveKind CaptureRegion = C->getCaptureRegion(); |
| 3064 | // Find the particular capture region for the clause if the |
| 3065 | // directive is a combined one with multiple capture regions. |
| 3066 | // If the directive is not a combined one, the capture region |
| 3067 | // associated with the clause is OMPD_unknown and is generated |
| 3068 | // only once. |
| 3069 | if (CaptureRegion == ThisCaptureRegion || |
| 3070 | CaptureRegion == OMPD_unknown) { |
| 3071 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3072 | for (Decl *D : DS->decls()) |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3073 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 3074 | } |
| 3075 | } |
| 3076 | } |
| 3077 | } |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3078 | SR = ActOnCapturedRegionEnd(SR.get()); |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 3079 | } |
| Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 3080 | return SR; |
| Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
| Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 3083 | static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, |
| 3084 | OpenMPDirectiveKind CancelRegion, |
| 3085 | SourceLocation StartLoc) { |
| 3086 | // CancelRegion is only needed for cancel and cancellation_point. |
| 3087 | if (CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_cancellation_point) |
| 3088 | return false; |
| 3089 | |
| 3090 | if (CancelRegion == OMPD_parallel || CancelRegion == OMPD_for || |
| 3091 | CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) |
| 3092 | return false; |
| 3093 | |
| 3094 | SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 3095 | << getOpenMPDirectiveName(CancelRegion); |
| 3096 | return true; |
| 3097 | } |
| 3098 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3099 | static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3100 | OpenMPDirectiveKind CurrentRegion, |
| 3101 | const DeclarationNameInfo &CurrentName, |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3102 | OpenMPDirectiveKind CancelRegion, |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3103 | SourceLocation StartLoc) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3104 | if (Stack->getCurScope()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3105 | OpenMPDirectiveKind ParentRegion = Stack->getParentDirective(); |
| 3106 | OpenMPDirectiveKind OffendingRegion = ParentRegion; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3107 | bool NestingProhibited = false; |
| 3108 | bool CloseNesting = true; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3109 | bool OrphanSeen = false; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3110 | enum { |
| 3111 | NoRecommend, |
| 3112 | ShouldBeInParallelRegion, |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3113 | ShouldBeInOrderedRegion, |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3114 | ShouldBeInTargetRegion, |
| 3115 | ShouldBeInTeamsRegion |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3116 | } Recommend = NoRecommend; |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3117 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3118 | // OpenMP [2.16, Nesting of Regions] |
| 3119 | // OpenMP constructs may not be nested inside a simd region. |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3120 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3121 | // An ordered construct with the simd clause is the only OpenMP |
| 3122 | // construct that can appear in the simd region. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3123 | // Allowing a SIMD construct nested in another SIMD construct is an |
| Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3124 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 3125 | // message. |
| 3126 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 3127 | ? diag::err_omp_prohibited_region_simd |
| 3128 | : diag::warn_omp_nesting_simd); |
| 3129 | return CurrentRegion != OMPD_simd; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3130 | } |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3131 | if (ParentRegion == OMPD_atomic) { |
| 3132 | // OpenMP [2.16, Nesting of Regions] |
| 3133 | // OpenMP constructs may not be nested inside an atomic region. |
| 3134 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 3135 | return true; |
| 3136 | } |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3137 | if (CurrentRegion == OMPD_section) { |
| 3138 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 3139 | // Orphaned section directives are prohibited. That is, the section |
| 3140 | // directives must appear within the sections construct and must not be |
| 3141 | // encountered elsewhere in the sections region. |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3142 | if (ParentRegion != OMPD_sections && |
| 3143 | ParentRegion != OMPD_parallel_sections) { |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3144 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 3145 | << (ParentRegion != OMPD_unknown) |
| 3146 | << getOpenMPDirectiveName(ParentRegion); |
| 3147 | return true; |
| 3148 | } |
| 3149 | return false; |
| 3150 | } |
| Alexey Bataev | 185e88d | 2019-01-08 15:53:42 +0000 | [diff] [blame] | 3151 | // Allow some constructs (except teams and cancellation constructs) to be |
| 3152 | // orphaned (they could be used in functions, called from OpenMP regions |
| 3153 | // with the required preconditions). |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 3154 | if (ParentRegion == OMPD_unknown && |
| Alexey Bataev | 185e88d | 2019-01-08 15:53:42 +0000 | [diff] [blame] | 3155 | !isOpenMPNestingTeamsDirective(CurrentRegion) && |
| 3156 | CurrentRegion != OMPD_cancellation_point && |
| 3157 | CurrentRegion != OMPD_cancel) |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3158 | return false; |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3159 | if (CurrentRegion == OMPD_cancellation_point || |
| 3160 | CurrentRegion == OMPD_cancel) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3161 | // OpenMP [2.16, Nesting of Regions] |
| 3162 | // A cancellation point construct for which construct-type-clause is |
| 3163 | // taskgroup must be nested inside a task construct. A cancellation |
| 3164 | // point construct for which construct-type-clause is not taskgroup must |
| 3165 | // be closely nested inside an OpenMP construct that matches the type |
| 3166 | // specified in construct-type-clause. |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3167 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 3168 | // nested inside a task construct. A cancel construct for which |
| 3169 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 3170 | // OpenMP construct that matches the type specified in |
| 3171 | // construct-type-clause. |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3172 | NestingProhibited = |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3173 | !((CancelRegion == OMPD_parallel && |
| 3174 | (ParentRegion == OMPD_parallel || |
| 3175 | ParentRegion == OMPD_target_parallel)) || |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3176 | (CancelRegion == OMPD_for && |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3177 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 3178 | ParentRegion == OMPD_target_parallel_for || |
| 3179 | ParentRegion == OMPD_distribute_parallel_for || |
| Alexey Bataev | 16e7988 | 2017-11-22 21:12:03 +0000 | [diff] [blame] | 3180 | ParentRegion == OMPD_teams_distribute_parallel_for || |
| 3181 | ParentRegion == OMPD_target_teams_distribute_parallel_for)) || |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3182 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 3183 | (CancelRegion == OMPD_sections && |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3184 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 3185 | ParentRegion == OMPD_parallel_sections))); |
| Alexey Bataev | 185e88d | 2019-01-08 15:53:42 +0000 | [diff] [blame] | 3186 | OrphanSeen = ParentRegion == OMPD_unknown; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3187 | } else if (CurrentRegion == OMPD_master) { |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3188 | // OpenMP [2.16, Nesting of Regions] |
| 3189 | // A master region may not be closely nested inside a worksharing, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3190 | // atomic, or explicit task region. |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3191 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3192 | isOpenMPTaskingDirective(ParentRegion); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3193 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 3194 | // OpenMP [2.16, Nesting of Regions] |
| 3195 | // A critical region may not be nested (closely or otherwise) inside a |
| 3196 | // critical region with the same name. Note that this restriction is not |
| 3197 | // sufficient to prevent deadlock. |
| 3198 | SourceLocation PreviousCriticalLoc; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3199 | bool DeadLock = Stack->hasDirective( |
| 3200 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 3201 | const DeclarationNameInfo &DNI, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3202 | SourceLocation Loc) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3203 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 3204 | PreviousCriticalLoc = Loc; |
| 3205 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3206 | } |
| 3207 | return false; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3208 | }, |
| 3209 | false /* skip top directive */); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3210 | if (DeadLock) { |
| 3211 | SemaRef.Diag(StartLoc, |
| 3212 | diag::err_omp_prohibited_region_critical_same_name) |
| 3213 | << CurrentName.getName(); |
| 3214 | if (PreviousCriticalLoc.isValid()) |
| 3215 | SemaRef.Diag(PreviousCriticalLoc, |
| 3216 | diag::note_omp_previous_critical_region); |
| 3217 | return true; |
| 3218 | } |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3219 | } else if (CurrentRegion == OMPD_barrier) { |
| 3220 | // OpenMP [2.16, Nesting of Regions] |
| 3221 | // A barrier region may not be closely nested inside a worksharing, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3222 | // explicit task, critical, ordered, atomic, or master region. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3223 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 3224 | isOpenMPTaskingDirective(ParentRegion) || |
| 3225 | ParentRegion == OMPD_master || |
| 3226 | ParentRegion == OMPD_critical || |
| 3227 | ParentRegion == OMPD_ordered; |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3228 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 3229 | !isOpenMPParallelDirective(CurrentRegion) && |
| 3230 | !isOpenMPTeamsDirective(CurrentRegion)) { |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3231 | // OpenMP [2.16, Nesting of Regions] |
| 3232 | // A worksharing region may not be closely nested inside a worksharing, |
| 3233 | // explicit task, critical, ordered, atomic, or master region. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3234 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 3235 | isOpenMPTaskingDirective(ParentRegion) || |
| 3236 | ParentRegion == OMPD_master || |
| 3237 | ParentRegion == OMPD_critical || |
| 3238 | ParentRegion == OMPD_ordered; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3239 | Recommend = ShouldBeInParallelRegion; |
| 3240 | } else if (CurrentRegion == OMPD_ordered) { |
| 3241 | // OpenMP [2.16, Nesting of Regions] |
| 3242 | // An ordered region may not be closely nested inside a critical, |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3243 | // atomic, or explicit task region. |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3244 | // An ordered region must be closely nested inside a loop region (or |
| 3245 | // parallel loop region) with an ordered clause. |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3246 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 3247 | // An ordered construct with the simd clause is the only OpenMP construct |
| 3248 | // that can appear in the simd region. |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3249 | NestingProhibited = ParentRegion == OMPD_critical || |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3250 | isOpenMPTaskingDirective(ParentRegion) || |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3251 | !(isOpenMPSimdDirective(ParentRegion) || |
| 3252 | Stack->isParentOrderedRegion()); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3253 | Recommend = ShouldBeInOrderedRegion; |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 3254 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3255 | // OpenMP [2.16, Nesting of Regions] |
| 3256 | // If specified, a teams construct must be contained within a target |
| 3257 | // construct. |
| 3258 | NestingProhibited = ParentRegion != OMPD_target; |
| Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3259 | OrphanSeen = ParentRegion == OMPD_unknown; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3260 | Recommend = ShouldBeInTargetRegion; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3261 | } |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 3262 | if (!NestingProhibited && |
| 3263 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
| 3264 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
| 3265 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3266 | // OpenMP [2.16, Nesting of Regions] |
| 3267 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 3268 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 3269 | // constructs that can be closely nested in the teams region. |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3270 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 3271 | !isOpenMPDistributeDirective(CurrentRegion); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3272 | Recommend = ShouldBeInParallelRegion; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3273 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3274 | if (!NestingProhibited && |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3275 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3276 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 3277 | // The region associated with the distribute construct must be strictly |
| 3278 | // nested inside a teams region |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 3279 | NestingProhibited = |
| 3280 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3281 | Recommend = ShouldBeInTeamsRegion; |
| 3282 | } |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3283 | if (!NestingProhibited && |
| 3284 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 3285 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 3286 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 3287 | // If a target, target update, target data, target enter data, or |
| 3288 | // target exit data construct is encountered during execution of a |
| 3289 | // target region, the behavior is unspecified. |
| 3290 | NestingProhibited = Stack->hasDirective( |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3291 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3292 | SourceLocation) { |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3293 | if (isOpenMPTargetExecutionDirective(K)) { |
| 3294 | OffendingRegion = K; |
| 3295 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3296 | } |
| 3297 | return false; |
| Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3298 | }, |
| 3299 | false /* don't skip top directive */); |
| 3300 | CloseNesting = false; |
| 3301 | } |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3302 | if (NestingProhibited) { |
| Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3303 | if (OrphanSeen) { |
| 3304 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 3305 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 3306 | } else { |
| 3307 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 3308 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 3309 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 3310 | } |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3311 | return true; |
| 3312 | } |
| 3313 | } |
| 3314 | return false; |
| 3315 | } |
| 3316 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3317 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 3318 | ArrayRef<OMPClause *> Clauses, |
| 3319 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 3320 | bool ErrorFound = false; |
| 3321 | unsigned NamedModifiersNumber = 0; |
| 3322 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 3323 | OMPD_unknown + 1); |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3324 | SmallVector<SourceLocation, 4> NameModifierLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3325 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3326 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 3327 | // At most one if clause without a directive-name-modifier can appear on |
| 3328 | // the directive. |
| 3329 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 3330 | if (FoundNameModifiers[CurNM]) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3331 | S.Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3332 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 3333 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 3334 | ErrorFound = true; |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3335 | } else if (CurNM != OMPD_unknown) { |
| 3336 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3337 | ++NamedModifiersNumber; |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3338 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3339 | FoundNameModifiers[CurNM] = IC; |
| 3340 | if (CurNM == OMPD_unknown) |
| 3341 | continue; |
| 3342 | // Check if the specified name modifier is allowed for the current |
| 3343 | // directive. |
| 3344 | // At most one if clause with the particular directive-name-modifier can |
| 3345 | // appear on the directive. |
| 3346 | bool MatchFound = false; |
| 3347 | for (auto NM : AllowedNameModifiers) { |
| 3348 | if (CurNM == NM) { |
| 3349 | MatchFound = true; |
| 3350 | break; |
| 3351 | } |
| 3352 | } |
| 3353 | if (!MatchFound) { |
| 3354 | S.Diag(IC->getNameModifierLoc(), |
| 3355 | diag::err_omp_wrong_if_directive_name_modifier) |
| 3356 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 3357 | ErrorFound = true; |
| 3358 | } |
| 3359 | } |
| 3360 | } |
| 3361 | // If any if clause on the directive includes a directive-name-modifier then |
| 3362 | // all if clauses on the directive must include a directive-name-modifier. |
| 3363 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 3364 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3365 | S.Diag(FoundNameModifiers[OMPD_unknown]->getBeginLoc(), |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3366 | diag::err_omp_no_more_if_clause); |
| 3367 | } else { |
| 3368 | std::string Values; |
| 3369 | std::string Sep(", "); |
| 3370 | unsigned AllowedCnt = 0; |
| 3371 | unsigned TotalAllowedNum = |
| 3372 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 3373 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 3374 | ++Cnt) { |
| 3375 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 3376 | if (!FoundNameModifiers[NM]) { |
| 3377 | Values += "'"; |
| 3378 | Values += getOpenMPDirectiveName(NM); |
| 3379 | Values += "'"; |
| 3380 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 3381 | Values += " or "; |
| 3382 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 3383 | Values += Sep; |
| 3384 | ++AllowedCnt; |
| 3385 | } |
| 3386 | } |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 3387 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getBeginLoc(), |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3388 | diag::err_omp_unnamed_if_clause) |
| 3389 | << (TotalAllowedNum > 1) << Values; |
| 3390 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3391 | for (SourceLocation Loc : NameModifierLoc) { |
| Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3392 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 3393 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3394 | ErrorFound = true; |
| 3395 | } |
| 3396 | return ErrorFound; |
| 3397 | } |
| 3398 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3399 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 3400 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 3401 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 3402 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3403 | StmtResult Res = StmtError(); |
| Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 3404 | // First check CancelRegion which is then used in checkNestingOfRegions. |
| 3405 | if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) || |
| 3406 | checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3407 | StartLoc)) |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3408 | return StmtError(); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3409 | |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3410 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3411 | VarsWithInheritedDSAType VarsWithInheritedDSA; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3412 | bool ErrorFound = false; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3413 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
| Alexey Bataev | 0dce2ea | 2017-09-21 14:06:59 +0000 | [diff] [blame] | 3414 | if (AStmt && !CurContext->isDependentContext()) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3415 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3416 | |
| 3417 | // Check default data sharing attributes for referenced variables. |
| 3418 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| Arpith Chacko Jacob | 1f46b70 | 2017-01-23 15:38:49 +0000 | [diff] [blame] | 3419 | int ThisCaptureLevel = getOpenMPCaptureLevels(Kind); |
| 3420 | Stmt *S = AStmt; |
| 3421 | while (--ThisCaptureLevel >= 0) |
| 3422 | S = cast<CapturedStmt>(S)->getCapturedStmt(); |
| 3423 | DSAChecker.Visit(S); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3424 | if (DSAChecker.isErrorFound()) |
| 3425 | return StmtError(); |
| 3426 | // Generate list of implicitly defined firstprivate variables. |
| 3427 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3428 | |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3429 | SmallVector<Expr *, 4> ImplicitFirstprivates( |
| 3430 | DSAChecker.getImplicitFirstprivate().begin(), |
| 3431 | DSAChecker.getImplicitFirstprivate().end()); |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3432 | SmallVector<Expr *, 4> ImplicitMaps(DSAChecker.getImplicitMap().begin(), |
| 3433 | DSAChecker.getImplicitMap().end()); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3434 | // Mark taskgroup task_reduction descriptors as implicitly firstprivate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3435 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3436 | if (auto *IRC = dyn_cast<OMPInReductionClause>(C)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3437 | for (Expr *E : IRC->taskgroup_descriptors()) |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3438 | if (E) |
| 3439 | ImplicitFirstprivates.emplace_back(E); |
| 3440 | } |
| 3441 | } |
| 3442 | if (!ImplicitFirstprivates.empty()) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3443 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3444 | ImplicitFirstprivates, SourceLocation(), SourceLocation(), |
| 3445 | SourceLocation())) { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3446 | ClausesWithImplicit.push_back(Implicit); |
| 3447 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 3448 | ImplicitFirstprivates.size(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3449 | } else { |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3450 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3451 | } |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3452 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3453 | if (!ImplicitMaps.empty()) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 3454 | CXXScopeSpec MapperIdScopeSpec; |
| 3455 | DeclarationNameInfo MapperId; |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3456 | if (OMPClause *Implicit = ActOnOpenMPMapClause( |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 3457 | llvm::None, llvm::None, MapperIdScopeSpec, MapperId, |
| 3458 | OMPC_MAP_tofrom, /*IsMapTypeImplicit=*/true, SourceLocation(), |
| 3459 | SourceLocation(), ImplicitMaps, OMPVarListLocTy())) { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3460 | ClausesWithImplicit.emplace_back(Implicit); |
| 3461 | ErrorFound |= |
| 3462 | cast<OMPMapClause>(Implicit)->varlist_size() != ImplicitMaps.size(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3463 | } else { |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3464 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3465 | } |
| Alexey Bataev | f47c4b4 | 2017-09-26 13:47:31 +0000 | [diff] [blame] | 3466 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3467 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3468 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3469 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3470 | switch (Kind) { |
| 3471 | case OMPD_parallel: |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3472 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3473 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3474 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3475 | break; |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3476 | case OMPD_simd: |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3477 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3478 | VarsWithInheritedDSA); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3479 | break; |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3480 | case OMPD_for: |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3481 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3482 | VarsWithInheritedDSA); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3483 | break; |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3484 | case OMPD_for_simd: |
| 3485 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3486 | EndLoc, VarsWithInheritedDSA); |
| 3487 | break; |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3488 | case OMPD_sections: |
| 3489 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3490 | EndLoc); |
| 3491 | break; |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3492 | case OMPD_section: |
| 3493 | assert(ClausesWithImplicit.empty() && |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3494 | "No clauses are allowed for 'omp section' directive"); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3495 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3496 | break; |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3497 | case OMPD_single: |
| 3498 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3499 | EndLoc); |
| 3500 | break; |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3501 | case OMPD_master: |
| 3502 | assert(ClausesWithImplicit.empty() && |
| 3503 | "No clauses are allowed for 'omp master' directive"); |
| 3504 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3505 | break; |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3506 | case OMPD_critical: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3507 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3508 | StartLoc, EndLoc); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3509 | break; |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3510 | case OMPD_parallel_for: |
| 3511 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3512 | EndLoc, VarsWithInheritedDSA); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3513 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3514 | break; |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3515 | case OMPD_parallel_for_simd: |
| 3516 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3517 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3518 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3519 | break; |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3520 | case OMPD_parallel_sections: |
| 3521 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3522 | StartLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3523 | AllowedNameModifiers.push_back(OMPD_parallel); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3524 | break; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3525 | case OMPD_task: |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3526 | Res = |
| 3527 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3528 | AllowedNameModifiers.push_back(OMPD_task); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3529 | break; |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3530 | case OMPD_taskyield: |
| 3531 | assert(ClausesWithImplicit.empty() && |
| 3532 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3533 | assert(AStmt == nullptr && |
| 3534 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3535 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3536 | break; |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3537 | case OMPD_barrier: |
| 3538 | assert(ClausesWithImplicit.empty() && |
| 3539 | "No clauses are allowed for 'omp barrier' directive"); |
| 3540 | assert(AStmt == nullptr && |
| 3541 | "No associated statement allowed for 'omp barrier' directive"); |
| 3542 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3543 | break; |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3544 | case OMPD_taskwait: |
| 3545 | assert(ClausesWithImplicit.empty() && |
| 3546 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3547 | assert(AStmt == nullptr && |
| 3548 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3549 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3550 | break; |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3551 | case OMPD_taskgroup: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 3552 | Res = ActOnOpenMPTaskgroupDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3553 | EndLoc); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3554 | break; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3555 | case OMPD_flush: |
| 3556 | assert(AStmt == nullptr && |
| 3557 | "No associated statement allowed for 'omp flush' directive"); |
| 3558 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3559 | break; |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3560 | case OMPD_ordered: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3561 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3562 | EndLoc); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3563 | break; |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3564 | case OMPD_atomic: |
| 3565 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3566 | EndLoc); |
| 3567 | break; |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3568 | case OMPD_teams: |
| 3569 | Res = |
| 3570 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3571 | break; |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3572 | case OMPD_target: |
| 3573 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3574 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3575 | AllowedNameModifiers.push_back(OMPD_target); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3576 | break; |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3577 | case OMPD_target_parallel: |
| 3578 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3579 | StartLoc, EndLoc); |
| 3580 | AllowedNameModifiers.push_back(OMPD_target); |
| 3581 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3582 | break; |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3583 | case OMPD_target_parallel_for: |
| 3584 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3585 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3586 | AllowedNameModifiers.push_back(OMPD_target); |
| 3587 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3588 | break; |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3589 | case OMPD_cancellation_point: |
| 3590 | assert(ClausesWithImplicit.empty() && |
| 3591 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3592 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3593 | "cancellation point' directive"); |
| 3594 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3595 | break; |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3596 | case OMPD_cancel: |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3597 | assert(AStmt == nullptr && |
| 3598 | "No associated statement allowed for 'omp cancel' directive"); |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3599 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3600 | CancelRegion); |
| 3601 | AllowedNameModifiers.push_back(OMPD_cancel); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3602 | break; |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3603 | case OMPD_target_data: |
| 3604 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3605 | EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3606 | AllowedNameModifiers.push_back(OMPD_target_data); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3607 | break; |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3608 | case OMPD_target_enter_data: |
| 3609 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3610 | EndLoc, AStmt); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3611 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3612 | break; |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3613 | case OMPD_target_exit_data: |
| 3614 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3615 | EndLoc, AStmt); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3616 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3617 | break; |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3618 | case OMPD_taskloop: |
| 3619 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3620 | EndLoc, VarsWithInheritedDSA); |
| 3621 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3622 | break; |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3623 | case OMPD_taskloop_simd: |
| 3624 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3625 | EndLoc, VarsWithInheritedDSA); |
| 3626 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3627 | break; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3628 | case OMPD_distribute: |
| 3629 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3630 | EndLoc, VarsWithInheritedDSA); |
| 3631 | break; |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 3632 | case OMPD_target_update: |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 3633 | Res = ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, |
| 3634 | EndLoc, AStmt); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 3635 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 3636 | break; |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 3637 | case OMPD_distribute_parallel_for: |
| 3638 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 3639 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3640 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3641 | break; |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 3642 | case OMPD_distribute_parallel_for_simd: |
| 3643 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 3644 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3645 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3646 | break; |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 3647 | case OMPD_distribute_simd: |
| 3648 | Res = ActOnOpenMPDistributeSimdDirective( |
| 3649 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3650 | break; |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3651 | case OMPD_target_parallel_for_simd: |
| 3652 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 3653 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3654 | AllowedNameModifiers.push_back(OMPD_target); |
| 3655 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3656 | break; |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3657 | case OMPD_target_simd: |
| 3658 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3659 | EndLoc, VarsWithInheritedDSA); |
| 3660 | AllowedNameModifiers.push_back(OMPD_target); |
| 3661 | break; |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3662 | case OMPD_teams_distribute: |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3663 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 3664 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3665 | break; |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 3666 | case OMPD_teams_distribute_simd: |
| 3667 | Res = ActOnOpenMPTeamsDistributeSimdDirective( |
| 3668 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3669 | break; |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 3670 | case OMPD_teams_distribute_parallel_for_simd: |
| 3671 | Res = ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 3672 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3673 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3674 | break; |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 3675 | case OMPD_teams_distribute_parallel_for: |
| 3676 | Res = ActOnOpenMPTeamsDistributeParallelForDirective( |
| 3677 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3678 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3679 | break; |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 3680 | case OMPD_target_teams: |
| 3681 | Res = ActOnOpenMPTargetTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3682 | EndLoc); |
| 3683 | AllowedNameModifiers.push_back(OMPD_target); |
| 3684 | break; |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 3685 | case OMPD_target_teams_distribute: |
| 3686 | Res = ActOnOpenMPTargetTeamsDistributeDirective( |
| 3687 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3688 | AllowedNameModifiers.push_back(OMPD_target); |
| 3689 | break; |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 3690 | case OMPD_target_teams_distribute_parallel_for: |
| 3691 | Res = ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 3692 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3693 | AllowedNameModifiers.push_back(OMPD_target); |
| 3694 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3695 | break; |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 3696 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 3697 | Res = ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 3698 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3699 | AllowedNameModifiers.push_back(OMPD_target); |
| 3700 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3701 | break; |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 3702 | case OMPD_target_teams_distribute_simd: |
| 3703 | Res = ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 3704 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3705 | AllowedNameModifiers.push_back(OMPD_target); |
| 3706 | break; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 3707 | case OMPD_declare_target: |
| 3708 | case OMPD_end_declare_target: |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3709 | case OMPD_threadprivate: |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3710 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 3711 | case OMPD_declare_mapper: |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3712 | case OMPD_declare_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 3713 | case OMPD_requires: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3714 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3715 | case OMPD_unknown: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3716 | llvm_unreachable("Unknown OpenMP directive"); |
| 3717 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3718 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3719 | for (const auto &P : VarsWithInheritedDSA) { |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3720 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3721 | << P.first << P.second->getSourceRange(); |
| 3722 | } |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3723 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3724 | |
| 3725 | if (!AllowedNameModifiers.empty()) |
| 3726 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3727 | ErrorFound; |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3728 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3729 | if (ErrorFound) |
| 3730 | return StmtError(); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3731 | return Res; |
| 3732 | } |
| 3733 | |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3734 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 3735 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3736 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3737 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 3738 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3739 | assert(Aligneds.size() == Alignments.size()); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3740 | assert(Linears.size() == LinModifiers.size()); |
| 3741 | assert(Linears.size() == Steps.size()); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3742 | if (!DG || DG.get().isNull()) |
| 3743 | return DeclGroupPtrTy(); |
| 3744 | |
| 3745 | if (!DG.get().isSingleDecl()) { |
| Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 3746 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3747 | return DG; |
| 3748 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3749 | Decl *ADecl = DG.get().getSingleDecl(); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3750 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 3751 | ADecl = FTD->getTemplatedDecl(); |
| 3752 | |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3753 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 3754 | if (!FD) { |
| 3755 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3756 | return DeclGroupPtrTy(); |
| 3757 | } |
| 3758 | |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3759 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3760 | // The parameter of the simdlen clause must be a constant positive integer |
| 3761 | // expression. |
| 3762 | ExprResult SL; |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3763 | if (Simdlen) |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3764 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3765 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3766 | // The special this pointer can be used as if was one of the arguments to the |
| 3767 | // function in any of the linear, aligned, or uniform clauses. |
| 3768 | // The uniform clause declares one or more arguments to have an invariant |
| 3769 | // value for all concurrent invocations of the function in the execution of a |
| 3770 | // single SIMD loop. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3771 | llvm::DenseMap<const Decl *, const Expr *> UniformedArgs; |
| 3772 | const Expr *UniformedLinearThis = nullptr; |
| 3773 | for (const Expr *E : Uniforms) { |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3774 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3775 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3776 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3777 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3778 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3779 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| Alexey Bataev | 43a919f | 2018-04-13 17:48:43 +0000 | [diff] [blame] | 3780 | UniformedArgs.try_emplace(PVD->getCanonicalDecl(), E); |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3781 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3782 | } |
| 3783 | if (isa<CXXThisExpr>(E)) { |
| 3784 | UniformedLinearThis = E; |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3785 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3786 | } |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3787 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3788 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3789 | } |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3790 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3791 | // The aligned clause declares that the object to which each list item points |
| 3792 | // is aligned to the number of bytes expressed in the optional parameter of |
| 3793 | // the aligned clause. |
| 3794 | // The special this pointer can be used as if was one of the arguments to the |
| 3795 | // function in any of the linear, aligned, or uniform clauses. |
| 3796 | // The type of list items appearing in the aligned clause must be array, |
| 3797 | // pointer, reference to array, or reference to pointer. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3798 | llvm::DenseMap<const Decl *, const Expr *> AlignedArgs; |
| 3799 | const Expr *AlignedThis = nullptr; |
| 3800 | for (const Expr *E : Aligneds) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3801 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3802 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3803 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3804 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3805 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3806 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3807 | ->getCanonicalDecl() == CanonPVD) { |
| 3808 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3809 | // A list-item cannot appear in more than one aligned clause. |
| 3810 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 3811 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3812 | << 1 << E->getSourceRange(); |
| 3813 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 3814 | diag::note_omp_explicit_dsa) |
| 3815 | << getOpenMPClauseName(OMPC_aligned); |
| 3816 | continue; |
| 3817 | } |
| 3818 | AlignedArgs[CanonPVD] = E; |
| 3819 | QualType QTy = PVD->getType() |
| 3820 | .getNonReferenceType() |
| 3821 | .getUnqualifiedType() |
| 3822 | .getCanonicalType(); |
| 3823 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 3824 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 3825 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 3826 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 3827 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 3828 | } |
| 3829 | continue; |
| 3830 | } |
| 3831 | } |
| 3832 | if (isa<CXXThisExpr>(E)) { |
| 3833 | if (AlignedThis) { |
| 3834 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3835 | << 2 << E->getSourceRange(); |
| 3836 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3837 | << getOpenMPClauseName(OMPC_aligned); |
| 3838 | } |
| 3839 | AlignedThis = E; |
| 3840 | continue; |
| 3841 | } |
| 3842 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3843 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3844 | } |
| 3845 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 3846 | // positive integer expression. If no optional parameter is specified, |
| 3847 | // implementation-defined default alignments for SIMD instructions on the |
| 3848 | // target platforms are assumed. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3849 | SmallVector<const Expr *, 4> NewAligns; |
| 3850 | for (Expr *E : Alignments) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3851 | ExprResult Align; |
| 3852 | if (E) |
| 3853 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 3854 | NewAligns.push_back(Align.get()); |
| 3855 | } |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3856 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3857 | // The linear clause declares one or more list items to be private to a SIMD |
| 3858 | // lane and to have a linear relationship with respect to the iteration space |
| 3859 | // of a loop. |
| 3860 | // The special this pointer can be used as if was one of the arguments to the |
| 3861 | // function in any of the linear, aligned, or uniform clauses. |
| 3862 | // When a linear-step expression is specified in a linear clause it must be |
| 3863 | // either a constant integer expression or an integer-typed parameter that is |
| 3864 | // specified in a uniform clause on the directive. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3865 | llvm::DenseMap<const Decl *, const Expr *> LinearArgs; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3866 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 3867 | auto MI = LinModifiers.begin(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3868 | for (const Expr *E : Linears) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3869 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 3870 | ++MI; |
| 3871 | E = E->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3872 | if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3873 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3874 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3875 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3876 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3877 | ->getCanonicalDecl() == CanonPVD) { |
| 3878 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 3879 | // A list-item cannot appear in more than one linear clause. |
| 3880 | if (LinearArgs.count(CanonPVD) > 0) { |
| 3881 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3882 | << getOpenMPClauseName(OMPC_linear) |
| 3883 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 3884 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 3885 | diag::note_omp_explicit_dsa) |
| 3886 | << getOpenMPClauseName(OMPC_linear); |
| 3887 | continue; |
| 3888 | } |
| 3889 | // Each argument can appear in at most one uniform or linear clause. |
| 3890 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 3891 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3892 | << getOpenMPClauseName(OMPC_linear) |
| 3893 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 3894 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 3895 | diag::note_omp_explicit_dsa) |
| 3896 | << getOpenMPClauseName(OMPC_uniform); |
| 3897 | continue; |
| 3898 | } |
| 3899 | LinearArgs[CanonPVD] = E; |
| 3900 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3901 | E->isInstantiationDependent() || |
| 3902 | E->containsUnexpandedParameterPack()) |
| 3903 | continue; |
| 3904 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 3905 | PVD->getOriginalType()); |
| 3906 | continue; |
| 3907 | } |
| 3908 | } |
| 3909 | if (isa<CXXThisExpr>(E)) { |
| 3910 | if (UniformedLinearThis) { |
| 3911 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3912 | << getOpenMPClauseName(OMPC_linear) |
| 3913 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 3914 | << E->getSourceRange(); |
| 3915 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3916 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 3917 | : OMPC_linear); |
| 3918 | continue; |
| 3919 | } |
| 3920 | UniformedLinearThis = E; |
| 3921 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3922 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 3923 | continue; |
| 3924 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 3925 | E->getType()); |
| 3926 | continue; |
| 3927 | } |
| 3928 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3929 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3930 | } |
| 3931 | Expr *Step = nullptr; |
| 3932 | Expr *NewStep = nullptr; |
| 3933 | SmallVector<Expr *, 4> NewSteps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3934 | for (Expr *E : Steps) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3935 | // Skip the same step expression, it was checked already. |
| 3936 | if (Step == E || !E) { |
| 3937 | NewSteps.push_back(E ? NewStep : nullptr); |
| 3938 | continue; |
| 3939 | } |
| 3940 | Step = E; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3941 | if (const auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 3942 | if (const auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3943 | const VarDecl *CanonPVD = PVD->getCanonicalDecl(); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3944 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 3945 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 3946 | << Step->getSourceRange(); |
| 3947 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 3948 | E->isInstantiationDependent() || |
| 3949 | E->containsUnexpandedParameterPack() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3950 | CanonPVD->getType()->hasIntegerRepresentation()) { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3951 | NewSteps.push_back(Step); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3952 | } else { |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3953 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 3954 | << Step->getSourceRange(); |
| 3955 | } |
| 3956 | continue; |
| 3957 | } |
| 3958 | NewStep = Step; |
| 3959 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 3960 | !Step->isInstantiationDependent() && |
| 3961 | !Step->containsUnexpandedParameterPack()) { |
| 3962 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 3963 | .get(); |
| 3964 | if (NewStep) |
| 3965 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 3966 | } |
| 3967 | NewSteps.push_back(NewStep); |
| 3968 | } |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3969 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 3970 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3971 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3972 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 3973 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 3974 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 3975 | NewSteps.data(), NewSteps.size(), SR); |
| Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3976 | ADecl->addAttr(NewAttr); |
| 3977 | return ConvertDeclToDeclGroup(ADecl); |
| 3978 | } |
| 3979 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3980 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3981 | Stmt *AStmt, |
| 3982 | SourceLocation StartLoc, |
| 3983 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3984 | if (!AStmt) |
| 3985 | return StmtError(); |
| 3986 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 3987 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3988 | // 1.2.2 OpenMP Language Terminology |
| 3989 | // Structured block - An executable statement with a single entry at the |
| 3990 | // top and a single exit at the bottom. |
| 3991 | // The point of exit cannot be a branch out of the structured block. |
| 3992 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3993 | CS->getCapturedDecl()->setNothrow(); |
| 3994 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 3995 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3996 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3997 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3998 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3999 | } |
| 4000 | |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4001 | namespace { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4002 | /// Helper class for checking canonical form of the OpenMP loops and |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4003 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 4004 | /// for IR generation. |
| 4005 | class OpenMPIterationSpaceChecker { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4006 | /// Reference to Sema. |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4007 | Sema &SemaRef; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4008 | /// A location for diagnostics (when there is no some better location). |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4009 | SourceLocation DefaultLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4010 | /// A location for diagnostics (when increment is not compatible). |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4011 | SourceLocation ConditionLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4012 | /// A source location for referring to loop init later. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4013 | SourceRange InitSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4014 | /// A source location for referring to condition later. |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4015 | SourceRange ConditionSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4016 | /// A source location for referring to increment later. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4017 | SourceRange IncrementSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4018 | /// Loop variable. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4019 | ValueDecl *LCDecl = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4020 | /// Reference to loop variable. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4021 | Expr *LCRef = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4022 | /// Lower bound (initializer for the var). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4023 | Expr *LB = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4024 | /// Upper bound. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4025 | Expr *UB = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4026 | /// Loop step (increment). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4027 | Expr *Step = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4028 | /// This flag is true when condition is one of: |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4029 | /// Var < UB |
| 4030 | /// Var <= UB |
| 4031 | /// UB > Var |
| 4032 | /// UB >= Var |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4033 | /// This will have no value when the condition is != |
| 4034 | llvm::Optional<bool> TestIsLessOp; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4035 | /// This flag is true when condition is strict ( < or > ). |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4036 | bool TestIsStrictOp = false; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4037 | /// This flag is true when step is subtracted on each iteration. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4038 | bool SubtractStep = false; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4039 | |
| 4040 | public: |
| 4041 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4042 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4043 | /// Check init-expr for canonical loop form and save loop counter |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4044 | /// variable - #Var and its initialization value - #LB. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4045 | bool checkAndSetInit(Stmt *S, bool EmitDiags = true); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4046 | /// Check test-expr for canonical form, save upper-bound (#UB), flags |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4047 | /// for less/greater and for strict/non-strict comparison. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4048 | bool checkAndSetCond(Expr *S); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4049 | /// Check incr-expr for canonical loop form and return true if it |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4050 | /// does not conform, otherwise save loop step (#Step). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4051 | bool checkAndSetInc(Expr *S); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4052 | /// Return the loop counter variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4053 | ValueDecl *getLoopDecl() const { return LCDecl; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4054 | /// Return the reference expression to loop counter variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4055 | Expr *getLoopDeclRefExpr() const { return LCRef; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4056 | /// Source range of the loop init. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4057 | SourceRange getInitSrcRange() const { return InitSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4058 | /// Source range of the loop condition. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4059 | SourceRange getConditionSrcRange() const { return ConditionSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4060 | /// Source range of the loop increment. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4061 | SourceRange getIncrementSrcRange() const { return IncrementSrcRange; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4062 | /// True if the step should be subtracted. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4063 | bool shouldSubtractStep() const { return SubtractStep; } |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 4064 | /// True, if the compare operator is strict (<, > or !=). |
| 4065 | bool isStrictTestOp() const { return TestIsStrictOp; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4066 | /// Build the expression to calculate the number of iterations. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4067 | Expr *buildNumIterations( |
| 4068 | Scope *S, const bool LimitedType, |
| 4069 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4070 | /// Build the precondition expression for the loops. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4071 | Expr * |
| 4072 | buildPreCond(Scope *S, Expr *Cond, |
| 4073 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4074 | /// Build reference expression to the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4075 | DeclRefExpr * |
| 4076 | buildCounterVar(llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 4077 | DSAStackTy &DSA) const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4078 | /// Build reference expression to the private counter be used for |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4079 | /// codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4080 | Expr *buildPrivateCounterVar() const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4081 | /// Build initialization of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4082 | Expr *buildCounterInit() const; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4083 | /// Build step of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4084 | Expr *buildCounterStep() const; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4085 | /// Build loop data with counter value for depend clauses in ordered |
| 4086 | /// directives. |
| 4087 | Expr * |
| 4088 | buildOrderedLoopData(Scope *S, Expr *Counter, |
| 4089 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 4090 | SourceLocation Loc, Expr *Inc = nullptr, |
| 4091 | OverloadedOperatorKind OOK = OO_Amp); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4092 | /// Return true if any expression is dependent. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4093 | bool dependent() const; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4094 | |
| 4095 | private: |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4096 | /// Check the right-hand side of an assignment in the increment |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4097 | /// expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4098 | bool checkAndSetIncRHS(Expr *RHS); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4099 | /// Helper to set loop counter variable and its initializer. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4100 | bool setLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4101 | /// Helper to set upper bound. |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4102 | bool setUB(Expr *NewUB, llvm::Optional<bool> LessOp, bool StrictOp, |
| 4103 | SourceRange SR, SourceLocation SL); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4104 | /// Helper to set loop increment. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4105 | bool setStep(Expr *NewStep, bool Subtract); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4106 | }; |
| 4107 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4108 | bool OpenMPIterationSpaceChecker::dependent() const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4109 | if (!LCDecl) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4110 | assert(!LB && !UB && !Step); |
| 4111 | return false; |
| 4112 | } |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4113 | return LCDecl->getType()->isDependentType() || |
| 4114 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 4115 | (Step && Step->isValueDependent()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4116 | } |
| 4117 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4118 | bool OpenMPIterationSpaceChecker::setLCDeclAndLB(ValueDecl *NewLCDecl, |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4119 | Expr *NewLCRefExpr, |
| 4120 | Expr *NewLB) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4121 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4122 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
| Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4123 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4124 | if (!NewLCDecl || !NewLB) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4125 | return true; |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4126 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 4127 | LCRef = NewLCRefExpr; |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4128 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 4129 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 4130 | if ((Ctor->isCopyOrMoveConstructor() || |
| 4131 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 4132 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4133 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4134 | LB = NewLB; |
| 4135 | return false; |
| 4136 | } |
| 4137 | |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 4138 | bool OpenMPIterationSpaceChecker::setUB(Expr *NewUB, |
| 4139 | llvm::Optional<bool> LessOp, |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4140 | bool StrictOp, SourceRange SR, |
| 4141 | SourceLocation SL) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4142 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4143 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 4144 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4145 | if (!NewUB) |
| 4146 | return true; |
| 4147 | UB = NewUB; |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4148 | if (LessOp) |
| 4149 | TestIsLessOp = LessOp; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4150 | TestIsStrictOp = StrictOp; |
| 4151 | ConditionSrcRange = SR; |
| 4152 | ConditionLoc = SL; |
| 4153 | return false; |
| 4154 | } |
| 4155 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4156 | bool OpenMPIterationSpaceChecker::setStep(Expr *NewStep, bool Subtract) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4157 | // State consistency checking to ensure correct usage. |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4158 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4159 | if (!NewStep) |
| 4160 | return true; |
| 4161 | if (!NewStep->isValueDependent()) { |
| 4162 | // Check that the step is integer expression. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4163 | SourceLocation StepLoc = NewStep->getBeginLoc(); |
| Alexey Bataev | 5372fb8 | 2017-08-31 23:06:52 +0000 | [diff] [blame] | 4164 | ExprResult Val = SemaRef.PerformOpenMPImplicitIntegerConversion( |
| 4165 | StepLoc, getExprAsWritten(NewStep)); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4166 | if (Val.isInvalid()) |
| 4167 | return true; |
| 4168 | NewStep = Val.get(); |
| 4169 | |
| 4170 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 4171 | // If test-expr is of form var relational-op b and relational-op is < or |
| 4172 | // <= then incr-expr must cause var to increase on each iteration of the |
| 4173 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 4174 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 4175 | // the loop. |
| 4176 | // If test-expr is of form b relational-op var and relational-op is < or |
| 4177 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 4178 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 4179 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 4180 | // the loop. |
| 4181 | llvm::APSInt Result; |
| 4182 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4183 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 4184 | bool IsConstNeg = |
| 4185 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4186 | bool IsConstPos = |
| 4187 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4188 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4189 | |
| 4190 | // != with increment is treated as <; != with decrement is treated as > |
| 4191 | if (!TestIsLessOp.hasValue()) |
| 4192 | TestIsLessOp = IsConstPos || (IsUnsigned && !Subtract); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4193 | if (UB && (IsConstZero || |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 4194 | (TestIsLessOp.getValue() ? |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4195 | (IsConstNeg || (IsUnsigned && Subtract)) : |
| 4196 | (IsConstPos || (IsUnsigned && !Subtract))))) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4197 | SemaRef.Diag(NewStep->getExprLoc(), |
| 4198 | diag::err_omp_loop_incr_not_compatible) |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4199 | << LCDecl << TestIsLessOp.getValue() << NewStep->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4200 | SemaRef.Diag(ConditionLoc, |
| 4201 | diag::note_omp_loop_cond_requres_compatible_incr) |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4202 | << TestIsLessOp.getValue() << ConditionSrcRange; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4203 | return true; |
| 4204 | } |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4205 | if (TestIsLessOp.getValue() == Subtract) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4206 | NewStep = |
| 4207 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 4208 | .get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4209 | Subtract = !Subtract; |
| 4210 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
| 4213 | Step = NewStep; |
| 4214 | SubtractStep = Subtract; |
| 4215 | return false; |
| 4216 | } |
| 4217 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4218 | bool OpenMPIterationSpaceChecker::checkAndSetInit(Stmt *S, bool EmitDiags) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4219 | // Check init-expr for canonical loop form and save loop counter |
| 4220 | // variable - #Var and its initialization value - #LB. |
| 4221 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 4222 | // var = lb |
| 4223 | // integer-type var = lb |
| 4224 | // random-access-iterator-type var = lb |
| 4225 | // pointer-type var = lb |
| 4226 | // |
| 4227 | if (!S) { |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4228 | if (EmitDiags) { |
| 4229 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 4230 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4231 | return true; |
| 4232 | } |
| Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4233 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4234 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4235 | S = ExprTemp->getSubExpr(); |
| 4236 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4237 | InitSrcRange = S->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4238 | if (Expr *E = dyn_cast<Expr>(S)) |
| 4239 | S = E->IgnoreParens(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4240 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4241 | if (BO->getOpcode() == BO_Assign) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4242 | Expr *LHS = BO->getLHS()->IgnoreParens(); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4243 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 4244 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 4245 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4246 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4247 | return setLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4248 | } |
| 4249 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 4250 | if (ME->isArrow() && |
| 4251 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4252 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4253 | } |
| 4254 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4255 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4256 | if (DS->isSingleDecl()) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4257 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4258 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4259 | // Accept non-canonical init form here but emit ext. warning. |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4260 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4261 | SemaRef.Diag(S->getBeginLoc(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4262 | diag::ext_omp_loop_not_canonical_init) |
| 4263 | << S->getSourceRange(); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4264 | return setLCDeclAndLB( |
| 4265 | Var, |
| 4266 | buildDeclRefExpr(SemaRef, Var, |
| 4267 | Var->getType().getNonReferenceType(), |
| 4268 | DS->getBeginLoc()), |
| 4269 | Var->getInit()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4270 | } |
| 4271 | } |
| 4272 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4273 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4274 | if (CE->getOperator() == OO_Equal) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4275 | Expr *LHS = CE->getArg(0); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4276 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4277 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 4278 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4279 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4280 | return setLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4281 | } |
| 4282 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 4283 | if (ME->isArrow() && |
| 4284 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4285 | return setLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4286 | } |
| 4287 | } |
| 4288 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4289 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4290 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4291 | return false; |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4292 | if (EmitDiags) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4293 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_loop_not_canonical_init) |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4294 | << S->getSourceRange(); |
| 4295 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4296 | return true; |
| 4297 | } |
| 4298 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4299 | /// Ignore parenthesizes, implicit casts, copy constructor and return the |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4300 | /// variable (which may be the loop variable) if possible. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4301 | static const ValueDecl *getInitLCDecl(const Expr *E) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4302 | if (!E) |
| Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 4303 | return nullptr; |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4304 | E = getExprAsWritten(E); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4305 | if (const auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4306 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 4307 | if ((Ctor->isCopyOrMoveConstructor() || |
| 4308 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 4309 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4310 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4311 | if (const auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 4312 | if (const auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4313 | return getCanonicalDecl(VD); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4314 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4315 | if (const auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4316 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4317 | return getCanonicalDecl(ME->getMemberDecl()); |
| 4318 | return nullptr; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4319 | } |
| 4320 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4321 | bool OpenMPIterationSpaceChecker::checkAndSetCond(Expr *S) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4322 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 4323 | // less/greater and for strict/non-strict comparison. |
| 4324 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4325 | // var relational-op b |
| 4326 | // b relational-op var |
| 4327 | // |
| 4328 | if (!S) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4329 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4330 | return true; |
| 4331 | } |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4332 | S = getExprAsWritten(S); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4333 | SourceLocation CondLoc = S->getBeginLoc(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4334 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4335 | if (BO->isRelationalOp()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4336 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 4337 | return setUB(BO->getRHS(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4338 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 4339 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4340 | BO->getSourceRange(), BO->getOperatorLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4341 | if (getInitLCDecl(BO->getRHS()) == LCDecl) |
| 4342 | return setUB(BO->getLHS(), |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4343 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 4344 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4345 | BO->getSourceRange(), BO->getOperatorLoc()); |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4346 | } else if (BO->getOpcode() == BO_NE) |
| 4347 | return setUB(getInitLCDecl(BO->getLHS()) == LCDecl ? |
| 4348 | BO->getRHS() : BO->getLHS(), |
| 4349 | /*LessOp=*/llvm::None, |
| 4350 | /*StrictOp=*/true, |
| 4351 | BO->getSourceRange(), BO->getOperatorLoc()); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4352 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4353 | if (CE->getNumArgs() == 2) { |
| 4354 | auto Op = CE->getOperator(); |
| 4355 | switch (Op) { |
| 4356 | case OO_Greater: |
| 4357 | case OO_GreaterEqual: |
| 4358 | case OO_Less: |
| 4359 | case OO_LessEqual: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4360 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4361 | return setUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4362 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4363 | CE->getOperatorLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4364 | if (getInitLCDecl(CE->getArg(1)) == LCDecl) |
| 4365 | return setUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4366 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4367 | CE->getOperatorLoc()); |
| 4368 | break; |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 4369 | case OO_ExclaimEqual: |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4370 | return setUB(getInitLCDecl(CE->getArg(0)) == LCDecl ? |
| 4371 | CE->getArg(1) : CE->getArg(0), |
| 4372 | /*LessOp=*/llvm::None, |
| 4373 | /*StrictOp=*/true, |
| 4374 | CE->getSourceRange(), |
| 4375 | CE->getOperatorLoc()); |
| 4376 | break; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4377 | default: |
| 4378 | break; |
| 4379 | } |
| 4380 | } |
| 4381 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4382 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4383 | return false; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4384 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4385 | << S->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4386 | return true; |
| 4387 | } |
| 4388 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4389 | bool OpenMPIterationSpaceChecker::checkAndSetIncRHS(Expr *RHS) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4390 | // RHS of canonical loop form increment can be: |
| 4391 | // var + incr |
| 4392 | // incr + var |
| 4393 | // var - incr |
| 4394 | // |
| 4395 | RHS = RHS->IgnoreParenImpCasts(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4396 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4397 | if (BO->isAdditiveOp()) { |
| 4398 | bool IsAdd = BO->getOpcode() == BO_Add; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4399 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 4400 | return setStep(BO->getRHS(), !IsAdd); |
| 4401 | if (IsAdd && getInitLCDecl(BO->getRHS()) == LCDecl) |
| 4402 | return setStep(BO->getLHS(), /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4403 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4404 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4405 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 4406 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4407 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4408 | return setStep(CE->getArg(1), !IsAdd); |
| 4409 | if (IsAdd && getInitLCDecl(CE->getArg(1)) == LCDecl) |
| 4410 | return setStep(CE->getArg(0), /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4411 | } |
| 4412 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4413 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4414 | return false; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4415 | SemaRef.Diag(RHS->getBeginLoc(), diag::err_omp_loop_not_canonical_incr) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4416 | << RHS->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4417 | return true; |
| 4418 | } |
| 4419 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4420 | bool OpenMPIterationSpaceChecker::checkAndSetInc(Expr *S) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4421 | // Check incr-expr for canonical loop form and return true if it |
| 4422 | // does not conform. |
| 4423 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4424 | // ++var |
| 4425 | // var++ |
| 4426 | // --var |
| 4427 | // var-- |
| 4428 | // var += incr |
| 4429 | // var -= incr |
| 4430 | // var = var + incr |
| 4431 | // var = incr + var |
| 4432 | // var = var - incr |
| 4433 | // |
| 4434 | if (!S) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4435 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4436 | return true; |
| 4437 | } |
| Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4438 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4439 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4440 | S = ExprTemp->getSubExpr(); |
| 4441 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4442 | IncrementSrcRange = S->getSourceRange(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4443 | S = S->IgnoreParens(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4444 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4445 | if (UO->isIncrementDecrementOp() && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4446 | getInitLCDecl(UO->getSubExpr()) == LCDecl) |
| 4447 | return setStep(SemaRef |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4448 | .ActOnIntegerConstant(UO->getBeginLoc(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4449 | (UO->isDecrementOp() ? -1 : 1)) |
| 4450 | .get(), |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4451 | /*Subtract=*/false); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4452 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4453 | switch (BO->getOpcode()) { |
| 4454 | case BO_AddAssign: |
| 4455 | case BO_SubAssign: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4456 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 4457 | return setStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4458 | break; |
| 4459 | case BO_Assign: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4460 | if (getInitLCDecl(BO->getLHS()) == LCDecl) |
| 4461 | return checkAndSetIncRHS(BO->getRHS()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4462 | break; |
| 4463 | default: |
| 4464 | break; |
| 4465 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4466 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4467 | switch (CE->getOperator()) { |
| 4468 | case OO_PlusPlus: |
| 4469 | case OO_MinusMinus: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4470 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4471 | return setStep(SemaRef |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4472 | .ActOnIntegerConstant( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4473 | CE->getBeginLoc(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4474 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 4475 | .get(), |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4476 | /*Subtract=*/false); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4477 | break; |
| 4478 | case OO_PlusEqual: |
| 4479 | case OO_MinusEqual: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4480 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4481 | return setStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4482 | break; |
| 4483 | case OO_Equal: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4484 | if (getInitLCDecl(CE->getArg(0)) == LCDecl) |
| 4485 | return checkAndSetIncRHS(CE->getArg(1)); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4486 | break; |
| 4487 | default: |
| 4488 | break; |
| 4489 | } |
| 4490 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4491 | if (dependent() || SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4492 | return false; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4493 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_loop_not_canonical_incr) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4494 | << S->getSourceRange() << LCDecl; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4495 | return true; |
| 4496 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4497 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4498 | static ExprResult |
| 4499 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4500 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 4501 | if (SemaRef.CurContext->isDependentContext()) |
| 4502 | return ExprResult(Capture); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4503 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 4504 | return SemaRef.PerformImplicitConversion( |
| 4505 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 4506 | /*AllowExplicit=*/true); |
| 4507 | auto I = Captures.find(Capture); |
| 4508 | if (I != Captures.end()) |
| 4509 | return buildCapture(SemaRef, Capture, I->second); |
| 4510 | DeclRefExpr *Ref = nullptr; |
| 4511 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 4512 | Captures[Capture] = Ref; |
| 4513 | return Res; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4516 | /// Build the expression to calculate the number of iterations. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4517 | Expr *OpenMPIterationSpaceChecker::buildNumIterations( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4518 | Scope *S, const bool LimitedType, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4519 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4520 | ExprResult Diff; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4521 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4522 | if (VarType->isIntegerType() || VarType->isPointerType() || |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4523 | SemaRef.getLangOpts().CPlusPlus) { |
| 4524 | // Upper - Lower |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4525 | Expr *UBExpr = TestIsLessOp.getValue() ? UB : LB; |
| 4526 | Expr *LBExpr = TestIsLessOp.getValue() ? LB : UB; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4527 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 4528 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4529 | if (!Upper || !Lower) |
| 4530 | return nullptr; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4531 | |
| 4532 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 4533 | |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4534 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4535 | // BuildBinOp already emitted error, this one is to point user to upper |
| 4536 | // and lower bound, and to tell what is passed to 'operator-'. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4537 | SemaRef.Diag(Upper->getBeginLoc(), diag::err_omp_loop_diff_cxx) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4538 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 4539 | return nullptr; |
| 4540 | } |
| 4541 | } |
| 4542 | |
| 4543 | if (!Diff.isUsable()) |
| 4544 | return nullptr; |
| 4545 | |
| 4546 | // Upper - Lower [- 1] |
| 4547 | if (TestIsStrictOp) |
| 4548 | Diff = SemaRef.BuildBinOp( |
| 4549 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 4550 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4551 | if (!Diff.isUsable()) |
| 4552 | return nullptr; |
| 4553 | |
| 4554 | // Upper - Lower [- 1] + Step |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4555 | ExprResult NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4556 | if (!NewStep.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4557 | return nullptr; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4558 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4559 | if (!Diff.isUsable()) |
| 4560 | return nullptr; |
| 4561 | |
| 4562 | // Parentheses (for dumping/debugging purposes only). |
| 4563 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 4564 | if (!Diff.isUsable()) |
| 4565 | return nullptr; |
| 4566 | |
| 4567 | // (Upper - Lower [- 1] + Step) / Step |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4568 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4569 | if (!Diff.isUsable()) |
| 4570 | return nullptr; |
| 4571 | |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4572 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4573 | QualType Type = Diff.get()->getType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4574 | ASTContext &C = SemaRef.Context; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4575 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 4576 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 4577 | if (!Type->isIntegerType() || UseVarType) { |
| 4578 | unsigned NewSize = |
| 4579 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 4580 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 4581 | : Type->hasSignedIntegerRepresentation(); |
| 4582 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4583 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 4584 | Diff = SemaRef.PerformImplicitConversion( |
| 4585 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 4586 | if (!Diff.isUsable()) |
| 4587 | return nullptr; |
| 4588 | } |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4589 | } |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4590 | if (LimitedType) { |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4591 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 4592 | if (NewSize != C.getTypeSize(Type)) { |
| 4593 | if (NewSize < C.getTypeSize(Type)) { |
| 4594 | assert(NewSize == 64 && "incorrect loop var size"); |
| 4595 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 4596 | << InitSrcRange << ConditionSrcRange; |
| 4597 | } |
| 4598 | QualType NewType = C.getIntTypeForBitwidth( |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4599 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 4600 | C.getTypeSize(Type) < NewSize); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4601 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 4602 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 4603 | Sema::AA_Converting, true); |
| 4604 | if (!Diff.isUsable()) |
| 4605 | return nullptr; |
| 4606 | } |
| Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4607 | } |
| 4608 | } |
| 4609 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4610 | return Diff.get(); |
| 4611 | } |
| 4612 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4613 | Expr *OpenMPIterationSpaceChecker::buildPreCond( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4614 | Scope *S, Expr *Cond, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4615 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) const { |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4616 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 4617 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4618 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4619 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4620 | ExprResult NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 4621 | ExprResult NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4622 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 4623 | return nullptr; |
| 4624 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4625 | ExprResult CondExpr = |
| 4626 | SemaRef.BuildBinOp(S, DefaultLoc, |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 4627 | TestIsLessOp.getValue() ? |
| Kelvin Li | efbe4af | 2018-11-21 19:10:48 +0000 | [diff] [blame] | 4628 | (TestIsStrictOp ? BO_LT : BO_LE) : |
| 4629 | (TestIsStrictOp ? BO_GT : BO_GE), |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4630 | NewLB.get(), NewUB.get()); |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4631 | if (CondExpr.isUsable()) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4632 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 4633 | SemaRef.Context.BoolTy)) |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4634 | CondExpr = SemaRef.PerformImplicitConversion( |
| 4635 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 4636 | /*AllowExplicit=*/true); |
| Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4637 | } |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4638 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| Sergi Mateo Bellido | f3e00fe | 2019-02-01 08:39:01 +0000 | [diff] [blame] | 4639 | // Otherwise use original loop condition and evaluate it in runtime. |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4640 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 4641 | } |
| 4642 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4643 | /// Build reference expression to the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4644 | DeclRefExpr *OpenMPIterationSpaceChecker::buildCounterVar( |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4645 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, |
| 4646 | DSAStackTy &DSA) const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4647 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 4648 | if (!VD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4649 | VD = SemaRef.isOpenMPCapturedDecl(LCDecl); |
| 4650 | DeclRefExpr *Ref = buildDeclRefExpr( |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4651 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4652 | const DSAStackTy::DSAVarData Data = |
| 4653 | DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4654 | // If the loop control decl is explicitly marked as private, do not mark it |
| 4655 | // as captured again. |
| 4656 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 4657 | Captures.insert(std::make_pair(LCRef, Ref)); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4658 | return Ref; |
| 4659 | } |
| 4660 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4661 | DefaultLoc); |
| 4662 | } |
| 4663 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4664 | Expr *OpenMPIterationSpaceChecker::buildPrivateCounterVar() const { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4665 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4666 | QualType Type = LCDecl->getType().getNonReferenceType(); |
| 4667 | VarDecl *PrivateVar = buildVarDecl( |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 4668 | SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 4669 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr, |
| 4670 | isa<VarDecl>(LCDecl) |
| 4671 | ? buildDeclRefExpr(SemaRef, cast<VarDecl>(LCDecl), Type, DefaultLoc) |
| 4672 | : nullptr); |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4673 | if (PrivateVar->isInvalidDecl()) |
| 4674 | return nullptr; |
| 4675 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 4676 | } |
| 4677 | return nullptr; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4678 | } |
| 4679 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4680 | /// Build initialization of the counter to be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4681 | Expr *OpenMPIterationSpaceChecker::buildCounterInit() const { return LB; } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4682 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4683 | /// Build step of the counter be used for codegen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4684 | Expr *OpenMPIterationSpaceChecker::buildCounterStep() const { return Step; } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4685 | |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4686 | Expr *OpenMPIterationSpaceChecker::buildOrderedLoopData( |
| 4687 | Scope *S, Expr *Counter, |
| 4688 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures, SourceLocation Loc, |
| 4689 | Expr *Inc, OverloadedOperatorKind OOK) { |
| 4690 | Expr *Cnt = SemaRef.DefaultLvalueConversion(Counter).get(); |
| 4691 | if (!Cnt) |
| 4692 | return nullptr; |
| 4693 | if (Inc) { |
| 4694 | assert((OOK == OO_Plus || OOK == OO_Minus) && |
| 4695 | "Expected only + or - operations for depend clauses."); |
| 4696 | BinaryOperatorKind BOK = (OOK == OO_Plus) ? BO_Add : BO_Sub; |
| 4697 | Cnt = SemaRef.BuildBinOp(S, Loc, BOK, Cnt, Inc).get(); |
| 4698 | if (!Cnt) |
| 4699 | return nullptr; |
| 4700 | } |
| 4701 | ExprResult Diff; |
| 4702 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| 4703 | if (VarType->isIntegerType() || VarType->isPointerType() || |
| 4704 | SemaRef.getLangOpts().CPlusPlus) { |
| 4705 | // Upper - Lower |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 4706 | Expr *Upper = TestIsLessOp.getValue() |
| 4707 | ? Cnt |
| 4708 | : tryBuildCapture(SemaRef, UB, Captures).get(); |
| 4709 | Expr *Lower = TestIsLessOp.getValue() |
| 4710 | ? tryBuildCapture(SemaRef, LB, Captures).get() |
| 4711 | : Cnt; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4712 | if (!Upper || !Lower) |
| 4713 | return nullptr; |
| 4714 | |
| 4715 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 4716 | |
| 4717 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
| 4718 | // BuildBinOp already emitted error, this one is to point user to upper |
| 4719 | // and lower bound, and to tell what is passed to 'operator-'. |
| 4720 | SemaRef.Diag(Upper->getBeginLoc(), diag::err_omp_loop_diff_cxx) |
| 4721 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 4722 | return nullptr; |
| 4723 | } |
| 4724 | } |
| 4725 | |
| 4726 | if (!Diff.isUsable()) |
| 4727 | return nullptr; |
| 4728 | |
| 4729 | // Parentheses (for dumping/debugging purposes only). |
| 4730 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 4731 | if (!Diff.isUsable()) |
| 4732 | return nullptr; |
| 4733 | |
| 4734 | ExprResult NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 4735 | if (!NewStep.isUsable()) |
| 4736 | return nullptr; |
| 4737 | // (Upper - Lower) / Step |
| 4738 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
| 4739 | if (!Diff.isUsable()) |
| 4740 | return nullptr; |
| 4741 | |
| 4742 | return Diff.get(); |
| 4743 | } |
| 4744 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4745 | /// Iteration space of a single for loop. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4746 | struct LoopIterationSpace final { |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 4747 | /// True if the condition operator is the strict compare operator (<, > or |
| 4748 | /// !=). |
| 4749 | bool IsStrictCompare = false; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4750 | /// Condition of the loop. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4751 | Expr *PreCond = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4752 | /// This expression calculates the number of iterations in the loop. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4753 | /// It is always possible to calculate it before starting the loop. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4754 | Expr *NumIterations = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4755 | /// The loop counter variable. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4756 | Expr *CounterVar = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4757 | /// Private loop counter variable. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4758 | Expr *PrivateCounterVar = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4759 | /// This is initializer for the initial value of #CounterVar. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4760 | Expr *CounterInit = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4761 | /// This is step for the #CounterVar used to generate its update: |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4762 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4763 | Expr *CounterStep = nullptr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4764 | /// Should step be subtracted? |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4765 | bool Subtract = false; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4766 | /// Source range of the loop init. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4767 | SourceRange InitSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4768 | /// Source range of the loop condition. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4769 | SourceRange CondSrcRange; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4770 | /// Source range of the loop increment. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4771 | SourceRange IncSrcRange; |
| 4772 | }; |
| 4773 | |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4774 | } // namespace |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4775 | |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4776 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 4777 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 4778 | assert(Init && "Expected loop in canonical form."); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4779 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 4780 | if (AssociatedLoops > 0 && |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4781 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| Alexey Bataev | ce90181 | 2018-12-19 18:16:37 +0000 | [diff] [blame] | 4782 | DSAStack->loopStart(); |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4783 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4784 | if (!ISC.checkAndSetInit(Init, /*EmitDiags=*/false)) { |
| 4785 | if (ValueDecl *D = ISC.getLoopDecl()) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4786 | auto *VD = dyn_cast<VarDecl>(D); |
| 4787 | if (!VD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4788 | if (VarDecl *Private = isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4789 | VD = Private; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4790 | } else { |
| 4791 | DeclRefExpr *Ref = buildCapture(*this, D, ISC.getLoopDeclRefExpr(), |
| 4792 | /*WithInit=*/false); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4793 | VD = cast<VarDecl>(Ref->getDecl()); |
| 4794 | } |
| 4795 | } |
| 4796 | DSAStack->addLoopControlVariable(D, VD); |
| Alexey Bataev | 6ab5bb1 | 2018-10-29 15:01:58 +0000 | [diff] [blame] | 4797 | const Decl *LD = DSAStack->getPossiblyLoopCunter(); |
| 4798 | if (LD != D->getCanonicalDecl()) { |
| 4799 | DSAStack->resetPossibleLoopCounter(); |
| 4800 | if (auto *Var = dyn_cast_or_null<VarDecl>(LD)) |
| 4801 | MarkDeclarationsReferencedInExpr( |
| 4802 | buildDeclRefExpr(*this, const_cast<VarDecl *>(Var), |
| 4803 | Var->getType().getNonLValueExprType(Context), |
| 4804 | ForLoc, /*RefersToCapture=*/true)); |
| 4805 | } |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4806 | } |
| 4807 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4808 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
| Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4809 | } |
| 4810 | } |
| 4811 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4812 | /// Called on a for stmt to check and extract its iteration space |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4813 | /// for further processing (such as collapsing). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4814 | static bool checkOpenMPIterationSpace( |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4815 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 4816 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4817 | unsigned TotalNestedLoopCount, Expr *CollapseLoopCountExpr, |
| 4818 | Expr *OrderedLoopCountExpr, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4819 | Sema::VarsWithInheritedDSAType &VarsWithImplicitDSA, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4820 | LoopIterationSpace &ResultIterSpace, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4821 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4822 | // OpenMP [2.6, Canonical Loop Form] |
| 4823 | // for (init-expr; test-expr; incr-expr) structured-block |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4824 | auto *For = dyn_cast_or_null<ForStmt>(S); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4825 | if (!For) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4826 | SemaRef.Diag(S->getBeginLoc(), diag::err_omp_not_for) |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4827 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4828 | << getOpenMPDirectiveName(DKind) << TotalNestedLoopCount |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4829 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4830 | if (TotalNestedLoopCount > 1) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4831 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 4832 | SemaRef.Diag(DSA.getConstructLoc(), |
| 4833 | diag::note_omp_collapse_ordered_expr) |
| 4834 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 4835 | << OrderedLoopCountExpr->getSourceRange(); |
| 4836 | else if (CollapseLoopCountExpr) |
| 4837 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4838 | diag::note_omp_collapse_ordered_expr) |
| 4839 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 4840 | else |
| 4841 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4842 | diag::note_omp_collapse_ordered_expr) |
| 4843 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 4844 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4845 | return true; |
| 4846 | } |
| 4847 | assert(For->getBody()); |
| 4848 | |
| 4849 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 4850 | |
| 4851 | // Check init. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4852 | Stmt *Init = For->getInit(); |
| 4853 | if (ISC.checkAndSetInit(Init)) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4854 | return true; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4855 | |
| 4856 | bool HasErrors = false; |
| 4857 | |
| 4858 | // Check loop variable's type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4859 | if (ValueDecl *LCDecl = ISC.getLoopDecl()) { |
| 4860 | Expr *LoopDeclRefExpr = ISC.getLoopDeclRefExpr(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4861 | |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4862 | // OpenMP [2.6, Canonical Loop Form] |
| 4863 | // Var is one of the following: |
| 4864 | // A variable of signed or unsigned integer type. |
| 4865 | // For C++, a variable of a random access iterator type. |
| 4866 | // For C, a variable of a pointer type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4867 | QualType VarType = LCDecl->getType().getNonReferenceType(); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4868 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 4869 | !VarType->isPointerType() && |
| 4870 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4871 | SemaRef.Diag(Init->getBeginLoc(), diag::err_omp_loop_variable_type) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4872 | << SemaRef.getLangOpts().CPlusPlus; |
| 4873 | HasErrors = true; |
| 4874 | } |
| 4875 | |
| 4876 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 4877 | // a Construct |
| 4878 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4879 | // parallel for construct is (are) private. |
| 4880 | // The loop iteration variable in the associated for-loop of a simd |
| 4881 | // construct with just one associated for-loop is linear with a |
| 4882 | // constant-linear-step that is the increment of the associated for-loop. |
| 4883 | // Exclude loop var from the list of variables with implicitly defined data |
| 4884 | // sharing attributes. |
| 4885 | VarsWithImplicitDSA.erase(LCDecl); |
| 4886 | |
| 4887 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4888 | // in a Construct, C/C++]. |
| 4889 | // The loop iteration variable in the associated for-loop of a simd |
| 4890 | // construct with just one associated for-loop may be listed in a linear |
| 4891 | // clause with a constant-linear-step that is the increment of the |
| 4892 | // associated for-loop. |
| 4893 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4894 | // parallel for construct may be listed in a private or lastprivate clause. |
| 4895 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 4896 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 4897 | // declared in the loop and it is predetermined as a private. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4898 | OpenMPClauseKind PredeterminedCKind = |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4899 | isOpenMPSimdDirective(DKind) |
| 4900 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 4901 | : OMPC_private; |
| 4902 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4903 | DVar.CKind != PredeterminedCKind) || |
| 4904 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 4905 | isOpenMPDistributeDirective(DKind)) && |
| 4906 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4907 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 4908 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 4909 | SemaRef.Diag(Init->getBeginLoc(), diag::err_omp_loop_var_dsa) |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4910 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4911 | << getOpenMPClauseName(PredeterminedCKind); |
| 4912 | if (DVar.RefExpr == nullptr) |
| 4913 | DVar.CKind = PredeterminedCKind; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4914 | reportOriginalDsa(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4915 | HasErrors = true; |
| 4916 | } else if (LoopDeclRefExpr != nullptr) { |
| 4917 | // Make the loop iteration variable private (for worksharing constructs), |
| 4918 | // linear (for simd directives with the only one associated loop) or |
| 4919 | // lastprivate (for simd directives with several collapsed or ordered |
| 4920 | // loops). |
| 4921 | if (DVar.CKind == OMPC_unknown) |
| Alexey Bataev | c2cdff6 | 2019-01-29 21:12:28 +0000 | [diff] [blame] | 4922 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4923 | } |
| 4924 | |
| 4925 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 4926 | |
| 4927 | // Check test-expr. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4928 | HasErrors |= ISC.checkAndSetCond(For->getCond()); |
| Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4929 | |
| 4930 | // Check incr-expr. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4931 | HasErrors |= ISC.checkAndSetInc(For->getInc()); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4932 | } |
| 4933 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4934 | if (ISC.dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4935 | return HasErrors; |
| 4936 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4937 | // Build the loop's iteration space representation. |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4938 | ResultIterSpace.PreCond = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4939 | ISC.buildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
| 4940 | ResultIterSpace.NumIterations = ISC.buildNumIterations( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4941 | DSA.getCurScope(), |
| 4942 | (isOpenMPWorksharingDirective(DKind) || |
| 4943 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 4944 | Captures); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 4945 | ResultIterSpace.CounterVar = ISC.buildCounterVar(Captures, DSA); |
| 4946 | ResultIterSpace.PrivateCounterVar = ISC.buildPrivateCounterVar(); |
| 4947 | ResultIterSpace.CounterInit = ISC.buildCounterInit(); |
| 4948 | ResultIterSpace.CounterStep = ISC.buildCounterStep(); |
| 4949 | ResultIterSpace.InitSrcRange = ISC.getInitSrcRange(); |
| 4950 | ResultIterSpace.CondSrcRange = ISC.getConditionSrcRange(); |
| 4951 | ResultIterSpace.IncSrcRange = ISC.getIncrementSrcRange(); |
| 4952 | ResultIterSpace.Subtract = ISC.shouldSubtractStep(); |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 4953 | ResultIterSpace.IsStrictCompare = ISC.isStrictTestOp(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4954 | |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4955 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4956 | ResultIterSpace.NumIterations == nullptr || |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4957 | ResultIterSpace.CounterVar == nullptr || |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4958 | ResultIterSpace.PrivateCounterVar == nullptr || |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4959 | ResultIterSpace.CounterInit == nullptr || |
| 4960 | ResultIterSpace.CounterStep == nullptr); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 4961 | if (!HasErrors && DSA.isOrderedRegion()) { |
| 4962 | if (DSA.getOrderedRegionParam().second->getNumForLoops()) { |
| 4963 | if (CurrentNestedLoopCount < |
| 4964 | DSA.getOrderedRegionParam().second->getLoopNumIterations().size()) { |
| 4965 | DSA.getOrderedRegionParam().second->setLoopNumIterations( |
| 4966 | CurrentNestedLoopCount, ResultIterSpace.NumIterations); |
| 4967 | DSA.getOrderedRegionParam().second->setLoopCounter( |
| 4968 | CurrentNestedLoopCount, ResultIterSpace.CounterVar); |
| 4969 | } |
| 4970 | } |
| 4971 | for (auto &Pair : DSA.getDoacrossDependClauses()) { |
| 4972 | if (CurrentNestedLoopCount >= Pair.first->getNumLoops()) { |
| 4973 | // Erroneous case - clause has some problems. |
| 4974 | continue; |
| 4975 | } |
| 4976 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_sink && |
| 4977 | Pair.second.size() <= CurrentNestedLoopCount) { |
| 4978 | // Erroneous case - clause has some problems. |
| 4979 | Pair.first->setLoopData(CurrentNestedLoopCount, nullptr); |
| 4980 | continue; |
| 4981 | } |
| 4982 | Expr *CntValue; |
| 4983 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 4984 | CntValue = ISC.buildOrderedLoopData( |
| 4985 | DSA.getCurScope(), ResultIterSpace.CounterVar, Captures, |
| 4986 | Pair.first->getDependencyLoc()); |
| 4987 | else |
| 4988 | CntValue = ISC.buildOrderedLoopData( |
| 4989 | DSA.getCurScope(), ResultIterSpace.CounterVar, Captures, |
| 4990 | Pair.first->getDependencyLoc(), |
| 4991 | Pair.second[CurrentNestedLoopCount].first, |
| 4992 | Pair.second[CurrentNestedLoopCount].second); |
| 4993 | Pair.first->setLoopData(CurrentNestedLoopCount, CntValue); |
| 4994 | } |
| 4995 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4996 | |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4997 | return HasErrors; |
| 4998 | } |
| 4999 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5000 | /// Build 'VarRef = Start. |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5001 | static ExprResult |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5002 | buildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5003 | ExprResult Start, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5004 | llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5005 | // Build 'VarRef = Start. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5006 | ExprResult NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5007 | if (!NewStart.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5008 | return ExprError(); |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 5009 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 5010 | VarRef.get()->getType())) { |
| 5011 | NewStart = SemaRef.PerformImplicitConversion( |
| 5012 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 5013 | /*AllowExplicit=*/true); |
| 5014 | if (!NewStart.isUsable()) |
| 5015 | return ExprError(); |
| 5016 | } |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5017 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5018 | ExprResult Init = |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5019 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 5020 | return Init; |
| 5021 | } |
| 5022 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5023 | /// Build 'VarRef = Start + Iter * Step'. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5024 | static ExprResult buildCounterUpdate( |
| 5025 | Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 5026 | ExprResult Start, ExprResult Iter, ExprResult Step, bool Subtract, |
| 5027 | llvm::MapVector<const Expr *, DeclRefExpr *> *Captures = nullptr) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5028 | // Add parentheses (for debugging purposes only). |
| 5029 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 5030 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 5031 | !Step.isUsable()) |
| 5032 | return ExprError(); |
| 5033 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5034 | ExprResult NewStep = Step; |
| 5035 | if (Captures) |
| 5036 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5037 | if (NewStep.isInvalid()) |
| 5038 | return ExprError(); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5039 | ExprResult Update = |
| 5040 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5041 | if (!Update.isUsable()) |
| 5042 | return ExprError(); |
| 5043 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 5044 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 5045 | // 'VarRef = Start (+|-) Iter * Step'. |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5046 | ExprResult NewStart = Start; |
| 5047 | if (Captures) |
| 5048 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5049 | if (NewStart.isInvalid()) |
| 5050 | return ExprError(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5051 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 5052 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 5053 | ExprResult SavedUpdate = Update; |
| 5054 | ExprResult UpdateVal; |
| 5055 | if (VarRef.get()->getType()->isOverloadableType() || |
| 5056 | NewStart.get()->getType()->isOverloadableType() || |
| 5057 | Update.get()->getType()->isOverloadableType()) { |
| 5058 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 5059 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 5060 | Update = |
| 5061 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 5062 | if (Update.isUsable()) { |
| 5063 | UpdateVal = |
| 5064 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 5065 | VarRef.get(), SavedUpdate.get()); |
| 5066 | if (UpdateVal.isUsable()) { |
| 5067 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 5068 | UpdateVal.get()); |
| 5069 | } |
| 5070 | } |
| 5071 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 5072 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5073 | |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 5074 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 5075 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 5076 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 5077 | NewStart.get(), SavedUpdate.get()); |
| 5078 | if (!Update.isUsable()) |
| 5079 | return ExprError(); |
| 5080 | |
| Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 5081 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 5082 | VarRef.get()->getType())) { |
| 5083 | Update = SemaRef.PerformImplicitConversion( |
| 5084 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 5085 | if (!Update.isUsable()) |
| 5086 | return ExprError(); |
| 5087 | } |
| Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 5088 | |
| 5089 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 5090 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5091 | return Update; |
| 5092 | } |
| 5093 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5094 | /// Convert integer expression \a E to make it have at least \a Bits |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5095 | /// bits. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5096 | static ExprResult widenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5097 | if (E == nullptr) |
| 5098 | return ExprError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5099 | ASTContext &C = SemaRef.Context; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5100 | QualType OldType = E->getType(); |
| 5101 | unsigned HasBits = C.getTypeSize(OldType); |
| 5102 | if (HasBits >= Bits) |
| 5103 | return ExprResult(E); |
| 5104 | // OK to convert to signed, because new type has more bits than old. |
| 5105 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 5106 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 5107 | true); |
| 5108 | } |
| 5109 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5110 | /// Check if the given expression \a E is a constant integer that fits |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5111 | /// into \a Bits bits. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5112 | static bool fitsInto(unsigned Bits, bool Signed, const Expr *E, Sema &SemaRef) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5113 | if (E == nullptr) |
| 5114 | return false; |
| 5115 | llvm::APSInt Result; |
| 5116 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 5117 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 5118 | return false; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5119 | } |
| 5120 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5121 | /// Build preinits statement for the given declarations. |
| 5122 | static Stmt *buildPreInits(ASTContext &Context, |
| Alexey Bataev | c551406 | 2017-10-25 15:44:52 +0000 | [diff] [blame] | 5123 | MutableArrayRef<Decl *> PreInits) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5124 | if (!PreInits.empty()) { |
| 5125 | return new (Context) DeclStmt( |
| 5126 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 5127 | SourceLocation(), SourceLocation()); |
| 5128 | } |
| 5129 | return nullptr; |
| 5130 | } |
| 5131 | |
| 5132 | /// Build preinits statement for the given declarations. |
| Alexey Bataev | c551406 | 2017-10-25 15:44:52 +0000 | [diff] [blame] | 5133 | static Stmt * |
| 5134 | buildPreInits(ASTContext &Context, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5135 | const llvm::MapVector<const Expr *, DeclRefExpr *> &Captures) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5136 | if (!Captures.empty()) { |
| 5137 | SmallVector<Decl *, 16> PreInits; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5138 | for (const auto &Pair : Captures) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5139 | PreInits.push_back(Pair.second->getDecl()); |
| 5140 | return buildPreInits(Context, PreInits); |
| 5141 | } |
| 5142 | return nullptr; |
| 5143 | } |
| 5144 | |
| 5145 | /// Build postupdate expression for the given list of postupdates expressions. |
| 5146 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 5147 | Expr *PostUpdate = nullptr; |
| 5148 | if (!PostUpdates.empty()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5149 | for (Expr *E : PostUpdates) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5150 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 5151 | E->getExprLoc(), |
| 5152 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 5153 | E->getExprLoc(), E) |
| 5154 | .get(); |
| 5155 | PostUpdate = PostUpdate |
| 5156 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 5157 | PostUpdate, ConvE) |
| 5158 | .get() |
| 5159 | : ConvE; |
| 5160 | } |
| 5161 | } |
| 5162 | return PostUpdate; |
| 5163 | } |
| 5164 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5165 | /// 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] | 5166 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 5167 | /// number of collapsed loops otherwise. |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5168 | static unsigned |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5169 | checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5170 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 5171 | DSAStackTy &DSA, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5172 | Sema::VarsWithInheritedDSAType &VarsWithImplicitDSA, |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5173 | OMPLoopDirective::HelperExprs &Built) { |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5174 | unsigned NestedLoopCount = 1; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5175 | if (CollapseLoopCountExpr) { |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5176 | // Found 'collapse' clause - calculate collapse number. |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 5177 | Expr::EvalResult Result; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5178 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 5179 | NestedLoopCount = Result.Val.getInt().getLimitedValue(); |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5180 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 5181 | unsigned OrderedLoopCount = 1; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5182 | if (OrderedLoopCountExpr) { |
| 5183 | // Found 'ordered' clause - calculate collapse number. |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 5184 | Expr::EvalResult EVResult; |
| 5185 | if (OrderedLoopCountExpr->EvaluateAsInt(EVResult, SemaRef.getASTContext())) { |
| 5186 | llvm::APSInt Result = EVResult.Val.getInt(); |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5187 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 5188 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 5189 | diag::err_omp_wrong_ordered_loop_count) |
| 5190 | << OrderedLoopCountExpr->getSourceRange(); |
| 5191 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 5192 | diag::note_collapse_loop_count) |
| 5193 | << CollapseLoopCountExpr->getSourceRange(); |
| 5194 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 5195 | OrderedLoopCount = Result.getLimitedValue(); |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5196 | } |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5197 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5198 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 5199 | // 'for simd', etc.). |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5200 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5201 | SmallVector<LoopIterationSpace, 4> IterSpaces( |
| 5202 | std::max(OrderedLoopCount, NestedLoopCount)); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5203 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5204 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 5205 | if (checkOpenMPIterationSpace( |
| 5206 | DKind, CurStmt, SemaRef, DSA, Cnt, NestedLoopCount, |
| 5207 | std::max(OrderedLoopCount, NestedLoopCount), CollapseLoopCountExpr, |
| 5208 | OrderedLoopCountExpr, VarsWithImplicitDSA, IterSpaces[Cnt], |
| 5209 | Captures)) |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5210 | return 0; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5211 | // 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] | 5212 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 5213 | // All loops associated with the construct must be perfectly nested; that |
| 5214 | // is, there must be no intervening code nor any OpenMP directive between |
| 5215 | // any two loops. |
| 5216 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5217 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 5218 | for (unsigned Cnt = NestedLoopCount; Cnt < OrderedLoopCount; ++Cnt) { |
| 5219 | if (checkOpenMPIterationSpace( |
| 5220 | DKind, CurStmt, SemaRef, DSA, Cnt, NestedLoopCount, |
| 5221 | std::max(OrderedLoopCount, NestedLoopCount), CollapseLoopCountExpr, |
| 5222 | OrderedLoopCountExpr, VarsWithImplicitDSA, IterSpaces[Cnt], |
| 5223 | Captures)) |
| 5224 | return 0; |
| 5225 | if (Cnt > 0 && IterSpaces[Cnt].CounterVar) { |
| 5226 | // Handle initialization of captured loop iterator variables. |
| 5227 | auto *DRE = cast<DeclRefExpr>(IterSpaces[Cnt].CounterVar); |
| 5228 | if (isa<OMPCapturedExprDecl>(DRE->getDecl())) { |
| 5229 | Captures[DRE] = DRE; |
| 5230 | } |
| 5231 | } |
| 5232 | // Move on to the next nested for loop, or to the loop body. |
| 5233 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 5234 | // All loops associated with the construct must be perfectly nested; that |
| 5235 | // is, there must be no intervening code nor any OpenMP directive between |
| 5236 | // any two loops. |
| 5237 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
| 5238 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5239 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5240 | Built.clear(/* size */ NestedLoopCount); |
| 5241 | |
| 5242 | if (SemaRef.CurContext->isDependentContext()) |
| 5243 | return NestedLoopCount; |
| 5244 | |
| 5245 | // An example of what is generated for the following code: |
| 5246 | // |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5247 | // #pragma omp simd collapse(2) ordered(2) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5248 | // for (i = 0; i < NI; ++i) |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5249 | // for (k = 0; k < NK; ++k) |
| 5250 | // for (j = J0; j < NJ; j+=2) { |
| 5251 | // <loop body> |
| 5252 | // } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5253 | // |
| 5254 | // We generate the code below. |
| 5255 | // Note: the loop body may be outlined in CodeGen. |
| 5256 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 5257 | // iterations and operator+= to calculate counter value. |
| 5258 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 5259 | // or i64 is currently supported). |
| 5260 | // |
| 5261 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 5262 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 5263 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 5264 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 5265 | // // similar updates for vars in clauses (e.g. 'linear') |
| 5266 | // <loop body (using local i and j)> |
| 5267 | // } |
| 5268 | // i = NI; // assign final values of counters |
| 5269 | // j = NJ; |
| 5270 | // |
| 5271 | |
| 5272 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 5273 | // the iteration counts of the collapsed for loops. |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5274 | // Precondition tests if there is at least one iteration (all conditions are |
| 5275 | // true). |
| 5276 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5277 | Expr *N0 = IterSpaces[0].NumIterations; |
| 5278 | ExprResult LastIteration32 = |
| 5279 | widenIterationCount(/*Bits=*/32, |
| 5280 | SemaRef |
| 5281 | .PerformImplicitConversion( |
| 5282 | N0->IgnoreImpCasts(), N0->getType(), |
| 5283 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 5284 | .get(), |
| 5285 | SemaRef); |
| 5286 | ExprResult LastIteration64 = widenIterationCount( |
| 5287 | /*Bits=*/64, |
| 5288 | SemaRef |
| 5289 | .PerformImplicitConversion(N0->IgnoreImpCasts(), N0->getType(), |
| 5290 | Sema::AA_Converting, |
| 5291 | /*AllowExplicit=*/true) |
| 5292 | .get(), |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5293 | SemaRef); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5294 | |
| 5295 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 5296 | return NestedLoopCount; |
| 5297 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5298 | ASTContext &C = SemaRef.Context; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5299 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 5300 | |
| 5301 | Scope *CurScope = DSA.getCurScope(); |
| 5302 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5303 | if (PreCond.isUsable()) { |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 5304 | PreCond = |
| 5305 | SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, |
| 5306 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5307 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5308 | Expr *N = IterSpaces[Cnt].NumIterations; |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 5309 | SourceLocation Loc = N->getExprLoc(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5310 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 5311 | if (LastIteration32.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5312 | LastIteration32 = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 5313 | CurScope, Loc, BO_Mul, LastIteration32.get(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5314 | SemaRef |
| 5315 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 5316 | Sema::AA_Converting, |
| 5317 | /*AllowExplicit=*/true) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5318 | .get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5319 | if (LastIteration64.isUsable()) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5320 | LastIteration64 = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 5321 | CurScope, Loc, BO_Mul, LastIteration64.get(), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5322 | SemaRef |
| 5323 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 5324 | Sema::AA_Converting, |
| 5325 | /*AllowExplicit=*/true) |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5326 | .get()); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5327 | } |
| 5328 | |
| 5329 | // Choose either the 32-bit or 64-bit version. |
| 5330 | ExprResult LastIteration = LastIteration64; |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 5331 | if (SemaRef.getLangOpts().OpenMPOptimisticCollapse || |
| 5332 | (LastIteration32.isUsable() && |
| 5333 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 5334 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 5335 | fitsInto( |
| 5336 | /*Bits=*/32, |
| 5337 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 5338 | LastIteration64.get(), SemaRef)))) |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5339 | LastIteration = LastIteration32; |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5340 | QualType VType = LastIteration.get()->getType(); |
| 5341 | QualType RealVType = VType; |
| 5342 | QualType StrideVType = VType; |
| 5343 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 5344 | VType = |
| 5345 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 5346 | StrideVType = |
| 5347 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 5348 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5349 | |
| 5350 | if (!LastIteration.isUsable()) |
| 5351 | return 0; |
| 5352 | |
| 5353 | // Save the number of iterations. |
| 5354 | ExprResult NumIterations = LastIteration; |
| 5355 | { |
| 5356 | LastIteration = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 5357 | CurScope, LastIteration.get()->getExprLoc(), BO_Sub, |
| 5358 | LastIteration.get(), |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5359 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5360 | if (!LastIteration.isUsable()) |
| 5361 | return 0; |
| 5362 | } |
| 5363 | |
| 5364 | // Calculate the last iteration number beforehand instead of doing this on |
| 5365 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 5366 | llvm::APSInt Result; |
| 5367 | bool IsConstant = |
| 5368 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 5369 | ExprResult CalcLastIteration; |
| 5370 | if (!IsConstant) { |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5371 | ExprResult SaveRef = |
| 5372 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5373 | LastIteration = SaveRef; |
| 5374 | |
| 5375 | // Prepare SaveRef + 1. |
| 5376 | NumIterations = SemaRef.BuildBinOp( |
| Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 5377 | CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5378 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5379 | if (!NumIterations.isUsable()) |
| 5380 | return 0; |
| 5381 | } |
| 5382 | |
| 5383 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 5384 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5385 | // Build variables passed into runtime, necessary for worksharing directives. |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5386 | ExprResult LB, UB, IL, ST, EUB, CombLB, CombUB, PrevLB, PrevUB, CombEUB; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5387 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5388 | isOpenMPDistributeDirective(DKind)) { |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5389 | // Lower bound variable, initialized with zero. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5390 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 5391 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 5392 | SemaRef.AddInitializerToDecl(LBDecl, |
| 5393 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5394 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5395 | |
| 5396 | // Upper bound variable, initialized with last iteration number. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5397 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 5398 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5399 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 5400 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5401 | |
| 5402 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 5403 | // This will be used to implement clause 'lastprivate'. |
| 5404 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5405 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 5406 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 5407 | SemaRef.AddInitializerToDecl(ILDecl, |
| 5408 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5409 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5410 | |
| 5411 | // Stride variable returned by runtime (we initialize it to 1 by default). |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5412 | VarDecl *STDecl = |
| 5413 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 5414 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 5415 | SemaRef.AddInitializerToDecl(STDecl, |
| 5416 | SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 5417 | /*DirectInit*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5418 | |
| 5419 | // Build expression: UB = min(UB, LastIteration) |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5420 | // It is necessary for CodeGen of directives with static scheduling. |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5421 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 5422 | UB.get(), LastIteration.get()); |
| 5423 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| Alexey Bataev | 86ec3fe | 2018-07-25 14:40:26 +0000 | [diff] [blame] | 5424 | LastIteration.get()->getExprLoc(), InitLoc, IsUBGreater.get(), |
| 5425 | LastIteration.get(), UB.get()); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5426 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 5427 | CondOp.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5428 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5429 | |
| 5430 | // If we have a combined directive that combines 'distribute', 'for' or |
| 5431 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 5432 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 5433 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 5434 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5435 | // Lower bound variable, initialized with zero. |
| 5436 | VarDecl *CombLBDecl = |
| 5437 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.lb"); |
| 5438 | CombLB = buildDeclRefExpr(SemaRef, CombLBDecl, VType, InitLoc); |
| 5439 | SemaRef.AddInitializerToDecl( |
| 5440 | CombLBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5441 | /*DirectInit*/ false); |
| 5442 | |
| 5443 | // Upper bound variable, initialized with last iteration number. |
| 5444 | VarDecl *CombUBDecl = |
| 5445 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.ub"); |
| 5446 | CombUB = buildDeclRefExpr(SemaRef, CombUBDecl, VType, InitLoc); |
| 5447 | SemaRef.AddInitializerToDecl(CombUBDecl, LastIteration.get(), |
| 5448 | /*DirectInit*/ false); |
| 5449 | |
| 5450 | ExprResult CombIsUBGreater = SemaRef.BuildBinOp( |
| 5451 | CurScope, InitLoc, BO_GT, CombUB.get(), LastIteration.get()); |
| 5452 | ExprResult CombCondOp = |
| 5453 | SemaRef.ActOnConditionalOp(InitLoc, InitLoc, CombIsUBGreater.get(), |
| 5454 | LastIteration.get(), CombUB.get()); |
| 5455 | CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(), |
| 5456 | CombCondOp.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5457 | CombEUB = |
| 5458 | SemaRef.ActOnFinishFullExpr(CombEUB.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5459 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5460 | const CapturedDecl *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5461 | // We expect to have at least 2 more parameters than the 'parallel' |
| 5462 | // directive does - the lower and upper bounds of the previous schedule. |
| 5463 | assert(CD->getNumParams() >= 4 && |
| 5464 | "Unexpected number of parameters in loop combined directive"); |
| 5465 | |
| 5466 | // Set the proper type for the bounds given what we learned from the |
| 5467 | // enclosed loops. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5468 | ImplicitParamDecl *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 5469 | ImplicitParamDecl *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5470 | |
| 5471 | // Previous lower and upper bounds are obtained from the region |
| 5472 | // parameters. |
| 5473 | PrevLB = |
| 5474 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 5475 | PrevUB = |
| 5476 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 5477 | } |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5478 | } |
| 5479 | |
| 5480 | // Build the iteration variable and its initialization before loop. |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5481 | ExprResult IV; |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5482 | ExprResult Init, CombInit; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5483 | { |
| Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5484 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 5485 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5486 | Expr *RHS = |
| 5487 | (isOpenMPWorksharingDirective(DKind) || |
| 5488 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 5489 | ? LB.get() |
| 5490 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5491 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5492 | Init = SemaRef.ActOnFinishFullExpr(Init.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5493 | |
| 5494 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5495 | Expr *CombRHS = |
| 5496 | (isOpenMPWorksharingDirective(DKind) || |
| 5497 | isOpenMPTaskLoopDirective(DKind) || |
| 5498 | isOpenMPDistributeDirective(DKind)) |
| 5499 | ? CombLB.get() |
| 5500 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 5501 | CombInit = |
| 5502 | SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), CombRHS); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5503 | CombInit = |
| 5504 | SemaRef.ActOnFinishFullExpr(CombInit.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5505 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5506 | } |
| 5507 | |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5508 | bool UseStrictCompare = |
| 5509 | RealVType->hasUnsignedIntegerRepresentation() && |
| 5510 | llvm::all_of(IterSpaces, [](const LoopIterationSpace &LIS) { |
| 5511 | return LIS.IsStrictCompare; |
| 5512 | }); |
| 5513 | // Loop condition (IV < NumIterations) or (IV <= UB or IV < UB + 1 (for |
| 5514 | // unsigned IV)) for worksharing loops. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5515 | SourceLocation CondLoc = AStmt->getBeginLoc(); |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5516 | Expr *BoundUB = UB.get(); |
| 5517 | if (UseStrictCompare) { |
| 5518 | BoundUB = |
| 5519 | SemaRef |
| 5520 | .BuildBinOp(CurScope, CondLoc, BO_Add, BoundUB, |
| 5521 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()) |
| 5522 | .get(); |
| 5523 | BoundUB = |
| 5524 | SemaRef.ActOnFinishFullExpr(BoundUB, /*DiscardedValue*/ false).get(); |
| 5525 | } |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5526 | ExprResult Cond = |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5527 | (isOpenMPWorksharingDirective(DKind) || |
| 5528 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5529 | ? SemaRef.BuildBinOp(CurScope, CondLoc, |
| 5530 | UseStrictCompare ? BO_LT : BO_LE, IV.get(), |
| 5531 | BoundUB) |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5532 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 5533 | NumIterations.get()); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 5534 | ExprResult CombDistCond; |
| 5535 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5536 | CombDistCond = SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 5537 | NumIterations.get()); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 5538 | } |
| 5539 | |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5540 | ExprResult CombCond; |
| 5541 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5542 | Expr *BoundCombUB = CombUB.get(); |
| 5543 | if (UseStrictCompare) { |
| 5544 | BoundCombUB = |
| 5545 | SemaRef |
| 5546 | .BuildBinOp( |
| 5547 | CurScope, CondLoc, BO_Add, BoundCombUB, |
| 5548 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()) |
| 5549 | .get(); |
| 5550 | BoundCombUB = |
| 5551 | SemaRef.ActOnFinishFullExpr(BoundCombUB, /*DiscardedValue*/ false) |
| 5552 | .get(); |
| 5553 | } |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5554 | CombCond = |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5555 | SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE, |
| 5556 | IV.get(), BoundCombUB); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5557 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5558 | // Loop increment (IV = IV + 1) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5559 | SourceLocation IncLoc = AStmt->getBeginLoc(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5560 | ExprResult Inc = |
| 5561 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 5562 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 5563 | if (!Inc.isUsable()) |
| 5564 | return 0; |
| 5565 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5566 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get(), /*DiscardedValue*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5567 | if (!Inc.isUsable()) |
| 5568 | return 0; |
| 5569 | |
| 5570 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 5571 | // Used for directives with static scheduling. |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5572 | // In combined construct, add combined version that use CombLB and CombUB |
| 5573 | // base variables for the update |
| 5574 | ExprResult NextLB, NextUB, CombNextLB, CombNextUB; |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5575 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5576 | isOpenMPDistributeDirective(DKind)) { |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5577 | // LB + ST |
| 5578 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 5579 | if (!NextLB.isUsable()) |
| 5580 | return 0; |
| 5581 | // LB = LB + ST |
| 5582 | NextLB = |
| 5583 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5584 | NextLB = |
| 5585 | SemaRef.ActOnFinishFullExpr(NextLB.get(), /*DiscardedValue*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5586 | if (!NextLB.isUsable()) |
| 5587 | return 0; |
| 5588 | // UB + ST |
| 5589 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 5590 | if (!NextUB.isUsable()) |
| 5591 | return 0; |
| 5592 | // UB = UB + ST |
| 5593 | NextUB = |
| 5594 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5595 | NextUB = |
| 5596 | SemaRef.ActOnFinishFullExpr(NextUB.get(), /*DiscardedValue*/ false); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5597 | if (!NextUB.isUsable()) |
| 5598 | return 0; |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5599 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5600 | CombNextLB = |
| 5601 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombLB.get(), ST.get()); |
| 5602 | if (!NextLB.isUsable()) |
| 5603 | return 0; |
| 5604 | // LB = LB + ST |
| 5605 | CombNextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombLB.get(), |
| 5606 | CombNextLB.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5607 | CombNextLB = SemaRef.ActOnFinishFullExpr(CombNextLB.get(), |
| 5608 | /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5609 | if (!CombNextLB.isUsable()) |
| 5610 | return 0; |
| 5611 | // UB + ST |
| 5612 | CombNextUB = |
| 5613 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombUB.get(), ST.get()); |
| 5614 | if (!CombNextUB.isUsable()) |
| 5615 | return 0; |
| 5616 | // UB = UB + ST |
| 5617 | CombNextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombUB.get(), |
| 5618 | CombNextUB.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5619 | CombNextUB = SemaRef.ActOnFinishFullExpr(CombNextUB.get(), |
| 5620 | /*DiscardedValue*/ false); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5621 | if (!CombNextUB.isUsable()) |
| 5622 | return 0; |
| 5623 | } |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5624 | } |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5625 | |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5626 | // Create increment expression for distribute loop when combined in a same |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5627 | // directive with for as IV = IV + ST; ensure upper bound expression based |
| 5628 | // on PrevUB instead of NumIterations - used to implement 'for' when found |
| 5629 | // in combination with 'distribute', like in 'distribute parallel for' |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5630 | SourceLocation DistIncLoc = AStmt->getBeginLoc(); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 5631 | ExprResult DistCond, DistInc, PrevEUB, ParForInDistCond; |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5632 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5633 | DistCond = SemaRef.BuildBinOp( |
| 5634 | CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE, IV.get(), BoundUB); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5635 | assert(DistCond.isUsable() && "distribute cond expr was not built"); |
| 5636 | |
| 5637 | DistInc = |
| 5638 | SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Add, IV.get(), ST.get()); |
| 5639 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 5640 | DistInc = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, IV.get(), |
| 5641 | DistInc.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5642 | DistInc = |
| 5643 | SemaRef.ActOnFinishFullExpr(DistInc.get(), /*DiscardedValue*/ false); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5644 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 5645 | |
| 5646 | // Build expression: UB = min(UB, prevUB) for #for in composite or combined |
| 5647 | // construct |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 5648 | SourceLocation DistEUBLoc = AStmt->getBeginLoc(); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5649 | ExprResult IsUBGreater = |
| 5650 | SemaRef.BuildBinOp(CurScope, DistEUBLoc, BO_GT, UB.get(), PrevUB.get()); |
| 5651 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 5652 | DistEUBLoc, DistEUBLoc, IsUBGreater.get(), PrevUB.get(), UB.get()); |
| 5653 | PrevEUB = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, UB.get(), |
| 5654 | CondOp.get()); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5655 | PrevEUB = |
| 5656 | SemaRef.ActOnFinishFullExpr(PrevEUB.get(), /*DiscardedValue*/ false); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 5657 | |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5658 | // Build IV <= PrevUB or IV < PrevUB + 1 for unsigned IV to be used in |
| 5659 | // parallel for is in combination with a distribute directive with |
| 5660 | // schedule(static, 1) |
| 5661 | Expr *BoundPrevUB = PrevUB.get(); |
| 5662 | if (UseStrictCompare) { |
| 5663 | BoundPrevUB = |
| 5664 | SemaRef |
| 5665 | .BuildBinOp( |
| 5666 | CurScope, CondLoc, BO_Add, BoundPrevUB, |
| 5667 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()) |
| 5668 | .get(); |
| 5669 | BoundPrevUB = |
| 5670 | SemaRef.ActOnFinishFullExpr(BoundPrevUB, /*DiscardedValue*/ false) |
| 5671 | .get(); |
| 5672 | } |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 5673 | ParForInDistCond = |
| Alexey Bataev | 316ccf6 | 2019-01-29 18:51:58 +0000 | [diff] [blame] | 5674 | SemaRef.BuildBinOp(CurScope, CondLoc, UseStrictCompare ? BO_LT : BO_LE, |
| 5675 | IV.get(), BoundPrevUB); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5676 | } |
| 5677 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5678 | // Build updates and final values of the loop counters. |
| 5679 | bool HasErrors = false; |
| 5680 | Built.Counters.resize(NestedLoopCount); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5681 | Built.Inits.resize(NestedLoopCount); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5682 | Built.Updates.resize(NestedLoopCount); |
| 5683 | Built.Finals.resize(NestedLoopCount); |
| 5684 | { |
| Gheorghe-Teodor Bercea | 67796064 | 2019-01-09 20:45:26 +0000 | [diff] [blame] | 5685 | // We implement the following algorithm for obtaining the |
| 5686 | // original loop iteration variable values based on the |
| 5687 | // value of the collapsed loop iteration variable IV. |
| 5688 | // |
| 5689 | // Let n+1 be the number of collapsed loops in the nest. |
| 5690 | // Iteration variables (I0, I1, .... In) |
| 5691 | // Iteration counts (N0, N1, ... Nn) |
| 5692 | // |
| 5693 | // Acc = IV; |
| 5694 | // |
| 5695 | // To compute Ik for loop k, 0 <= k <= n, generate: |
| 5696 | // Prod = N(k+1) * N(k+2) * ... * Nn; |
| 5697 | // Ik = Acc / Prod; |
| 5698 | // Acc -= Ik * Prod; |
| 5699 | // |
| 5700 | ExprResult Acc = IV; |
| 5701 | for (unsigned int Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5702 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 5703 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5704 | ExprResult Iter; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5705 | |
| Gheorghe-Teodor Bercea | 67796064 | 2019-01-09 20:45:26 +0000 | [diff] [blame] | 5706 | // Compute prod |
| 5707 | ExprResult Prod = |
| 5708 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 5709 | for (unsigned int K = Cnt+1; K < NestedLoopCount; ++K) |
| 5710 | Prod = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Prod.get(), |
| 5711 | IterSpaces[K].NumIterations); |
| 5712 | |
| 5713 | // Iter = Acc / Prod |
| 5714 | // If there is at least one more inner loop to avoid |
| 5715 | // multiplication by 1. |
| 5716 | if (Cnt + 1 < NestedLoopCount) |
| 5717 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, |
| 5718 | Acc.get(), Prod.get()); |
| 5719 | else |
| 5720 | Iter = Acc; |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5721 | if (!Iter.isUsable()) { |
| 5722 | HasErrors = true; |
| 5723 | break; |
| 5724 | } |
| 5725 | |
| Gheorghe-Teodor Bercea | 67796064 | 2019-01-09 20:45:26 +0000 | [diff] [blame] | 5726 | // Update Acc: |
| 5727 | // Acc -= Iter * Prod |
| 5728 | // Check if there is at least one more inner loop to avoid |
| 5729 | // multiplication by 1. |
| 5730 | if (Cnt + 1 < NestedLoopCount) |
| 5731 | Prod = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, |
| 5732 | Iter.get(), Prod.get()); |
| 5733 | else |
| 5734 | Prod = Iter; |
| 5735 | Acc = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Sub, |
| 5736 | Acc.get(), Prod.get()); |
| 5737 | |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5738 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5739 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5740 | DeclRefExpr *CounterVar = buildDeclRefExpr( |
| 5741 | SemaRef, VD, IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 5742 | /*RefersToCapture=*/true); |
| 5743 | ExprResult Init = buildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5744 | IS.CounterInit, Captures); |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5745 | if (!Init.isUsable()) { |
| 5746 | HasErrors = true; |
| 5747 | break; |
| 5748 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5749 | ExprResult Update = buildCounterUpdate( |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5750 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 5751 | IS.CounterStep, IS.Subtract, &Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5752 | if (!Update.isUsable()) { |
| 5753 | HasErrors = true; |
| 5754 | break; |
| 5755 | } |
| 5756 | |
| 5757 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5758 | ExprResult Final = buildCounterUpdate( |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5759 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5760 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5761 | if (!Final.isUsable()) { |
| 5762 | HasErrors = true; |
| 5763 | break; |
| 5764 | } |
| 5765 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5766 | if (!Update.isUsable() || !Final.isUsable()) { |
| 5767 | HasErrors = true; |
| 5768 | break; |
| 5769 | } |
| 5770 | // Save results |
| 5771 | Built.Counters[Cnt] = IS.CounterVar; |
| Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 5772 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
| Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5773 | Built.Inits[Cnt] = Init.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5774 | Built.Updates[Cnt] = Update.get(); |
| 5775 | Built.Finals[Cnt] = Final.get(); |
| 5776 | } |
| 5777 | } |
| 5778 | |
| 5779 | if (HasErrors) |
| 5780 | return 0; |
| 5781 | |
| 5782 | // Save results |
| 5783 | Built.IterationVarRef = IV.get(); |
| 5784 | Built.LastIteration = LastIteration.get(); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5785 | Built.NumIterations = NumIterations.get(); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 5786 | Built.CalcLastIteration = SemaRef |
| 5787 | .ActOnFinishFullExpr(CalcLastIteration.get(), |
| 5788 | /*DiscardedValue*/ false) |
| 5789 | .get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5790 | Built.PreCond = PreCond.get(); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5791 | Built.PreInits = buildPreInits(C, Captures); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5792 | Built.Cond = Cond.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5793 | Built.Init = Init.get(); |
| 5794 | Built.Inc = Inc.get(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5795 | Built.LB = LB.get(); |
| 5796 | Built.UB = UB.get(); |
| 5797 | Built.IL = IL.get(); |
| 5798 | Built.ST = ST.get(); |
| 5799 | Built.EUB = EUB.get(); |
| 5800 | Built.NLB = NextLB.get(); |
| 5801 | Built.NUB = NextUB.get(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5802 | Built.PrevLB = PrevLB.get(); |
| 5803 | Built.PrevUB = PrevUB.get(); |
| Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 5804 | Built.DistInc = DistInc.get(); |
| 5805 | Built.PrevEUB = PrevEUB.get(); |
| Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 5806 | Built.DistCombinedFields.LB = CombLB.get(); |
| 5807 | Built.DistCombinedFields.UB = CombUB.get(); |
| 5808 | Built.DistCombinedFields.EUB = CombEUB.get(); |
| 5809 | Built.DistCombinedFields.Init = CombInit.get(); |
| 5810 | Built.DistCombinedFields.Cond = CombCond.get(); |
| 5811 | Built.DistCombinedFields.NLB = CombNextLB.get(); |
| 5812 | Built.DistCombinedFields.NUB = CombNextUB.get(); |
| Gheorghe-Teodor Bercea | e925676 | 2018-10-29 15:45:47 +0000 | [diff] [blame] | 5813 | Built.DistCombinedFields.DistCond = CombDistCond.get(); |
| 5814 | Built.DistCombinedFields.ParForInDistCond = ParForInDistCond.get(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5815 | |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5816 | return NestedLoopCount; |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5817 | } |
| 5818 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5819 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
| Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5820 | auto CollapseClauses = |
| 5821 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 5822 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 5823 | return (*CollapseClauses.begin())->getNumForLoops(); |
| Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5824 | return nullptr; |
| 5825 | } |
| 5826 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5827 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
| Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5828 | auto OrderedClauses = |
| 5829 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 5830 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 5831 | return (*OrderedClauses.begin())->getNumForLoops(); |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5832 | return nullptr; |
| 5833 | } |
| 5834 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5835 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 5836 | const ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5837 | const OMPSafelenClause *Safelen = nullptr; |
| 5838 | const OMPSimdlenClause *Simdlen = nullptr; |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5839 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5840 | for (const OMPClause *Clause : Clauses) { |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5841 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5842 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5843 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5844 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5845 | if (Safelen && Simdlen) |
| 5846 | break; |
| 5847 | } |
| 5848 | |
| 5849 | if (Simdlen && Safelen) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5850 | const Expr *SimdlenLength = Simdlen->getSimdlen(); |
| 5851 | const Expr *SafelenLength = Safelen->getSafelen(); |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5852 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 5853 | SimdlenLength->isInstantiationDependent() || |
| 5854 | SimdlenLength->containsUnexpandedParameterPack()) |
| 5855 | return false; |
| 5856 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 5857 | SafelenLength->isInstantiationDependent() || |
| 5858 | SafelenLength->containsUnexpandedParameterPack()) |
| 5859 | return false; |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 5860 | Expr::EvalResult SimdlenResult, SafelenResult; |
| 5861 | SimdlenLength->EvaluateAsInt(SimdlenResult, S.Context); |
| 5862 | SafelenLength->EvaluateAsInt(SafelenResult, S.Context); |
| 5863 | llvm::APSInt SimdlenRes = SimdlenResult.Val.getInt(); |
| 5864 | llvm::APSInt SafelenRes = SafelenResult.Val.getInt(); |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5865 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 5866 | // If both simdlen and safelen clauses are specified, the value of the |
| 5867 | // simdlen parameter must be less than or equal to the value of the safelen |
| 5868 | // parameter. |
| 5869 | if (SimdlenRes > SafelenRes) { |
| 5870 | S.Diag(SimdlenLength->getExprLoc(), |
| 5871 | diag::err_omp_wrong_simdlen_safelen_values) |
| 5872 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 5873 | return true; |
| 5874 | } |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5875 | } |
| 5876 | return false; |
| 5877 | } |
| 5878 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5879 | StmtResult |
| 5880 | Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 5881 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 5882 | VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5883 | if (!AStmt) |
| 5884 | return StmtError(); |
| 5885 | |
| 5886 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5887 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5888 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5889 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5890 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5891 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5892 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5893 | if (NestedLoopCount == 0) |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5894 | return StmtError(); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5895 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5896 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5897 | "omp simd loop exprs were not built"); |
| 5898 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5899 | if (!CurContext->isDependentContext()) { |
| 5900 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5901 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5902 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5903 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5904 | B.NumIterations, *this, CurScope, |
| 5905 | DSAStack)) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5906 | return StmtError(); |
| 5907 | } |
| 5908 | } |
| 5909 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5910 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5911 | return StmtError(); |
| 5912 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5913 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5914 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5915 | Clauses, AStmt, B); |
| Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5916 | } |
| 5917 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5918 | StmtResult |
| 5919 | Sema::ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 5920 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 5921 | VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5922 | if (!AStmt) |
| 5923 | return StmtError(); |
| 5924 | |
| 5925 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5926 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5927 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5928 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5929 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5930 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5931 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
| Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5932 | if (NestedLoopCount == 0) |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5933 | return StmtError(); |
| 5934 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5935 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5936 | "omp for loop exprs were not built"); |
| 5937 | |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5938 | if (!CurContext->isDependentContext()) { |
| 5939 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5940 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5941 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5942 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5943 | B.NumIterations, *this, CurScope, |
| 5944 | DSAStack)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5945 | return StmtError(); |
| 5946 | } |
| 5947 | } |
| 5948 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5949 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5950 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5951 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5952 | } |
| 5953 | |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5954 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 5955 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5956 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5957 | if (!AStmt) |
| 5958 | return StmtError(); |
| 5959 | |
| 5960 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5961 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5962 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5963 | // define the nested loops number. |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5964 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5965 | checkOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5966 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5967 | VarsWithImplicitDSA, B); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5968 | if (NestedLoopCount == 0) |
| 5969 | return StmtError(); |
| 5970 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5971 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5972 | "omp for simd loop exprs were not built"); |
| 5973 | |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5974 | if (!CurContext->isDependentContext()) { |
| 5975 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 5976 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5977 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5978 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5979 | B.NumIterations, *this, CurScope, |
| 5980 | DSAStack)) |
| Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5981 | return StmtError(); |
| 5982 | } |
| 5983 | } |
| 5984 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5985 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5986 | return StmtError(); |
| 5987 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 5988 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5989 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5990 | Clauses, AStmt, B); |
| Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5991 | } |
| 5992 | |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5993 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5994 | Stmt *AStmt, |
| 5995 | SourceLocation StartLoc, |
| 5996 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5997 | if (!AStmt) |
| 5998 | return StmtError(); |
| 5999 | |
| 6000 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6001 | auto BaseStmt = AStmt; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6002 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6003 | BaseStmt = CS->getCapturedStmt(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6004 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6005 | auto S = C->children(); |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 6006 | if (S.begin() == S.end()) |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6007 | return StmtError(); |
| 6008 | // All associated statements must be '#pragma omp section' except for |
| 6009 | // the first one. |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 6010 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6011 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 6012 | if (SectionStmt) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6013 | Diag(SectionStmt->getBeginLoc(), |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6014 | diag::err_omp_sections_substmt_not_section); |
| 6015 | return StmtError(); |
| 6016 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6017 | cast<OMPSectionDirective>(SectionStmt) |
| 6018 | ->setHasCancel(DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6019 | } |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6020 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6021 | Diag(AStmt->getBeginLoc(), diag::err_omp_sections_not_compound_stmt); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6022 | return StmtError(); |
| 6023 | } |
| 6024 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6025 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6026 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6027 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 6028 | DSAStack->isCancelRegion()); |
| Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 6029 | } |
| 6030 | |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6031 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 6032 | SourceLocation StartLoc, |
| 6033 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6034 | if (!AStmt) |
| 6035 | return StmtError(); |
| 6036 | |
| 6037 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6038 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6039 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6040 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6041 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6042 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 6043 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 6044 | } |
| 6045 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6046 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 6047 | Stmt *AStmt, |
| 6048 | SourceLocation StartLoc, |
| 6049 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6050 | if (!AStmt) |
| 6051 | return StmtError(); |
| 6052 | |
| 6053 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 6054 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6055 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 6056 | |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 6057 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 6058 | // The copyprivate clause must not be used with the nowait clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6059 | const OMPClause *Nowait = nullptr; |
| 6060 | const OMPClause *Copyprivate = nullptr; |
| 6061 | for (const OMPClause *Clause : Clauses) { |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 6062 | if (Clause->getClauseKind() == OMPC_nowait) |
| 6063 | Nowait = Clause; |
| 6064 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 6065 | Copyprivate = Clause; |
| 6066 | if (Copyprivate && Nowait) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6067 | Diag(Copyprivate->getBeginLoc(), |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 6068 | diag::err_omp_single_copyprivate_with_nowait); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6069 | Diag(Nowait->getBeginLoc(), diag::note_omp_nowait_clause_here); |
| Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 6070 | return StmtError(); |
| 6071 | } |
| 6072 | } |
| 6073 | |
| Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 6074 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6075 | } |
| 6076 | |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 6077 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 6078 | SourceLocation StartLoc, |
| 6079 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6080 | if (!AStmt) |
| 6081 | return StmtError(); |
| 6082 | |
| 6083 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 6084 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6085 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 6086 | |
| 6087 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 6088 | } |
| 6089 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6090 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 6091 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 6092 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6093 | if (!AStmt) |
| 6094 | return StmtError(); |
| 6095 | |
| 6096 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6097 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6098 | bool ErrorFound = false; |
| 6099 | llvm::APSInt Hint; |
| 6100 | SourceLocation HintLoc; |
| 6101 | bool DependentHint = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6102 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6103 | if (C->getClauseKind() == OMPC_hint) { |
| 6104 | if (!DirName.getName()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6105 | Diag(C->getBeginLoc(), diag::err_omp_hint_clause_no_name); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6106 | ErrorFound = true; |
| 6107 | } |
| 6108 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 6109 | if (E->isTypeDependent() || E->isValueDependent() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6110 | E->isInstantiationDependent()) { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6111 | DependentHint = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6112 | } else { |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6113 | Hint = E->EvaluateKnownConstInt(Context); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6114 | HintLoc = C->getBeginLoc(); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6115 | } |
| 6116 | } |
| 6117 | } |
| 6118 | if (ErrorFound) |
| 6119 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6120 | const auto Pair = DSAStack->getCriticalWithHint(DirName); |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6121 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 6122 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 6123 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6124 | if (HintLoc.isValid()) |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6125 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 6126 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6127 | else |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6128 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6129 | if (const auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6130 | Diag(C->getBeginLoc(), diag::note_omp_critical_hint_here) |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6131 | << 1 |
| 6132 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 6133 | /*Radix=*/10, /*Signed=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6134 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6135 | Diag(Pair.first->getBeginLoc(), diag::note_omp_critical_no_hint) << 1; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6136 | } |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6137 | } |
| 6138 | } |
| 6139 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6140 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6141 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6142 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 6143 | Clauses, AStmt); |
| 6144 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 6145 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 6146 | return Dir; |
| Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 6147 | } |
| 6148 | |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6149 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 6150 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6151 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6152 | if (!AStmt) |
| 6153 | return StmtError(); |
| 6154 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6155 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6156 | // 1.2.2 OpenMP Language Terminology |
| 6157 | // Structured block - An executable statement with a single entry at the |
| 6158 | // top and a single exit at the bottom. |
| 6159 | // The point of exit cannot be a branch out of the structured block. |
| 6160 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6161 | CS->getCapturedDecl()->setNothrow(); |
| 6162 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 6163 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6164 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6165 | // define the nested loops number. |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6166 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6167 | checkOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6168 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6169 | VarsWithImplicitDSA, B); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6170 | if (NestedLoopCount == 0) |
| 6171 | return StmtError(); |
| 6172 | |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6173 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6174 | "omp parallel for loop exprs were not built"); |
| 6175 | |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 6176 | if (!CurContext->isDependentContext()) { |
| 6177 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6178 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6179 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 6180 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6181 | B.NumIterations, *this, CurScope, |
| 6182 | DSAStack)) |
| Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 6183 | return StmtError(); |
| 6184 | } |
| 6185 | } |
| 6186 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6187 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 6188 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6189 | NestedLoopCount, Clauses, AStmt, B, |
| 6190 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 6191 | } |
| 6192 | |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 6193 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 6194 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6195 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6196 | if (!AStmt) |
| 6197 | return StmtError(); |
| 6198 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6199 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 6200 | // 1.2.2 OpenMP Language Terminology |
| 6201 | // Structured block - An executable statement with a single entry at the |
| 6202 | // top and a single exit at the bottom. |
| 6203 | // The point of exit cannot be a branch out of the structured block. |
| 6204 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6205 | CS->getCapturedDecl()->setNothrow(); |
| 6206 | |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 6207 | OMPLoopDirective::HelperExprs B; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6208 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6209 | // define the nested loops number. |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 6210 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6211 | checkOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6212 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6213 | VarsWithImplicitDSA, B); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 6214 | if (NestedLoopCount == 0) |
| 6215 | return StmtError(); |
| 6216 | |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 6217 | if (!CurContext->isDependentContext()) { |
| 6218 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6219 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6220 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 6221 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6222 | B.NumIterations, *this, CurScope, |
| 6223 | DSAStack)) |
| Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 6224 | return StmtError(); |
| 6225 | } |
| 6226 | } |
| 6227 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6228 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6229 | return StmtError(); |
| 6230 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6231 | setFunctionHasBranchProtectedScope(); |
| Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6232 | return OMPParallelForSimdDirective::Create( |
| Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 6233 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 6234 | } |
| 6235 | |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6236 | StmtResult |
| 6237 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 6238 | Stmt *AStmt, SourceLocation StartLoc, |
| 6239 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6240 | if (!AStmt) |
| 6241 | return StmtError(); |
| 6242 | |
| 6243 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6244 | auto BaseStmt = AStmt; |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6245 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6246 | BaseStmt = CS->getCapturedStmt(); |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6247 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6248 | auto S = C->children(); |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 6249 | if (S.begin() == S.end()) |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6250 | return StmtError(); |
| 6251 | // All associated statements must be '#pragma omp section' except for |
| 6252 | // the first one. |
| Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 6253 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6254 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 6255 | if (SectionStmt) |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6256 | Diag(SectionStmt->getBeginLoc(), |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6257 | diag::err_omp_parallel_sections_substmt_not_section); |
| 6258 | return StmtError(); |
| 6259 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6260 | cast<OMPSectionDirective>(SectionStmt) |
| 6261 | ->setHasCancel(DSAStack->isCancelRegion()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6262 | } |
| 6263 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6264 | Diag(AStmt->getBeginLoc(), |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6265 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 6266 | return StmtError(); |
| 6267 | } |
| 6268 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6269 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6270 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6271 | return OMPParallelSectionsDirective::Create( |
| 6272 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
| Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6273 | } |
| 6274 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6275 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 6276 | Stmt *AStmt, SourceLocation StartLoc, |
| 6277 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6278 | if (!AStmt) |
| 6279 | return StmtError(); |
| 6280 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6281 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6282 | // 1.2.2 OpenMP Language Terminology |
| 6283 | // Structured block - An executable statement with a single entry at the |
| 6284 | // top and a single exit at the bottom. |
| 6285 | // The point of exit cannot be a branch out of the structured block. |
| 6286 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6287 | CS->getCapturedDecl()->setNothrow(); |
| 6288 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6289 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6290 | |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6291 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 6292 | DSAStack->isCancelRegion()); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6293 | } |
| 6294 | |
| Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6295 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 6296 | SourceLocation EndLoc) { |
| 6297 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 6298 | } |
| 6299 | |
| Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 6300 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 6301 | SourceLocation EndLoc) { |
| 6302 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 6303 | } |
| 6304 | |
| Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 6305 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 6306 | SourceLocation EndLoc) { |
| 6307 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 6308 | } |
| 6309 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 6310 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
| 6311 | Stmt *AStmt, |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 6312 | SourceLocation StartLoc, |
| 6313 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6314 | if (!AStmt) |
| 6315 | return StmtError(); |
| 6316 | |
| 6317 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 6318 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6319 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 6320 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 6321 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 6322 | AStmt, |
| 6323 | DSAStack->getTaskgroupReductionRef()); |
| Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6326 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 6327 | SourceLocation StartLoc, |
| 6328 | SourceLocation EndLoc) { |
| 6329 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 6330 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6331 | } |
| 6332 | |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6333 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 6334 | Stmt *AStmt, |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 6335 | SourceLocation StartLoc, |
| 6336 | SourceLocation EndLoc) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6337 | const OMPClause *DependFound = nullptr; |
| 6338 | const OMPClause *DependSourceClause = nullptr; |
| 6339 | const OMPClause *DependSinkClause = nullptr; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6340 | bool ErrorFound = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6341 | const OMPThreadsClause *TC = nullptr; |
| 6342 | const OMPSIMDClause *SC = nullptr; |
| 6343 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6344 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 6345 | DependFound = C; |
| 6346 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 6347 | if (DependSourceClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6348 | Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6349 | << getOpenMPDirectiveName(OMPD_ordered) |
| 6350 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 6351 | ErrorFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6352 | } else { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6353 | DependSourceClause = C; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6354 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6355 | if (DependSinkClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6356 | Diag(C->getBeginLoc(), diag::err_omp_depend_sink_source_not_allowed) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6357 | << 0; |
| 6358 | ErrorFound = true; |
| 6359 | } |
| 6360 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 6361 | if (DependSourceClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6362 | Diag(C->getBeginLoc(), diag::err_omp_depend_sink_source_not_allowed) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6363 | << 1; |
| 6364 | ErrorFound = true; |
| 6365 | } |
| 6366 | DependSinkClause = C; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6367 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6368 | } else if (C->getClauseKind() == OMPC_threads) { |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6369 | TC = cast<OMPThreadsClause>(C); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6370 | } else if (C->getClauseKind() == OMPC_simd) { |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6371 | SC = cast<OMPSIMDClause>(C); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6372 | } |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6373 | } |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6374 | if (!ErrorFound && !SC && |
| 6375 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6376 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 6377 | // An ordered construct with the simd clause is the only OpenMP construct |
| 6378 | // that can appear in the simd region. |
| 6379 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6380 | ErrorFound = true; |
| 6381 | } else if (DependFound && (TC || SC)) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6382 | Diag(DependFound->getBeginLoc(), diag::err_omp_depend_clause_thread_simd) |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6383 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 6384 | ErrorFound = true; |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6385 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam().first) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6386 | Diag(DependFound->getBeginLoc(), |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6387 | diag::err_omp_ordered_directive_without_param); |
| 6388 | ErrorFound = true; |
| 6389 | } else if (TC || Clauses.empty()) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 6390 | if (const Expr *Param = DSAStack->getParentOrderedRegionParam().first) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6391 | SourceLocation ErrLoc = TC ? TC->getBeginLoc() : StartLoc; |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6392 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 6393 | << (TC != nullptr); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6394 | Diag(Param->getBeginLoc(), diag::note_omp_ordered_param); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6395 | ErrorFound = true; |
| 6396 | } |
| 6397 | } |
| 6398 | if ((!AStmt && !DependFound) || ErrorFound) |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6399 | return StmtError(); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6400 | |
| 6401 | if (AStmt) { |
| 6402 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6403 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 6404 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6405 | } |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6406 | |
| 6407 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 6408 | } |
| 6409 | |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6410 | namespace { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6411 | /// Helper class for checking expression in 'omp atomic [update]' |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6412 | /// construct. |
| 6413 | class OpenMPAtomicUpdateChecker { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6414 | /// Error results for atomic update expressions. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6415 | enum ExprAnalysisErrorCode { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6416 | /// A statement is not an expression statement. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6417 | NotAnExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6418 | /// Expression is not builtin binary or unary operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6419 | NotABinaryOrUnaryExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6420 | /// Unary operation is not post-/pre- increment/decrement operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6421 | NotAnUnaryIncDecExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6422 | /// An expression is not of scalar type. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6423 | NotAScalarType, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6424 | /// A binary operation is not an assignment operation. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6425 | NotAnAssignmentOp, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6426 | /// RHS part of the binary operation is not a binary expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6427 | NotABinaryExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6428 | /// RHS part is not additive/multiplicative/shift/biwise binary |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6429 | /// expression. |
| 6430 | NotABinaryOperator, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6431 | /// RHS binary operation does not have reference to the updated LHS |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6432 | /// part. |
| 6433 | NotAnUpdateExpression, |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6434 | /// No errors is found. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6435 | NoError |
| 6436 | }; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6437 | /// Reference to Sema. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6438 | Sema &SemaRef; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6439 | /// A location for note diagnostics (when error is found). |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6440 | SourceLocation NoteLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6441 | /// 'x' lvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6442 | Expr *X; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6443 | /// 'expr' rvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6444 | Expr *E; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6445 | /// Helper expression of the form |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6446 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6447 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6448 | Expr *UpdateExpr; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6449 | /// Is 'x' a LHS in a RHS part of full update expression. It is |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6450 | /// important for non-associative operations. |
| 6451 | bool IsXLHSInRHSPart; |
| 6452 | BinaryOperatorKind Op; |
| 6453 | SourceLocation OpLoc; |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6454 | /// true if the source expression is a postfix unary operation, false |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6455 | /// if it is a prefix unary operation. |
| 6456 | bool IsPostfixUpdate; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6457 | |
| 6458 | public: |
| 6459 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6460 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6461 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6462 | /// Check specified statement that it is suitable for 'atomic update' |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6463 | /// constructs and extract 'x', 'expr' and Operation from the original |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6464 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 6465 | /// without error notification. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6466 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 6467 | /// \param NoteId Diagnostic note for the main error message. |
| 6468 | /// \return true if statement is not an update expression, false otherwise. |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6469 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6470 | /// Return the 'x' lvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6471 | Expr *getX() const { return X; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6472 | /// Return the 'expr' rvalue part of the source atomic expression. |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6473 | Expr *getExpr() const { return E; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6474 | /// Return the update expression used in calculation of the updated |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6475 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6476 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6477 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6478 | /// Return true if 'x' is LHS in RHS part of full update expression, |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6479 | /// false otherwise. |
| 6480 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 6481 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 6482 | /// true if the source expression is a postfix unary operation, false |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6483 | /// if it is a prefix unary operation. |
| 6484 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 6485 | |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6486 | private: |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6487 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 6488 | unsigned NoteId = 0); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6489 | }; |
| 6490 | } // namespace |
| 6491 | |
| 6492 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 6493 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 6494 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6495 | SourceLocation ErrorLoc, NoteLoc; |
| 6496 | SourceRange ErrorRange, NoteRange; |
| 6497 | // Allowed constructs are: |
| 6498 | // x = x binop expr; |
| 6499 | // x = expr binop x; |
| 6500 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 6501 | X = AtomicBinOp->getLHS(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6502 | if (const auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6503 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 6504 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 6505 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 6506 | AtomicInnerBinOp->isBitwiseOp()) { |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6507 | Op = AtomicInnerBinOp->getOpcode(); |
| 6508 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6509 | Expr *LHS = AtomicInnerBinOp->getLHS(); |
| 6510 | Expr *RHS = AtomicInnerBinOp->getRHS(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6511 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 6512 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 6513 | /*Canonical=*/true); |
| 6514 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 6515 | /*Canonical=*/true); |
| 6516 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 6517 | /*Canonical=*/true); |
| 6518 | if (XId == LHSId) { |
| 6519 | E = RHS; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6520 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6521 | } else if (XId == RHSId) { |
| 6522 | E = LHS; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6523 | IsXLHSInRHSPart = false; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6524 | } else { |
| 6525 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6526 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6527 | NoteLoc = X->getExprLoc(); |
| 6528 | NoteRange = X->getSourceRange(); |
| 6529 | ErrorFound = NotAnUpdateExpression; |
| 6530 | } |
| 6531 | } else { |
| 6532 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6533 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6534 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 6535 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6536 | ErrorFound = NotABinaryOperator; |
| 6537 | } |
| 6538 | } else { |
| 6539 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 6540 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 6541 | ErrorFound = NotABinaryExpression; |
| 6542 | } |
| 6543 | } else { |
| 6544 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6545 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6546 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 6547 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6548 | ErrorFound = NotAnAssignmentOp; |
| 6549 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6550 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6551 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6552 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6553 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6554 | } |
| 6555 | if (SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6556 | E = X = UpdateExpr = nullptr; |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6557 | return ErrorFound != NoError; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6558 | } |
| 6559 | |
| 6560 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 6561 | unsigned NoteId) { |
| 6562 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6563 | SourceLocation ErrorLoc, NoteLoc; |
| 6564 | SourceRange ErrorRange, NoteRange; |
| 6565 | // Allowed constructs are: |
| 6566 | // x++; |
| 6567 | // x--; |
| 6568 | // ++x; |
| 6569 | // --x; |
| 6570 | // x binop= expr; |
| 6571 | // x = x binop expr; |
| 6572 | // x = expr binop x; |
| 6573 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 6574 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 6575 | if (AtomicBody->getType()->isScalarType() || |
| 6576 | AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6577 | if (const auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6578 | AtomicBody->IgnoreParenImpCasts())) { |
| 6579 | // Check for Compound Assignment Operation |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6580 | Op = BinaryOperator::getOpForCompoundAssignment( |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6581 | AtomicCompAssignOp->getOpcode()); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6582 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6583 | E = AtomicCompAssignOp->getRHS(); |
| Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 6584 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6585 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6586 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 6587 | AtomicBody->IgnoreParenImpCasts())) { |
| 6588 | // Check for Binary Operation |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6589 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6590 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6591 | } else if (const auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6592 | AtomicBody->IgnoreParenImpCasts())) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6593 | // Check for Unary Operation |
| 6594 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6595 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6596 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 6597 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 6598 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6599 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 6600 | IsXLHSInRHSPart = true; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6601 | } else { |
| 6602 | ErrorFound = NotAnUnaryIncDecExpression; |
| 6603 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 6604 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 6605 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 6606 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6607 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6608 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6609 | ErrorFound = NotABinaryOrUnaryExpression; |
| 6610 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 6611 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 6612 | } |
| 6613 | } else { |
| 6614 | ErrorFound = NotAScalarType; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6615 | NoteLoc = ErrorLoc = AtomicBody->getBeginLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6616 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6617 | } |
| 6618 | } else { |
| 6619 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6620 | NoteLoc = ErrorLoc = S->getBeginLoc(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6621 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6622 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6623 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6624 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6625 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6626 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6627 | } |
| 6628 | if (SemaRef.CurContext->isDependentContext()) |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6629 | E = X = UpdateExpr = nullptr; |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6630 | if (ErrorFound == NoError && E && X) { |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6631 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 6632 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 6633 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 6634 | auto *OVEX = new (SemaRef.getASTContext()) |
| 6635 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 6636 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 6637 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6638 | ExprResult Update = |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6639 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 6640 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 6641 | if (Update.isInvalid()) |
| 6642 | return true; |
| 6643 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 6644 | Sema::AA_Casting); |
| 6645 | if (Update.isInvalid()) |
| 6646 | return true; |
| 6647 | UpdateExpr = Update.get(); |
| 6648 | } |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6649 | return ErrorFound != NoError; |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6650 | } |
| 6651 | |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6652 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 6653 | Stmt *AStmt, |
| 6654 | SourceLocation StartLoc, |
| 6655 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6656 | if (!AStmt) |
| 6657 | return StmtError(); |
| 6658 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6659 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6660 | // 1.2.2 OpenMP Language Terminology |
| 6661 | // Structured block - An executable statement with a single entry at the |
| 6662 | // top and a single exit at the bottom. |
| 6663 | // The point of exit cannot be a branch out of the structured block. |
| 6664 | // longjmp() and throw() must not violate the entry/exit criteria. |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6665 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 6666 | SourceLocation AtomicKindLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6667 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6668 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6669 | C->getClauseKind() == OMPC_update || |
| 6670 | C->getClauseKind() == OMPC_capture) { |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6671 | if (AtomicKind != OMPC_unknown) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6672 | Diag(C->getBeginLoc(), diag::err_omp_atomic_several_clauses) |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 6673 | << SourceRange(C->getBeginLoc(), C->getEndLoc()); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6674 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 6675 | << getOpenMPClauseName(AtomicKind); |
| 6676 | } else { |
| 6677 | AtomicKind = C->getClauseKind(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6678 | AtomicKindLoc = C->getBeginLoc(); |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6679 | } |
| 6680 | } |
| 6681 | } |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6682 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6683 | Stmt *Body = CS->getCapturedStmt(); |
| Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 6684 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 6685 | Body = EWC->getSubExpr(); |
| 6686 | |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6687 | Expr *X = nullptr; |
| 6688 | Expr *V = nullptr; |
| 6689 | Expr *E = nullptr; |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6690 | Expr *UE = nullptr; |
| 6691 | bool IsXLHSInRHSPart = false; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6692 | bool IsPostfixUpdate = false; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6693 | // OpenMP [2.12.6, atomic Construct] |
| 6694 | // In the next expressions: |
| 6695 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 6696 | // * During the execution of an atomic region, multiple syntactic |
| 6697 | // occurrences of x must designate the same storage location. |
| 6698 | // * Neither of v and expr (as applicable) may access the storage location |
| 6699 | // designated by x. |
| 6700 | // * Neither of x and expr (as applicable) may access the storage location |
| 6701 | // designated by v. |
| 6702 | // * expr is an expression with scalar type. |
| 6703 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 6704 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 6705 | // * The expression x binop expr must be numerically equivalent to x binop |
| 6706 | // (expr). This requirement is satisfied if the operators in expr have |
| 6707 | // precedence greater than binop, or by using parentheses around expr or |
| 6708 | // subexpressions of expr. |
| 6709 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 6710 | // binop x. This requirement is satisfied if the operators in expr have |
| 6711 | // precedence equal to or greater than binop, or by using parentheses around |
| 6712 | // expr or subexpressions of expr. |
| 6713 | // * For forms that allow multiple occurrences of x, the number of times |
| 6714 | // that x is evaluated is unspecified. |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6715 | if (AtomicKind == OMPC_read) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6716 | enum { |
| 6717 | NotAnExpression, |
| 6718 | NotAnAssignmentOp, |
| 6719 | NotAScalarType, |
| 6720 | NotAnLValue, |
| 6721 | NoError |
| 6722 | } ErrorFound = NoError; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6723 | SourceLocation ErrorLoc, NoteLoc; |
| 6724 | SourceRange ErrorRange, NoteRange; |
| 6725 | // If clause is read: |
| 6726 | // v = x; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6727 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6728 | const auto *AtomicBinOp = |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6729 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6730 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6731 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6732 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6733 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6734 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 6735 | if (!X->isLValue() || !V->isLValue()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6736 | const Expr *NotLValueExpr = X->isLValue() ? V : X; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6737 | ErrorFound = NotAnLValue; |
| 6738 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6739 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6740 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 6741 | NoteRange = NotLValueExpr->getSourceRange(); |
| 6742 | } |
| 6743 | } else if (!X->isInstantiationDependent() || |
| 6744 | !V->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6745 | const Expr *NotScalarExpr = |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6746 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6747 | ? V |
| 6748 | : X; |
| 6749 | ErrorFound = NotAScalarType; |
| 6750 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6751 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6752 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6753 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6754 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6755 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6756 | ErrorFound = NotAnAssignmentOp; |
| 6757 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6758 | ErrorRange = AtomicBody->getSourceRange(); |
| 6759 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6760 | : AtomicBody->getExprLoc(); |
| 6761 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6762 | : AtomicBody->getSourceRange(); |
| 6763 | } |
| 6764 | } else { |
| 6765 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6766 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6767 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6768 | } |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6769 | if (ErrorFound != NoError) { |
| 6770 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 6771 | << ErrorRange; |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6772 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6773 | << NoteRange; |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6774 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6775 | } |
| 6776 | if (CurContext->isDependentContext()) |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6777 | V = X = nullptr; |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6778 | } else if (AtomicKind == OMPC_write) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6779 | enum { |
| 6780 | NotAnExpression, |
| 6781 | NotAnAssignmentOp, |
| 6782 | NotAScalarType, |
| 6783 | NotAnLValue, |
| 6784 | NoError |
| 6785 | } ErrorFound = NoError; |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6786 | SourceLocation ErrorLoc, NoteLoc; |
| 6787 | SourceRange ErrorRange, NoteRange; |
| 6788 | // If clause is write: |
| 6789 | // x = expr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6790 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6791 | const auto *AtomicBinOp = |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6792 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6793 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 6794 | X = AtomicBinOp->getLHS(); |
| 6795 | E = AtomicBinOp->getRHS(); |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6796 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6797 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 6798 | if (!X->isLValue()) { |
| 6799 | ErrorFound = NotAnLValue; |
| 6800 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6801 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6802 | NoteLoc = X->getExprLoc(); |
| 6803 | NoteRange = X->getSourceRange(); |
| 6804 | } |
| 6805 | } else if (!X->isInstantiationDependent() || |
| 6806 | !E->isInstantiationDependent()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6807 | const Expr *NotScalarExpr = |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6808 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6809 | ? E |
| 6810 | : X; |
| 6811 | ErrorFound = NotAScalarType; |
| 6812 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6813 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6814 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6815 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6816 | } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6817 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6818 | ErrorFound = NotAnAssignmentOp; |
| 6819 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6820 | ErrorRange = AtomicBody->getSourceRange(); |
| 6821 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6822 | : AtomicBody->getExprLoc(); |
| 6823 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6824 | : AtomicBody->getSourceRange(); |
| 6825 | } |
| 6826 | } else { |
| 6827 | ErrorFound = NotAnExpression; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 6828 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6829 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6830 | } |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6831 | if (ErrorFound != NoError) { |
| 6832 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 6833 | << ErrorRange; |
| 6834 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6835 | << NoteRange; |
| 6836 | return StmtError(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6837 | } |
| 6838 | if (CurContext->isDependentContext()) |
| Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6839 | E = X = nullptr; |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6840 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6841 | // If clause is update: |
| 6842 | // x++; |
| 6843 | // x--; |
| 6844 | // ++x; |
| 6845 | // --x; |
| 6846 | // x binop= expr; |
| 6847 | // x = x binop expr; |
| 6848 | // x = expr binop x; |
| 6849 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6850 | if (Checker.checkStatement( |
| 6851 | Body, (AtomicKind == OMPC_update) |
| 6852 | ? diag::err_omp_atomic_update_not_expression_statement |
| 6853 | : diag::err_omp_atomic_not_expression_statement, |
| 6854 | diag::note_omp_atomic_update)) |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6855 | return StmtError(); |
| Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6856 | if (!CurContext->isDependentContext()) { |
| 6857 | E = Checker.getExpr(); |
| 6858 | X = Checker.getX(); |
| Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6859 | UE = Checker.getUpdateExpr(); |
| 6860 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6861 | } |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6862 | } else if (AtomicKind == OMPC_capture) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6863 | enum { |
| 6864 | NotAnAssignmentOp, |
| 6865 | NotACompoundStatement, |
| 6866 | NotTwoSubstatements, |
| 6867 | NotASpecificExpression, |
| 6868 | NoError |
| 6869 | } ErrorFound = NoError; |
| 6870 | SourceLocation ErrorLoc, NoteLoc; |
| 6871 | SourceRange ErrorRange, NoteRange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6872 | if (const auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6873 | // If clause is a capture: |
| 6874 | // v = x++; |
| 6875 | // v = x--; |
| 6876 | // v = ++x; |
| 6877 | // v = --x; |
| 6878 | // v = x binop= expr; |
| 6879 | // v = x = x binop expr; |
| 6880 | // v = x = expr binop x; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6881 | const auto *AtomicBinOp = |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6882 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6883 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6884 | V = AtomicBinOp->getLHS(); |
| 6885 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6886 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6887 | if (Checker.checkStatement( |
| 6888 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 6889 | diag::note_omp_atomic_update)) |
| 6890 | return StmtError(); |
| 6891 | E = Checker.getExpr(); |
| 6892 | X = Checker.getX(); |
| 6893 | UE = Checker.getUpdateExpr(); |
| 6894 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 6895 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6896 | } else if (!AtomicBody->isInstantiationDependent()) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6897 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6898 | ErrorRange = AtomicBody->getSourceRange(); |
| 6899 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6900 | : AtomicBody->getExprLoc(); |
| 6901 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6902 | : AtomicBody->getSourceRange(); |
| 6903 | ErrorFound = NotAnAssignmentOp; |
| 6904 | } |
| 6905 | if (ErrorFound != NoError) { |
| 6906 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 6907 | << ErrorRange; |
| 6908 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6909 | return StmtError(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6910 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6911 | if (CurContext->isDependentContext()) |
| 6912 | UE = V = E = X = nullptr; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6913 | } else { |
| 6914 | // If clause is a capture: |
| 6915 | // { v = x; x = expr; } |
| 6916 | // { v = x; x++; } |
| 6917 | // { v = x; x--; } |
| 6918 | // { v = x; ++x; } |
| 6919 | // { v = x; --x; } |
| 6920 | // { v = x; x binop= expr; } |
| 6921 | // { v = x; x = x binop expr; } |
| 6922 | // { v = x; x = expr binop x; } |
| 6923 | // { x++; v = x; } |
| 6924 | // { x--; v = x; } |
| 6925 | // { ++x; v = x; } |
| 6926 | // { --x; v = x; } |
| 6927 | // { x binop= expr; v = x; } |
| 6928 | // { x = x binop expr; v = x; } |
| 6929 | // { x = expr binop x; v = x; } |
| 6930 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 6931 | // Check that this is { expr1; expr2; } |
| 6932 | if (CS->size() == 2) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6933 | Stmt *First = CS->body_front(); |
| 6934 | Stmt *Second = CS->body_back(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6935 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 6936 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6937 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 6938 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6939 | // Need to find what subexpression is 'v' and what is 'x'. |
| 6940 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6941 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 6942 | BinaryOperator *BinOp = nullptr; |
| 6943 | if (IsUpdateExprFound) { |
| 6944 | BinOp = dyn_cast<BinaryOperator>(First); |
| 6945 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6946 | } |
| 6947 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6948 | // { v = x; x++; } |
| 6949 | // { v = x; x--; } |
| 6950 | // { v = x; ++x; } |
| 6951 | // { v = x; --x; } |
| 6952 | // { v = x; x binop= expr; } |
| 6953 | // { v = x; x = x binop expr; } |
| 6954 | // { v = x; x = expr binop x; } |
| 6955 | // Check that the first expression has form v = x. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6956 | Expr *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6957 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6958 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6959 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6960 | IsUpdateExprFound = XId == PossibleXId; |
| 6961 | if (IsUpdateExprFound) { |
| 6962 | V = BinOp->getLHS(); |
| 6963 | X = Checker.getX(); |
| 6964 | E = Checker.getExpr(); |
| 6965 | UE = Checker.getUpdateExpr(); |
| 6966 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6967 | IsPostfixUpdate = true; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6968 | } |
| 6969 | } |
| 6970 | if (!IsUpdateExprFound) { |
| 6971 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 6972 | BinOp = nullptr; |
| 6973 | if (IsUpdateExprFound) { |
| 6974 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 6975 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6976 | } |
| 6977 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6978 | // { x++; v = x; } |
| 6979 | // { x--; v = x; } |
| 6980 | // { ++x; v = x; } |
| 6981 | // { --x; v = x; } |
| 6982 | // { x binop= expr; v = x; } |
| 6983 | // { x = x binop expr; v = x; } |
| 6984 | // { x = expr binop x; v = x; } |
| 6985 | // Check that the second expression has form v = x. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 6986 | Expr *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6987 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6988 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6989 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6990 | IsUpdateExprFound = XId == PossibleXId; |
| 6991 | if (IsUpdateExprFound) { |
| 6992 | V = BinOp->getLHS(); |
| 6993 | X = Checker.getX(); |
| 6994 | E = Checker.getExpr(); |
| 6995 | UE = Checker.getUpdateExpr(); |
| 6996 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6997 | IsPostfixUpdate = false; |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6998 | } |
| 6999 | } |
| 7000 | } |
| 7001 | if (!IsUpdateExprFound) { |
| 7002 | // { v = x; x = expr; } |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 7003 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 7004 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 7005 | if (!FirstExpr || !SecondExpr || |
| 7006 | !(FirstExpr->isInstantiationDependent() || |
| 7007 | SecondExpr->isInstantiationDependent())) { |
| 7008 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 7009 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7010 | ErrorFound = NotAnAssignmentOp; |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 7011 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7012 | : First->getBeginLoc(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 7013 | NoteRange = ErrorRange = FirstBinOp |
| 7014 | ? FirstBinOp->getSourceRange() |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7015 | : SourceRange(ErrorLoc, ErrorLoc); |
| 7016 | } else { |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 7017 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 7018 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 7019 | ErrorFound = NotAnAssignmentOp; |
| 7020 | NoteLoc = ErrorLoc = SecondBinOp |
| 7021 | ? SecondBinOp->getOperatorLoc() |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7022 | : Second->getBeginLoc(); |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 7023 | NoteRange = ErrorRange = |
| 7024 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 7025 | : SourceRange(ErrorLoc, ErrorLoc); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7026 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7027 | Expr *PossibleXRHSInFirst = |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 7028 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7029 | Expr *PossibleXLHSInSecond = |
| Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 7030 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 7031 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 7032 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 7033 | /*Canonical=*/true); |
| 7034 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 7035 | /*Canonical=*/true); |
| 7036 | IsUpdateExprFound = X1Id == X2Id; |
| 7037 | if (IsUpdateExprFound) { |
| 7038 | V = FirstBinOp->getLHS(); |
| 7039 | X = SecondBinOp->getLHS(); |
| 7040 | E = SecondBinOp->getRHS(); |
| 7041 | UE = nullptr; |
| 7042 | IsXLHSInRHSPart = false; |
| 7043 | IsPostfixUpdate = true; |
| 7044 | } else { |
| 7045 | ErrorFound = NotASpecificExpression; |
| 7046 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 7047 | ErrorRange = FirstBinOp->getSourceRange(); |
| 7048 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 7049 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 7050 | } |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7051 | } |
| 7052 | } |
| 7053 | } |
| 7054 | } |
| 7055 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7056 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7057 | NoteRange = ErrorRange = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7058 | SourceRange(Body->getBeginLoc(), Body->getBeginLoc()); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7059 | ErrorFound = NotTwoSubstatements; |
| 7060 | } |
| 7061 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7062 | NoteLoc = ErrorLoc = Body->getBeginLoc(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7063 | NoteRange = ErrorRange = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7064 | SourceRange(Body->getBeginLoc(), Body->getBeginLoc()); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7065 | ErrorFound = NotACompoundStatement; |
| 7066 | } |
| 7067 | if (ErrorFound != NoError) { |
| 7068 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 7069 | << ErrorRange; |
| 7070 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 7071 | return StmtError(); |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7072 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7073 | if (CurContext->isDependentContext()) |
| 7074 | UE = V = E = X = nullptr; |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7075 | } |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7076 | } |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 7077 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7078 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 7079 | |
| Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 7080 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 7081 | X, V, E, UE, IsXLHSInRHSPart, |
| 7082 | IsPostfixUpdate); |
| Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 7083 | } |
| 7084 | |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 7085 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 7086 | Stmt *AStmt, |
| 7087 | SourceLocation StartLoc, |
| 7088 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7089 | if (!AStmt) |
| 7090 | return StmtError(); |
| 7091 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7092 | auto *CS = cast<CapturedStmt>(AStmt); |
| Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 7093 | // 1.2.2 OpenMP Language Terminology |
| 7094 | // Structured block - An executable statement with a single entry at the |
| 7095 | // top and a single exit at the bottom. |
| 7096 | // The point of exit cannot be a branch out of the structured block. |
| 7097 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7098 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 7099 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target); |
| 7100 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7101 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7102 | // 1.2.2 OpenMP Language Terminology |
| 7103 | // Structured block - An executable statement with a single entry at the |
| 7104 | // top and a single exit at the bottom. |
| 7105 | // The point of exit cannot be a branch out of the structured block. |
| 7106 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7107 | CS->getCapturedDecl()->setNothrow(); |
| 7108 | } |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 7109 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7110 | // OpenMP [2.16, Nesting of Regions] |
| 7111 | // If specified, a teams construct must be contained within a target |
| 7112 | // construct. That target construct must contain no statements or directives |
| 7113 | // outside of the teams construct. |
| 7114 | if (DSAStack->hasInnerTeamsRegion()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7115 | const Stmt *S = CS->IgnoreContainers(/*IgnoreCaptured=*/true); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7116 | bool OMPTeamsFound = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7117 | if (const auto *CS = dyn_cast<CompoundStmt>(S)) { |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7118 | auto I = CS->body_begin(); |
| 7119 | while (I != CS->body_end()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7120 | const auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
| Kelvin Li | 620ba60 | 2019-02-05 16:43:00 +0000 | [diff] [blame] | 7121 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind()) || |
| 7122 | OMPTeamsFound) { |
| 7123 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7124 | OMPTeamsFound = false; |
| 7125 | break; |
| 7126 | } |
| 7127 | ++I; |
| 7128 | } |
| 7129 | assert(I != CS->body_end() && "Not found statement"); |
| 7130 | S = *I; |
| Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 7131 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7132 | const auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 7133 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7134 | } |
| 7135 | if (!OMPTeamsFound) { |
| 7136 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 7137 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 7138 | diag::note_omp_nested_teams_construct_here); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7139 | Diag(S->getBeginLoc(), diag::note_omp_nested_statement_here) |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7140 | << isa<OMPExecutableDirective>(S); |
| 7141 | return StmtError(); |
| 7142 | } |
| 7143 | } |
| 7144 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7145 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 7146 | |
| 7147 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 7148 | } |
| 7149 | |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 7150 | StmtResult |
| 7151 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 7152 | Stmt *AStmt, SourceLocation StartLoc, |
| 7153 | SourceLocation EndLoc) { |
| 7154 | if (!AStmt) |
| 7155 | return StmtError(); |
| 7156 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7157 | auto *CS = cast<CapturedStmt>(AStmt); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 7158 | // 1.2.2 OpenMP Language Terminology |
| 7159 | // Structured block - An executable statement with a single entry at the |
| 7160 | // top and a single exit at the bottom. |
| 7161 | // The point of exit cannot be a branch out of the structured block. |
| 7162 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7163 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 7164 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel); |
| 7165 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7166 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7167 | // 1.2.2 OpenMP Language Terminology |
| 7168 | // Structured block - An executable statement with a single entry at the |
| 7169 | // top and a single exit at the bottom. |
| 7170 | // The point of exit cannot be a branch out of the structured block. |
| 7171 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7172 | CS->getCapturedDecl()->setNothrow(); |
| 7173 | } |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 7174 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7175 | setFunctionHasBranchProtectedScope(); |
| Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 7176 | |
| 7177 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7178 | AStmt); |
| 7179 | } |
| 7180 | |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7181 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 7182 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7183 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7184 | if (!AStmt) |
| 7185 | return StmtError(); |
| 7186 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7187 | auto *CS = cast<CapturedStmt>(AStmt); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7188 | // 1.2.2 OpenMP Language Terminology |
| 7189 | // Structured block - An executable statement with a single entry at the |
| 7190 | // top and a single exit at the bottom. |
| 7191 | // The point of exit cannot be a branch out of the structured block. |
| 7192 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7193 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 7194 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel_for); |
| 7195 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7196 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7197 | // 1.2.2 OpenMP Language Terminology |
| 7198 | // Structured block - An executable statement with a single entry at the |
| 7199 | // top and a single exit at the bottom. |
| 7200 | // The point of exit cannot be a branch out of the structured block. |
| 7201 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7202 | CS->getCapturedDecl()->setNothrow(); |
| 7203 | } |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7204 | |
| 7205 | OMPLoopDirective::HelperExprs B; |
| 7206 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7207 | // define the nested loops number. |
| 7208 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7209 | checkOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 7210 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7211 | VarsWithImplicitDSA, B); |
| 7212 | if (NestedLoopCount == 0) |
| 7213 | return StmtError(); |
| 7214 | |
| 7215 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7216 | "omp target parallel for loop exprs were not built"); |
| 7217 | |
| 7218 | if (!CurContext->isDependentContext()) { |
| 7219 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7220 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7221 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7222 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7223 | B.NumIterations, *this, CurScope, |
| 7224 | DSAStack)) |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7225 | return StmtError(); |
| 7226 | } |
| 7227 | } |
| 7228 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7229 | setFunctionHasBranchProtectedScope(); |
| Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 7230 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 7231 | NestedLoopCount, Clauses, AStmt, |
| 7232 | B, DSAStack->isCancelRegion()); |
| 7233 | } |
| 7234 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 7235 | /// Check for existence of a map clause in the list of clauses. |
| 7236 | static bool hasClauses(ArrayRef<OMPClause *> Clauses, |
| 7237 | const OpenMPClauseKind K) { |
| 7238 | return llvm::any_of( |
| 7239 | Clauses, [K](const OMPClause *C) { return C->getClauseKind() == K; }); |
| 7240 | } |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7241 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 7242 | template <typename... Params> |
| 7243 | static bool hasClauses(ArrayRef<OMPClause *> Clauses, const OpenMPClauseKind K, |
| 7244 | const Params... ClauseTypes) { |
| 7245 | return hasClauses(Clauses, K) || hasClauses(Clauses, ClauseTypes...); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7246 | } |
| 7247 | |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 7248 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 7249 | Stmt *AStmt, |
| 7250 | SourceLocation StartLoc, |
| 7251 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7252 | if (!AStmt) |
| 7253 | return StmtError(); |
| 7254 | |
| 7255 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7256 | |
| Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 7257 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 7258 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 7259 | if (!hasClauses(Clauses, OMPC_map, OMPC_use_device_ptr)) { |
| 7260 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 7261 | << "'map' or 'use_device_ptr'" |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7262 | << getOpenMPDirectiveName(OMPD_target_data); |
| Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 7263 | return StmtError(); |
| 7264 | } |
| 7265 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7266 | setFunctionHasBranchProtectedScope(); |
| Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 7267 | |
| 7268 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7269 | AStmt); |
| 7270 | } |
| 7271 | |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7272 | StmtResult |
| 7273 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 7274 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7275 | SourceLocation EndLoc, Stmt *AStmt) { |
| 7276 | if (!AStmt) |
| 7277 | return StmtError(); |
| 7278 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7279 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7280 | // 1.2.2 OpenMP Language Terminology |
| 7281 | // Structured block - An executable statement with a single entry at the |
| 7282 | // top and a single exit at the bottom. |
| 7283 | // The point of exit cannot be a branch out of the structured block. |
| 7284 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7285 | CS->getCapturedDecl()->setNothrow(); |
| 7286 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_enter_data); |
| 7287 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7288 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7289 | // 1.2.2 OpenMP Language Terminology |
| 7290 | // Structured block - An executable statement with a single entry at the |
| 7291 | // top and a single exit at the bottom. |
| 7292 | // The point of exit cannot be a branch out of the structured block. |
| 7293 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7294 | CS->getCapturedDecl()->setNothrow(); |
| 7295 | } |
| 7296 | |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7297 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 7298 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 7299 | if (!hasClauses(Clauses, OMPC_map)) { |
| 7300 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 7301 | << "'map'" << getOpenMPDirectiveName(OMPD_target_enter_data); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7302 | return StmtError(); |
| 7303 | } |
| 7304 | |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7305 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7306 | AStmt); |
| Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7307 | } |
| 7308 | |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 7309 | StmtResult |
| 7310 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 7311 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7312 | SourceLocation EndLoc, Stmt *AStmt) { |
| 7313 | if (!AStmt) |
| 7314 | return StmtError(); |
| 7315 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7316 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7317 | // 1.2.2 OpenMP Language Terminology |
| 7318 | // Structured block - An executable statement with a single entry at the |
| 7319 | // top and a single exit at the bottom. |
| 7320 | // The point of exit cannot be a branch out of the structured block. |
| 7321 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7322 | CS->getCapturedDecl()->setNothrow(); |
| 7323 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_exit_data); |
| 7324 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7325 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7326 | // 1.2.2 OpenMP Language Terminology |
| 7327 | // Structured block - An executable statement with a single entry at the |
| 7328 | // top and a single exit at the bottom. |
| 7329 | // The point of exit cannot be a branch out of the structured block. |
| 7330 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7331 | CS->getCapturedDecl()->setNothrow(); |
| 7332 | } |
| 7333 | |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 7334 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 7335 | // At least one map clause must appear on the directive. |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 7336 | if (!hasClauses(Clauses, OMPC_map)) { |
| 7337 | Diag(StartLoc, diag::err_omp_no_clause_for_directive) |
| 7338 | << "'map'" << getOpenMPDirectiveName(OMPD_target_exit_data); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 7339 | return StmtError(); |
| 7340 | } |
| 7341 | |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7342 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7343 | AStmt); |
| Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 7344 | } |
| 7345 | |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7346 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 7347 | SourceLocation StartLoc, |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7348 | SourceLocation EndLoc, |
| 7349 | Stmt *AStmt) { |
| 7350 | if (!AStmt) |
| 7351 | return StmtError(); |
| 7352 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7353 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7354 | // 1.2.2 OpenMP Language Terminology |
| 7355 | // Structured block - An executable statement with a single entry at the |
| 7356 | // top and a single exit at the bottom. |
| 7357 | // The point of exit cannot be a branch out of the structured block. |
| 7358 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7359 | CS->getCapturedDecl()->setNothrow(); |
| 7360 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_update); |
| 7361 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7362 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7363 | // 1.2.2 OpenMP Language Terminology |
| 7364 | // Structured block - An executable statement with a single entry at the |
| 7365 | // top and a single exit at the bottom. |
| 7366 | // The point of exit cannot be a branch out of the structured block. |
| 7367 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7368 | CS->getCapturedDecl()->setNothrow(); |
| 7369 | } |
| 7370 | |
| Alexey Bataev | 95b64a9 | 2017-05-30 16:00:04 +0000 | [diff] [blame] | 7371 | if (!hasClauses(Clauses, OMPC_to, OMPC_from)) { |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7372 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 7373 | return StmtError(); |
| 7374 | } |
| Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 7375 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7376 | AStmt); |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7377 | } |
| 7378 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7379 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 7380 | Stmt *AStmt, SourceLocation StartLoc, |
| 7381 | SourceLocation EndLoc) { |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7382 | if (!AStmt) |
| 7383 | return StmtError(); |
| 7384 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7385 | auto *CS = cast<CapturedStmt>(AStmt); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7386 | // 1.2.2 OpenMP Language Terminology |
| 7387 | // Structured block - An executable statement with a single entry at the |
| 7388 | // top and a single exit at the bottom. |
| 7389 | // The point of exit cannot be a branch out of the structured block. |
| 7390 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7391 | CS->getCapturedDecl()->setNothrow(); |
| 7392 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7393 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7394 | |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 7395 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 7396 | |
| Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7397 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 7398 | } |
| 7399 | |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7400 | StmtResult |
| 7401 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 7402 | SourceLocation EndLoc, |
| 7403 | OpenMPDirectiveKind CancelRegion) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7404 | if (DSAStack->isParentNowaitRegion()) { |
| 7405 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 7406 | return StmtError(); |
| 7407 | } |
| 7408 | if (DSAStack->isParentOrderedRegion()) { |
| 7409 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 7410 | return StmtError(); |
| 7411 | } |
| 7412 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 7413 | CancelRegion); |
| 7414 | } |
| 7415 | |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 7416 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 7417 | SourceLocation StartLoc, |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7418 | SourceLocation EndLoc, |
| 7419 | OpenMPDirectiveKind CancelRegion) { |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7420 | if (DSAStack->isParentNowaitRegion()) { |
| 7421 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 7422 | return StmtError(); |
| 7423 | } |
| 7424 | if (DSAStack->isParentOrderedRegion()) { |
| 7425 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 7426 | return StmtError(); |
| 7427 | } |
| Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 7428 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
| Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 7429 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7430 | CancelRegion); |
| Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7431 | } |
| 7432 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7433 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 7434 | ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7435 | const OMPClause *PrevClause = nullptr; |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7436 | bool ErrorFound = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7437 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7438 | if (C->getClauseKind() == OMPC_grainsize || |
| 7439 | C->getClauseKind() == OMPC_num_tasks) { |
| 7440 | if (!PrevClause) |
| 7441 | PrevClause = C; |
| 7442 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7443 | S.Diag(C->getBeginLoc(), |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7444 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 7445 | << getOpenMPClauseName(C->getClauseKind()) |
| 7446 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7447 | S.Diag(PrevClause->getBeginLoc(), |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7448 | diag::note_omp_previous_grainsize_num_tasks) |
| 7449 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 7450 | ErrorFound = true; |
| 7451 | } |
| 7452 | } |
| 7453 | } |
| 7454 | return ErrorFound; |
| 7455 | } |
| 7456 | |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7457 | static bool checkReductionClauseWithNogroup(Sema &S, |
| 7458 | ArrayRef<OMPClause *> Clauses) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7459 | const OMPClause *ReductionClause = nullptr; |
| 7460 | const OMPClause *NogroupClause = nullptr; |
| 7461 | for (const OMPClause *C : Clauses) { |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7462 | if (C->getClauseKind() == OMPC_reduction) { |
| 7463 | ReductionClause = C; |
| 7464 | if (NogroupClause) |
| 7465 | break; |
| 7466 | continue; |
| 7467 | } |
| 7468 | if (C->getClauseKind() == OMPC_nogroup) { |
| 7469 | NogroupClause = C; |
| 7470 | if (ReductionClause) |
| 7471 | break; |
| 7472 | continue; |
| 7473 | } |
| 7474 | } |
| 7475 | if (ReductionClause && NogroupClause) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 7476 | S.Diag(ReductionClause->getBeginLoc(), diag::err_omp_reduction_with_nogroup) |
| 7477 | << SourceRange(NogroupClause->getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 7478 | NogroupClause->getEndLoc()); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7479 | return true; |
| 7480 | } |
| 7481 | return false; |
| 7482 | } |
| 7483 | |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7484 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 7485 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7486 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7487 | if (!AStmt) |
| 7488 | return StmtError(); |
| 7489 | |
| 7490 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7491 | OMPLoopDirective::HelperExprs B; |
| 7492 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7493 | // define the nested loops number. |
| 7494 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7495 | checkOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7496 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7497 | VarsWithImplicitDSA, B); |
| 7498 | if (NestedLoopCount == 0) |
| 7499 | return StmtError(); |
| 7500 | |
| 7501 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7502 | "omp for loop exprs were not built"); |
| 7503 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7504 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7505 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7506 | // not appear on the same taskloop directive. |
| 7507 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7508 | return StmtError(); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7509 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7510 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 7511 | // clause must not be specified. |
| 7512 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 7513 | return StmtError(); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7514 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7515 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7516 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 7517 | NestedLoopCount, Clauses, AStmt, B); |
| 7518 | } |
| 7519 | |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7520 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 7521 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7522 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7523 | if (!AStmt) |
| 7524 | return StmtError(); |
| 7525 | |
| 7526 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7527 | OMPLoopDirective::HelperExprs B; |
| 7528 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7529 | // define the nested loops number. |
| 7530 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7531 | checkOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7532 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 7533 | VarsWithImplicitDSA, B); |
| 7534 | if (NestedLoopCount == 0) |
| 7535 | return StmtError(); |
| 7536 | |
| 7537 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7538 | "omp for loop exprs were not built"); |
| 7539 | |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7540 | if (!CurContext->isDependentContext()) { |
| 7541 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7542 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7543 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7544 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7545 | B.NumIterations, *this, CurScope, |
| 7546 | DSAStack)) |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7547 | return StmtError(); |
| 7548 | } |
| 7549 | } |
| 7550 | |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7551 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7552 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7553 | // not appear on the same taskloop directive. |
| 7554 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7555 | return StmtError(); |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 7556 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7557 | // If a reduction clause is present on the taskloop directive, the nogroup |
| 7558 | // clause must not be specified. |
| 7559 | if (checkReductionClauseWithNogroup(*this, Clauses)) |
| 7560 | return StmtError(); |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7561 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7562 | return StmtError(); |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7563 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7564 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7565 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7566 | NestedLoopCount, Clauses, AStmt, B); |
| 7567 | } |
| 7568 | |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7569 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 7570 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7571 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7572 | if (!AStmt) |
| 7573 | return StmtError(); |
| 7574 | |
| 7575 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7576 | OMPLoopDirective::HelperExprs B; |
| 7577 | // In presence of clause 'collapse' with number of loops, it will |
| 7578 | // define the nested loops number. |
| 7579 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7580 | checkOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7581 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7582 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7583 | if (NestedLoopCount == 0) |
| 7584 | return StmtError(); |
| 7585 | |
| 7586 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7587 | "omp for loop exprs were not built"); |
| 7588 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7589 | setFunctionHasBranchProtectedScope(); |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7590 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 7591 | NestedLoopCount, Clauses, AStmt, B); |
| 7592 | } |
| 7593 | |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7594 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 7595 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7596 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7597 | if (!AStmt) |
| 7598 | return StmtError(); |
| 7599 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7600 | auto *CS = cast<CapturedStmt>(AStmt); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7601 | // 1.2.2 OpenMP Language Terminology |
| 7602 | // Structured block - An executable statement with a single entry at the |
| 7603 | // top and a single exit at the bottom. |
| 7604 | // The point of exit cannot be a branch out of the structured block. |
| 7605 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7606 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 7607 | for (int ThisCaptureLevel = |
| 7608 | getOpenMPCaptureLevels(OMPD_distribute_parallel_for); |
| 7609 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7610 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7611 | // 1.2.2 OpenMP Language Terminology |
| 7612 | // Structured block - An executable statement with a single entry at the |
| 7613 | // top and a single exit at the bottom. |
| 7614 | // The point of exit cannot be a branch out of the structured block. |
| 7615 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7616 | CS->getCapturedDecl()->setNothrow(); |
| 7617 | } |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7618 | |
| 7619 | OMPLoopDirective::HelperExprs B; |
| 7620 | // In presence of clause 'collapse' with number of loops, it will |
| 7621 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7622 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7623 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 7624 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7625 | VarsWithImplicitDSA, B); |
| 7626 | if (NestedLoopCount == 0) |
| 7627 | return StmtError(); |
| 7628 | |
| 7629 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7630 | "omp for loop exprs were not built"); |
| 7631 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7632 | setFunctionHasBranchProtectedScope(); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7633 | return OMPDistributeParallelForDirective::Create( |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 7634 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 7635 | DSAStack->isCancelRegion()); |
| Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7636 | } |
| 7637 | |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7638 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 7639 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7640 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7641 | if (!AStmt) |
| 7642 | return StmtError(); |
| 7643 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7644 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7645 | // 1.2.2 OpenMP Language Terminology |
| 7646 | // Structured block - An executable statement with a single entry at the |
| 7647 | // top and a single exit at the bottom. |
| 7648 | // The point of exit cannot be a branch out of the structured block. |
| 7649 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7650 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 7651 | for (int ThisCaptureLevel = |
| 7652 | getOpenMPCaptureLevels(OMPD_distribute_parallel_for_simd); |
| 7653 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7654 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7655 | // 1.2.2 OpenMP Language Terminology |
| 7656 | // Structured block - An executable statement with a single entry at the |
| 7657 | // top and a single exit at the bottom. |
| 7658 | // The point of exit cannot be a branch out of the structured block. |
| 7659 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7660 | CS->getCapturedDecl()->setNothrow(); |
| 7661 | } |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7662 | |
| 7663 | OMPLoopDirective::HelperExprs B; |
| 7664 | // In presence of clause 'collapse' with number of loops, it will |
| 7665 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7666 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7667 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 7668 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7669 | VarsWithImplicitDSA, B); |
| 7670 | if (NestedLoopCount == 0) |
| 7671 | return StmtError(); |
| 7672 | |
| 7673 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7674 | "omp for loop exprs were not built"); |
| 7675 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7676 | if (!CurContext->isDependentContext()) { |
| 7677 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7678 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7679 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7680 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7681 | B.NumIterations, *this, CurScope, |
| 7682 | DSAStack)) |
| 7683 | return StmtError(); |
| 7684 | } |
| 7685 | } |
| 7686 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7687 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7688 | return StmtError(); |
| 7689 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7690 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7691 | return OMPDistributeParallelForSimdDirective::Create( |
| 7692 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7693 | } |
| 7694 | |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7695 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 7696 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7697 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7698 | if (!AStmt) |
| 7699 | return StmtError(); |
| 7700 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7701 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7702 | // 1.2.2 OpenMP Language Terminology |
| 7703 | // Structured block - An executable statement with a single entry at the |
| 7704 | // top and a single exit at the bottom. |
| 7705 | // The point of exit cannot be a branch out of the structured block. |
| 7706 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7707 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 617db5f | 2017-12-04 15:38:33 +0000 | [diff] [blame] | 7708 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_distribute_simd); |
| 7709 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7710 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7711 | // 1.2.2 OpenMP Language Terminology |
| 7712 | // Structured block - An executable statement with a single entry at the |
| 7713 | // top and a single exit at the bottom. |
| 7714 | // The point of exit cannot be a branch out of the structured block. |
| 7715 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7716 | CS->getCapturedDecl()->setNothrow(); |
| 7717 | } |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7718 | |
| 7719 | OMPLoopDirective::HelperExprs B; |
| 7720 | // In presence of clause 'collapse' with number of loops, it will |
| 7721 | // define the nested loops number. |
| 7722 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7723 | checkOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 617db5f | 2017-12-04 15:38:33 +0000 | [diff] [blame] | 7724 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 7725 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7726 | if (NestedLoopCount == 0) |
| 7727 | return StmtError(); |
| 7728 | |
| 7729 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7730 | "omp for loop exprs were not built"); |
| 7731 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7732 | if (!CurContext->isDependentContext()) { |
| 7733 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7734 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 7735 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7736 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7737 | B.NumIterations, *this, CurScope, |
| 7738 | DSAStack)) |
| 7739 | return StmtError(); |
| 7740 | } |
| 7741 | } |
| 7742 | |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7743 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7744 | return StmtError(); |
| 7745 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7746 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7747 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7748 | NestedLoopCount, Clauses, AStmt, B); |
| 7749 | } |
| 7750 | |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7751 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 7752 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7753 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7754 | if (!AStmt) |
| 7755 | return StmtError(); |
| 7756 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7757 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7758 | // 1.2.2 OpenMP Language Terminology |
| 7759 | // Structured block - An executable statement with a single entry at the |
| 7760 | // top and a single exit at the bottom. |
| 7761 | // The point of exit cannot be a branch out of the structured block. |
| 7762 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7763 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 7764 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_parallel_for); |
| 7765 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7766 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7767 | // 1.2.2 OpenMP Language Terminology |
| 7768 | // Structured block - An executable statement with a single entry at the |
| 7769 | // top and a single exit at the bottom. |
| 7770 | // The point of exit cannot be a branch out of the structured block. |
| 7771 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7772 | CS->getCapturedDecl()->setNothrow(); |
| 7773 | } |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7774 | |
| 7775 | OMPLoopDirective::HelperExprs B; |
| 7776 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7777 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7778 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7779 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 7780 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7781 | VarsWithImplicitDSA, B); |
| 7782 | if (NestedLoopCount == 0) |
| 7783 | return StmtError(); |
| 7784 | |
| 7785 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7786 | "omp target parallel for simd loop exprs were not built"); |
| 7787 | |
| 7788 | if (!CurContext->isDependentContext()) { |
| 7789 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7790 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7791 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7792 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7793 | B.NumIterations, *this, CurScope, |
| 7794 | DSAStack)) |
| 7795 | return StmtError(); |
| 7796 | } |
| 7797 | } |
| Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7798 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7799 | return StmtError(); |
| 7800 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7801 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7802 | return OMPTargetParallelForSimdDirective::Create( |
| 7803 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7804 | } |
| 7805 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7806 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 7807 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7808 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7809 | if (!AStmt) |
| 7810 | return StmtError(); |
| 7811 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7812 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7813 | // 1.2.2 OpenMP Language Terminology |
| 7814 | // Structured block - An executable statement with a single entry at the |
| 7815 | // top and a single exit at the bottom. |
| 7816 | // The point of exit cannot be a branch out of the structured block. |
| 7817 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7818 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | f836537 | 2017-11-17 17:57:25 +0000 | [diff] [blame] | 7819 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_simd); |
| 7820 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7821 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7822 | // 1.2.2 OpenMP Language Terminology |
| 7823 | // Structured block - An executable statement with a single entry at the |
| 7824 | // top and a single exit at the bottom. |
| 7825 | // The point of exit cannot be a branch out of the structured block. |
| 7826 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7827 | CS->getCapturedDecl()->setNothrow(); |
| 7828 | } |
| 7829 | |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7830 | OMPLoopDirective::HelperExprs B; |
| 7831 | // In presence of clause 'collapse' with number of loops, it will define the |
| 7832 | // nested loops number. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7833 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7834 | checkOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | f836537 | 2017-11-17 17:57:25 +0000 | [diff] [blame] | 7835 | getOrderedNumberExpr(Clauses), CS, *this, *DSAStack, |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7836 | VarsWithImplicitDSA, B); |
| 7837 | if (NestedLoopCount == 0) |
| 7838 | return StmtError(); |
| 7839 | |
| 7840 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7841 | "omp target simd loop exprs were not built"); |
| 7842 | |
| 7843 | if (!CurContext->isDependentContext()) { |
| 7844 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7845 | for (OMPClause *C : Clauses) { |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7846 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7847 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7848 | B.NumIterations, *this, CurScope, |
| 7849 | DSAStack)) |
| 7850 | return StmtError(); |
| 7851 | } |
| 7852 | } |
| 7853 | |
| 7854 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7855 | return StmtError(); |
| 7856 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7857 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7858 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7859 | NestedLoopCount, Clauses, AStmt, B); |
| 7860 | } |
| 7861 | |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7862 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 7863 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7864 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7865 | if (!AStmt) |
| 7866 | return StmtError(); |
| 7867 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7868 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7869 | // 1.2.2 OpenMP Language Terminology |
| 7870 | // Structured block - An executable statement with a single entry at the |
| 7871 | // top and a single exit at the bottom. |
| 7872 | // The point of exit cannot be a branch out of the structured block. |
| 7873 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7874 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 95c6dd4 | 2017-11-29 15:14:16 +0000 | [diff] [blame] | 7875 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_teams_distribute); |
| 7876 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7877 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7878 | // 1.2.2 OpenMP Language Terminology |
| 7879 | // Structured block - An executable statement with a single entry at the |
| 7880 | // top and a single exit at the bottom. |
| 7881 | // The point of exit cannot be a branch out of the structured block. |
| 7882 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7883 | CS->getCapturedDecl()->setNothrow(); |
| 7884 | } |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7885 | |
| 7886 | OMPLoopDirective::HelperExprs B; |
| 7887 | // In presence of clause 'collapse' with number of loops, it will |
| 7888 | // define the nested loops number. |
| 7889 | unsigned NestedLoopCount = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7890 | checkOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 95c6dd4 | 2017-11-29 15:14:16 +0000 | [diff] [blame] | 7891 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 7892 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7893 | if (NestedLoopCount == 0) |
| 7894 | return StmtError(); |
| 7895 | |
| 7896 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7897 | "omp teams distribute loop exprs were not built"); |
| 7898 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7899 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 7900 | |
| 7901 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 7902 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7903 | return OMPTeamsDistributeDirective::Create( |
| 7904 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7905 | } |
| 7906 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7907 | StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective( |
| 7908 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7909 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7910 | if (!AStmt) |
| 7911 | return StmtError(); |
| 7912 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7913 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7914 | // 1.2.2 OpenMP Language Terminology |
| 7915 | // Structured block - An executable statement with a single entry at the |
| 7916 | // top and a single exit at the bottom. |
| 7917 | // The point of exit cannot be a branch out of the structured block. |
| 7918 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7919 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 7920 | for (int ThisCaptureLevel = |
| 7921 | getOpenMPCaptureLevels(OMPD_teams_distribute_simd); |
| 7922 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7923 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7924 | // 1.2.2 OpenMP Language Terminology |
| 7925 | // Structured block - An executable statement with a single entry at the |
| 7926 | // top and a single exit at the bottom. |
| 7927 | // The point of exit cannot be a branch out of the structured block. |
| 7928 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7929 | CS->getCapturedDecl()->setNothrow(); |
| 7930 | } |
| 7931 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7932 | |
| 7933 | OMPLoopDirective::HelperExprs B; |
| 7934 | // In presence of clause 'collapse' with number of loops, it will |
| 7935 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7936 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 7937 | OMPD_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | 999277a | 2017-12-06 14:31:09 +0000 | [diff] [blame] | 7938 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 7939 | VarsWithImplicitDSA, B); |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7940 | |
| 7941 | if (NestedLoopCount == 0) |
| 7942 | return StmtError(); |
| 7943 | |
| 7944 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7945 | "omp teams distribute simd loop exprs were not built"); |
| 7946 | |
| 7947 | if (!CurContext->isDependentContext()) { |
| 7948 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7949 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7950 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 7951 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7952 | B.NumIterations, *this, CurScope, |
| 7953 | DSAStack)) |
| 7954 | return StmtError(); |
| 7955 | } |
| 7956 | } |
| 7957 | |
| 7958 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7959 | return StmtError(); |
| 7960 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 7961 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 7962 | |
| 7963 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 7964 | |
| Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 7965 | return OMPTeamsDistributeSimdDirective::Create( |
| 7966 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7967 | } |
| 7968 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7969 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 7970 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7971 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7972 | if (!AStmt) |
| 7973 | return StmtError(); |
| 7974 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7975 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7976 | // 1.2.2 OpenMP Language Terminology |
| 7977 | // Structured block - An executable statement with a single entry at the |
| 7978 | // top and a single exit at the bottom. |
| 7979 | // The point of exit cannot be a branch out of the structured block. |
| 7980 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7981 | CS->getCapturedDecl()->setNothrow(); |
| 7982 | |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 7983 | for (int ThisCaptureLevel = |
| 7984 | getOpenMPCaptureLevels(OMPD_teams_distribute_parallel_for_simd); |
| 7985 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 7986 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 7987 | // 1.2.2 OpenMP Language Terminology |
| 7988 | // Structured block - An executable statement with a single entry at the |
| 7989 | // top and a single exit at the bottom. |
| 7990 | // The point of exit cannot be a branch out of the structured block. |
| 7991 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7992 | CS->getCapturedDecl()->setNothrow(); |
| 7993 | } |
| 7994 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7995 | OMPLoopDirective::HelperExprs B; |
| 7996 | // In presence of clause 'collapse' with number of loops, it will |
| 7997 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 7998 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7999 | OMPD_teams_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 56a2aa4 | 2017-12-04 20:57:19 +0000 | [diff] [blame] | 8000 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8001 | VarsWithImplicitDSA, B); |
| 8002 | |
| 8003 | if (NestedLoopCount == 0) |
| 8004 | return StmtError(); |
| 8005 | |
| 8006 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 8007 | "omp for loop exprs were not built"); |
| 8008 | |
| 8009 | if (!CurContext->isDependentContext()) { |
| 8010 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8011 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8012 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 8013 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 8014 | B.NumIterations, *this, CurScope, |
| 8015 | DSAStack)) |
| 8016 | return StmtError(); |
| 8017 | } |
| 8018 | } |
| 8019 | |
| 8020 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 8021 | return StmtError(); |
| 8022 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8023 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 8024 | |
| 8025 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 8026 | |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8027 | return OMPTeamsDistributeParallelForSimdDirective::Create( |
| 8028 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 8029 | } |
| 8030 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8031 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective( |
| 8032 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8033 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8034 | if (!AStmt) |
| 8035 | return StmtError(); |
| 8036 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8037 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8038 | // 1.2.2 OpenMP Language Terminology |
| 8039 | // Structured block - An executable statement with a single entry at the |
| 8040 | // top and a single exit at the bottom. |
| 8041 | // The point of exit cannot be a branch out of the structured block. |
| 8042 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8043 | CS->getCapturedDecl()->setNothrow(); |
| 8044 | |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8045 | for (int ThisCaptureLevel = |
| 8046 | getOpenMPCaptureLevels(OMPD_teams_distribute_parallel_for); |
| 8047 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 8048 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 8049 | // 1.2.2 OpenMP Language Terminology |
| 8050 | // Structured block - An executable statement with a single entry at the |
| 8051 | // top and a single exit at the bottom. |
| 8052 | // The point of exit cannot be a branch out of the structured block. |
| 8053 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8054 | CS->getCapturedDecl()->setNothrow(); |
| 8055 | } |
| 8056 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8057 | OMPLoopDirective::HelperExprs B; |
| 8058 | // In presence of clause 'collapse' with number of loops, it will |
| 8059 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8060 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8061 | OMPD_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8062 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8063 | VarsWithImplicitDSA, B); |
| 8064 | |
| 8065 | if (NestedLoopCount == 0) |
| 8066 | return StmtError(); |
| 8067 | |
| 8068 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 8069 | "omp for loop exprs were not built"); |
| 8070 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8071 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | ceabd41 | 2017-11-30 18:01:54 +0000 | [diff] [blame] | 8072 | |
| 8073 | DSAStack->setParentTeamsRegionLoc(StartLoc); |
| 8074 | |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8075 | return OMPTeamsDistributeParallelForDirective::Create( |
| Alexey Bataev | dcb4b8fb | 2017-11-22 20:19:50 +0000 | [diff] [blame] | 8076 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 8077 | DSAStack->isCancelRegion()); |
| Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 8078 | } |
| 8079 | |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8080 | StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 8081 | Stmt *AStmt, |
| 8082 | SourceLocation StartLoc, |
| 8083 | SourceLocation EndLoc) { |
| 8084 | if (!AStmt) |
| 8085 | return StmtError(); |
| 8086 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8087 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8088 | // 1.2.2 OpenMP Language Terminology |
| 8089 | // Structured block - An executable statement with a single entry at the |
| 8090 | // top and a single exit at the bottom. |
| 8091 | // The point of exit cannot be a branch out of the structured block. |
| 8092 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8093 | CS->getCapturedDecl()->setNothrow(); |
| 8094 | |
| Alexey Bataev | f9fc42e | 2017-11-22 14:25:55 +0000 | [diff] [blame] | 8095 | for (int ThisCaptureLevel = getOpenMPCaptureLevels(OMPD_target_teams); |
| 8096 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 8097 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 8098 | // 1.2.2 OpenMP Language Terminology |
| 8099 | // Structured block - An executable statement with a single entry at the |
| 8100 | // top and a single exit at the bottom. |
| 8101 | // The point of exit cannot be a branch out of the structured block. |
| 8102 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8103 | CS->getCapturedDecl()->setNothrow(); |
| 8104 | } |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8105 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8106 | |
| 8107 | return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 8108 | AStmt); |
| 8109 | } |
| 8110 | |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8111 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeDirective( |
| 8112 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8113 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8114 | if (!AStmt) |
| 8115 | return StmtError(); |
| 8116 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8117 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8118 | // 1.2.2 OpenMP Language Terminology |
| 8119 | // Structured block - An executable statement with a single entry at the |
| 8120 | // top and a single exit at the bottom. |
| 8121 | // The point of exit cannot be a branch out of the structured block. |
| 8122 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8123 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 8124 | for (int ThisCaptureLevel = |
| 8125 | getOpenMPCaptureLevels(OMPD_target_teams_distribute); |
| 8126 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 8127 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 8128 | // 1.2.2 OpenMP Language Terminology |
| 8129 | // Structured block - An executable statement with a single entry at the |
| 8130 | // top and a single exit at the bottom. |
| 8131 | // The point of exit cannot be a branch out of the structured block. |
| 8132 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8133 | CS->getCapturedDecl()->setNothrow(); |
| 8134 | } |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8135 | |
| 8136 | OMPLoopDirective::HelperExprs B; |
| 8137 | // In presence of clause 'collapse' with number of loops, it will |
| 8138 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8139 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Alexey Bataev | dfa430f | 2017-12-08 15:03:50 +0000 | [diff] [blame] | 8140 | OMPD_target_teams_distribute, getCollapseNumberExpr(Clauses), |
| 8141 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8142 | VarsWithImplicitDSA, B); |
| 8143 | if (NestedLoopCount == 0) |
| 8144 | return StmtError(); |
| 8145 | |
| 8146 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 8147 | "omp target teams distribute loop exprs were not built"); |
| 8148 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8149 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 8150 | return OMPTargetTeamsDistributeDirective::Create( |
| 8151 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 8152 | } |
| 8153 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8154 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 8155 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8156 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8157 | if (!AStmt) |
| 8158 | return StmtError(); |
| 8159 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8160 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8161 | // 1.2.2 OpenMP Language Terminology |
| 8162 | // Structured block - An executable statement with a single entry at the |
| 8163 | // top and a single exit at the bottom. |
| 8164 | // The point of exit cannot be a branch out of the structured block. |
| 8165 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8166 | CS->getCapturedDecl()->setNothrow(); |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 8167 | for (int ThisCaptureLevel = |
| 8168 | getOpenMPCaptureLevels(OMPD_target_teams_distribute_parallel_for); |
| 8169 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 8170 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 8171 | // 1.2.2 OpenMP Language Terminology |
| 8172 | // Structured block - An executable statement with a single entry at the |
| 8173 | // top and a single exit at the bottom. |
| 8174 | // The point of exit cannot be a branch out of the structured block. |
| 8175 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8176 | CS->getCapturedDecl()->setNothrow(); |
| 8177 | } |
| 8178 | |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8179 | OMPLoopDirective::HelperExprs B; |
| 8180 | // In presence of clause 'collapse' with number of loops, it will |
| 8181 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8182 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 8183 | OMPD_target_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 8184 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8185 | VarsWithImplicitDSA, B); |
| 8186 | if (NestedLoopCount == 0) |
| 8187 | return StmtError(); |
| 8188 | |
| 8189 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 8190 | "omp target teams distribute parallel for loop exprs were not built"); |
| 8191 | |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 8192 | if (!CurContext->isDependentContext()) { |
| 8193 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8194 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 8195 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 8196 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 8197 | B.NumIterations, *this, CurScope, |
| 8198 | DSAStack)) |
| 8199 | return StmtError(); |
| 8200 | } |
| 8201 | } |
| 8202 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8203 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8204 | return OMPTargetTeamsDistributeParallelForDirective::Create( |
| Alexey Bataev | 16e7988 | 2017-11-22 21:12:03 +0000 | [diff] [blame] | 8205 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B, |
| 8206 | DSAStack->isCancelRegion()); |
| Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8207 | } |
| 8208 | |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8209 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 8210 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8211 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8212 | if (!AStmt) |
| 8213 | return StmtError(); |
| 8214 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8215 | auto *CS = cast<CapturedStmt>(AStmt); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8216 | // 1.2.2 OpenMP Language Terminology |
| 8217 | // Structured block - An executable statement with a single entry at the |
| 8218 | // top and a single exit at the bottom. |
| 8219 | // The point of exit cannot be a branch out of the structured block. |
| 8220 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8221 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 8222 | for (int ThisCaptureLevel = getOpenMPCaptureLevels( |
| 8223 | OMPD_target_teams_distribute_parallel_for_simd); |
| 8224 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 8225 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 8226 | // 1.2.2 OpenMP Language Terminology |
| 8227 | // Structured block - An executable statement with a single entry at the |
| 8228 | // top and a single exit at the bottom. |
| 8229 | // The point of exit cannot be a branch out of the structured block. |
| 8230 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8231 | CS->getCapturedDecl()->setNothrow(); |
| 8232 | } |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8233 | |
| 8234 | OMPLoopDirective::HelperExprs B; |
| 8235 | // In presence of clause 'collapse' with number of loops, it will |
| 8236 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8237 | unsigned NestedLoopCount = |
| 8238 | checkOpenMPLoop(OMPD_target_teams_distribute_parallel_for_simd, |
| Alexey Bataev | 647dd84 | 2018-01-15 20:59:40 +0000 | [diff] [blame] | 8239 | getCollapseNumberExpr(Clauses), |
| 8240 | nullptr /*ordered not a clause on distribute*/, CS, *this, |
| 8241 | *DSAStack, VarsWithImplicitDSA, B); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8242 | if (NestedLoopCount == 0) |
| 8243 | return StmtError(); |
| 8244 | |
| 8245 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 8246 | "omp target teams distribute parallel for simd loop exprs were not " |
| 8247 | "built"); |
| 8248 | |
| 8249 | if (!CurContext->isDependentContext()) { |
| 8250 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8251 | for (OMPClause *C : Clauses) { |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8252 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 8253 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 8254 | B.NumIterations, *this, CurScope, |
| 8255 | DSAStack)) |
| 8256 | return StmtError(); |
| 8257 | } |
| 8258 | } |
| 8259 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 8260 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 8261 | return StmtError(); |
| 8262 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8263 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8264 | return OMPTargetTeamsDistributeParallelForSimdDirective::Create( |
| 8265 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 8266 | } |
| 8267 | |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8268 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 8269 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8270 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA) { |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8271 | if (!AStmt) |
| 8272 | return StmtError(); |
| 8273 | |
| 8274 | auto *CS = cast<CapturedStmt>(AStmt); |
| 8275 | // 1.2.2 OpenMP Language Terminology |
| 8276 | // Structured block - An executable statement with a single entry at the |
| 8277 | // top and a single exit at the bottom. |
| 8278 | // The point of exit cannot be a branch out of the structured block. |
| 8279 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8280 | CS->getCapturedDecl()->setNothrow(); |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 8281 | for (int ThisCaptureLevel = |
| 8282 | getOpenMPCaptureLevels(OMPD_target_teams_distribute_simd); |
| 8283 | ThisCaptureLevel > 1; --ThisCaptureLevel) { |
| 8284 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
| 8285 | // 1.2.2 OpenMP Language Terminology |
| 8286 | // Structured block - An executable statement with a single entry at the |
| 8287 | // top and a single exit at the bottom. |
| 8288 | // The point of exit cannot be a branch out of the structured block. |
| 8289 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 8290 | CS->getCapturedDecl()->setNothrow(); |
| 8291 | } |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8292 | |
| 8293 | OMPLoopDirective::HelperExprs B; |
| 8294 | // In presence of clause 'collapse' with number of loops, it will |
| 8295 | // define the nested loops number. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8296 | unsigned NestedLoopCount = checkOpenMPLoop( |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8297 | OMPD_target_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| Alexey Bataev | fbe17fb | 2017-12-13 19:45:06 +0000 | [diff] [blame] | 8298 | nullptr /*ordered not a clause on distribute*/, CS, *this, *DSAStack, |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8299 | VarsWithImplicitDSA, B); |
| 8300 | if (NestedLoopCount == 0) |
| 8301 | return StmtError(); |
| 8302 | |
| 8303 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 8304 | "omp target teams distribute simd loop exprs were not built"); |
| 8305 | |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 8306 | if (!CurContext->isDependentContext()) { |
| 8307 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8308 | for (OMPClause *C : Clauses) { |
| Alexey Bataev | 438388c | 2017-11-22 18:34:02 +0000 | [diff] [blame] | 8309 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 8310 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 8311 | B.NumIterations, *this, CurScope, |
| 8312 | DSAStack)) |
| 8313 | return StmtError(); |
| 8314 | } |
| 8315 | } |
| 8316 | |
| 8317 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 8318 | return StmtError(); |
| 8319 | |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 8320 | setFunctionHasBranchProtectedScope(); |
| Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8321 | return OMPTargetTeamsDistributeSimdDirective::Create( |
| 8322 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 8323 | } |
| 8324 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8325 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8326 | SourceLocation StartLoc, |
| 8327 | SourceLocation LParenLoc, |
| 8328 | SourceLocation EndLoc) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8329 | OMPClause *Res = nullptr; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8330 | switch (Kind) { |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8331 | case OMPC_final: |
| 8332 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8333 | break; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8334 | case OMPC_num_threads: |
| 8335 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8336 | break; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8337 | case OMPC_safelen: |
| 8338 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8339 | break; |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8340 | case OMPC_simdlen: |
| 8341 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8342 | break; |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8343 | case OMPC_collapse: |
| 8344 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8345 | break; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 8346 | case OMPC_ordered: |
| 8347 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 8348 | break; |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8349 | case OMPC_device: |
| 8350 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8351 | break; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8352 | case OMPC_num_teams: |
| 8353 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8354 | break; |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8355 | case OMPC_thread_limit: |
| 8356 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8357 | break; |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8358 | case OMPC_priority: |
| 8359 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8360 | break; |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8361 | case OMPC_grainsize: |
| 8362 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8363 | break; |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8364 | case OMPC_num_tasks: |
| 8365 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8366 | break; |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8367 | case OMPC_hint: |
| 8368 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 8369 | break; |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8370 | case OMPC_if: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8371 | case OMPC_default: |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8372 | case OMPC_proc_bind: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8373 | case OMPC_schedule: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8374 | case OMPC_private: |
| 8375 | case OMPC_firstprivate: |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8376 | case OMPC_lastprivate: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8377 | case OMPC_shared: |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8378 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8379 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8380 | case OMPC_in_reduction: |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8381 | case OMPC_linear: |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8382 | case OMPC_aligned: |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8383 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8384 | case OMPC_copyprivate: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8385 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8386 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8387 | case OMPC_mergeable: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8388 | case OMPC_threadprivate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8389 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8390 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8391 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8392 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8393 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8394 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8395 | case OMPC_depend: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8396 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8397 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8398 | case OMPC_map: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8399 | case OMPC_nogroup: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8400 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8401 | case OMPC_defaultmap: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8402 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8403 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8404 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8405 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8406 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8407 | case OMPC_is_device_ptr: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8408 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 8409 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 8410 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 8411 | case OMPC_dynamic_allocators: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 8412 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8413 | llvm_unreachable("Clause is not allowed."); |
| 8414 | } |
| 8415 | return Res; |
| 8416 | } |
| 8417 | |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8418 | // An OpenMP directive such as 'target parallel' has two captured regions: |
| 8419 | // for the 'target' and 'parallel' respectively. This function returns |
| 8420 | // the region in which to capture expressions associated with a clause. |
| 8421 | // A return value of OMPD_unknown signifies that the expression should not |
| 8422 | // be captured. |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8423 | static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( |
| 8424 | OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
| 8425 | OpenMPDirectiveKind NameModifier = OMPD_unknown) { |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8426 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8427 | switch (CKind) { |
| 8428 | case OMPC_if: |
| 8429 | switch (DKind) { |
| 8430 | case OMPD_target_parallel: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8431 | case OMPD_target_parallel_for: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 8432 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8433 | // If this clause applies to the nested 'parallel' region, capture within |
| 8434 | // the 'target' region, otherwise do not capture. |
| 8435 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 8436 | CaptureRegion = OMPD_target; |
| 8437 | break; |
| Carlo Bertolli | 52978c3 | 2018-01-03 21:12:44 +0000 | [diff] [blame] | 8438 | case OMPD_target_teams_distribute_parallel_for: |
| 8439 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 8440 | // If this clause applies to the nested 'parallel' region, capture within |
| 8441 | // the 'teams' region, otherwise do not capture. |
| 8442 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 8443 | CaptureRegion = OMPD_teams; |
| 8444 | break; |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8445 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8446 | case OMPD_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8447 | CaptureRegion = OMPD_teams; |
| 8448 | break; |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 8449 | case OMPD_target_update: |
| Alexey Bataev | fab20e4 | 2017-12-27 18:49:38 +0000 | [diff] [blame] | 8450 | case OMPD_target_enter_data: |
| 8451 | case OMPD_target_exit_data: |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 8452 | CaptureRegion = OMPD_task; |
| 8453 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8454 | case OMPD_cancel: |
| 8455 | case OMPD_parallel: |
| 8456 | case OMPD_parallel_sections: |
| 8457 | case OMPD_parallel_for: |
| 8458 | case OMPD_parallel_for_simd: |
| 8459 | case OMPD_target: |
| 8460 | case OMPD_target_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8461 | case OMPD_target_teams: |
| 8462 | case OMPD_target_teams_distribute: |
| 8463 | case OMPD_target_teams_distribute_simd: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8464 | case OMPD_distribute_parallel_for: |
| 8465 | case OMPD_distribute_parallel_for_simd: |
| 8466 | case OMPD_task: |
| 8467 | case OMPD_taskloop: |
| 8468 | case OMPD_taskloop_simd: |
| 8469 | case OMPD_target_data: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8470 | // Do not capture if-clause expressions. |
| 8471 | break; |
| 8472 | case OMPD_threadprivate: |
| 8473 | case OMPD_taskyield: |
| 8474 | case OMPD_barrier: |
| 8475 | case OMPD_taskwait: |
| 8476 | case OMPD_cancellation_point: |
| 8477 | case OMPD_flush: |
| 8478 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 8479 | case OMPD_declare_mapper: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8480 | case OMPD_declare_simd: |
| 8481 | case OMPD_declare_target: |
| 8482 | case OMPD_end_declare_target: |
| 8483 | case OMPD_teams: |
| 8484 | case OMPD_simd: |
| 8485 | case OMPD_for: |
| 8486 | case OMPD_for_simd: |
| 8487 | case OMPD_sections: |
| 8488 | case OMPD_section: |
| 8489 | case OMPD_single: |
| 8490 | case OMPD_master: |
| 8491 | case OMPD_critical: |
| 8492 | case OMPD_taskgroup: |
| 8493 | case OMPD_distribute: |
| 8494 | case OMPD_ordered: |
| 8495 | case OMPD_atomic: |
| 8496 | case OMPD_distribute_simd: |
| 8497 | case OMPD_teams_distribute: |
| 8498 | case OMPD_teams_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8499 | case OMPD_requires: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8500 | llvm_unreachable("Unexpected OpenMP directive with if-clause"); |
| 8501 | case OMPD_unknown: |
| 8502 | llvm_unreachable("Unknown OpenMP directive"); |
| 8503 | } |
| 8504 | break; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8505 | case OMPC_num_threads: |
| 8506 | switch (DKind) { |
| 8507 | case OMPD_target_parallel: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8508 | case OMPD_target_parallel_for: |
| Alexey Bataev | 5d7edca | 2017-11-09 17:32:15 +0000 | [diff] [blame] | 8509 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8510 | CaptureRegion = OMPD_target; |
| 8511 | break; |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8512 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8513 | case OMPD_teams_distribute_parallel_for_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 8514 | case OMPD_target_teams_distribute_parallel_for: |
| 8515 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8516 | CaptureRegion = OMPD_teams; |
| 8517 | break; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8518 | case OMPD_parallel: |
| 8519 | case OMPD_parallel_sections: |
| 8520 | case OMPD_parallel_for: |
| 8521 | case OMPD_parallel_for_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8522 | case OMPD_distribute_parallel_for: |
| 8523 | case OMPD_distribute_parallel_for_simd: |
| 8524 | // Do not capture num_threads-clause expressions. |
| 8525 | break; |
| 8526 | case OMPD_target_data: |
| 8527 | case OMPD_target_enter_data: |
| 8528 | case OMPD_target_exit_data: |
| 8529 | case OMPD_target_update: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8530 | case OMPD_target: |
| 8531 | case OMPD_target_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8532 | case OMPD_target_teams: |
| 8533 | case OMPD_target_teams_distribute: |
| 8534 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8535 | case OMPD_cancel: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8536 | case OMPD_task: |
| 8537 | case OMPD_taskloop: |
| 8538 | case OMPD_taskloop_simd: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8539 | case OMPD_threadprivate: |
| 8540 | case OMPD_taskyield: |
| 8541 | case OMPD_barrier: |
| 8542 | case OMPD_taskwait: |
| 8543 | case OMPD_cancellation_point: |
| 8544 | case OMPD_flush: |
| 8545 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 8546 | case OMPD_declare_mapper: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8547 | case OMPD_declare_simd: |
| 8548 | case OMPD_declare_target: |
| 8549 | case OMPD_end_declare_target: |
| 8550 | case OMPD_teams: |
| 8551 | case OMPD_simd: |
| 8552 | case OMPD_for: |
| 8553 | case OMPD_for_simd: |
| 8554 | case OMPD_sections: |
| 8555 | case OMPD_section: |
| 8556 | case OMPD_single: |
| 8557 | case OMPD_master: |
| 8558 | case OMPD_critical: |
| 8559 | case OMPD_taskgroup: |
| 8560 | case OMPD_distribute: |
| 8561 | case OMPD_ordered: |
| 8562 | case OMPD_atomic: |
| 8563 | case OMPD_distribute_simd: |
| 8564 | case OMPD_teams_distribute: |
| 8565 | case OMPD_teams_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8566 | case OMPD_requires: |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 8567 | llvm_unreachable("Unexpected OpenMP directive with num_threads-clause"); |
| 8568 | case OMPD_unknown: |
| 8569 | llvm_unreachable("Unknown OpenMP directive"); |
| 8570 | } |
| 8571 | break; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8572 | case OMPC_num_teams: |
| 8573 | switch (DKind) { |
| 8574 | case OMPD_target_teams: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8575 | case OMPD_target_teams_distribute: |
| 8576 | case OMPD_target_teams_distribute_simd: |
| 8577 | case OMPD_target_teams_distribute_parallel_for: |
| 8578 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8579 | CaptureRegion = OMPD_target; |
| 8580 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8581 | case OMPD_teams_distribute_parallel_for: |
| 8582 | case OMPD_teams_distribute_parallel_for_simd: |
| 8583 | case OMPD_teams: |
| 8584 | case OMPD_teams_distribute: |
| 8585 | case OMPD_teams_distribute_simd: |
| 8586 | // Do not capture num_teams-clause expressions. |
| 8587 | break; |
| 8588 | case OMPD_distribute_parallel_for: |
| 8589 | case OMPD_distribute_parallel_for_simd: |
| 8590 | case OMPD_task: |
| 8591 | case OMPD_taskloop: |
| 8592 | case OMPD_taskloop_simd: |
| 8593 | case OMPD_target_data: |
| 8594 | case OMPD_target_enter_data: |
| 8595 | case OMPD_target_exit_data: |
| 8596 | case OMPD_target_update: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8597 | case OMPD_cancel: |
| 8598 | case OMPD_parallel: |
| 8599 | case OMPD_parallel_sections: |
| 8600 | case OMPD_parallel_for: |
| 8601 | case OMPD_parallel_for_simd: |
| 8602 | case OMPD_target: |
| 8603 | case OMPD_target_simd: |
| 8604 | case OMPD_target_parallel: |
| 8605 | case OMPD_target_parallel_for: |
| 8606 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8607 | case OMPD_threadprivate: |
| 8608 | case OMPD_taskyield: |
| 8609 | case OMPD_barrier: |
| 8610 | case OMPD_taskwait: |
| 8611 | case OMPD_cancellation_point: |
| 8612 | case OMPD_flush: |
| 8613 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 8614 | case OMPD_declare_mapper: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8615 | case OMPD_declare_simd: |
| 8616 | case OMPD_declare_target: |
| 8617 | case OMPD_end_declare_target: |
| 8618 | case OMPD_simd: |
| 8619 | case OMPD_for: |
| 8620 | case OMPD_for_simd: |
| 8621 | case OMPD_sections: |
| 8622 | case OMPD_section: |
| 8623 | case OMPD_single: |
| 8624 | case OMPD_master: |
| 8625 | case OMPD_critical: |
| 8626 | case OMPD_taskgroup: |
| 8627 | case OMPD_distribute: |
| 8628 | case OMPD_ordered: |
| 8629 | case OMPD_atomic: |
| 8630 | case OMPD_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8631 | case OMPD_requires: |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 8632 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 8633 | case OMPD_unknown: |
| 8634 | llvm_unreachable("Unknown OpenMP directive"); |
| 8635 | } |
| 8636 | break; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8637 | case OMPC_thread_limit: |
| 8638 | switch (DKind) { |
| 8639 | case OMPD_target_teams: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8640 | case OMPD_target_teams_distribute: |
| 8641 | case OMPD_target_teams_distribute_simd: |
| 8642 | case OMPD_target_teams_distribute_parallel_for: |
| 8643 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8644 | CaptureRegion = OMPD_target; |
| 8645 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8646 | case OMPD_teams_distribute_parallel_for: |
| 8647 | case OMPD_teams_distribute_parallel_for_simd: |
| 8648 | case OMPD_teams: |
| 8649 | case OMPD_teams_distribute: |
| 8650 | case OMPD_teams_distribute_simd: |
| 8651 | // Do not capture thread_limit-clause expressions. |
| 8652 | break; |
| 8653 | case OMPD_distribute_parallel_for: |
| 8654 | case OMPD_distribute_parallel_for_simd: |
| 8655 | case OMPD_task: |
| 8656 | case OMPD_taskloop: |
| 8657 | case OMPD_taskloop_simd: |
| 8658 | case OMPD_target_data: |
| 8659 | case OMPD_target_enter_data: |
| 8660 | case OMPD_target_exit_data: |
| 8661 | case OMPD_target_update: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8662 | case OMPD_cancel: |
| 8663 | case OMPD_parallel: |
| 8664 | case OMPD_parallel_sections: |
| 8665 | case OMPD_parallel_for: |
| 8666 | case OMPD_parallel_for_simd: |
| 8667 | case OMPD_target: |
| 8668 | case OMPD_target_simd: |
| 8669 | case OMPD_target_parallel: |
| 8670 | case OMPD_target_parallel_for: |
| 8671 | case OMPD_target_parallel_for_simd: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8672 | case OMPD_threadprivate: |
| 8673 | case OMPD_taskyield: |
| 8674 | case OMPD_barrier: |
| 8675 | case OMPD_taskwait: |
| 8676 | case OMPD_cancellation_point: |
| 8677 | case OMPD_flush: |
| 8678 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 8679 | case OMPD_declare_mapper: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8680 | case OMPD_declare_simd: |
| 8681 | case OMPD_declare_target: |
| 8682 | case OMPD_end_declare_target: |
| 8683 | case OMPD_simd: |
| 8684 | case OMPD_for: |
| 8685 | case OMPD_for_simd: |
| 8686 | case OMPD_sections: |
| 8687 | case OMPD_section: |
| 8688 | case OMPD_single: |
| 8689 | case OMPD_master: |
| 8690 | case OMPD_critical: |
| 8691 | case OMPD_taskgroup: |
| 8692 | case OMPD_distribute: |
| 8693 | case OMPD_ordered: |
| 8694 | case OMPD_atomic: |
| 8695 | case OMPD_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8696 | case OMPD_requires: |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 8697 | llvm_unreachable("Unexpected OpenMP directive with thread_limit-clause"); |
| 8698 | case OMPD_unknown: |
| 8699 | llvm_unreachable("Unknown OpenMP directive"); |
| 8700 | } |
| 8701 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8702 | case OMPC_schedule: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8703 | switch (DKind) { |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8704 | case OMPD_parallel_for: |
| 8705 | case OMPD_parallel_for_simd: |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 8706 | case OMPD_distribute_parallel_for: |
| Alexey Bataev | 974acd6 | 2017-11-27 19:38:52 +0000 | [diff] [blame] | 8707 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 8708 | case OMPD_teams_distribute_parallel_for: |
| 8709 | case OMPD_teams_distribute_parallel_for_simd: |
| 8710 | case OMPD_target_parallel_for: |
| 8711 | case OMPD_target_parallel_for_simd: |
| 8712 | case OMPD_target_teams_distribute_parallel_for: |
| 8713 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Alexey Bataev | 7f96c37 | 2017-11-22 17:19:31 +0000 | [diff] [blame] | 8714 | CaptureRegion = OMPD_parallel; |
| 8715 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8716 | case OMPD_for: |
| 8717 | case OMPD_for_simd: |
| 8718 | // Do not capture schedule-clause expressions. |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8719 | break; |
| 8720 | case OMPD_task: |
| 8721 | case OMPD_taskloop: |
| 8722 | case OMPD_taskloop_simd: |
| 8723 | case OMPD_target_data: |
| 8724 | case OMPD_target_enter_data: |
| 8725 | case OMPD_target_exit_data: |
| 8726 | case OMPD_target_update: |
| 8727 | case OMPD_teams: |
| 8728 | case OMPD_teams_distribute: |
| 8729 | case OMPD_teams_distribute_simd: |
| 8730 | case OMPD_target_teams_distribute: |
| 8731 | case OMPD_target_teams_distribute_simd: |
| 8732 | case OMPD_target: |
| 8733 | case OMPD_target_simd: |
| 8734 | case OMPD_target_parallel: |
| 8735 | case OMPD_cancel: |
| 8736 | case OMPD_parallel: |
| 8737 | case OMPD_parallel_sections: |
| 8738 | case OMPD_threadprivate: |
| 8739 | case OMPD_taskyield: |
| 8740 | case OMPD_barrier: |
| 8741 | case OMPD_taskwait: |
| 8742 | case OMPD_cancellation_point: |
| 8743 | case OMPD_flush: |
| 8744 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 8745 | case OMPD_declare_mapper: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8746 | case OMPD_declare_simd: |
| 8747 | case OMPD_declare_target: |
| 8748 | case OMPD_end_declare_target: |
| 8749 | case OMPD_simd: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8750 | case OMPD_sections: |
| 8751 | case OMPD_section: |
| 8752 | case OMPD_single: |
| 8753 | case OMPD_master: |
| 8754 | case OMPD_critical: |
| 8755 | case OMPD_taskgroup: |
| 8756 | case OMPD_distribute: |
| 8757 | case OMPD_ordered: |
| 8758 | case OMPD_atomic: |
| 8759 | case OMPD_distribute_simd: |
| 8760 | case OMPD_target_teams: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8761 | case OMPD_requires: |
| Alexey Bataev | fb0ebec | 2017-11-08 20:16:14 +0000 | [diff] [blame] | 8762 | llvm_unreachable("Unexpected OpenMP directive with schedule clause"); |
| 8763 | case OMPD_unknown: |
| 8764 | llvm_unreachable("Unknown OpenMP directive"); |
| 8765 | } |
| 8766 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8767 | case OMPC_dist_schedule: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8768 | switch (DKind) { |
| 8769 | case OMPD_teams_distribute_parallel_for: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8770 | case OMPD_teams_distribute_parallel_for_simd: |
| 8771 | case OMPD_teams_distribute: |
| 8772 | case OMPD_teams_distribute_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8773 | case OMPD_target_teams_distribute_parallel_for: |
| 8774 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8775 | case OMPD_target_teams_distribute: |
| 8776 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | fd9b2af | 2018-01-04 20:50:08 +0000 | [diff] [blame] | 8777 | CaptureRegion = OMPD_teams; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8778 | break; |
| 8779 | case OMPD_distribute_parallel_for: |
| 8780 | case OMPD_distribute_parallel_for_simd: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8781 | case OMPD_distribute: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8782 | case OMPD_distribute_simd: |
| 8783 | // Do not capture thread_limit-clause expressions. |
| 8784 | break; |
| 8785 | case OMPD_parallel_for: |
| 8786 | case OMPD_parallel_for_simd: |
| 8787 | case OMPD_target_parallel_for_simd: |
| 8788 | case OMPD_target_parallel_for: |
| 8789 | case OMPD_task: |
| 8790 | case OMPD_taskloop: |
| 8791 | case OMPD_taskloop_simd: |
| 8792 | case OMPD_target_data: |
| 8793 | case OMPD_target_enter_data: |
| 8794 | case OMPD_target_exit_data: |
| 8795 | case OMPD_target_update: |
| 8796 | case OMPD_teams: |
| 8797 | case OMPD_target: |
| 8798 | case OMPD_target_simd: |
| 8799 | case OMPD_target_parallel: |
| 8800 | case OMPD_cancel: |
| 8801 | case OMPD_parallel: |
| 8802 | case OMPD_parallel_sections: |
| 8803 | case OMPD_threadprivate: |
| 8804 | case OMPD_taskyield: |
| 8805 | case OMPD_barrier: |
| 8806 | case OMPD_taskwait: |
| 8807 | case OMPD_cancellation_point: |
| 8808 | case OMPD_flush: |
| 8809 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 8810 | case OMPD_declare_mapper: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8811 | case OMPD_declare_simd: |
| 8812 | case OMPD_declare_target: |
| 8813 | case OMPD_end_declare_target: |
| 8814 | case OMPD_simd: |
| 8815 | case OMPD_for: |
| 8816 | case OMPD_for_simd: |
| 8817 | case OMPD_sections: |
| 8818 | case OMPD_section: |
| 8819 | case OMPD_single: |
| 8820 | case OMPD_master: |
| 8821 | case OMPD_critical: |
| 8822 | case OMPD_taskgroup: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8823 | case OMPD_ordered: |
| 8824 | case OMPD_atomic: |
| 8825 | case OMPD_target_teams: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8826 | case OMPD_requires: |
| Carlo Bertolli | 62fae15 | 2017-11-20 20:46:39 +0000 | [diff] [blame] | 8827 | llvm_unreachable("Unexpected OpenMP directive with schedule clause"); |
| 8828 | case OMPD_unknown: |
| 8829 | llvm_unreachable("Unknown OpenMP directive"); |
| 8830 | } |
| 8831 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8832 | case OMPC_device: |
| 8833 | switch (DKind) { |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 8834 | case OMPD_target_update: |
| Alexey Bataev | fab20e4 | 2017-12-27 18:49:38 +0000 | [diff] [blame] | 8835 | case OMPD_target_enter_data: |
| 8836 | case OMPD_target_exit_data: |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 8837 | case OMPD_target: |
| Alexey Bataev | f41c88f | 2018-01-16 15:05:16 +0000 | [diff] [blame] | 8838 | case OMPD_target_simd: |
| Alexey Bataev | 0c869ef | 2018-01-16 15:57:07 +0000 | [diff] [blame] | 8839 | case OMPD_target_teams: |
| Alexey Bataev | 54d5c7d | 2018-01-16 16:27:49 +0000 | [diff] [blame] | 8840 | case OMPD_target_parallel: |
| Alexey Bataev | 79df756 | 2018-01-16 16:46:46 +0000 | [diff] [blame] | 8841 | case OMPD_target_teams_distribute: |
| Alexey Bataev | 8d16a43 | 2018-01-16 17:22:50 +0000 | [diff] [blame] | 8842 | case OMPD_target_teams_distribute_simd: |
| Alexey Bataev | 8ed89551 | 2018-01-16 17:41:04 +0000 | [diff] [blame] | 8843 | case OMPD_target_parallel_for: |
| Alexey Bataev | d60d1ba | 2018-01-16 17:55:15 +0000 | [diff] [blame] | 8844 | case OMPD_target_parallel_for_simd: |
| Alexey Bataev | 9f9fb0b | 2018-01-16 19:02:33 +0000 | [diff] [blame] | 8845 | case OMPD_target_teams_distribute_parallel_for: |
| Alexey Bataev | 9350fc3 | 2018-01-16 19:18:24 +0000 | [diff] [blame] | 8846 | case OMPD_target_teams_distribute_parallel_for_simd: |
| Alexey Bataev | d2202ca | 2017-12-27 17:58:32 +0000 | [diff] [blame] | 8847 | CaptureRegion = OMPD_task; |
| 8848 | break; |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8849 | case OMPD_target_data: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8850 | // Do not capture device-clause expressions. |
| 8851 | break; |
| 8852 | case OMPD_teams_distribute_parallel_for: |
| 8853 | case OMPD_teams_distribute_parallel_for_simd: |
| 8854 | case OMPD_teams: |
| 8855 | case OMPD_teams_distribute: |
| 8856 | case OMPD_teams_distribute_simd: |
| 8857 | case OMPD_distribute_parallel_for: |
| 8858 | case OMPD_distribute_parallel_for_simd: |
| 8859 | case OMPD_task: |
| 8860 | case OMPD_taskloop: |
| 8861 | case OMPD_taskloop_simd: |
| 8862 | case OMPD_cancel: |
| 8863 | case OMPD_parallel: |
| 8864 | case OMPD_parallel_sections: |
| 8865 | case OMPD_parallel_for: |
| 8866 | case OMPD_parallel_for_simd: |
| 8867 | case OMPD_threadprivate: |
| 8868 | case OMPD_taskyield: |
| 8869 | case OMPD_barrier: |
| 8870 | case OMPD_taskwait: |
| 8871 | case OMPD_cancellation_point: |
| 8872 | case OMPD_flush: |
| 8873 | case OMPD_declare_reduction: |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 8874 | case OMPD_declare_mapper: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8875 | case OMPD_declare_simd: |
| 8876 | case OMPD_declare_target: |
| 8877 | case OMPD_end_declare_target: |
| 8878 | case OMPD_simd: |
| 8879 | case OMPD_for: |
| 8880 | case OMPD_for_simd: |
| 8881 | case OMPD_sections: |
| 8882 | case OMPD_section: |
| 8883 | case OMPD_single: |
| 8884 | case OMPD_master: |
| 8885 | case OMPD_critical: |
| 8886 | case OMPD_taskgroup: |
| 8887 | case OMPD_distribute: |
| 8888 | case OMPD_ordered: |
| 8889 | case OMPD_atomic: |
| 8890 | case OMPD_distribute_simd: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8891 | case OMPD_requires: |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8892 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 8893 | case OMPD_unknown: |
| 8894 | llvm_unreachable("Unknown OpenMP directive"); |
| 8895 | } |
| 8896 | break; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8897 | case OMPC_firstprivate: |
| 8898 | case OMPC_lastprivate: |
| 8899 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 8900 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 8901 | case OMPC_in_reduction: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8902 | case OMPC_linear: |
| 8903 | case OMPC_default: |
| 8904 | case OMPC_proc_bind: |
| 8905 | case OMPC_final: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8906 | case OMPC_safelen: |
| 8907 | case OMPC_simdlen: |
| 8908 | case OMPC_collapse: |
| 8909 | case OMPC_private: |
| 8910 | case OMPC_shared: |
| 8911 | case OMPC_aligned: |
| 8912 | case OMPC_copyin: |
| 8913 | case OMPC_copyprivate: |
| 8914 | case OMPC_ordered: |
| 8915 | case OMPC_nowait: |
| 8916 | case OMPC_untied: |
| 8917 | case OMPC_mergeable: |
| 8918 | case OMPC_threadprivate: |
| 8919 | case OMPC_flush: |
| 8920 | case OMPC_read: |
| 8921 | case OMPC_write: |
| 8922 | case OMPC_update: |
| 8923 | case OMPC_capture: |
| 8924 | case OMPC_seq_cst: |
| 8925 | case OMPC_depend: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8926 | case OMPC_threads: |
| 8927 | case OMPC_simd: |
| 8928 | case OMPC_map: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8929 | case OMPC_priority: |
| 8930 | case OMPC_grainsize: |
| 8931 | case OMPC_nogroup: |
| 8932 | case OMPC_num_tasks: |
| 8933 | case OMPC_hint: |
| 8934 | case OMPC_defaultmap: |
| 8935 | case OMPC_unknown: |
| 8936 | case OMPC_uniform: |
| 8937 | case OMPC_to: |
| 8938 | case OMPC_from: |
| 8939 | case OMPC_use_device_ptr: |
| 8940 | case OMPC_is_device_ptr: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 8941 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 8942 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 8943 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 8944 | case OMPC_dynamic_allocators: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 8945 | case OMPC_atomic_default_mem_order: |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8946 | llvm_unreachable("Unexpected OpenMP clause."); |
| 8947 | } |
| 8948 | return CaptureRegion; |
| 8949 | } |
| 8950 | |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8951 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 8952 | Expr *Condition, SourceLocation StartLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8953 | SourceLocation LParenLoc, |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 8954 | SourceLocation NameModifierLoc, |
| 8955 | SourceLocation ColonLoc, |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8956 | SourceLocation EndLoc) { |
| 8957 | Expr *ValExpr = Condition; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8958 | Stmt *HelperValStmt = nullptr; |
| 8959 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8960 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 8961 | !Condition->isInstantiationDependent() && |
| 8962 | !Condition->containsUnexpandedParameterPack()) { |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 8963 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8964 | if (Val.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8965 | return nullptr; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8966 | |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 8967 | ValExpr = Val.get(); |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8968 | |
| 8969 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 8970 | CaptureRegion = |
| 8971 | getOpenMPCaptureRegionForClause(DKind, OMPC_if, NameModifier); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 8972 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 8973 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 8974 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8975 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 8976 | HelperValStmt = buildPreInits(Context, Captures); |
| 8977 | } |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8978 | } |
| 8979 | |
| Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 8980 | return new (Context) |
| 8981 | OMPIfClause(NameModifier, ValExpr, HelperValStmt, CaptureRegion, StartLoc, |
| 8982 | LParenLoc, NameModifierLoc, ColonLoc, EndLoc); |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8983 | } |
| 8984 | |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8985 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 8986 | SourceLocation StartLoc, |
| 8987 | SourceLocation LParenLoc, |
| 8988 | SourceLocation EndLoc) { |
| 8989 | Expr *ValExpr = Condition; |
| 8990 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 8991 | !Condition->isInstantiationDependent() && |
| 8992 | !Condition->containsUnexpandedParameterPack()) { |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 8993 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8994 | if (Val.isInvalid()) |
| 8995 | return nullptr; |
| 8996 | |
| Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 8997 | ValExpr = MakeFullExpr(Val.get()).get(); |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8998 | } |
| 8999 | |
| 9000 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9001 | } |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9002 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 9003 | Expr *Op) { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9004 | if (!Op) |
| 9005 | return ExprError(); |
| 9006 | |
| 9007 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 9008 | public: |
| 9009 | IntConvertDiagnoser() |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9010 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
| Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 9011 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 9012 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9013 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 9014 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9015 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 9016 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9017 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 9018 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9019 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 9020 | QualType T, |
| 9021 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9022 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 9023 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9024 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 9025 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9026 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9027 | << ConvTy->isEnumeralType() << ConvTy; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9028 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9029 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 9030 | QualType T) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9031 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 9032 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9033 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 9034 | QualType ConvTy) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9035 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9036 | << ConvTy->isEnumeralType() << ConvTy; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9037 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9038 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 9039 | QualType) override { |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9040 | llvm_unreachable("conversion functions are permitted"); |
| 9041 | } |
| 9042 | } ConvertDiagnoser; |
| 9043 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 9044 | } |
| 9045 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9046 | static bool isNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9047 | OpenMPClauseKind CKind, |
| 9048 | bool StrictlyPositive) { |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9049 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 9050 | !ValExpr->isInstantiationDependent()) { |
| 9051 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 9052 | ExprResult Value = |
| 9053 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 9054 | if (Value.isInvalid()) |
| 9055 | return false; |
| 9056 | |
| 9057 | ValExpr = Value.get(); |
| 9058 | // The expression must evaluate to a non-negative integer value. |
| 9059 | llvm::APSInt Result; |
| 9060 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9061 | Result.isSigned() && |
| 9062 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 9063 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9064 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9065 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 9066 | << ValExpr->getSourceRange(); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9067 | return false; |
| 9068 | } |
| 9069 | } |
| 9070 | return true; |
| 9071 | } |
| 9072 | |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9073 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 9074 | SourceLocation StartLoc, |
| 9075 | SourceLocation LParenLoc, |
| 9076 | SourceLocation EndLoc) { |
| 9077 | Expr *ValExpr = NumThreads; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 9078 | Stmt *HelperValStmt = nullptr; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9079 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9080 | // OpenMP [2.5, Restrictions] |
| 9081 | // The num_threads expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9082 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9083 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9084 | return nullptr; |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9085 | |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 9086 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 9087 | OpenMPDirectiveKind CaptureRegion = |
| 9088 | getOpenMPCaptureRegionForClause(DKind, OMPC_num_threads); |
| 9089 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 9090 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9091 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 9092 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 9093 | HelperValStmt = buildPreInits(Context, Captures); |
| 9094 | } |
| 9095 | |
| 9096 | return new (Context) OMPNumThreadsClause( |
| 9097 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9098 | } |
| 9099 | |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9100 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9101 | OpenMPClauseKind CKind, |
| 9102 | bool StrictlyPositive) { |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9103 | if (!E) |
| 9104 | return ExprError(); |
| 9105 | if (E->isValueDependent() || E->isTypeDependent() || |
| 9106 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 9107 | return E; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9108 | llvm::APSInt Result; |
| 9109 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 9110 | if (ICE.isInvalid()) |
| 9111 | return ExprError(); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9112 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 9113 | (!StrictlyPositive && !Result.isNonNegative())) { |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9114 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9115 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 9116 | << E->getSourceRange(); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9117 | return ExprError(); |
| 9118 | } |
| Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 9119 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 9120 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 9121 | << E->getSourceRange(); |
| 9122 | return ExprError(); |
| 9123 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9124 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 9125 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
| Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 9126 | else if (CKind == OMPC_ordered) |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9127 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9128 | return ICE; |
| 9129 | } |
| 9130 | |
| 9131 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 9132 | SourceLocation LParenLoc, |
| 9133 | SourceLocation EndLoc) { |
| 9134 | // OpenMP [2.8.1, simd construct, Description] |
| 9135 | // The parameter of the safelen clause must be a constant |
| 9136 | // positive integer expression. |
| 9137 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 9138 | if (Safelen.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9139 | return nullptr; |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9140 | return new (Context) |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9141 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9142 | } |
| 9143 | |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 9144 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 9145 | SourceLocation LParenLoc, |
| 9146 | SourceLocation EndLoc) { |
| 9147 | // OpenMP [2.8.1, simd construct, Description] |
| 9148 | // The parameter of the simdlen clause must be a constant |
| 9149 | // positive integer expression. |
| 9150 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 9151 | if (Simdlen.isInvalid()) |
| 9152 | return nullptr; |
| 9153 | return new (Context) |
| 9154 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 9155 | } |
| 9156 | |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 9157 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 9158 | SourceLocation StartLoc, |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 9159 | SourceLocation LParenLoc, |
| 9160 | SourceLocation EndLoc) { |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 9161 | // OpenMP [2.7.1, loop construct, Description] |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 9162 | // OpenMP [2.8.1, simd construct, Description] |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 9163 | // OpenMP [2.9.6, distribute construct, Description] |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 9164 | // The parameter of the collapse clause must be a constant |
| 9165 | // positive integer expression. |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 9166 | ExprResult NumForLoopsResult = |
| 9167 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 9168 | if (NumForLoopsResult.isInvalid()) |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 9169 | return nullptr; |
| 9170 | return new (Context) |
| Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 9171 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 9172 | } |
| 9173 | |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 9174 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 9175 | SourceLocation EndLoc, |
| 9176 | SourceLocation LParenLoc, |
| 9177 | Expr *NumForLoops) { |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 9178 | // OpenMP [2.7.1, loop construct, Description] |
| 9179 | // OpenMP [2.8.1, simd construct, Description] |
| 9180 | // OpenMP [2.9.6, distribute construct, Description] |
| 9181 | // The parameter of the ordered clause must be a constant |
| 9182 | // positive integer expression if any. |
| 9183 | if (NumForLoops && LParenLoc.isValid()) { |
| 9184 | ExprResult NumForLoopsResult = |
| 9185 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 9186 | if (NumForLoopsResult.isInvalid()) |
| 9187 | return nullptr; |
| 9188 | NumForLoops = NumForLoopsResult.get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9189 | } else { |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9190 | NumForLoops = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9191 | } |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 9192 | auto *Clause = OMPOrderedClause::Create( |
| 9193 | Context, NumForLoops, NumForLoops ? DSAStack->getAssociatedLoops() : 0, |
| 9194 | StartLoc, LParenLoc, EndLoc); |
| 9195 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops, Clause); |
| 9196 | return Clause; |
| Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 9197 | } |
| 9198 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9199 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 9200 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 9201 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9202 | OMPClause *Res = nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9203 | switch (Kind) { |
| 9204 | case OMPC_default: |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9205 | Res = |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9206 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 9207 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9208 | break; |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 9209 | case OMPC_proc_bind: |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9210 | Res = ActOnOpenMPProcBindClause( |
| 9211 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 9212 | LParenLoc, EndLoc); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 9213 | break; |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 9214 | case OMPC_atomic_default_mem_order: |
| 9215 | Res = ActOnOpenMPAtomicDefaultMemOrderClause( |
| 9216 | static_cast<OpenMPAtomicDefaultMemOrderClauseKind>(Argument), |
| 9217 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
| 9218 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 9219 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 9220 | case OMPC_final: |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9221 | case OMPC_num_threads: |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9222 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 9223 | case OMPC_simdlen: |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 9224 | case OMPC_collapse: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9225 | case OMPC_schedule: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9226 | case OMPC_private: |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9227 | case OMPC_firstprivate: |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9228 | case OMPC_lastprivate: |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9229 | case OMPC_shared: |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9230 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9231 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 9232 | case OMPC_in_reduction: |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9233 | case OMPC_linear: |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9234 | case OMPC_aligned: |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9235 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9236 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9237 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9238 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 9239 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 9240 | case OMPC_mergeable: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9241 | case OMPC_threadprivate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9242 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9243 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9244 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 9245 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9246 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 9247 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9248 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9249 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9250 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 9251 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9252 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9253 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9254 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9255 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9256 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 9257 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9258 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9259 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9260 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9261 | case OMPC_defaultmap: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9262 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 9263 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9264 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9265 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9266 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9267 | case OMPC_is_device_ptr: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 9268 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 9269 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 9270 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 9271 | case OMPC_dynamic_allocators: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9272 | llvm_unreachable("Clause is not allowed."); |
| 9273 | } |
| 9274 | return Res; |
| 9275 | } |
| 9276 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9277 | static std::string |
| 9278 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 9279 | ArrayRef<unsigned> Exclude = llvm::None) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9280 | SmallString<256> Buffer; |
| 9281 | llvm::raw_svector_ostream Out(Buffer); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9282 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 9283 | unsigned Skipped = Exclude.size(); |
| 9284 | auto S = Exclude.begin(), E = Exclude.end(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9285 | for (unsigned I = First; I < Last; ++I) { |
| 9286 | if (std::find(S, E, I) != E) { |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9287 | --Skipped; |
| 9288 | continue; |
| 9289 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9290 | Out << "'" << getOpenMPSimpleClauseTypeName(K, I) << "'"; |
| 9291 | if (I == Bound - Skipped) |
| 9292 | Out << " or "; |
| 9293 | else if (I != Bound + 1 - Skipped) |
| 9294 | Out << ", "; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9295 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9296 | return Out.str(); |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9297 | } |
| 9298 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9299 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 9300 | SourceLocation KindKwLoc, |
| 9301 | SourceLocation StartLoc, |
| 9302 | SourceLocation LParenLoc, |
| 9303 | SourceLocation EndLoc) { |
| 9304 | if (Kind == OMPC_DEFAULT_unknown) { |
| Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 9305 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 9306 | "OMPC_DEFAULT_unknown not greater than 0"); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9307 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9308 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 9309 | /*Last=*/OMPC_DEFAULT_unknown) |
| 9310 | << getOpenMPClauseName(OMPC_default); |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9311 | return nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9312 | } |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9313 | switch (Kind) { |
| 9314 | case OMPC_DEFAULT_none: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9315 | DSAStack->setDefaultDSANone(KindKwLoc); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9316 | break; |
| 9317 | case OMPC_DEFAULT_shared: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9318 | DSAStack->setDefaultDSAShared(KindKwLoc); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9319 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 9320 | case OMPC_DEFAULT_unknown: |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 9321 | llvm_unreachable("Clause kind is not allowed."); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9322 | break; |
| 9323 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9324 | return new (Context) |
| 9325 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9326 | } |
| 9327 | |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 9328 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 9329 | SourceLocation KindKwLoc, |
| 9330 | SourceLocation StartLoc, |
| 9331 | SourceLocation LParenLoc, |
| 9332 | SourceLocation EndLoc) { |
| 9333 | if (Kind == OMPC_PROC_BIND_unknown) { |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 9334 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9335 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 9336 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 9337 | << getOpenMPClauseName(OMPC_proc_bind); |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9338 | return nullptr; |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 9339 | } |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9340 | return new (Context) |
| 9341 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 9342 | } |
| 9343 | |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 9344 | OMPClause *Sema::ActOnOpenMPAtomicDefaultMemOrderClause( |
| 9345 | OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindKwLoc, |
| 9346 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 9347 | if (Kind == OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown) { |
| 9348 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
| 9349 | << getListOfPossibleValues( |
| 9350 | OMPC_atomic_default_mem_order, /*First=*/0, |
| 9351 | /*Last=*/OMPC_ATOMIC_DEFAULT_MEM_ORDER_unknown) |
| 9352 | << getOpenMPClauseName(OMPC_atomic_default_mem_order); |
| 9353 | return nullptr; |
| 9354 | } |
| 9355 | return new (Context) OMPAtomicDefaultMemOrderClause(Kind, KindKwLoc, StartLoc, |
| 9356 | LParenLoc, EndLoc); |
| 9357 | } |
| 9358 | |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9359 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9360 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9361 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9362 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9363 | SourceLocation EndLoc) { |
| 9364 | OMPClause *Res = nullptr; |
| 9365 | switch (Kind) { |
| 9366 | case OMPC_schedule: |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9367 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 9368 | assert(Argument.size() == NumberOfElements && |
| 9369 | ArgumentLoc.size() == NumberOfElements); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9370 | Res = ActOnOpenMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9371 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 9372 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 9373 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 9374 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 9375 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9376 | break; |
| 9377 | case OMPC_if: |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9378 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 9379 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 9380 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 9381 | DelimLoc, EndLoc); |
| Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9382 | break; |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9383 | case OMPC_dist_schedule: |
| 9384 | Res = ActOnOpenMPDistScheduleClause( |
| 9385 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 9386 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 9387 | break; |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9388 | case OMPC_defaultmap: |
| 9389 | enum { Modifier, DefaultmapKind }; |
| 9390 | Res = ActOnOpenMPDefaultmapClause( |
| 9391 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 9392 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9393 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 9394 | EndLoc); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9395 | break; |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 9396 | case OMPC_final: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9397 | case OMPC_num_threads: |
| 9398 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 9399 | case OMPC_simdlen: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9400 | case OMPC_collapse: |
| 9401 | case OMPC_default: |
| 9402 | case OMPC_proc_bind: |
| 9403 | case OMPC_private: |
| 9404 | case OMPC_firstprivate: |
| 9405 | case OMPC_lastprivate: |
| 9406 | case OMPC_shared: |
| 9407 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9408 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 9409 | case OMPC_in_reduction: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9410 | case OMPC_linear: |
| 9411 | case OMPC_aligned: |
| 9412 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9413 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9414 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9415 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 9416 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 9417 | case OMPC_mergeable: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9418 | case OMPC_threadprivate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9419 | case OMPC_flush: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9420 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9421 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 9422 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9423 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 9424 | case OMPC_seq_cst: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9425 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9426 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9427 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 9428 | case OMPC_simd: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9429 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9430 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9431 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9432 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9433 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 9434 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9435 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9436 | case OMPC_hint: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9437 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 9438 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9439 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9440 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9441 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9442 | case OMPC_is_device_ptr: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 9443 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 9444 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 9445 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 9446 | case OMPC_dynamic_allocators: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 9447 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9448 | llvm_unreachable("Clause is not allowed."); |
| 9449 | } |
| 9450 | return Res; |
| 9451 | } |
| 9452 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9453 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 9454 | OpenMPScheduleClauseModifier M2, |
| 9455 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 9456 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 9457 | SmallVector<unsigned, 2> Excluded; |
| 9458 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 9459 | Excluded.push_back(M2); |
| 9460 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 9461 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 9462 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 9463 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 9464 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 9465 | << getListOfPossibleValues(OMPC_schedule, |
| 9466 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 9467 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 9468 | Excluded) |
| 9469 | << getOpenMPClauseName(OMPC_schedule); |
| 9470 | return true; |
| 9471 | } |
| 9472 | return false; |
| 9473 | } |
| 9474 | |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9475 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9476 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9477 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9478 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 9479 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 9480 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 9481 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 9482 | return nullptr; |
| 9483 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 9484 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 9485 | // but not both. |
| 9486 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 9487 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 9488 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 9489 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 9490 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 9491 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 9492 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 9493 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 9494 | return nullptr; |
| 9495 | } |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9496 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 9497 | std::string Values; |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9498 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 9499 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 9500 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 9501 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 9502 | Exclude); |
| 9503 | } else { |
| 9504 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 9505 | /*Last=*/OMPC_SCHEDULE_unknown); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9506 | } |
| 9507 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 9508 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 9509 | return nullptr; |
| 9510 | } |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9511 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 9512 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 9513 | // schedule(guided). |
| 9514 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 9515 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 9516 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 9517 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 9518 | diag::err_omp_schedule_nonmonotonic_static); |
| 9519 | return nullptr; |
| 9520 | } |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9521 | Expr *ValExpr = ChunkSize; |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 9522 | Stmt *HelperValStmt = nullptr; |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9523 | if (ChunkSize) { |
| 9524 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 9525 | !ChunkSize->isInstantiationDependent() && |
| 9526 | !ChunkSize->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9527 | SourceLocation ChunkSizeLoc = ChunkSize->getBeginLoc(); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9528 | ExprResult Val = |
| 9529 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 9530 | if (Val.isInvalid()) |
| 9531 | return nullptr; |
| 9532 | |
| 9533 | ValExpr = Val.get(); |
| 9534 | |
| 9535 | // OpenMP [2.7.1, Restrictions] |
| 9536 | // chunk_size must be a loop invariant integer expression with a positive |
| 9537 | // value. |
| 9538 | llvm::APSInt Result; |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 9539 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 9540 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 9541 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9542 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
| Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 9543 | return nullptr; |
| 9544 | } |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 9545 | } else if (getOpenMPCaptureRegionForClause( |
| 9546 | DSAStack->getCurrentDirective(), OMPC_schedule) != |
| 9547 | OMPD_unknown && |
| Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 9548 | !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 9549 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9550 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9551 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 9552 | HelperValStmt = buildPreInits(Context, Captures); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9553 | } |
| 9554 | } |
| 9555 | } |
| 9556 | |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9557 | return new (Context) |
| 9558 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 9559 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9560 | } |
| 9561 | |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9562 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 9563 | SourceLocation StartLoc, |
| 9564 | SourceLocation EndLoc) { |
| 9565 | OMPClause *Res = nullptr; |
| 9566 | switch (Kind) { |
| 9567 | case OMPC_ordered: |
| 9568 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 9569 | break; |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9570 | case OMPC_nowait: |
| 9571 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 9572 | break; |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 9573 | case OMPC_untied: |
| 9574 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 9575 | break; |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 9576 | case OMPC_mergeable: |
| 9577 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 9578 | break; |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9579 | case OMPC_read: |
| 9580 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 9581 | break; |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9582 | case OMPC_write: |
| 9583 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 9584 | break; |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 9585 | case OMPC_update: |
| 9586 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 9587 | break; |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9588 | case OMPC_capture: |
| 9589 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 9590 | break; |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 9591 | case OMPC_seq_cst: |
| 9592 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 9593 | break; |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9594 | case OMPC_threads: |
| 9595 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 9596 | break; |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 9597 | case OMPC_simd: |
| 9598 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 9599 | break; |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 9600 | case OMPC_nogroup: |
| 9601 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 9602 | break; |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 9603 | case OMPC_unified_address: |
| 9604 | Res = ActOnOpenMPUnifiedAddressClause(StartLoc, EndLoc); |
| 9605 | break; |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 9606 | case OMPC_unified_shared_memory: |
| 9607 | Res = ActOnOpenMPUnifiedSharedMemoryClause(StartLoc, EndLoc); |
| 9608 | break; |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 9609 | case OMPC_reverse_offload: |
| 9610 | Res = ActOnOpenMPReverseOffloadClause(StartLoc, EndLoc); |
| 9611 | break; |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 9612 | case OMPC_dynamic_allocators: |
| 9613 | Res = ActOnOpenMPDynamicAllocatorsClause(StartLoc, EndLoc); |
| 9614 | break; |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9615 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 9616 | case OMPC_final: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9617 | case OMPC_num_threads: |
| 9618 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 9619 | case OMPC_simdlen: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9620 | case OMPC_collapse: |
| 9621 | case OMPC_schedule: |
| 9622 | case OMPC_private: |
| 9623 | case OMPC_firstprivate: |
| 9624 | case OMPC_lastprivate: |
| 9625 | case OMPC_shared: |
| 9626 | case OMPC_reduction: |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9627 | case OMPC_task_reduction: |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 9628 | case OMPC_in_reduction: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9629 | case OMPC_linear: |
| 9630 | case OMPC_aligned: |
| 9631 | case OMPC_copyin: |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9632 | case OMPC_copyprivate: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9633 | case OMPC_default: |
| 9634 | case OMPC_proc_bind: |
| 9635 | case OMPC_threadprivate: |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9636 | case OMPC_flush: |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9637 | case OMPC_depend: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9638 | case OMPC_device: |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9639 | case OMPC_map: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9640 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9641 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9642 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9643 | case OMPC_grainsize: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9644 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9645 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9646 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9647 | case OMPC_defaultmap: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9648 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 9649 | case OMPC_uniform: |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9650 | case OMPC_to: |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9651 | case OMPC_from: |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9652 | case OMPC_use_device_ptr: |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9653 | case OMPC_is_device_ptr: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 9654 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9655 | llvm_unreachable("Clause is not allowed."); |
| 9656 | } |
| 9657 | return Res; |
| 9658 | } |
| 9659 | |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9660 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 9661 | SourceLocation EndLoc) { |
| Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 9662 | DSAStack->setNowaitRegion(); |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9663 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 9664 | } |
| 9665 | |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 9666 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 9667 | SourceLocation EndLoc) { |
| 9668 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 9669 | } |
| 9670 | |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 9671 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 9672 | SourceLocation EndLoc) { |
| 9673 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 9674 | } |
| 9675 | |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9676 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 9677 | SourceLocation EndLoc) { |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9678 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 9679 | } |
| 9680 | |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9681 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 9682 | SourceLocation EndLoc) { |
| 9683 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 9684 | } |
| 9685 | |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 9686 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 9687 | SourceLocation EndLoc) { |
| 9688 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 9689 | } |
| 9690 | |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9691 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 9692 | SourceLocation EndLoc) { |
| 9693 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 9694 | } |
| 9695 | |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 9696 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 9697 | SourceLocation EndLoc) { |
| 9698 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 9699 | } |
| 9700 | |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9701 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 9702 | SourceLocation EndLoc) { |
| 9703 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 9704 | } |
| 9705 | |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 9706 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 9707 | SourceLocation EndLoc) { |
| 9708 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 9709 | } |
| 9710 | |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 9711 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 9712 | SourceLocation EndLoc) { |
| 9713 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 9714 | } |
| 9715 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 9716 | OMPClause *Sema::ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc, |
| 9717 | SourceLocation EndLoc) { |
| 9718 | return new (Context) OMPUnifiedAddressClause(StartLoc, EndLoc); |
| 9719 | } |
| 9720 | |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 9721 | OMPClause *Sema::ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc, |
| 9722 | SourceLocation EndLoc) { |
| 9723 | return new (Context) OMPUnifiedSharedMemoryClause(StartLoc, EndLoc); |
| 9724 | } |
| 9725 | |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 9726 | OMPClause *Sema::ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, |
| 9727 | SourceLocation EndLoc) { |
| 9728 | return new (Context) OMPReverseOffloadClause(StartLoc, EndLoc); |
| 9729 | } |
| 9730 | |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 9731 | OMPClause *Sema::ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, |
| 9732 | SourceLocation EndLoc) { |
| 9733 | return new (Context) OMPDynamicAllocatorsClause(StartLoc, EndLoc); |
| 9734 | } |
| 9735 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9736 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 9737 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9738 | const OMPVarListLocTy &Locs, SourceLocation ColonLoc, |
| 9739 | CXXScopeSpec &ReductionOrMapperIdScopeSpec, |
| 9740 | DeclarationNameInfo &ReductionOrMapperId, OpenMPDependClauseKind DepKind, |
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 9741 | OpenMPLinearClauseKind LinKind, |
| 9742 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9743 | ArrayRef<SourceLocation> MapTypeModifiersLoc, OpenMPMapClauseKind MapType, |
| 9744 | bool IsMapTypeImplicit, SourceLocation DepLinMapLoc) { |
| 9745 | SourceLocation StartLoc = Locs.StartLoc; |
| 9746 | SourceLocation LParenLoc = Locs.LParenLoc; |
| 9747 | SourceLocation EndLoc = Locs.EndLoc; |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9748 | OMPClause *Res = nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9749 | switch (Kind) { |
| 9750 | case OMPC_private: |
| 9751 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9752 | break; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 9753 | case OMPC_firstprivate: |
| 9754 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9755 | break; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9756 | case OMPC_lastprivate: |
| 9757 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9758 | break; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9759 | case OMPC_shared: |
| 9760 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9761 | break; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9762 | case OMPC_reduction: |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9763 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9764 | EndLoc, ReductionOrMapperIdScopeSpec, |
| 9765 | ReductionOrMapperId); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9766 | break; |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9767 | case OMPC_task_reduction: |
| 9768 | Res = ActOnOpenMPTaskReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9769 | EndLoc, ReductionOrMapperIdScopeSpec, |
| 9770 | ReductionOrMapperId); |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 9771 | break; |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 9772 | case OMPC_in_reduction: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9773 | Res = ActOnOpenMPInReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 9774 | EndLoc, ReductionOrMapperIdScopeSpec, |
| 9775 | ReductionOrMapperId); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 9776 | break; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9777 | case OMPC_linear: |
| 9778 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9779 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9780 | break; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9781 | case OMPC_aligned: |
| 9782 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 9783 | ColonLoc, EndLoc); |
| 9784 | break; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9785 | case OMPC_copyin: |
| 9786 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9787 | break; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9788 | case OMPC_copyprivate: |
| 9789 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9790 | break; |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9791 | case OMPC_flush: |
| 9792 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 9793 | break; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9794 | case OMPC_depend: |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9795 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9796 | StartLoc, LParenLoc, EndLoc); |
| 9797 | break; |
| 9798 | case OMPC_map: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9799 | Res = ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc, |
| 9800 | ReductionOrMapperIdScopeSpec, |
| 9801 | ReductionOrMapperId, MapType, IsMapTypeImplicit, |
| 9802 | DepLinMapLoc, ColonLoc, VarList, Locs); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9803 | break; |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9804 | case OMPC_to: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9805 | Res = ActOnOpenMPToClause(VarList, Locs); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9806 | break; |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9807 | case OMPC_from: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9808 | Res = ActOnOpenMPFromClause(VarList, Locs); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 9809 | break; |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9810 | case OMPC_use_device_ptr: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9811 | Res = ActOnOpenMPUseDevicePtrClause(VarList, Locs); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 9812 | break; |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9813 | case OMPC_is_device_ptr: |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 9814 | Res = ActOnOpenMPIsDevicePtrClause(VarList, Locs); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 9815 | break; |
| Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 9816 | case OMPC_if: |
| Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 9817 | case OMPC_final: |
| Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 9818 | case OMPC_num_threads: |
| Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 9819 | case OMPC_safelen: |
| Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 9820 | case OMPC_simdlen: |
| Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 9821 | case OMPC_collapse: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9822 | case OMPC_default: |
| Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 9823 | case OMPC_proc_bind: |
| Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 9824 | case OMPC_schedule: |
| Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 9825 | case OMPC_ordered: |
| Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 9826 | case OMPC_nowait: |
| Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 9827 | case OMPC_untied: |
| Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 9828 | case OMPC_mergeable: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9829 | case OMPC_threadprivate: |
| Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 9830 | case OMPC_read: |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9831 | case OMPC_write: |
| Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 9832 | case OMPC_update: |
| Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 9833 | case OMPC_capture: |
| Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 9834 | case OMPC_seq_cst: |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9835 | case OMPC_device: |
| Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 9836 | case OMPC_threads: |
| Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 9837 | case OMPC_simd: |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 9838 | case OMPC_num_teams: |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9839 | case OMPC_thread_limit: |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9840 | case OMPC_priority: |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 9841 | case OMPC_grainsize: |
| Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 9842 | case OMPC_nogroup: |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 9843 | case OMPC_num_tasks: |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 9844 | case OMPC_hint: |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 9845 | case OMPC_dist_schedule: |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 9846 | case OMPC_defaultmap: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9847 | case OMPC_unknown: |
| Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 9848 | case OMPC_uniform: |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 9849 | case OMPC_unified_address: |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 9850 | case OMPC_unified_shared_memory: |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 9851 | case OMPC_reverse_offload: |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 9852 | case OMPC_dynamic_allocators: |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 9853 | case OMPC_atomic_default_mem_order: |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9854 | llvm_unreachable("Clause is not allowed."); |
| 9855 | } |
| 9856 | return Res; |
| 9857 | } |
| 9858 | |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 9859 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9860 | ExprObjectKind OK, SourceLocation Loc) { |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 9861 | ExprResult Res = BuildDeclRefExpr( |
| 9862 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 9863 | if (!Res.isUsable()) |
| 9864 | return ExprError(); |
| 9865 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 9866 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 9867 | if (!Res.isUsable()) |
| 9868 | return ExprError(); |
| 9869 | } |
| 9870 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 9871 | Res = DefaultLvalueConversion(Res.get()); |
| 9872 | if (!Res.isUsable()) |
| 9873 | return ExprError(); |
| 9874 | } |
| 9875 | return Res; |
| 9876 | } |
| 9877 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9878 | static std::pair<ValueDecl *, bool> |
| 9879 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 9880 | SourceRange &ERange, bool AllowArraySection = false) { |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9881 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 9882 | RefExpr->containsUnexpandedParameterPack()) |
| 9883 | return std::make_pair(nullptr, true); |
| 9884 | |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9885 | // OpenMP [3.1, C/C++] |
| 9886 | // A list item is a variable name. |
| 9887 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 9888 | // A variable that is part of another variable (as an array or |
| 9889 | // structure element) cannot appear in a private clause. |
| 9890 | RefExpr = RefExpr->IgnoreParens(); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9891 | enum { |
| 9892 | NoArrayExpr = -1, |
| 9893 | ArraySubscript = 0, |
| 9894 | OMPArraySection = 1 |
| 9895 | } IsArrayExpr = NoArrayExpr; |
| 9896 | if (AllowArraySection) { |
| 9897 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9898 | Expr *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9899 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 9900 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 9901 | RefExpr = Base; |
| 9902 | IsArrayExpr = ArraySubscript; |
| 9903 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9904 | Expr *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9905 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 9906 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 9907 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 9908 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 9909 | RefExpr = Base; |
| 9910 | IsArrayExpr = OMPArraySection; |
| 9911 | } |
| 9912 | } |
| 9913 | ELoc = RefExpr->getExprLoc(); |
| 9914 | ERange = RefExpr->getSourceRange(); |
| 9915 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9916 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 9917 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 9918 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 9919 | (S.getCurrentThisType().isNull() || !ME || |
| 9920 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 9921 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9922 | if (IsArrayExpr != NoArrayExpr) { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9923 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 9924 | << ERange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9925 | } else { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9926 | S.Diag(ELoc, |
| 9927 | AllowArraySection |
| 9928 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 9929 | : diag::err_omp_expected_var_name_member_expr) |
| 9930 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 9931 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9932 | return std::make_pair(nullptr, false); |
| 9933 | } |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 9934 | return std::make_pair( |
| 9935 | getCanonicalDecl(DE ? DE->getDecl() : ME->getMemberDecl()), false); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9936 | } |
| 9937 | |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9938 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 9939 | SourceLocation StartLoc, |
| 9940 | SourceLocation LParenLoc, |
| 9941 | SourceLocation EndLoc) { |
| 9942 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9943 | SmallVector<Expr *, 8> PrivateCopies; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9944 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9945 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9946 | SourceLocation ELoc; |
| 9947 | SourceRange ERange; |
| 9948 | Expr *SimpleRefExpr = RefExpr; |
| 9949 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9950 | if (Res.second) { |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9951 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9952 | Vars.push_back(RefExpr); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 9953 | PrivateCopies.push_back(nullptr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9954 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 9955 | ValueDecl *D = Res.first; |
| 9956 | if (!D) |
| 9957 | continue; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9958 | |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9959 | QualType Type = D->getType(); |
| 9960 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9961 | |
| 9962 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 9963 | // A variable that appears in a private clause must not have an incomplete |
| 9964 | // type or a reference type. |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9965 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9966 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9967 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 9968 | |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 9969 | // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions] |
| 9970 | // A variable that is privatized must not have a const-qualified type |
| 9971 | // unless it is of class type with a mutable member. This restriction does |
| 9972 | // not apply to the firstprivate clause. |
| 9973 | // |
| 9974 | // OpenMP 3.1 [2.9.3.3, private clause, Restrictions] |
| 9975 | // A variable that appears in a private clause must not have a |
| 9976 | // const-qualified type unless it is of class type with a mutable member. |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 9977 | if (rejectConstNotMutableType(*this, D, Type, OMPC_private, ELoc)) |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 9978 | continue; |
| 9979 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9980 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9981 | // in a Construct] |
| 9982 | // Variables with the predetermined data-sharing attributes may not be |
| 9983 | // listed in data-sharing attributes clauses, except for the cases |
| 9984 | // listed below. For these exceptions only, listing a predetermined |
| 9985 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9986 | // the variable's predetermined data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9987 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9988 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9989 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9990 | << getOpenMPClauseName(OMPC_private); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9991 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9992 | continue; |
| 9993 | } |
| 9994 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 9995 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9996 | // Variably modified types are not supported for tasks. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9997 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 9998 | isOpenMPTaskingDirective(CurrDir)) { |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9999 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 10000 | << getOpenMPClauseName(OMPC_private) << Type |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 10001 | << getOpenMPDirectiveName(CurrDir); |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10002 | bool IsDecl = |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10003 | !VD || |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10004 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10005 | Diag(D->getLocation(), |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10006 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10007 | << D; |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10008 | continue; |
| 10009 | } |
| 10010 | |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10011 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 10012 | // A list item cannot appear in both a map clause and a data-sharing |
| 10013 | // attribute clause on the same construct |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10014 | if (isOpenMPTargetExecutionDirective(CurrDir)) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10015 | OpenMPClauseKind ConflictKind; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10016 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10017 | VD, /*CurrentRegionOnly=*/true, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10018 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 10019 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 10020 | ConflictKind = WhereFoundClauseKind; |
| 10021 | return true; |
| 10022 | })) { |
| 10023 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10024 | << getOpenMPClauseName(OMPC_private) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10025 | << getOpenMPClauseName(ConflictKind) |
| Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 10026 | << getOpenMPDirectiveName(CurrDir); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10027 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10028 | continue; |
| 10029 | } |
| 10030 | } |
| 10031 | |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10032 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 10033 | // A variable of class type (or array thereof) that appears in a private |
| 10034 | // clause requires an accessible, unambiguous default constructor for the |
| 10035 | // class type. |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 10036 | // Generate helper private variable and initialize it with the default |
| 10037 | // value. The address of the original variable is replaced by the address of |
| 10038 | // the new private variable in CodeGen. This new variable is not added to |
| 10039 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 10040 | // proper diagnostics. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10041 | Type = Type.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10042 | VarDecl *VDPrivate = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 10043 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 10044 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 10045 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 10046 | ActOnUninitializedDecl(VDPrivate); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 10047 | if (VDPrivate->isInvalidDecl()) |
| 10048 | continue; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10049 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10050 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 10051 | |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 10052 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 10053 | if (!VD && !CurContext->isDependentContext()) |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 10054 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 10055 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 10056 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 10057 | ? RefExpr->IgnoreParens() |
| 10058 | : Ref); |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 10059 | PrivateCopies.push_back(VDPrivateRefExpr); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 10060 | } |
| 10061 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10062 | if (Vars.empty()) |
| 10063 | return nullptr; |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 10064 | |
| Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 10065 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 10066 | PrivateCopies); |
| Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 10067 | } |
| 10068 | |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10069 | namespace { |
| 10070 | class DiagsUninitializedSeveretyRAII { |
| 10071 | private: |
| 10072 | DiagnosticsEngine &Diags; |
| 10073 | SourceLocation SavedLoc; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10074 | bool IsIgnored = false; |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10075 | |
| 10076 | public: |
| 10077 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 10078 | bool IsIgnored) |
| 10079 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 10080 | if (!IsIgnored) { |
| 10081 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 10082 | /*Map*/ diag::Severity::Ignored, Loc); |
| 10083 | } |
| 10084 | } |
| 10085 | ~DiagsUninitializedSeveretyRAII() { |
| 10086 | if (!IsIgnored) |
| 10087 | Diags.popMappings(SavedLoc); |
| 10088 | } |
| 10089 | }; |
| Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 10090 | } |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10091 | |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10092 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 10093 | SourceLocation StartLoc, |
| 10094 | SourceLocation LParenLoc, |
| 10095 | SourceLocation EndLoc) { |
| 10096 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10097 | SmallVector<Expr *, 8> PrivateCopies; |
| 10098 | SmallVector<Expr *, 8> Inits; |
| Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 10099 | SmallVector<Decl *, 4> ExprCaptures; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10100 | bool IsImplicitClause = |
| 10101 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10102 | SourceLocation ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10103 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10104 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10105 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10106 | SourceLocation ELoc; |
| 10107 | SourceRange ERange; |
| 10108 | Expr *SimpleRefExpr = RefExpr; |
| 10109 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10110 | if (Res.second) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10111 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10112 | Vars.push_back(RefExpr); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10113 | PrivateCopies.push_back(nullptr); |
| 10114 | Inits.push_back(nullptr); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10115 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10116 | ValueDecl *D = Res.first; |
| 10117 | if (!D) |
| 10118 | continue; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10119 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10120 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10121 | QualType Type = D->getType(); |
| 10122 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10123 | |
| 10124 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 10125 | // A variable that appears in a private clause must not have an incomplete |
| 10126 | // type or a reference type. |
| 10127 | if (RequireCompleteType(ELoc, Type, |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10128 | diag::err_omp_firstprivate_incomplete_type)) |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10129 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 10130 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10131 | |
| 10132 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 10133 | // 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] | 10134 | // clause requires an accessible, unambiguous copy constructor for the |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10135 | // class type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10136 | QualType ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10137 | |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10138 | // If an implicit firstprivate variable found it was checked already. |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10139 | DSAStackTy::DSAVarData TopDVar; |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10140 | if (!IsImplicitClause) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10141 | DSAStackTy::DSAVarData DVar = |
| 10142 | DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10143 | TopDVar = DVar; |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10144 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10145 | bool IsConstant = ElemType.isConstant(Context); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10146 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 10147 | // A list item that specifies a given variable may not appear in more |
| 10148 | // than one clause on the same directive, except that a variable may be |
| 10149 | // specified in both firstprivate and lastprivate clauses. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10150 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 10151 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 10152 | // both. |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10153 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
| Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 10154 | (isOpenMPDistributeDirective(CurrDir) || |
| 10155 | DVar.CKind != OMPC_lastprivate) && |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10156 | DVar.RefExpr) { |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10157 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10158 | << getOpenMPClauseName(DVar.CKind) |
| 10159 | << getOpenMPClauseName(OMPC_firstprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10160 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10161 | continue; |
| 10162 | } |
| 10163 | |
| 10164 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 10165 | // in a Construct] |
| 10166 | // Variables with the predetermined data-sharing attributes may not be |
| 10167 | // listed in data-sharing attributes clauses, except for the cases |
| 10168 | // listed below. For these exceptions only, listing a predetermined |
| 10169 | // variable in a data-sharing attribute clause is allowed and overrides |
| 10170 | // the variable's predetermined data-sharing attributes. |
| 10171 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 10172 | // in a Construct, C/C++, p.2] |
| 10173 | // Variables with const-qualified type having no mutable member may be |
| 10174 | // listed in a firstprivate clause, even if they are static data members. |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10175 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10176 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 10177 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10178 | << getOpenMPClauseName(DVar.CKind) |
| 10179 | << getOpenMPClauseName(OMPC_firstprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10180 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10181 | continue; |
| 10182 | } |
| 10183 | |
| 10184 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 10185 | // A list item that is private within a parallel region must not appear |
| 10186 | // in a firstprivate clause on a worksharing construct if any of the |
| 10187 | // worksharing regions arising from the worksharing construct ever bind |
| 10188 | // to any of the parallel regions arising from the parallel construct. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10189 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 10190 | // A list item that is private within a teams region must not appear in a |
| 10191 | // firstprivate clause on a distribute construct if any of the distribute |
| 10192 | // regions arising from the distribute construct ever bind to any of the |
| 10193 | // teams regions arising from the teams construct. |
| 10194 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 10195 | // A list item that appears in a reduction clause of a teams construct |
| 10196 | // must not appear in a firstprivate clause on a distribute construct if |
| 10197 | // any of the distribute regions arising from the distribute construct |
| 10198 | // ever bind to any of the teams regions arising from the teams construct. |
| 10199 | if ((isOpenMPWorksharingDirective(CurrDir) || |
| 10200 | isOpenMPDistributeDirective(CurrDir)) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10201 | !isOpenMPParallelDirective(CurrDir) && |
| 10202 | !isOpenMPTeamsDirective(CurrDir)) { |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10203 | DVar = DSAStack->getImplicitDSA(D, true); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10204 | if (DVar.CKind != OMPC_shared && |
| 10205 | (isOpenMPParallelDirective(DVar.DKind) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10206 | isOpenMPTeamsDirective(DVar.DKind) || |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10207 | DVar.DKind == OMPD_unknown)) { |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 10208 | Diag(ELoc, diag::err_omp_required_access) |
| 10209 | << getOpenMPClauseName(OMPC_firstprivate) |
| 10210 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10211 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 10212 | continue; |
| 10213 | } |
| 10214 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10215 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 10216 | // A list item that appears in a reduction clause of a parallel construct |
| 10217 | // must not appear in a firstprivate clause on a worksharing or task |
| 10218 | // construct if any of the worksharing or task regions arising from the |
| 10219 | // worksharing or task construct ever bind to any of the parallel regions |
| 10220 | // arising from the parallel construct. |
| 10221 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 10222 | // A list item that appears in a reduction clause in worksharing |
| 10223 | // construct must not appear in a firstprivate clause in a task construct |
| 10224 | // encountered during execution of any of the worksharing regions arising |
| 10225 | // from the worksharing construct. |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 10226 | if (isOpenMPTaskingDirective(CurrDir)) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 10227 | DVar = DSAStack->hasInnermostDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10228 | D, [](OpenMPClauseKind C) { return C == OMPC_reduction; }, |
| 10229 | [](OpenMPDirectiveKind K) { |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 10230 | return isOpenMPParallelDirective(K) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10231 | isOpenMPWorksharingDirective(K) || |
| 10232 | isOpenMPTeamsDirective(K); |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 10233 | }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10234 | /*FromParent=*/true); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10235 | if (DVar.CKind == OMPC_reduction && |
| 10236 | (isOpenMPParallelDirective(DVar.DKind) || |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10237 | isOpenMPWorksharingDirective(DVar.DKind) || |
| 10238 | isOpenMPTeamsDirective(DVar.DKind))) { |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10239 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 10240 | << getOpenMPDirectiveName(DVar.DKind); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10241 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 10242 | continue; |
| 10243 | } |
| 10244 | } |
| Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 10245 | |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10246 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 10247 | // A list item cannot appear in both a map clause and a data-sharing |
| 10248 | // attribute clause on the same construct |
| Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 10249 | if (isOpenMPTargetExecutionDirective(CurrDir)) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10250 | OpenMPClauseKind ConflictKind; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10251 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10252 | VD, /*CurrentRegionOnly=*/true, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10253 | [&ConflictKind]( |
| 10254 | OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 10255 | OpenMPClauseKind WhereFoundClauseKind) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10256 | ConflictKind = WhereFoundClauseKind; |
| 10257 | return true; |
| 10258 | })) { |
| 10259 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10260 | << getOpenMPClauseName(OMPC_firstprivate) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10261 | << getOpenMPClauseName(ConflictKind) |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10262 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10263 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10264 | continue; |
| 10265 | } |
| 10266 | } |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10267 | } |
| 10268 | |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10269 | // Variably modified types are not supported for tasks. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 10270 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
| Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 10271 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10272 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 10273 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 10274 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 10275 | bool IsDecl = |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10276 | !VD || |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10277 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10278 | Diag(D->getLocation(), |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10279 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10280 | << D; |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10281 | continue; |
| 10282 | } |
| 10283 | |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10284 | Type = Type.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10285 | VarDecl *VDPrivate = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 10286 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 10287 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 10288 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10289 | // Generate helper private variable and initialize it with the value of the |
| 10290 | // original variable. The address of the original variable is replaced by |
| 10291 | // the address of the new private variable in the CodeGen. This new variable |
| 10292 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 10293 | // original variable for proper diagnostics and variable capturing. |
| 10294 | Expr *VDInitRefExpr = nullptr; |
| 10295 | // For arrays generate initializer for single element and replace it by the |
| 10296 | // original array element in CodeGen. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10297 | if (Type->isArrayType()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10298 | VarDecl *VDInit = |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10299 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10300 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10301 | Expr *Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10302 | ElemType = ElemType.getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10303 | VarDecl *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
| 10304 | ".firstprivate.temp"); |
| Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 10305 | InitializedEntity Entity = |
| 10306 | InitializedEntity::InitializeVariable(VDInitTemp); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10307 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 10308 | |
| 10309 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 10310 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 10311 | if (Result.isInvalid()) |
| 10312 | VDPrivate->setInvalidDecl(); |
| 10313 | else |
| 10314 | VDPrivate->setInit(Result.getAs<Expr>()); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 10315 | // Remove temp variable declaration. |
| 10316 | Context.Deallocate(VDInitTemp); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10317 | } else { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10318 | VarDecl *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 10319 | ".firstprivate.temp"); |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10320 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 10321 | RefExpr->getExprLoc()); |
| Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 10322 | AddInitializerToDecl(VDPrivate, |
| 10323 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 10324 | /*DirectInit=*/false); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10325 | } |
| 10326 | if (VDPrivate->isInvalidDecl()) { |
| 10327 | if (IsImplicitClause) { |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10328 | Diag(RefExpr->getExprLoc(), |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10329 | diag::note_omp_task_predetermined_firstprivate_here); |
| 10330 | } |
| 10331 | continue; |
| 10332 | } |
| 10333 | CurContext->addDecl(VDPrivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10334 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10335 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 10336 | RefExpr->getExprLoc()); |
| 10337 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 10338 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10339 | if (TopDVar.CKind == OMPC_lastprivate) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10340 | Ref = TopDVar.PrivateCopy; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10341 | } else { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 10342 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10343 | if (!isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10344 | ExprCaptures.push_back(Ref->getDecl()); |
| 10345 | } |
| Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 10346 | } |
| Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 10347 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 10348 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 10349 | ? RefExpr->IgnoreParens() |
| 10350 | : Ref); |
| Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 10351 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 10352 | Inits.push_back(VDInitRefExpr); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10353 | } |
| 10354 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10355 | if (Vars.empty()) |
| 10356 | return nullptr; |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10357 | |
| 10358 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10359 | Vars, PrivateCopies, Inits, |
| 10360 | buildPreInits(Context, ExprCaptures)); |
| Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 10361 | } |
| 10362 | |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10363 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 10364 | SourceLocation StartLoc, |
| 10365 | SourceLocation LParenLoc, |
| 10366 | SourceLocation EndLoc) { |
| 10367 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 10368 | SmallVector<Expr *, 8> SrcExprs; |
| 10369 | SmallVector<Expr *, 8> DstExprs; |
| 10370 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10371 | SmallVector<Decl *, 4> ExprCaptures; |
| 10372 | SmallVector<Expr *, 4> ExprPostUpdates; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10373 | for (Expr *RefExpr : VarList) { |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10374 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10375 | SourceLocation ELoc; |
| 10376 | SourceRange ERange; |
| 10377 | Expr *SimpleRefExpr = RefExpr; |
| 10378 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10379 | if (Res.second) { |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10380 | // It will be analyzed later. |
| 10381 | Vars.push_back(RefExpr); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 10382 | SrcExprs.push_back(nullptr); |
| 10383 | DstExprs.push_back(nullptr); |
| 10384 | AssignmentOps.push_back(nullptr); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10385 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10386 | ValueDecl *D = Res.first; |
| 10387 | if (!D) |
| 10388 | continue; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10389 | |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10390 | QualType Type = D->getType(); |
| 10391 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10392 | |
| 10393 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 10394 | // A variable that appears in a lastprivate clause must not have an |
| 10395 | // incomplete type or a reference type. |
| 10396 | if (RequireCompleteType(ELoc, Type, |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10397 | diag::err_omp_lastprivate_incomplete_type)) |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10398 | continue; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 10399 | Type = Type.getNonReferenceType(); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10400 | |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 10401 | // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions] |
| 10402 | // A variable that is privatized must not have a const-qualified type |
| 10403 | // unless it is of class type with a mutable member. This restriction does |
| 10404 | // not apply to the firstprivate clause. |
| 10405 | // |
| 10406 | // OpenMP 3.1 [2.9.3.5, lastprivate clause, Restrictions] |
| 10407 | // A variable that appears in a lastprivate clause must not have a |
| 10408 | // const-qualified type unless it is of class type with a mutable member. |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 10409 | if (rejectConstNotMutableType(*this, D, Type, OMPC_lastprivate, ELoc)) |
| Joel E. Denny | e6234d142 | 2019-01-04 22:11:31 +0000 | [diff] [blame] | 10410 | continue; |
| 10411 | |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10412 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10413 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 10414 | // in a Construct] |
| 10415 | // Variables with the predetermined data-sharing attributes may not be |
| 10416 | // listed in data-sharing attributes clauses, except for the cases |
| 10417 | // listed below. |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10418 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 10419 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 10420 | // both. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10421 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10422 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| Alexey Bataev | b358f99 | 2017-12-01 17:40:15 +0000 | [diff] [blame] | 10423 | (isOpenMPDistributeDirective(CurrDir) || |
| 10424 | DVar.CKind != OMPC_firstprivate) && |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10425 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 10426 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 10427 | << getOpenMPClauseName(DVar.CKind) |
| 10428 | << getOpenMPClauseName(OMPC_lastprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10429 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10430 | continue; |
| 10431 | } |
| 10432 | |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 10433 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 10434 | // A list item that is private within a parallel region, or that appears in |
| 10435 | // the reduction clause of a parallel construct, must not appear in a |
| 10436 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 10437 | // worksharing regions ever binds to any of the corresponding parallel |
| 10438 | // regions. |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 10439 | DSAStackTy::DSAVarData TopDVar = DVar; |
| Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 10440 | if (isOpenMPWorksharingDirective(CurrDir) && |
| Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 10441 | !isOpenMPParallelDirective(CurrDir) && |
| 10442 | !isOpenMPTeamsDirective(CurrDir)) { |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10443 | DVar = DSAStack->getImplicitDSA(D, true); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 10444 | if (DVar.CKind != OMPC_shared) { |
| 10445 | Diag(ELoc, diag::err_omp_required_access) |
| 10446 | << getOpenMPClauseName(OMPC_lastprivate) |
| 10447 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10448 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 10449 | continue; |
| 10450 | } |
| 10451 | } |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10452 | |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10453 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 10454 | // A variable of class type (or array thereof) that appears in a |
| 10455 | // lastprivate clause requires an accessible, unambiguous default |
| 10456 | // constructor for the class type, unless the list item is also specified |
| 10457 | // in a firstprivate clause. |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10458 | // A variable of class type (or array thereof) that appears in a |
| 10459 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 10460 | // operator for the class type. |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 10461 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10462 | VarDecl *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
| 10463 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 10464 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 10465 | DeclRefExpr *PseudoSrcExpr = |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10466 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10467 | VarDecl *DstVD = |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10468 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10469 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10470 | DeclRefExpr *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 10471 | // For arrays generate assignment operation for single element and replace |
| 10472 | // it by the original array element in CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10473 | ExprResult AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
| 10474 | PseudoDstExpr, PseudoSrcExpr); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 10475 | if (AssignmentOp.isInvalid()) |
| 10476 | continue; |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 10477 | AssignmentOp = |
| 10478 | ActOnFinishFullExpr(AssignmentOp.get(), ELoc, /*DiscardedValue*/ false); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 10479 | if (AssignmentOp.isInvalid()) |
| 10480 | continue; |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10481 | |
| Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 10482 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 10483 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10484 | if (TopDVar.CKind == OMPC_firstprivate) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10485 | Ref = TopDVar.PrivateCopy; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10486 | } else { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 10487 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10488 | if (!isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10489 | ExprCaptures.push_back(Ref->getDecl()); |
| 10490 | } |
| 10491 | if (TopDVar.CKind == OMPC_firstprivate || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10492 | (!isOpenMPCapturedDecl(D) && |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 10493 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10494 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 10495 | if (!RefRes.isUsable()) |
| 10496 | continue; |
| 10497 | ExprResult PostUpdateRes = |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10498 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 10499 | RefRes.get()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10500 | if (!PostUpdateRes.isUsable()) |
| 10501 | continue; |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 10502 | ExprPostUpdates.push_back( |
| 10503 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10504 | } |
| 10505 | } |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 10506 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 10507 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 10508 | ? RefExpr->IgnoreParens() |
| 10509 | : Ref); |
| Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 10510 | SrcExprs.push_back(PseudoSrcExpr); |
| 10511 | DstExprs.push_back(PseudoDstExpr); |
| 10512 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10513 | } |
| 10514 | |
| 10515 | if (Vars.empty()) |
| 10516 | return nullptr; |
| 10517 | |
| 10518 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 10519 | Vars, SrcExprs, DstExprs, AssignmentOps, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10520 | buildPreInits(Context, ExprCaptures), |
| 10521 | buildPostUpdate(*this, ExprPostUpdates)); |
| Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 10522 | } |
| 10523 | |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10524 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 10525 | SourceLocation StartLoc, |
| 10526 | SourceLocation LParenLoc, |
| 10527 | SourceLocation EndLoc) { |
| 10528 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10529 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 10530 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10531 | SourceLocation ELoc; |
| 10532 | SourceRange ERange; |
| 10533 | Expr *SimpleRefExpr = RefExpr; |
| 10534 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 10535 | if (Res.second) { |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10536 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10537 | Vars.push_back(RefExpr); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10538 | } |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 10539 | ValueDecl *D = Res.first; |
| 10540 | if (!D) |
| 10541 | continue; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10542 | |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 10543 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10544 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 10545 | // in a Construct] |
| 10546 | // Variables with the predetermined data-sharing attributes may not be |
| 10547 | // listed in data-sharing attributes clauses, except for the cases |
| 10548 | // listed below. For these exceptions only, listing a predetermined |
| 10549 | // variable in a data-sharing attribute clause is allowed and overrides |
| 10550 | // the variable's predetermined data-sharing attributes. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10551 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10552 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 10553 | DVar.RefExpr) { |
| 10554 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 10555 | << getOpenMPClauseName(OMPC_shared); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10556 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10557 | continue; |
| 10558 | } |
| 10559 | |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 10560 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10561 | if (!VD && isOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 10562 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 10563 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 10564 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 10565 | ? RefExpr->IgnoreParens() |
| 10566 | : Ref); |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10567 | } |
| 10568 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10569 | if (Vars.empty()) |
| 10570 | return nullptr; |
| Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 10571 | |
| 10572 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 10573 | } |
| 10574 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10575 | namespace { |
| 10576 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 10577 | DSAStackTy *Stack; |
| 10578 | |
| 10579 | public: |
| 10580 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10581 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 10582 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10583 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 10584 | return false; |
| 10585 | if (DVar.CKind != OMPC_unknown) |
| 10586 | return true; |
| Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 10587 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10588 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) { return true; }, |
| Alexey Bataev | effbdf1 | 2017-07-21 17:24:30 +0000 | [diff] [blame] | 10589 | /*FromParent=*/true); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10590 | return DVarPrivate.CKind != OMPC_unknown; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10591 | } |
| 10592 | return false; |
| 10593 | } |
| 10594 | bool VisitStmt(Stmt *S) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10595 | for (Stmt *Child : S->children()) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10596 | if (Child && Visit(Child)) |
| 10597 | return true; |
| 10598 | } |
| 10599 | return false; |
| 10600 | } |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 10601 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10602 | }; |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 10603 | } // namespace |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10604 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10605 | namespace { |
| 10606 | // Transform MemberExpression for specified FieldDecl of current class to |
| 10607 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 10608 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 10609 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10610 | ValueDecl *Field = nullptr; |
| 10611 | DeclRefExpr *CapturedExpr = nullptr; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10612 | |
| 10613 | public: |
| 10614 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 10615 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 10616 | |
| 10617 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 10618 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 10619 | E->getMemberDecl() == Field) { |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 10620 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 10621 | return CapturedExpr; |
| 10622 | } |
| 10623 | return BaseTransform::TransformMemberExpr(E); |
| 10624 | } |
| 10625 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 10626 | }; |
| 10627 | } // namespace |
| 10628 | |
| Alexey Bataev | 97d18bf | 2018-04-11 19:21:00 +0000 | [diff] [blame] | 10629 | template <typename T, typename U> |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 10630 | static T filterLookupForUDReductionAndMapper( |
| 10631 | SmallVectorImpl<U> &Lookups, const llvm::function_ref<T(ValueDecl *)> Gen) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10632 | for (U &Set : Lookups) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10633 | for (auto *D : Set) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10634 | if (T Res = Gen(cast<ValueDecl>(D))) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10635 | return Res; |
| 10636 | } |
| 10637 | } |
| 10638 | return T(); |
| 10639 | } |
| 10640 | |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10641 | static NamedDecl *findAcceptableDecl(Sema &SemaRef, NamedDecl *D) { |
| 10642 | assert(!LookupResult::isVisible(SemaRef, D) && "not in slow case"); |
| 10643 | |
| 10644 | for (auto RD : D->redecls()) { |
| 10645 | // Don't bother with extra checks if we already know this one isn't visible. |
| 10646 | if (RD == D) |
| 10647 | continue; |
| 10648 | |
| 10649 | auto ND = cast<NamedDecl>(RD); |
| 10650 | if (LookupResult::isVisible(SemaRef, ND)) |
| 10651 | return ND; |
| 10652 | } |
| 10653 | |
| 10654 | return nullptr; |
| 10655 | } |
| 10656 | |
| 10657 | static void |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 10658 | argumentDependentLookup(Sema &SemaRef, const DeclarationNameInfo &Id, |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10659 | SourceLocation Loc, QualType Ty, |
| 10660 | SmallVectorImpl<UnresolvedSet<8>> &Lookups) { |
| 10661 | // Find all of the associated namespaces and classes based on the |
| 10662 | // arguments we have. |
| 10663 | Sema::AssociatedNamespaceSet AssociatedNamespaces; |
| 10664 | Sema::AssociatedClassSet AssociatedClasses; |
| 10665 | OpaqueValueExpr OVE(Loc, Ty, VK_LValue); |
| 10666 | SemaRef.FindAssociatedClassesAndNamespaces(Loc, &OVE, AssociatedNamespaces, |
| 10667 | AssociatedClasses); |
| 10668 | |
| 10669 | // C++ [basic.lookup.argdep]p3: |
| 10670 | // Let X be the lookup set produced by unqualified lookup (3.4.1) |
| 10671 | // and let Y be the lookup set produced by argument dependent |
| 10672 | // lookup (defined as follows). If X contains [...] then Y is |
| 10673 | // empty. Otherwise Y is the set of declarations found in the |
| 10674 | // namespaces associated with the argument types as described |
| 10675 | // below. The set of declarations found by the lookup of the name |
| 10676 | // is the union of X and Y. |
| 10677 | // |
| 10678 | // Here, we compute Y and add its members to the overloaded |
| 10679 | // candidate set. |
| 10680 | for (auto *NS : AssociatedNamespaces) { |
| 10681 | // When considering an associated namespace, the lookup is the |
| 10682 | // same as the lookup performed when the associated namespace is |
| 10683 | // used as a qualifier (3.4.3.2) except that: |
| 10684 | // |
| 10685 | // -- Any using-directives in the associated namespace are |
| 10686 | // ignored. |
| 10687 | // |
| 10688 | // -- Any namespace-scope friend functions declared in |
| 10689 | // associated classes are visible within their respective |
| 10690 | // namespaces even if they are not visible during an ordinary |
| 10691 | // lookup (11.4). |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 10692 | DeclContext::lookup_result R = NS->lookup(Id.getName()); |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10693 | for (auto *D : R) { |
| 10694 | auto *Underlying = D; |
| 10695 | if (auto *USD = dyn_cast<UsingShadowDecl>(D)) |
| 10696 | Underlying = USD->getTargetDecl(); |
| 10697 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 10698 | if (!isa<OMPDeclareReductionDecl>(Underlying) && |
| 10699 | !isa<OMPDeclareMapperDecl>(Underlying)) |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10700 | continue; |
| 10701 | |
| 10702 | if (!SemaRef.isVisible(D)) { |
| 10703 | D = findAcceptableDecl(SemaRef, D); |
| 10704 | if (!D) |
| 10705 | continue; |
| 10706 | if (auto *USD = dyn_cast<UsingShadowDecl>(D)) |
| 10707 | Underlying = USD->getTargetDecl(); |
| 10708 | } |
| 10709 | Lookups.emplace_back(); |
| 10710 | Lookups.back().addDecl(Underlying); |
| 10711 | } |
| 10712 | } |
| 10713 | } |
| 10714 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10715 | static ExprResult |
| 10716 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 10717 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 10718 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 10719 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 10720 | if (ReductionIdScopeSpec.isInvalid()) |
| 10721 | return ExprError(); |
| 10722 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 10723 | if (S) { |
| 10724 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 10725 | Lookup.suppressDiagnostics(); |
| 10726 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10727 | NamedDecl *D = Lookup.getRepresentativeDecl(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10728 | do { |
| 10729 | S = S->getParent(); |
| 10730 | } while (S && !S->isDeclScope(D)); |
| 10731 | if (S) |
| 10732 | S = S->getParent(); |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10733 | Lookups.emplace_back(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10734 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 10735 | Lookup.clear(); |
| 10736 | } |
| 10737 | } else if (auto *ULE = |
| 10738 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 10739 | Lookups.push_back(UnresolvedSet<8>()); |
| 10740 | Decl *PrevD = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10741 | for (NamedDecl *D : ULE->decls()) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10742 | if (D == PrevD) |
| 10743 | Lookups.push_back(UnresolvedSet<8>()); |
| 10744 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 10745 | Lookups.back().addDecl(DRD); |
| 10746 | PrevD = D; |
| 10747 | } |
| 10748 | } |
| Alexey Bataev | fdc2035 | 2017-08-25 15:43:55 +0000 | [diff] [blame] | 10749 | if (SemaRef.CurContext->isDependentContext() || Ty->isDependentType() || |
| 10750 | Ty->isInstantiationDependentType() || |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10751 | Ty->containsUnexpandedParameterPack() || |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 10752 | filterLookupForUDReductionAndMapper<bool>(Lookups, [](ValueDecl *D) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10753 | return !D->isInvalidDecl() && |
| 10754 | (D->getType()->isDependentType() || |
| 10755 | D->getType()->isInstantiationDependentType() || |
| 10756 | D->getType()->containsUnexpandedParameterPack()); |
| 10757 | })) { |
| 10758 | UnresolvedSet<8> ResSet; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10759 | for (const UnresolvedSet<8> &Set : Lookups) { |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10760 | if (Set.empty()) |
| 10761 | continue; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10762 | ResSet.append(Set.begin(), Set.end()); |
| 10763 | // The last item marks the end of all declarations at the specified scope. |
| 10764 | ResSet.addDecl(Set[Set.size() - 1]); |
| 10765 | } |
| 10766 | return UnresolvedLookupExpr::Create( |
| 10767 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 10768 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 10769 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 10770 | } |
| Alexey Bataev | 43b90b7 | 2018-09-12 16:31:59 +0000 | [diff] [blame] | 10771 | // Lookup inside the classes. |
| 10772 | // C++ [over.match.oper]p3: |
| 10773 | // For a unary operator @ with an operand of a type whose |
| 10774 | // cv-unqualified version is T1, and for a binary operator @ with |
| 10775 | // a left operand of a type whose cv-unqualified version is T1 and |
| 10776 | // a right operand of a type whose cv-unqualified version is T2, |
| 10777 | // three sets of candidate functions, designated member |
| 10778 | // candidates, non-member candidates and built-in candidates, are |
| 10779 | // constructed as follows: |
| 10780 | // -- If T1 is a complete class type or a class currently being |
| 10781 | // defined, the set of member candidates is the result of the |
| 10782 | // qualified lookup of T1::operator@ (13.3.1.1.1); otherwise, |
| 10783 | // the set of member candidates is empty. |
| 10784 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 10785 | Lookup.suppressDiagnostics(); |
| 10786 | if (const auto *TyRec = Ty->getAs<RecordType>()) { |
| 10787 | // Complete the type if it can be completed. |
| 10788 | // If the type is neither complete nor being defined, bail out now. |
| 10789 | if (SemaRef.isCompleteType(Loc, Ty) || TyRec->isBeingDefined() || |
| 10790 | TyRec->getDecl()->getDefinition()) { |
| 10791 | Lookup.clear(); |
| 10792 | SemaRef.LookupQualifiedName(Lookup, TyRec->getDecl()); |
| 10793 | if (Lookup.empty()) { |
| 10794 | Lookups.emplace_back(); |
| 10795 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 10796 | } |
| 10797 | } |
| 10798 | } |
| 10799 | // Perform ADL. |
| 10800 | argumentDependentLookup(SemaRef, ReductionId, Loc, Ty, Lookups); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 10801 | if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>( |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10802 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 10803 | if (!D->isInvalidDecl() && |
| 10804 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 10805 | return D; |
| 10806 | return nullptr; |
| 10807 | })) |
| James Y Knight | b92d290 | 2019-02-05 16:05:50 +0000 | [diff] [blame] | 10808 | return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(), |
| 10809 | VK_LValue, Loc); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 10810 | if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>( |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10811 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 10812 | if (!D->isInvalidDecl() && |
| 10813 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 10814 | !Ty.isMoreQualifiedThan(D->getType())) |
| 10815 | return D; |
| 10816 | return nullptr; |
| 10817 | })) { |
| 10818 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 10819 | /*DetectVirtual=*/false); |
| 10820 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 10821 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 10822 | VD->getType().getUnqualifiedType()))) { |
| 10823 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 10824 | /*DiagID=*/0) != |
| 10825 | Sema::AR_inaccessible) { |
| 10826 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| James Y Knight | b92d290 | 2019-02-05 16:05:50 +0000 | [diff] [blame] | 10827 | return SemaRef.BuildDeclRefExpr( |
| 10828 | VD, VD->getType().getNonReferenceType(), VK_LValue, Loc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10829 | } |
| 10830 | } |
| 10831 | } |
| 10832 | } |
| 10833 | if (ReductionIdScopeSpec.isSet()) { |
| 10834 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 10835 | return ExprError(); |
| 10836 | } |
| 10837 | return ExprEmpty(); |
| 10838 | } |
| 10839 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10840 | namespace { |
| 10841 | /// Data for the reduction-based clauses. |
| 10842 | struct ReductionData { |
| 10843 | /// List of original reduction items. |
| 10844 | SmallVector<Expr *, 8> Vars; |
| 10845 | /// List of private copies of the reduction items. |
| 10846 | SmallVector<Expr *, 8> Privates; |
| 10847 | /// LHS expressions for the reduction_op expressions. |
| 10848 | SmallVector<Expr *, 8> LHSs; |
| 10849 | /// RHS expressions for the reduction_op expressions. |
| 10850 | SmallVector<Expr *, 8> RHSs; |
| 10851 | /// Reduction operation expression. |
| 10852 | SmallVector<Expr *, 8> ReductionOps; |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10853 | /// Taskgroup descriptors for the corresponding reduction items in |
| 10854 | /// in_reduction clauses. |
| 10855 | SmallVector<Expr *, 8> TaskgroupDescriptors; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10856 | /// List of captures for clause. |
| 10857 | SmallVector<Decl *, 4> ExprCaptures; |
| 10858 | /// List of postupdate expressions. |
| 10859 | SmallVector<Expr *, 4> ExprPostUpdates; |
| 10860 | ReductionData() = delete; |
| 10861 | /// Reserves required memory for the reduction data. |
| 10862 | ReductionData(unsigned Size) { |
| 10863 | Vars.reserve(Size); |
| 10864 | Privates.reserve(Size); |
| 10865 | LHSs.reserve(Size); |
| 10866 | RHSs.reserve(Size); |
| 10867 | ReductionOps.reserve(Size); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10868 | TaskgroupDescriptors.reserve(Size); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10869 | ExprCaptures.reserve(Size); |
| 10870 | ExprPostUpdates.reserve(Size); |
| 10871 | } |
| 10872 | /// Stores reduction item and reduction operation only (required for dependent |
| 10873 | /// reduction item). |
| 10874 | void push(Expr *Item, Expr *ReductionOp) { |
| 10875 | Vars.emplace_back(Item); |
| 10876 | Privates.emplace_back(nullptr); |
| 10877 | LHSs.emplace_back(nullptr); |
| 10878 | RHSs.emplace_back(nullptr); |
| 10879 | ReductionOps.emplace_back(ReductionOp); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10880 | TaskgroupDescriptors.emplace_back(nullptr); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10881 | } |
| 10882 | /// Stores reduction data. |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10883 | void push(Expr *Item, Expr *Private, Expr *LHS, Expr *RHS, Expr *ReductionOp, |
| 10884 | Expr *TaskgroupDescriptor) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10885 | Vars.emplace_back(Item); |
| 10886 | Privates.emplace_back(Private); |
| 10887 | LHSs.emplace_back(LHS); |
| 10888 | RHSs.emplace_back(RHS); |
| 10889 | ReductionOps.emplace_back(ReductionOp); |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 10890 | TaskgroupDescriptors.emplace_back(TaskgroupDescriptor); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10891 | } |
| 10892 | }; |
| 10893 | } // namespace |
| 10894 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10895 | static bool checkOMPArraySectionConstantForReduction( |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10896 | ASTContext &Context, const OMPArraySectionExpr *OASE, bool &SingleElement, |
| 10897 | SmallVectorImpl<llvm::APSInt> &ArraySizes) { |
| 10898 | const Expr *Length = OASE->getLength(); |
| 10899 | if (Length == nullptr) { |
| 10900 | // For array sections of the form [1:] or [:], we would need to analyze |
| 10901 | // the lower bound... |
| 10902 | if (OASE->getColonLoc().isValid()) |
| 10903 | return false; |
| 10904 | |
| 10905 | // This is an array subscript which has implicit length 1! |
| 10906 | SingleElement = true; |
| 10907 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 10908 | } else { |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 10909 | Expr::EvalResult Result; |
| 10910 | if (!Length->EvaluateAsInt(Result, Context)) |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10911 | return false; |
| 10912 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 10913 | llvm::APSInt ConstantLengthValue = Result.Val.getInt(); |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10914 | SingleElement = (ConstantLengthValue.getSExtValue() == 1); |
| 10915 | ArraySizes.push_back(ConstantLengthValue); |
| 10916 | } |
| 10917 | |
| 10918 | // Get the base of this array section and walk up from there. |
| 10919 | const Expr *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 10920 | |
| 10921 | // We require length = 1 for all array sections except the right-most to |
| 10922 | // guarantee that the memory region is contiguous and has no holes in it. |
| 10923 | while (const auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) { |
| 10924 | Length = TempOASE->getLength(); |
| 10925 | if (Length == nullptr) { |
| 10926 | // For array sections of the form [1:] or [:], we would need to analyze |
| 10927 | // the lower bound... |
| 10928 | if (OASE->getColonLoc().isValid()) |
| 10929 | return false; |
| 10930 | |
| 10931 | // This is an array subscript which has implicit length 1! |
| 10932 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 10933 | } else { |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 10934 | Expr::EvalResult Result; |
| 10935 | if (!Length->EvaluateAsInt(Result, Context)) |
| 10936 | return false; |
| 10937 | |
| 10938 | llvm::APSInt ConstantLengthValue = Result.Val.getInt(); |
| 10939 | if (ConstantLengthValue.getSExtValue() != 1) |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 10940 | return false; |
| 10941 | |
| 10942 | ArraySizes.push_back(ConstantLengthValue); |
| 10943 | } |
| 10944 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 10945 | } |
| 10946 | |
| 10947 | // If we have a single element, we don't need to add the implicit lengths. |
| 10948 | if (!SingleElement) { |
| 10949 | while (const auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) { |
| 10950 | // Has implicit length 1! |
| 10951 | ArraySizes.push_back(llvm::APSInt::get(1)); |
| 10952 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 10953 | } |
| 10954 | } |
| 10955 | |
| 10956 | // This array section can be privatized as a single value or as a constant |
| 10957 | // sized array. |
| 10958 | return true; |
| 10959 | } |
| 10960 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10961 | static bool actOnOMPReductionKindClause( |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 10962 | Sema &S, DSAStackTy *Stack, OpenMPClauseKind ClauseKind, |
| 10963 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 10964 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 10965 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10966 | ArrayRef<Expr *> UnresolvedReductions, ReductionData &RD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 10967 | DeclarationName DN = ReductionId.getName(); |
| 10968 | OverloadedOperatorKind OOK = DN.getCXXOverloadedOperator(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10969 | BinaryOperatorKind BOK = BO_Comma; |
| 10970 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 10971 | ASTContext &Context = S.Context; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10972 | // OpenMP [2.14.3.6, reduction clause] |
| 10973 | // C |
| 10974 | // reduction-identifier is either an identifier or one of the following |
| 10975 | // operators: +, -, *, &, |, ^, && and || |
| 10976 | // C++ |
| 10977 | // reduction-identifier is either an id-expression or one of the following |
| 10978 | // operators: +, -, *, &, |, ^, && and || |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10979 | switch (OOK) { |
| 10980 | case OO_Plus: |
| 10981 | case OO_Minus: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10982 | BOK = BO_Add; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10983 | break; |
| 10984 | case OO_Star: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10985 | BOK = BO_Mul; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10986 | break; |
| 10987 | case OO_Amp: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10988 | BOK = BO_And; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10989 | break; |
| 10990 | case OO_Pipe: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10991 | BOK = BO_Or; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10992 | break; |
| 10993 | case OO_Caret: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 10994 | BOK = BO_Xor; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 10995 | break; |
| 10996 | case OO_AmpAmp: |
| 10997 | BOK = BO_LAnd; |
| 10998 | break; |
| 10999 | case OO_PipePipe: |
| 11000 | BOK = BO_LOr; |
| 11001 | break; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11002 | case OO_New: |
| 11003 | case OO_Delete: |
| 11004 | case OO_Array_New: |
| 11005 | case OO_Array_Delete: |
| 11006 | case OO_Slash: |
| 11007 | case OO_Percent: |
| 11008 | case OO_Tilde: |
| 11009 | case OO_Exclaim: |
| 11010 | case OO_Equal: |
| 11011 | case OO_Less: |
| 11012 | case OO_Greater: |
| 11013 | case OO_LessEqual: |
| 11014 | case OO_GreaterEqual: |
| 11015 | case OO_PlusEqual: |
| 11016 | case OO_MinusEqual: |
| 11017 | case OO_StarEqual: |
| 11018 | case OO_SlashEqual: |
| 11019 | case OO_PercentEqual: |
| 11020 | case OO_CaretEqual: |
| 11021 | case OO_AmpEqual: |
| 11022 | case OO_PipeEqual: |
| 11023 | case OO_LessLess: |
| 11024 | case OO_GreaterGreater: |
| 11025 | case OO_LessLessEqual: |
| 11026 | case OO_GreaterGreaterEqual: |
| 11027 | case OO_EqualEqual: |
| 11028 | case OO_ExclaimEqual: |
| Richard Smith | d30b23d | 2017-12-01 02:13:10 +0000 | [diff] [blame] | 11029 | case OO_Spaceship: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11030 | case OO_PlusPlus: |
| 11031 | case OO_MinusMinus: |
| 11032 | case OO_Comma: |
| 11033 | case OO_ArrowStar: |
| 11034 | case OO_Arrow: |
| 11035 | case OO_Call: |
| 11036 | case OO_Subscript: |
| 11037 | case OO_Conditional: |
| Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 11038 | case OO_Coawait: |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11039 | case NUM_OVERLOADED_OPERATORS: |
| 11040 | llvm_unreachable("Unexpected reduction identifier"); |
| 11041 | case OO_None: |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11042 | if (IdentifierInfo *II = DN.getAsIdentifierInfo()) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11043 | if (II->isStr("max")) |
| 11044 | BOK = BO_GT; |
| 11045 | else if (II->isStr("min")) |
| 11046 | BOK = BO_LT; |
| 11047 | } |
| 11048 | break; |
| 11049 | } |
| 11050 | SourceRange ReductionIdRange; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11051 | if (ReductionIdScopeSpec.isValid()) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11052 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 11053 | else |
| 11054 | ReductionIdRange.setBegin(ReductionId.getBeginLoc()); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11055 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11056 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11057 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 11058 | bool FirstIter = true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11059 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11060 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11061 | // OpenMP [2.1, C/C++] |
| 11062 | // A list item is a variable or array section, subject to the restrictions |
| 11063 | // specified in Section 2.4 on page 42 and in each of the sections |
| 11064 | // describing clauses and directives for which a list appears. |
| 11065 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 11066 | // A variable that is part of another variable (as an array or |
| 11067 | // structure element) cannot appear in a private clause. |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11068 | if (!FirstIter && IR != ER) |
| 11069 | ++IR; |
| 11070 | FirstIter = false; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11071 | SourceLocation ELoc; |
| 11072 | SourceRange ERange; |
| 11073 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11074 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange, |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11075 | /*AllowArraySection=*/true); |
| 11076 | if (Res.second) { |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11077 | // Try to find 'declare reduction' corresponding construct before using |
| 11078 | // builtin/overloaded operators. |
| 11079 | QualType Type = Context.DependentTy; |
| 11080 | CXXCastPath BasePath; |
| 11081 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11082 | S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11083 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11084 | Expr *ReductionOp = nullptr; |
| 11085 | if (S.CurContext->isDependentContext() && |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11086 | (DeclareReductionRef.isUnset() || |
| 11087 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11088 | ReductionOp = DeclareReductionRef.get(); |
| 11089 | // It will be analyzed later. |
| 11090 | RD.push(RefExpr, ReductionOp); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11091 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11092 | ValueDecl *D = Res.first; |
| 11093 | if (!D) |
| 11094 | continue; |
| 11095 | |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11096 | Expr *TaskgroupDescriptor = nullptr; |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 11097 | QualType Type; |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11098 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 11099 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11100 | if (ASE) { |
| Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 11101 | Type = ASE->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11102 | } else if (OASE) { |
| 11103 | QualType BaseType = |
| 11104 | OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 11105 | if (const auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 11106 | Type = ATy->getElementType(); |
| 11107 | else |
| 11108 | Type = BaseType->getPointeeType(); |
| Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 11109 | Type = Type.getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11110 | } else { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11111 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11112 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11113 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 11114 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11115 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 11116 | // A variable that appears in a private clause must not have an incomplete |
| 11117 | // type or a reference type. |
| Joel E. Denny | 3cabf73 | 2018-06-28 19:54:49 +0000 | [diff] [blame] | 11118 | if (S.RequireCompleteType(ELoc, D->getType(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11119 | diag::err_omp_reduction_incomplete_type)) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11120 | continue; |
| 11121 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11122 | // A list item that appears in a reduction clause must not be |
| 11123 | // const-qualified. |
| Joel E. Denny | d264929 | 2019-01-04 22:11:56 +0000 | [diff] [blame] | 11124 | if (rejectConstNotMutableType(S, D, Type, ClauseKind, ELoc, |
| 11125 | /*AcceptIfMutable*/ false, ASE || OASE)) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11126 | continue; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 11127 | |
| 11128 | OpenMPDirectiveKind CurrDir = Stack->getCurrentDirective(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11129 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 11130 | // If a list-item is a reference type then it must bind to the same object |
| 11131 | // for all threads of the team. |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 11132 | if (!ASE && !OASE) { |
| 11133 | if (VD) { |
| 11134 | VarDecl *VDDef = VD->getDefinition(); |
| 11135 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
| 11136 | DSARefChecker Check(Stack); |
| 11137 | if (Check.Visit(VDDef->getInit())) { |
| 11138 | S.Diag(ELoc, diag::err_omp_reduction_ref_type_arg) |
| 11139 | << getOpenMPClauseName(ClauseKind) << ERange; |
| 11140 | S.Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 11141 | continue; |
| 11142 | } |
| Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 11143 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11144 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11145 | |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 11146 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 11147 | // in a Construct] |
| 11148 | // Variables with the predetermined data-sharing attributes may not be |
| 11149 | // listed in data-sharing attributes clauses, except for the cases |
| 11150 | // listed below. For these exceptions only, listing a predetermined |
| 11151 | // variable in a data-sharing attribute clause is allowed and overrides |
| 11152 | // the variable's predetermined data-sharing attributes. |
| 11153 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 11154 | // Any number of reduction clauses can be specified on the directive, |
| 11155 | // but a list item can appear only once in the reduction clauses for that |
| 11156 | // directive. |
| 11157 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(D, /*FromParent=*/false); |
| 11158 | if (DVar.CKind == OMPC_reduction) { |
| 11159 | S.Diag(ELoc, diag::err_omp_once_referenced) |
| 11160 | << getOpenMPClauseName(ClauseKind); |
| 11161 | if (DVar.RefExpr) |
| 11162 | S.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 11163 | continue; |
| 11164 | } |
| 11165 | if (DVar.CKind != OMPC_unknown) { |
| 11166 | S.Diag(ELoc, diag::err_omp_wrong_dsa) |
| 11167 | << getOpenMPClauseName(DVar.CKind) |
| 11168 | << getOpenMPClauseName(OMPC_reduction); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11169 | reportOriginalDsa(S, Stack, D, DVar); |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 11170 | continue; |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 11171 | } |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 11172 | |
| 11173 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 11174 | // A list item that appears in a reduction clause of a worksharing |
| 11175 | // construct must be shared in the parallel regions to which any of the |
| 11176 | // worksharing regions arising from the worksharing construct bind. |
| 11177 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 11178 | !isOpenMPParallelDirective(CurrDir) && |
| 11179 | !isOpenMPTeamsDirective(CurrDir)) { |
| 11180 | DVar = Stack->getImplicitDSA(D, true); |
| 11181 | if (DVar.CKind != OMPC_shared) { |
| 11182 | S.Diag(ELoc, diag::err_omp_required_access) |
| 11183 | << getOpenMPClauseName(OMPC_reduction) |
| 11184 | << getOpenMPClauseName(OMPC_shared); |
| 11185 | reportOriginalDsa(S, Stack, D, DVar); |
| 11186 | continue; |
| 11187 | } |
| 11188 | } |
| Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 11189 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 11190 | |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11191 | // Try to find 'declare reduction' corresponding construct before using |
| 11192 | // builtin/overloaded operators. |
| 11193 | CXXCastPath BasePath; |
| 11194 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11195 | S, ELoc, ERange, Stack->getCurScope(), ReductionIdScopeSpec, |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11196 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 11197 | if (DeclareReductionRef.isInvalid()) |
| 11198 | continue; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11199 | if (S.CurContext->isDependentContext() && |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11200 | (DeclareReductionRef.isUnset() || |
| 11201 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11202 | RD.push(RefExpr, DeclareReductionRef.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11203 | continue; |
| 11204 | } |
| 11205 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 11206 | // Not allowed reduction identifier is found. |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11207 | S.Diag(ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11208 | diag::err_omp_unknown_reduction_identifier) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11209 | << Type << ReductionIdRange; |
| 11210 | continue; |
| 11211 | } |
| 11212 | |
| 11213 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 11214 | // The type of a list item that appears in a reduction clause must be valid |
| 11215 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 11216 | // of the list item must be an allowed arithmetic data type: char, int, |
| 11217 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 11218 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 11219 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 11220 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 11221 | if (DeclareReductionRef.isUnset()) { |
| 11222 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 11223 | !(Type->isScalarType() || |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11224 | (S.getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 11225 | S.Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11226 | << getOpenMPClauseName(ClauseKind) << S.getLangOpts().CPlusPlus; |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11227 | if (!ASE && !OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11228 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 11229 | VarDecl::DeclarationOnly; |
| 11230 | S.Diag(D->getLocation(), |
| 11231 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11232 | << D; |
| 11233 | } |
| 11234 | continue; |
| 11235 | } |
| 11236 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11237 | !S.getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11238 | S.Diag(ELoc, diag::err_omp_clause_floating_type_arg) |
| 11239 | << getOpenMPClauseName(ClauseKind); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11240 | if (!ASE && !OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11241 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 11242 | VarDecl::DeclarationOnly; |
| 11243 | S.Diag(D->getLocation(), |
| 11244 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11245 | << D; |
| 11246 | } |
| 11247 | continue; |
| 11248 | } |
| 11249 | } |
| 11250 | |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11251 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11252 | VarDecl *LHSVD = buildVarDecl(S, ELoc, Type, ".reduction.lhs", |
| 11253 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11254 | VarDecl *RHSVD = buildVarDecl(S, ELoc, Type, D->getName(), |
| 11255 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11256 | QualType PrivateTy = Type; |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 11257 | |
| 11258 | // Try if we can determine constant lengths for all array sections and avoid |
| 11259 | // the VLA. |
| 11260 | bool ConstantLengthOASE = false; |
| 11261 | if (OASE) { |
| 11262 | bool SingleElement; |
| 11263 | llvm::SmallVector<llvm::APSInt, 4> ArraySizes; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11264 | ConstantLengthOASE = checkOMPArraySectionConstantForReduction( |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 11265 | Context, OASE, SingleElement, ArraySizes); |
| 11266 | |
| 11267 | // If we don't have a single element, we must emit a constant array type. |
| 11268 | if (ConstantLengthOASE && !SingleElement) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11269 | for (llvm::APSInt &Size : ArraySizes) |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 11270 | PrivateTy = Context.getConstantArrayType( |
| 11271 | PrivateTy, Size, ArrayType::Normal, /*IndexTypeQuals=*/0); |
| Jonas Hahnfeld | 4525c82 | 2017-10-23 19:01:35 +0000 | [diff] [blame] | 11272 | } |
| 11273 | } |
| 11274 | |
| 11275 | if ((OASE && !ConstantLengthOASE) || |
| Jonas Hahnfeld | 96087f3 | 2017-11-02 13:30:42 +0000 | [diff] [blame] | 11276 | (!OASE && !ASE && |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11277 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
| Jonas Hahnfeld | 87d4426 | 2017-11-18 21:00:46 +0000 | [diff] [blame] | 11278 | if (!Context.getTargetInfo().isVLASupported() && |
| 11279 | S.shouldDiagnoseTargetSupportFromOpenMP()) { |
| 11280 | S.Diag(ELoc, diag::err_omp_reduction_vla_unsupported) << !!OASE; |
| 11281 | S.Diag(ELoc, diag::note_vla_unsupported); |
| 11282 | continue; |
| 11283 | } |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11284 | // For arrays/array sections only: |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 11285 | // Create pseudo array type for private copy. The size for this array will |
| 11286 | // be generated during codegen. |
| 11287 | // For array subscripts or single variables Private Ty is the same as Type |
| 11288 | // (type of the variable or single array element). |
| 11289 | PrivateTy = Context.getVariableArrayType( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11290 | Type, |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 11291 | new (Context) OpaqueValueExpr(ELoc, Context.getSizeType(), VK_RValue), |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 11292 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11293 | } else if (!ASE && !OASE && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11294 | Context.getAsArrayType(D->getType().getNonReferenceType())) { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11295 | PrivateTy = D->getType().getNonReferenceType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11296 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 11297 | // Private copy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11298 | VarDecl *PrivateVD = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 11299 | buildVarDecl(S, ELoc, PrivateTy, D->getName(), |
| 11300 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 11301 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11302 | // Add initializer for private variable. |
| 11303 | Expr *Init = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11304 | DeclRefExpr *LHSDRE = buildDeclRefExpr(S, LHSVD, Type, ELoc); |
| 11305 | DeclRefExpr *RHSDRE = buildDeclRefExpr(S, RHSVD, Type, ELoc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11306 | if (DeclareReductionRef.isUsable()) { |
| 11307 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 11308 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 11309 | if (DRD->getInitializer()) { |
| 11310 | Init = DRDRef; |
| 11311 | RHSVD->setInit(DRDRef); |
| 11312 | RHSVD->setInitStyle(VarDecl::CallInit); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11313 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11314 | } else { |
| 11315 | switch (BOK) { |
| 11316 | case BO_Add: |
| 11317 | case BO_Xor: |
| 11318 | case BO_Or: |
| 11319 | case BO_LOr: |
| 11320 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 11321 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11322 | Init = S.ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11323 | break; |
| 11324 | case BO_Mul: |
| 11325 | case BO_LAnd: |
| 11326 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 11327 | // '*' and '&&' reduction ops - initializer is '1'. |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11328 | Init = S.ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11329 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11330 | break; |
| 11331 | case BO_And: { |
| 11332 | // '&' reduction op - initializer is '~0'. |
| 11333 | QualType OrigType = Type; |
| 11334 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 11335 | Type = ComplexTy->getElementType(); |
| 11336 | if (Type->isRealFloatingType()) { |
| 11337 | llvm::APFloat InitValue = |
| 11338 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 11339 | /*isIEEE=*/true); |
| 11340 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 11341 | Type, ELoc); |
| 11342 | } else if (Type->isScalarType()) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11343 | uint64_t Size = Context.getTypeSize(Type); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11344 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 11345 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 11346 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 11347 | } |
| 11348 | if (Init && OrigType->isAnyComplexType()) { |
| 11349 | // Init = 0xFFFF + 0xFFFFi; |
| 11350 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11351 | Init = S.CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11352 | } |
| 11353 | Type = OrigType; |
| 11354 | break; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11355 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11356 | case BO_LT: |
| 11357 | case BO_GT: { |
| 11358 | // 'min' reduction op - initializer is 'Largest representable number in |
| 11359 | // the reduction list item type'. |
| 11360 | // 'max' reduction op - initializer is 'Least representable number in |
| 11361 | // the reduction list item type'. |
| 11362 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 11363 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11364 | uint64_t Size = Context.getTypeSize(Type); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11365 | QualType IntTy = |
| 11366 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 11367 | llvm::APInt InitValue = |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11368 | (BOK != BO_LT) ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 11369 | : llvm::APInt::getMinValue(Size) |
| 11370 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 11371 | : llvm::APInt::getMaxValue(Size); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11372 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 11373 | if (Type->isPointerType()) { |
| 11374 | // Cast to pointer type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11375 | ExprResult CastExpr = S.BuildCStyleCastExpr( |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 11376 | ELoc, Context.getTrivialTypeSourceInfo(Type, ELoc), ELoc, Init); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11377 | if (CastExpr.isInvalid()) |
| 11378 | continue; |
| 11379 | Init = CastExpr.get(); |
| 11380 | } |
| 11381 | } else if (Type->isRealFloatingType()) { |
| 11382 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 11383 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 11384 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 11385 | Type, ELoc); |
| 11386 | } |
| 11387 | break; |
| 11388 | } |
| 11389 | case BO_PtrMemD: |
| 11390 | case BO_PtrMemI: |
| 11391 | case BO_MulAssign: |
| 11392 | case BO_Div: |
| 11393 | case BO_Rem: |
| 11394 | case BO_Sub: |
| 11395 | case BO_Shl: |
| 11396 | case BO_Shr: |
| 11397 | case BO_LE: |
| 11398 | case BO_GE: |
| 11399 | case BO_EQ: |
| 11400 | case BO_NE: |
| Richard Smith | c70f1d6 | 2017-12-14 15:16:18 +0000 | [diff] [blame] | 11401 | case BO_Cmp: |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11402 | case BO_AndAssign: |
| 11403 | case BO_XorAssign: |
| 11404 | case BO_OrAssign: |
| 11405 | case BO_Assign: |
| 11406 | case BO_AddAssign: |
| 11407 | case BO_SubAssign: |
| 11408 | case BO_DivAssign: |
| 11409 | case BO_RemAssign: |
| 11410 | case BO_ShlAssign: |
| 11411 | case BO_ShrAssign: |
| 11412 | case BO_Comma: |
| 11413 | llvm_unreachable("Unexpected reduction operation"); |
| 11414 | } |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11415 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11416 | if (Init && DeclareReductionRef.isUnset()) |
| 11417 | S.AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false); |
| 11418 | else if (!Init) |
| 11419 | S.ActOnUninitializedDecl(RHSVD); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11420 | if (RHSVD->isInvalidDecl()) |
| 11421 | continue; |
| 11422 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11423 | S.Diag(ELoc, diag::err_omp_reduction_id_not_compatible) |
| 11424 | << Type << ReductionIdRange; |
| 11425 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
| 11426 | VarDecl::DeclarationOnly; |
| 11427 | S.Diag(D->getLocation(), |
| 11428 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11429 | << D; |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11430 | continue; |
| 11431 | } |
| Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 11432 | // Store initializer for single element in private copy. Will be used during |
| 11433 | // codegen. |
| 11434 | PrivateVD->setInit(RHSVD->getInit()); |
| 11435 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11436 | DeclRefExpr *PrivateDRE = buildDeclRefExpr(S, PrivateVD, PrivateTy, ELoc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11437 | ExprResult ReductionOp; |
| 11438 | if (DeclareReductionRef.isUsable()) { |
| 11439 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 11440 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11441 | ExprResult LHS = S.CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 11442 | ExprResult RHS = S.CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11443 | if (!BasePath.empty()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11444 | LHS = S.DefaultLvalueConversion(LHS.get()); |
| 11445 | RHS = S.DefaultLvalueConversion(RHS.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11446 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 11447 | CK_UncheckedDerivedToBase, LHS.get(), |
| 11448 | &BasePath, LHS.get()->getValueKind()); |
| 11449 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 11450 | CK_UncheckedDerivedToBase, RHS.get(), |
| 11451 | &BasePath, RHS.get()->getValueKind()); |
| Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 11452 | } |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11453 | FunctionProtoType::ExtProtoInfo EPI; |
| 11454 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 11455 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 11456 | auto *OVE = new (Context) OpaqueValueExpr( |
| 11457 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11458 | S.DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11459 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| Bruno Ricci | c5885cf | 2018-12-21 15:20:32 +0000 | [diff] [blame] | 11460 | ReductionOp = |
| 11461 | CallExpr::Create(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11462 | } else { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11463 | ReductionOp = S.BuildBinOp( |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11464 | Stack->getCurScope(), ReductionId.getBeginLoc(), BOK, LHSDRE, RHSDRE); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11465 | if (ReductionOp.isUsable()) { |
| 11466 | if (BOK != BO_LT && BOK != BO_GT) { |
| 11467 | ReductionOp = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11468 | S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11469 | BO_Assign, LHSDRE, ReductionOp.get()); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11470 | } else { |
| Alexey Bataev | d070a58 | 2017-10-25 15:54:04 +0000 | [diff] [blame] | 11471 | auto *ConditionalOp = new (Context) |
| 11472 | ConditionalOperator(ReductionOp.get(), ELoc, LHSDRE, ELoc, RHSDRE, |
| 11473 | Type, VK_LValue, OK_Ordinary); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11474 | ReductionOp = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11475 | S.BuildBinOp(Stack->getCurScope(), ReductionId.getBeginLoc(), |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11476 | BO_Assign, LHSDRE, ConditionalOp); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11477 | } |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 11478 | if (ReductionOp.isUsable()) |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 11479 | ReductionOp = S.ActOnFinishFullExpr(ReductionOp.get(), |
| 11480 | /*DiscardedValue*/ false); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11481 | } |
| Alexey Bataev | 4d4624c | 2017-07-20 16:47:47 +0000 | [diff] [blame] | 11482 | if (!ReductionOp.isUsable()) |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11483 | continue; |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11484 | } |
| 11485 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11486 | // OpenMP [2.15.4.6, Restrictions, p.2] |
| 11487 | // A list item that appears in an in_reduction clause of a task construct |
| 11488 | // must appear in a task_reduction clause of a construct associated with a |
| 11489 | // taskgroup region that includes the participating task in its taskgroup |
| 11490 | // set. The construct associated with the innermost region that meets this |
| 11491 | // condition must specify the same reduction-identifier as the in_reduction |
| 11492 | // clause. |
| 11493 | if (ClauseKind == OMPC_in_reduction) { |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11494 | SourceRange ParentSR; |
| 11495 | BinaryOperatorKind ParentBOK; |
| 11496 | const Expr *ParentReductionOp; |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11497 | Expr *ParentBOKTD, *ParentReductionOpTD; |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11498 | DSAStackTy::DSAVarData ParentBOKDSA = |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11499 | Stack->getTopMostTaskgroupReductionData(D, ParentSR, ParentBOK, |
| 11500 | ParentBOKTD); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11501 | DSAStackTy::DSAVarData ParentReductionOpDSA = |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11502 | Stack->getTopMostTaskgroupReductionData( |
| 11503 | D, ParentSR, ParentReductionOp, ParentReductionOpTD); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11504 | bool IsParentBOK = ParentBOKDSA.DKind != OMPD_unknown; |
| 11505 | bool IsParentReductionOp = ParentReductionOpDSA.DKind != OMPD_unknown; |
| 11506 | if (!IsParentBOK && !IsParentReductionOp) { |
| 11507 | S.Diag(ELoc, diag::err_omp_in_reduction_not_task_reduction); |
| 11508 | continue; |
| 11509 | } |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11510 | if ((DeclareReductionRef.isUnset() && IsParentReductionOp) || |
| 11511 | (DeclareReductionRef.isUsable() && IsParentBOK) || BOK != ParentBOK || |
| 11512 | IsParentReductionOp) { |
| 11513 | bool EmitError = true; |
| 11514 | if (IsParentReductionOp && DeclareReductionRef.isUsable()) { |
| 11515 | llvm::FoldingSetNodeID RedId, ParentRedId; |
| 11516 | ParentReductionOp->Profile(ParentRedId, Context, /*Canonical=*/true); |
| 11517 | DeclareReductionRef.get()->Profile(RedId, Context, |
| 11518 | /*Canonical=*/true); |
| 11519 | EmitError = RedId != ParentRedId; |
| 11520 | } |
| 11521 | if (EmitError) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11522 | S.Diag(ReductionId.getBeginLoc(), |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11523 | diag::err_omp_reduction_identifier_mismatch) |
| 11524 | << ReductionIdRange << RefExpr->getSourceRange(); |
| 11525 | S.Diag(ParentSR.getBegin(), |
| 11526 | diag::note_omp_previous_reduction_identifier) |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11527 | << ParentSR |
| 11528 | << (IsParentBOK ? ParentBOKDSA.RefExpr |
| 11529 | : ParentReductionOpDSA.RefExpr) |
| 11530 | ->getSourceRange(); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11531 | continue; |
| 11532 | } |
| 11533 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11534 | TaskgroupDescriptor = IsParentBOK ? ParentBOKTD : ParentReductionOpTD; |
| 11535 | assert(TaskgroupDescriptor && "Taskgroup descriptor must be defined."); |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11536 | } |
| 11537 | |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11538 | DeclRefExpr *Ref = nullptr; |
| 11539 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11540 | if (!VD && !S.CurContext->isDependentContext()) { |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11541 | if (ASE || OASE) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11542 | TransformExprToCaptures RebuildToCapture(S, D); |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11543 | VarsExpr = |
| 11544 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 11545 | Ref = RebuildToCapture.getCapturedExpr(); |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 11546 | } else { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11547 | VarsExpr = Ref = buildCapture(S, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11548 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11549 | if (!S.isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11550 | RD.ExprCaptures.emplace_back(Ref->getDecl()); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11551 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11552 | ExprResult RefRes = S.DefaultLvalueConversion(Ref); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11553 | if (!RefRes.isUsable()) |
| 11554 | continue; |
| 11555 | ExprResult PostUpdateRes = |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11556 | S.BuildBinOp(Stack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 11557 | RefRes.get()); |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11558 | if (!PostUpdateRes.isUsable()) |
| 11559 | continue; |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11560 | if (isOpenMPTaskingDirective(Stack->getCurrentDirective()) || |
| 11561 | Stack->getCurrentDirective() == OMPD_taskgroup) { |
| 11562 | S.Diag(RefExpr->getExprLoc(), |
| 11563 | diag::err_omp_reduction_non_addressable_expression) |
| Alexey Bataev | bcd0ae0 | 2017-07-11 19:16:44 +0000 | [diff] [blame] | 11564 | << RefExpr->getSourceRange(); |
| 11565 | continue; |
| 11566 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11567 | RD.ExprPostUpdates.emplace_back( |
| 11568 | S.IgnoredValueConversions(PostUpdateRes.get()).get()); |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 11569 | } |
| 11570 | } |
| Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 11571 | } |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11572 | // All reduction items are still marked as reduction (to do not increase |
| 11573 | // code base size). |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11574 | Stack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11575 | if (CurrDir == OMPD_taskgroup) { |
| 11576 | if (DeclareReductionRef.isUsable()) |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 11577 | Stack->addTaskgroupReductionData(D, ReductionIdRange, |
| 11578 | DeclareReductionRef.get()); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11579 | else |
| Alexey Bataev | 3b1b895 | 2017-07-25 15:53:26 +0000 | [diff] [blame] | 11580 | Stack->addTaskgroupReductionData(D, ReductionIdRange, BOK); |
| Alexey Bataev | f189cb7 | 2017-07-24 14:52:13 +0000 | [diff] [blame] | 11581 | } |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11582 | RD.push(VarsExpr, PrivateDRE, LHSDRE, RHSDRE, ReductionOp.get(), |
| 11583 | TaskgroupDescriptor); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11584 | } |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11585 | return RD.Vars.empty(); |
| 11586 | } |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11587 | |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11588 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 11589 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 11590 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 11591 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 11592 | ArrayRef<Expr *> UnresolvedReductions) { |
| 11593 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11594 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_reduction, VarList, |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11595 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 11596 | ReductionIdScopeSpec, ReductionId, |
| 11597 | UnresolvedReductions, RD)) |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11598 | return nullptr; |
| Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 11599 | |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11600 | return OMPReductionClause::Create( |
| Alexey Bataev | fad872fc | 2017-07-18 15:32:58 +0000 | [diff] [blame] | 11601 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 11602 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 11603 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 11604 | buildPreInits(Context, RD.ExprCaptures), |
| 11605 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 11606 | } |
| 11607 | |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11608 | OMPClause *Sema::ActOnOpenMPTaskReductionClause( |
| 11609 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 11610 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 11611 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 11612 | ArrayRef<Expr *> UnresolvedReductions) { |
| 11613 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11614 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_task_reduction, VarList, |
| 11615 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 11616 | ReductionIdScopeSpec, ReductionId, |
| Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 11617 | UnresolvedReductions, RD)) |
| 11618 | return nullptr; |
| 11619 | |
| 11620 | return OMPTaskReductionClause::Create( |
| 11621 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 11622 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| 11623 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, |
| 11624 | buildPreInits(Context, RD.ExprCaptures), |
| 11625 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| 11626 | } |
| 11627 | |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11628 | OMPClause *Sema::ActOnOpenMPInReductionClause( |
| 11629 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 11630 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 11631 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 11632 | ArrayRef<Expr *> UnresolvedReductions) { |
| 11633 | ReductionData RD(VarList.size()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11634 | if (actOnOMPReductionKindClause(*this, DSAStack, OMPC_in_reduction, VarList, |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11635 | StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 11636 | ReductionIdScopeSpec, ReductionId, |
| 11637 | UnresolvedReductions, RD)) |
| 11638 | return nullptr; |
| 11639 | |
| 11640 | return OMPInReductionClause::Create( |
| 11641 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, RD.Vars, |
| 11642 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, |
| Alexey Bataev | 88202be | 2017-07-27 13:20:36 +0000 | [diff] [blame] | 11643 | RD.Privates, RD.LHSs, RD.RHSs, RD.ReductionOps, RD.TaskgroupDescriptors, |
| Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 11644 | buildPreInits(Context, RD.ExprCaptures), |
| 11645 | buildPostUpdate(*this, RD.ExprPostUpdates)); |
| 11646 | } |
| 11647 | |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11648 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 11649 | SourceLocation LinLoc) { |
| 11650 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 11651 | LinKind == OMPC_LINEAR_unknown) { |
| 11652 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 11653 | return true; |
| 11654 | } |
| 11655 | return false; |
| 11656 | } |
| 11657 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11658 | bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11659 | OpenMPLinearClauseKind LinKind, |
| 11660 | QualType Type) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11661 | const auto *VD = dyn_cast_or_null<VarDecl>(D); |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11662 | // A variable must not have an incomplete type or a reference type. |
| 11663 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 11664 | return true; |
| 11665 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 11666 | !Type->isReferenceType()) { |
| 11667 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 11668 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 11669 | return true; |
| 11670 | } |
| 11671 | Type = Type.getNonReferenceType(); |
| 11672 | |
| Joel E. Denny | bae586f | 2019-01-04 22:12:13 +0000 | [diff] [blame] | 11673 | // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions] |
| 11674 | // A variable that is privatized must not have a const-qualified type |
| 11675 | // unless it is of class type with a mutable member. This restriction does |
| 11676 | // not apply to the firstprivate clause. |
| 11677 | if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc)) |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11678 | return true; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11679 | |
| 11680 | // A list item must be of integral or pointer type. |
| 11681 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 11682 | const auto *Ty = Type.getTypePtrOrNull(); |
| 11683 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 11684 | !Ty->isPointerType())) { |
| 11685 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 11686 | if (D) { |
| 11687 | bool IsDecl = |
| 11688 | !VD || |
| 11689 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 11690 | Diag(D->getLocation(), |
| 11691 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 11692 | << D; |
| 11693 | } |
| 11694 | return true; |
| 11695 | } |
| 11696 | return false; |
| 11697 | } |
| 11698 | |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 11699 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 11700 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 11701 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 11702 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11703 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11704 | SmallVector<Expr *, 8> Privates; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11705 | SmallVector<Expr *, 8> Inits; |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 11706 | SmallVector<Decl *, 4> ExprCaptures; |
| 11707 | SmallVector<Expr *, 4> ExprPostUpdates; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11708 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 11709 | LinKind = OMPC_LINEAR_val; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11710 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11711 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11712 | SourceLocation ELoc; |
| 11713 | SourceRange ERange; |
| 11714 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 11715 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11716 | if (Res.second) { |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11717 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 11718 | Vars.push_back(RefExpr); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11719 | Privates.push_back(nullptr); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11720 | Inits.push_back(nullptr); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11721 | } |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11722 | ValueDecl *D = Res.first; |
| 11723 | if (!D) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11724 | continue; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11725 | |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11726 | QualType Type = D->getType(); |
| 11727 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11728 | |
| 11729 | // OpenMP [2.14.3.7, linear clause] |
| 11730 | // A list-item cannot appear in more than one linear clause. |
| 11731 | // A list-item that appears in a linear clause cannot appear in any |
| 11732 | // other data-sharing attribute clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11733 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11734 | if (DVar.RefExpr) { |
| 11735 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 11736 | << getOpenMPClauseName(OMPC_linear); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11737 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11738 | continue; |
| 11739 | } |
| 11740 | |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11741 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11742 | continue; |
| Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 11743 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11744 | |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11745 | // Build private copy of original var. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11746 | VarDecl *Private = |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 11747 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11748 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 11749 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11750 | DeclRefExpr *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11751 | // Build var to save initial value. |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11752 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11753 | Expr *InitExpr; |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11754 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 11755 | if (!VD && !CurContext->isDependentContext()) { |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 11756 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11757 | if (!isOpenMPCapturedDecl(D)) { |
| Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 11758 | ExprCaptures.push_back(Ref->getDecl()); |
| 11759 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 11760 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 11761 | if (!RefRes.isUsable()) |
| 11762 | continue; |
| 11763 | ExprResult PostUpdateRes = |
| 11764 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 11765 | SimpleRefExpr, RefRes.get()); |
| 11766 | if (!PostUpdateRes.isUsable()) |
| 11767 | continue; |
| 11768 | ExprPostUpdates.push_back( |
| 11769 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 11770 | } |
| 11771 | } |
| 11772 | } |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11773 | if (LinKind == OMPC_LINEAR_uval) |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11774 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11775 | else |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11776 | InitExpr = VD ? SimpleRefExpr : Ref; |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11777 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 11778 | /*DirectInit=*/false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11779 | DeclRefExpr *InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 11780 | |
| 11781 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 11782 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 11783 | ? RefExpr->IgnoreParens() |
| 11784 | : Ref); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11785 | Privates.push_back(PrivateRef); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11786 | Inits.push_back(InitRef); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11787 | } |
| 11788 | |
| 11789 | if (Vars.empty()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11790 | return nullptr; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11791 | |
| 11792 | Expr *StepExpr = Step; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11793 | Expr *CalcStepExpr = nullptr; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11794 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 11795 | !Step->isInstantiationDependent() && |
| 11796 | !Step->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11797 | SourceLocation StepLoc = Step->getBeginLoc(); |
| Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 11798 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11799 | if (Val.isInvalid()) |
| Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 11800 | return nullptr; |
| Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 11801 | StepExpr = Val.get(); |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11802 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11803 | // Build var to save the step value. |
| 11804 | VarDecl *SaveVar = |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 11805 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11806 | ExprResult SaveRef = |
| Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 11807 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11808 | ExprResult CalcStep = |
| 11809 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 11810 | CalcStep = ActOnFinishFullExpr(CalcStep.get(), /*DiscardedValue*/ false); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11811 | |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11812 | // Warn about zero linear step (it would be probably better specified as |
| 11813 | // making corresponding variables 'const'). |
| 11814 | llvm::APSInt Result; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11815 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 11816 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11817 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 11818 | << (Vars.size() > 1); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11819 | if (!IsConstant && CalcStep.isUsable()) { |
| 11820 | // Calculate the step beforehand instead of doing this on each iteration. |
| 11821 | // (This is not used if the number of iterations may be kfold-ed). |
| 11822 | CalcStepExpr = CalcStep.get(); |
| 11823 | } |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11824 | } |
| 11825 | |
| Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 11826 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 11827 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11828 | StepExpr, CalcStepExpr, |
| 11829 | buildPreInits(Context, ExprCaptures), |
| 11830 | buildPostUpdate(*this, ExprPostUpdates)); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11831 | } |
| 11832 | |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11833 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 11834 | Expr *NumIterations, Sema &SemaRef, |
| 11835 | Scope *S, DSAStackTy *Stack) { |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11836 | // Walk the vars and build update/final expressions for the CodeGen. |
| 11837 | SmallVector<Expr *, 8> Updates; |
| 11838 | SmallVector<Expr *, 8> Finals; |
| 11839 | Expr *Step = Clause.getStep(); |
| 11840 | Expr *CalcStep = Clause.getCalcStep(); |
| 11841 | // OpenMP [2.14.3.7, linear clause] |
| 11842 | // If linear-step is not specified it is assumed to be 1. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11843 | if (!Step) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11844 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11845 | else if (CalcStep) |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11846 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 11847 | bool HasErrors = false; |
| 11848 | auto CurInit = Clause.inits().begin(); |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 11849 | auto CurPrivate = Clause.privates().begin(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11850 | OpenMPLinearClauseKind LinKind = Clause.getModifier(); |
| 11851 | for (Expr *RefExpr : Clause.varlists()) { |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11852 | SourceLocation ELoc; |
| 11853 | SourceRange ERange; |
| 11854 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 11855 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11856 | ValueDecl *D = Res.first; |
| 11857 | if (Res.second || !D) { |
| 11858 | Updates.push_back(nullptr); |
| 11859 | Finals.push_back(nullptr); |
| 11860 | HasErrors = true; |
| 11861 | continue; |
| 11862 | } |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11863 | auto &&Info = Stack->isLoopControlVariable(D); |
| Alexey Bataev | 2b86f21 | 2017-11-29 21:31:48 +0000 | [diff] [blame] | 11864 | // OpenMP [2.15.11, distribute simd Construct] |
| 11865 | // A list item may not appear in a linear clause, unless it is the loop |
| 11866 | // iteration variable. |
| 11867 | if (isOpenMPDistributeDirective(Stack->getCurrentDirective()) && |
| 11868 | isOpenMPSimdDirective(Stack->getCurrentDirective()) && !Info.first) { |
| 11869 | SemaRef.Diag(ELoc, |
| 11870 | diag::err_omp_linear_distribute_var_non_loop_iteration); |
| 11871 | Updates.push_back(nullptr); |
| 11872 | Finals.push_back(nullptr); |
| 11873 | HasErrors = true; |
| 11874 | continue; |
| 11875 | } |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11876 | Expr *InitExpr = *CurInit; |
| 11877 | |
| 11878 | // Build privatized reference to the current linear var. |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11879 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
| Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 11880 | Expr *CapturedRef; |
| 11881 | if (LinKind == OMPC_LINEAR_uval) |
| 11882 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 11883 | else |
| 11884 | CapturedRef = |
| 11885 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 11886 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 11887 | /*RefersToCapture=*/true); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11888 | |
| 11889 | // Build update: Var = InitExpr + IV * Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11890 | ExprResult Update; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11891 | if (!Info.first) |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11892 | Update = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11893 | buildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11894 | InitExpr, IV, Step, /* Subtract */ false); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11895 | else |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11896 | Update = *CurPrivate; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11897 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getBeginLoc(), |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 11898 | /*DiscardedValue*/ false); |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11899 | |
| 11900 | // Build final: Var = InitExpr + NumIterations * Step |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11901 | ExprResult Final; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11902 | if (!Info.first) |
| 11903 | Final = |
| 11904 | buildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 11905 | InitExpr, NumIterations, Step, /*Subtract=*/false); |
| 11906 | else |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11907 | Final = *CurPrivate; |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 11908 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getBeginLoc(), |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 11909 | /*DiscardedValue*/ false); |
| Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 11910 | |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11911 | if (!Update.isUsable() || !Final.isUsable()) { |
| 11912 | Updates.push_back(nullptr); |
| 11913 | Finals.push_back(nullptr); |
| 11914 | HasErrors = true; |
| 11915 | } else { |
| 11916 | Updates.push_back(Update.get()); |
| 11917 | Finals.push_back(Final.get()); |
| 11918 | } |
| Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 11919 | ++CurInit; |
| 11920 | ++CurPrivate; |
| Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 11921 | } |
| 11922 | Clause.setUpdates(Updates); |
| 11923 | Clause.setFinals(Finals); |
| 11924 | return HasErrors; |
| Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 11925 | } |
| 11926 | |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11927 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 11928 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 11929 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11930 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11931 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11932 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 11933 | SourceLocation ELoc; |
| 11934 | SourceRange ERange; |
| 11935 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 11936 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11937 | if (Res.second) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11938 | // It will be analyzed later. |
| 11939 | Vars.push_back(RefExpr); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11940 | } |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11941 | ValueDecl *D = Res.first; |
| 11942 | if (!D) |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11943 | continue; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11944 | |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11945 | QualType QType = D->getType(); |
| 11946 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11947 | |
| 11948 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 11949 | // The type of list items appearing in the aligned clause must be |
| 11950 | // array, pointer, reference to array, or reference to pointer. |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 11951 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11952 | const Type *Ty = QType.getTypePtrOrNull(); |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11953 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11954 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11955 | << QType << getLangOpts().CPlusPlus << ERange; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11956 | bool IsDecl = |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11957 | !VD || |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11958 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11959 | Diag(D->getLocation(), |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11960 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11961 | << D; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11962 | continue; |
| 11963 | } |
| 11964 | |
| 11965 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 11966 | // A list-item cannot appear in more than one aligned clause. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11967 | if (const Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
| Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 11968 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11969 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 11970 | << getOpenMPClauseName(OMPC_aligned); |
| 11971 | continue; |
| 11972 | } |
| 11973 | |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11974 | DeclRefExpr *Ref = nullptr; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 11975 | if (!VD && isOpenMPCapturedDecl(D)) |
| Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 11976 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11977 | Vars.push_back(DefaultFunctionArrayConversion( |
| 11978 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 11979 | .get()); |
| Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 11980 | } |
| 11981 | |
| 11982 | // OpenMP [2.8.1, simd construct, Description] |
| 11983 | // The parameter of the aligned clause, alignment, must be a constant |
| 11984 | // positive integer expression. |
| 11985 | // If no optional parameter is specified, implementation-defined default |
| 11986 | // alignments for SIMD instructions on the target platforms are assumed. |
| 11987 | if (Alignment != nullptr) { |
| 11988 | ExprResult AlignResult = |
| 11989 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 11990 | if (AlignResult.isInvalid()) |
| 11991 | return nullptr; |
| 11992 | Alignment = AlignResult.get(); |
| 11993 | } |
| 11994 | if (Vars.empty()) |
| 11995 | return nullptr; |
| 11996 | |
| 11997 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 11998 | EndLoc, Vars, Alignment); |
| 11999 | } |
| 12000 | |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12001 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 12002 | SourceLocation StartLoc, |
| 12003 | SourceLocation LParenLoc, |
| 12004 | SourceLocation EndLoc) { |
| 12005 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 12006 | SmallVector<Expr *, 8> SrcExprs; |
| 12007 | SmallVector<Expr *, 8> DstExprs; |
| 12008 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12009 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12010 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 12011 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12012 | // It will be analyzed later. |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12013 | Vars.push_back(RefExpr); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 12014 | SrcExprs.push_back(nullptr); |
| 12015 | DstExprs.push_back(nullptr); |
| 12016 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12017 | continue; |
| 12018 | } |
| 12019 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12020 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12021 | // OpenMP [2.1, C/C++] |
| 12022 | // A list item is a variable name. |
| 12023 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 12024 | // A list item that appears in a copyin clause must be threadprivate. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12025 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12026 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 12027 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 12028 | << 0 << RefExpr->getSourceRange(); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12029 | continue; |
| 12030 | } |
| 12031 | |
| 12032 | Decl *D = DE->getDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12033 | auto *VD = cast<VarDecl>(D); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12034 | |
| 12035 | QualType Type = VD->getType(); |
| 12036 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 12037 | // It will be analyzed later. |
| 12038 | Vars.push_back(DE); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 12039 | SrcExprs.push_back(nullptr); |
| 12040 | DstExprs.push_back(nullptr); |
| 12041 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12042 | continue; |
| 12043 | } |
| 12044 | |
| 12045 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 12046 | // A list item that appears in a copyin clause must be threadprivate. |
| 12047 | if (!DSAStack->isThreadPrivate(VD)) { |
| 12048 | Diag(ELoc, diag::err_omp_required_access) |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12049 | << getOpenMPClauseName(OMPC_copyin) |
| 12050 | << getOpenMPDirectiveName(OMPD_threadprivate); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12051 | continue; |
| 12052 | } |
| 12053 | |
| 12054 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 12055 | // A variable of class type (or array thereof) that appears in a |
| Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 12056 | // copyin clause requires an accessible, unambiguous copy assignment |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12057 | // operator for the class type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12058 | QualType ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
| 12059 | VarDecl *SrcVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12060 | buildVarDecl(*this, DE->getBeginLoc(), ElemType.getUnqualifiedType(), |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 12061 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12062 | DeclRefExpr *PseudoSrcExpr = buildDeclRefExpr( |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12063 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12064 | VarDecl *DstVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12065 | buildVarDecl(*this, DE->getBeginLoc(), ElemType, ".copyin.dst", |
| Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 12066 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12067 | DeclRefExpr *PseudoDstExpr = |
| Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 12068 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 12069 | // For arrays generate assignment operation for single element and replace |
| 12070 | // it by the original array element in CodeGen. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12071 | ExprResult AssignmentOp = |
| 12072 | BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, PseudoDstExpr, |
| 12073 | PseudoSrcExpr); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 12074 | if (AssignmentOp.isInvalid()) |
| 12075 | continue; |
| 12076 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 12077 | /*DiscardedValue*/ false); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 12078 | if (AssignmentOp.isInvalid()) |
| 12079 | continue; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12080 | |
| 12081 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 12082 | Vars.push_back(DE); |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 12083 | SrcExprs.push_back(PseudoSrcExpr); |
| 12084 | DstExprs.push_back(PseudoDstExpr); |
| 12085 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12086 | } |
| 12087 | |
| Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 12088 | if (Vars.empty()) |
| 12089 | return nullptr; |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12090 | |
| Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 12091 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 12092 | SrcExprs, DstExprs, AssignmentOps); |
| Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 12093 | } |
| 12094 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12095 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 12096 | SourceLocation StartLoc, |
| 12097 | SourceLocation LParenLoc, |
| 12098 | SourceLocation EndLoc) { |
| 12099 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 12100 | SmallVector<Expr *, 8> SrcExprs; |
| 12101 | SmallVector<Expr *, 8> DstExprs; |
| 12102 | SmallVector<Expr *, 8> AssignmentOps; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12103 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12104 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 12105 | SourceLocation ELoc; |
| 12106 | SourceRange ERange; |
| 12107 | Expr *SimpleRefExpr = RefExpr; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 12108 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12109 | if (Res.second) { |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12110 | // It will be analyzed later. |
| 12111 | Vars.push_back(RefExpr); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 12112 | SrcExprs.push_back(nullptr); |
| 12113 | DstExprs.push_back(nullptr); |
| 12114 | AssignmentOps.push_back(nullptr); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12115 | } |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12116 | ValueDecl *D = Res.first; |
| 12117 | if (!D) |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12118 | continue; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12119 | |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12120 | QualType Type = D->getType(); |
| 12121 | auto *VD = dyn_cast<VarDecl>(D); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12122 | |
| 12123 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 12124 | // A list item that appears in a copyprivate clause may not appear in a |
| 12125 | // private or firstprivate clause on the single construct. |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12126 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12127 | DSAStackTy::DSAVarData DVar = |
| 12128 | DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 12129 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 12130 | DVar.RefExpr) { |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12131 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 12132 | << getOpenMPClauseName(DVar.CKind) |
| 12133 | << getOpenMPClauseName(OMPC_copyprivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12134 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12135 | continue; |
| 12136 | } |
| 12137 | |
| 12138 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 12139 | // All list items that appear in a copyprivate clause must be either |
| 12140 | // threadprivate or private in the enclosing context. |
| 12141 | if (DVar.CKind == OMPC_unknown) { |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12142 | DVar = DSAStack->getImplicitDSA(D, false); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12143 | if (DVar.CKind == OMPC_shared) { |
| 12144 | Diag(ELoc, diag::err_omp_required_access) |
| 12145 | << getOpenMPClauseName(OMPC_copyprivate) |
| 12146 | << "threadprivate or private in the enclosing context"; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12147 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12148 | continue; |
| 12149 | } |
| 12150 | } |
| 12151 | } |
| 12152 | |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 12153 | // Variably modified types are not supported. |
| Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 12154 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 12155 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12156 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 12157 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 12158 | bool IsDecl = |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12159 | !VD || |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 12160 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12161 | Diag(D->getLocation(), |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 12162 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12163 | << D; |
| Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 12164 | continue; |
| 12165 | } |
| Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 12166 | |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12167 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 12168 | // A variable of class type (or array thereof) that appears in a |
| 12169 | // copyin clause requires an accessible, unambiguous copy assignment |
| 12170 | // operator for the class type. |
| Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 12171 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 12172 | .getUnqualifiedType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12173 | VarDecl *SrcVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12174 | buildVarDecl(*this, RefExpr->getBeginLoc(), Type, ".copyprivate.src", |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12175 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12176 | DeclRefExpr *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
| 12177 | VarDecl *DstVD = |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 12178 | buildVarDecl(*this, RefExpr->getBeginLoc(), Type, ".copyprivate.dst", |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12179 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12180 | DeclRefExpr *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 12181 | ExprResult AssignmentOp = BuildBinOp( |
| 12182 | DSAStack->getCurScope(), ELoc, BO_Assign, PseudoDstExpr, PseudoSrcExpr); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 12183 | if (AssignmentOp.isInvalid()) |
| 12184 | continue; |
| Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 12185 | AssignmentOp = |
| 12186 | ActOnFinishFullExpr(AssignmentOp.get(), ELoc, /*DiscardedValue*/ false); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 12187 | if (AssignmentOp.isInvalid()) |
| 12188 | continue; |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12189 | |
| 12190 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 12191 | // implicitly private. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12192 | assert(VD || isOpenMPCapturedDecl(D)); |
| Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 12193 | Vars.push_back( |
| 12194 | VD ? RefExpr->IgnoreParens() |
| 12195 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 12196 | SrcExprs.push_back(PseudoSrcExpr); |
| 12197 | DstExprs.push_back(PseudoDstExpr); |
| 12198 | AssignmentOps.push_back(AssignmentOp.get()); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12199 | } |
| 12200 | |
| 12201 | if (Vars.empty()) |
| 12202 | return nullptr; |
| 12203 | |
| Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 12204 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 12205 | Vars, SrcExprs, DstExprs, AssignmentOps); |
| Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 12206 | } |
| 12207 | |
| Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 12208 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 12209 | SourceLocation StartLoc, |
| 12210 | SourceLocation LParenLoc, |
| 12211 | SourceLocation EndLoc) { |
| 12212 | if (VarList.empty()) |
| 12213 | return nullptr; |
| 12214 | |
| 12215 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 12216 | } |
| Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 12217 | |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12218 | OMPClause * |
| 12219 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 12220 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 12221 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 12222 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 12223 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12224 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 12225 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 12226 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
| Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 12227 | return nullptr; |
| 12228 | } |
| 12229 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12230 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 12231 | DepKind == OMPC_DEPEND_sink)) { |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 12232 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12233 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 12234 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 12235 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 12236 | << getOpenMPClauseName(OMPC_depend); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12237 | return nullptr; |
| 12238 | } |
| 12239 | SmallVector<Expr *, 8> Vars; |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 12240 | DSAStackTy::OperatorOffsetTy OpsOffs; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12241 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 12242 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 12243 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) { |
| 12244 | if (const Expr *OrderedCountExpr = |
| 12245 | DSAStack->getParentOrderedRegionParam().first) { |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12246 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 12247 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12248 | } |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12249 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12250 | for (Expr *RefExpr : VarList) { |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12251 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 12252 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 12253 | // It will be analyzed later. |
| 12254 | Vars.push_back(RefExpr); |
| 12255 | continue; |
| 12256 | } |
| 12257 | |
| 12258 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12259 | Expr *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12260 | if (DepKind == OMPC_DEPEND_sink) { |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 12261 | if (DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12262 | DepCounter >= TotalDepCount) { |
| 12263 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 12264 | continue; |
| 12265 | } |
| 12266 | ++DepCounter; |
| 12267 | // OpenMP [2.13.9, Summary] |
| 12268 | // depend(dependence-type : vec), where dependence-type is: |
| 12269 | // 'sink' and where vec is the iteration vector, which has the form: |
| 12270 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 12271 | // where n is the value specified by the ordered clause in the loop |
| 12272 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 12273 | // loop associated with the loop directive, and di is a constant |
| 12274 | // non-negative integer. |
| 12275 | if (CurContext->isDependentContext()) { |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12276 | // It will be analyzed later. |
| 12277 | Vars.push_back(RefExpr); |
| 12278 | continue; |
| 12279 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12280 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 12281 | OverloadedOperatorKind OOK = OO_None; |
| 12282 | SourceLocation OOLoc; |
| 12283 | Expr *LHS = SimpleExpr; |
| 12284 | Expr *RHS = nullptr; |
| 12285 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 12286 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 12287 | OOLoc = BO->getOperatorLoc(); |
| 12288 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 12289 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 12290 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 12291 | OOK = OCE->getOperator(); |
| 12292 | OOLoc = OCE->getOperatorLoc(); |
| 12293 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 12294 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 12295 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 12296 | OOK = MCE->getMethodDecl() |
| 12297 | ->getNameInfo() |
| 12298 | .getName() |
| 12299 | .getCXXOverloadedOperator(); |
| 12300 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 12301 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 12302 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12303 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12304 | SourceLocation ELoc; |
| 12305 | SourceRange ERange; |
| Alexey Bataev | bc52967 | 2018-09-28 19:33:14 +0000 | [diff] [blame] | 12306 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12307 | if (Res.second) { |
| 12308 | // It will be analyzed later. |
| 12309 | Vars.push_back(RefExpr); |
| 12310 | } |
| 12311 | ValueDecl *D = Res.first; |
| 12312 | if (!D) |
| 12313 | continue; |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12314 | |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12315 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 12316 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 12317 | continue; |
| 12318 | } |
| 12319 | if (RHS) { |
| 12320 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 12321 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 12322 | if (RHSRes.isInvalid()) |
| 12323 | continue; |
| 12324 | } |
| 12325 | if (!CurContext->isDependentContext() && |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 12326 | DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12327 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12328 | const ValueDecl *VD = |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12329 | DSAStack->getParentLoopControlVariable(DepCounter.getZExtValue()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12330 | if (VD) |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12331 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 12332 | << 1 << VD; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12333 | else |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12334 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) << 0; |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12335 | continue; |
| 12336 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12337 | OpsOffs.emplace_back(RHS, OOK); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12338 | } else { |
| 12339 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 12340 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 12341 | (ASE && |
| 12342 | !ASE->getBase()->getType().getNonReferenceType()->isPointerType() && |
| 12343 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
| 12344 | Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) |
| 12345 | << RefExpr->getSourceRange(); |
| 12346 | continue; |
| 12347 | } |
| 12348 | bool Suppress = getDiagnostics().getSuppressAllDiagnostics(); |
| 12349 | getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 12350 | ExprResult Res = |
| 12351 | CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RefExpr->IgnoreParenImpCasts()); |
| 12352 | getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 12353 | if (!Res.isUsable() && !isa<OMPArraySectionExpr>(SimpleExpr)) { |
| 12354 | Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) |
| 12355 | << RefExpr->getSourceRange(); |
| 12356 | continue; |
| 12357 | } |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12358 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12359 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 12360 | } |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12361 | |
| 12362 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 12363 | TotalDepCount > VarList.size() && |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 12364 | DSAStack->getParentOrderedRegionParam().first && |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12365 | DSAStack->getParentLoopControlVariable(VarList.size() + 1)) { |
| 12366 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 12367 | << 1 << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 12368 | } |
| 12369 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 12370 | Vars.empty()) |
| 12371 | return nullptr; |
| 12372 | |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 12373 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| Alexey Bataev | f138fda | 2018-08-13 19:04:24 +0000 | [diff] [blame] | 12374 | DepKind, DepLoc, ColonLoc, Vars, |
| 12375 | TotalDepCount.getZExtValue()); |
| Alexey Bataev | 17daedf | 2018-02-15 22:42:57 +0000 | [diff] [blame] | 12376 | if ((DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) && |
| 12377 | DSAStack->isParentOrderedRegion()) |
| Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 12378 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 12379 | return C; |
| Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 12380 | } |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 12381 | |
| 12382 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 12383 | SourceLocation LParenLoc, |
| 12384 | SourceLocation EndLoc) { |
| 12385 | Expr *ValExpr = Device; |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 12386 | Stmt *HelperValStmt = nullptr; |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 12387 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12388 | // OpenMP [2.9.1, Restrictions] |
| 12389 | // The device expression must evaluate to a non-negative integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12390 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 12391 | /*StrictlyPositive=*/false)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 12392 | return nullptr; |
| 12393 | |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 12394 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 12395 | OpenMPDirectiveKind CaptureRegion = |
| 12396 | getOpenMPCaptureRegionForClause(DKind, OMPC_device); |
| 12397 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 12398 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12399 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 931e19b | 2017-10-02 16:32:39 +0000 | [diff] [blame] | 12400 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 12401 | HelperValStmt = buildPreInits(Context, Captures); |
| 12402 | } |
| 12403 | |
| Alexey Bataev | 8451efa | 2018-01-15 19:06:12 +0000 | [diff] [blame] | 12404 | return new (Context) OMPDeviceClause(ValExpr, HelperValStmt, CaptureRegion, |
| 12405 | StartLoc, LParenLoc, EndLoc); |
| Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 12406 | } |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12407 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12408 | static bool checkTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| Alexey Bataev | 95c23e7 | 2018-02-27 21:31:11 +0000 | [diff] [blame] | 12409 | DSAStackTy *Stack, QualType QTy, |
| 12410 | bool FullCheck = true) { |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12411 | NamedDecl *ND; |
| 12412 | if (QTy->isIncompleteType(&ND)) { |
| 12413 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 12414 | return false; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12415 | } |
| Alexey Bataev | 95c23e7 | 2018-02-27 21:31:11 +0000 | [diff] [blame] | 12416 | if (FullCheck && !SemaRef.CurContext->isDependentContext() && |
| 12417 | !QTy.isTrivialType(SemaRef.Context)) |
| 12418 | SemaRef.Diag(SL, diag::warn_omp_non_trivial_type_mapped) << QTy << SR; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 12419 | return true; |
| 12420 | } |
| 12421 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 12422 | /// Return true if it can be proven that the provided array expression |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12423 | /// (array section or array subscript) does NOT specify the whole size of the |
| 12424 | /// array whose base type is \a BaseQTy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12425 | static bool checkArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12426 | const Expr *E, |
| 12427 | QualType BaseQTy) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12428 | const auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12429 | |
| 12430 | // If this is an array subscript, it refers to the whole size if the size of |
| 12431 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 12432 | // format of an array subscript if no colon is used. |
| 12433 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12434 | if (const auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12435 | return ATy->getSize().getSExtValue() != 1; |
| 12436 | // Size can't be evaluated statically. |
| 12437 | return false; |
| 12438 | } |
| 12439 | |
| 12440 | assert(OASE && "Expecting array section if not an array subscript."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12441 | const Expr *LowerBound = OASE->getLowerBound(); |
| 12442 | const Expr *Length = OASE->getLength(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12443 | |
| 12444 | // 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] | 12445 | // covering the whole dimension. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12446 | if (LowerBound) { |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 12447 | Expr::EvalResult Result; |
| 12448 | if (!LowerBound->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12449 | return false; // Can't get the integer value as a constant. |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 12450 | |
| 12451 | llvm::APSInt ConstLowerBound = Result.Val.getInt(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12452 | if (ConstLowerBound.getSExtValue()) |
| 12453 | return true; |
| 12454 | } |
| 12455 | |
| 12456 | // If we don't have a length we covering the whole dimension. |
| 12457 | if (!Length) |
| 12458 | return false; |
| 12459 | |
| 12460 | // If the base is a pointer, we don't have a way to get the size of the |
| 12461 | // pointee. |
| 12462 | if (BaseQTy->isPointerType()) |
| 12463 | return false; |
| 12464 | |
| 12465 | // We can only check if the length is the same as the size of the dimension |
| 12466 | // if we have a constant array. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12467 | const auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12468 | if (!CATy) |
| 12469 | return false; |
| 12470 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 12471 | Expr::EvalResult Result; |
| 12472 | if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12473 | return false; // Can't get the integer value as a constant. |
| 12474 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 12475 | llvm::APSInt ConstLength = Result.Val.getInt(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12476 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 12477 | } |
| 12478 | |
| 12479 | // Return true if it can be proven that the provided array expression (array |
| 12480 | // section or array subscript) does NOT specify a single element of the array |
| 12481 | // whose base type is \a BaseQTy. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12482 | static bool checkArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12483 | const Expr *E, |
| 12484 | QualType BaseQTy) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12485 | const auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12486 | |
| 12487 | // An array subscript always refer to a single element. Also, an array section |
| 12488 | // assumes the format of an array subscript if no colon is used. |
| 12489 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 12490 | return false; |
| 12491 | |
| 12492 | assert(OASE && "Expecting array section if not an array subscript."); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12493 | const Expr *Length = OASE->getLength(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12494 | |
| 12495 | // If we don't have a length we have to check if the array has unitary size |
| 12496 | // for this dimension. Also, we should always expect a length if the base type |
| 12497 | // is pointer. |
| 12498 | if (!Length) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12499 | if (const auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12500 | return ATy->getSize().getSExtValue() != 1; |
| 12501 | // We cannot assume anything. |
| 12502 | return false; |
| 12503 | } |
| 12504 | |
| 12505 | // Check if the length evaluates to 1. |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 12506 | Expr::EvalResult Result; |
| 12507 | if (!Length->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12508 | return false; // Can't get the integer value as a constant. |
| 12509 | |
| Fangrui Song | 407659a | 2018-11-30 23:41:18 +0000 | [diff] [blame] | 12510 | llvm::APSInt ConstLength = Result.Val.getInt(); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12511 | return ConstLength.getSExtValue() != 1; |
| 12512 | } |
| 12513 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12514 | // Return the expression of the base of the mappable expression or null if it |
| 12515 | // cannot be determined and do all the necessary checks to see if the expression |
| 12516 | // 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] | 12517 | // components of the expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12518 | static const Expr *checkMapClauseExpressionBase( |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12519 | Sema &SemaRef, Expr *E, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12520 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12521 | OpenMPClauseKind CKind, bool NoDiagnose) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12522 | SourceLocation ELoc = E->getExprLoc(); |
| 12523 | SourceRange ERange = E->getSourceRange(); |
| 12524 | |
| 12525 | // The base of elements of list in a map clause have to be either: |
| 12526 | // - a reference to variable or field. |
| 12527 | // - a member expression. |
| 12528 | // - an array expression. |
| 12529 | // |
| 12530 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 12531 | // reference to 'r'. |
| 12532 | // |
| 12533 | // If we have: |
| 12534 | // |
| 12535 | // struct SS { |
| 12536 | // Bla S; |
| 12537 | // foo() { |
| 12538 | // #pragma omp target map (S.Arr[:12]); |
| 12539 | // } |
| 12540 | // } |
| 12541 | // |
| 12542 | // We want to retrieve the member expression 'this->S'; |
| 12543 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12544 | const Expr *RelevantExpr = nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12545 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12546 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 12547 | // If a list item is an array section, it must specify contiguous storage. |
| 12548 | // |
| 12549 | // For this restriction it is sufficient that we make sure only references |
| 12550 | // to variables or fields and array expressions, and that no array sections |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12551 | // exist except in the rightmost expression (unless they cover the whole |
| 12552 | // dimension of the array). E.g. these would be invalid: |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12553 | // |
| 12554 | // r.ArrS[3:5].Arr[6:7] |
| 12555 | // |
| 12556 | // r.ArrS[3:5].x |
| 12557 | // |
| 12558 | // but these would be valid: |
| 12559 | // r.ArrS[3].Arr[6:7] |
| 12560 | // |
| 12561 | // r.ArrS[3].x |
| 12562 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12563 | bool AllowUnitySizeArraySection = true; |
| 12564 | bool AllowWholeSizeArraySection = true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12565 | |
| Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 12566 | while (!RelevantExpr) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12567 | E = E->IgnoreParenImpCasts(); |
| 12568 | |
| 12569 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 12570 | if (!isa<VarDecl>(CurE->getDecl())) |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12571 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12572 | |
| 12573 | RelevantExpr = CurE; |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12574 | |
| 12575 | // If we got a reference to a declaration, we should not expect any array |
| 12576 | // section before that. |
| 12577 | AllowUnitySizeArraySection = false; |
| 12578 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12579 | |
| 12580 | // Record the component. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12581 | CurComponents.emplace_back(CurE, CurE->getDecl()); |
| 12582 | } else if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12583 | Expr *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12584 | |
| 12585 | if (isa<CXXThisExpr>(BaseE)) |
| 12586 | // We found a base expression: this->Val. |
| 12587 | RelevantExpr = CurE; |
| 12588 | else |
| 12589 | E = BaseE; |
| 12590 | |
| 12591 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12592 | if (!NoDiagnose) { |
| 12593 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 12594 | << CurE->getSourceRange(); |
| 12595 | return nullptr; |
| 12596 | } |
| 12597 | if (RelevantExpr) |
| 12598 | return nullptr; |
| 12599 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12600 | } |
| 12601 | |
| 12602 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 12603 | |
| 12604 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 12605 | // A bit-field cannot appear in a map clause. |
| 12606 | // |
| 12607 | if (FD->isBitField()) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12608 | if (!NoDiagnose) { |
| 12609 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 12610 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
| 12611 | return nullptr; |
| 12612 | } |
| 12613 | if (RelevantExpr) |
| 12614 | return nullptr; |
| 12615 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12616 | } |
| 12617 | |
| 12618 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 12619 | // If the type of a list item is a reference to a type T then the type |
| 12620 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12621 | QualType CurType = BaseE->getType().getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12622 | |
| 12623 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 12624 | // A list item cannot be a variable that is a member of a structure with |
| 12625 | // a union type. |
| 12626 | // |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12627 | if (CurType->isUnionType()) { |
| 12628 | if (!NoDiagnose) { |
| 12629 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 12630 | << CurE->getSourceRange(); |
| 12631 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12632 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12633 | continue; |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12634 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12635 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12636 | // If we got a member expression, we should not expect any array section |
| 12637 | // before that: |
| 12638 | // |
| 12639 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 12640 | // If a list item is an element of a structure, only the rightmost symbol |
| 12641 | // of the variable reference can be an array section. |
| 12642 | // |
| 12643 | AllowUnitySizeArraySection = false; |
| 12644 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12645 | |
| 12646 | // Record the component. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12647 | CurComponents.emplace_back(CurE, FD); |
| 12648 | } else if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12649 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 12650 | |
| 12651 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12652 | if (!NoDiagnose) { |
| 12653 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 12654 | << 0 << CurE->getSourceRange(); |
| 12655 | return nullptr; |
| 12656 | } |
| 12657 | continue; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12658 | } |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12659 | |
| 12660 | // If we got an array subscript that express the whole dimension we |
| 12661 | // can have any array expressions before. If it only expressing part of |
| 12662 | // the dimension, we can only have unitary-size array expressions. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12663 | if (checkArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12664 | E->getType())) |
| 12665 | AllowWholeSizeArraySection = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12666 | |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 12667 | if (const auto *TE = dyn_cast<CXXThisExpr>(E)) { |
| 12668 | Expr::EvalResult Result; |
| 12669 | if (CurE->getIdx()->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 12670 | if (!Result.Val.getInt().isNullValue()) { |
| 12671 | SemaRef.Diag(CurE->getIdx()->getExprLoc(), |
| 12672 | diag::err_omp_invalid_map_this_expr); |
| 12673 | SemaRef.Diag(CurE->getIdx()->getExprLoc(), |
| 12674 | diag::note_omp_invalid_subscript_on_this_ptr_map); |
| 12675 | } |
| 12676 | } |
| 12677 | RelevantExpr = TE; |
| 12678 | } |
| 12679 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12680 | // Record the component - we don't have any declaration associated. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12681 | CurComponents.emplace_back(CurE, nullptr); |
| 12682 | } else if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12683 | assert(!NoDiagnose && "Array sections cannot be implicitly mapped."); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12684 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 12685 | |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12686 | QualType CurType = |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12687 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 12688 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12689 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 12690 | // If the type of a list item is a reference to a type T then the type |
| 12691 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12692 | if (CurType->isReferenceType()) |
| 12693 | CurType = CurType->getPointeeType(); |
| 12694 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12695 | bool IsPointer = CurType->isAnyPointerType(); |
| 12696 | |
| 12697 | if (!IsPointer && !CurType->isArrayType()) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12698 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 12699 | << 0 << CurE->getSourceRange(); |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12700 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12701 | } |
| 12702 | |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12703 | bool NotWhole = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12704 | checkArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12705 | bool NotUnity = |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12706 | checkArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12707 | |
| Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 12708 | if (AllowWholeSizeArraySection) { |
| 12709 | // Any array section is currently allowed. Allowing a whole size array |
| 12710 | // section implies allowing a unity array section as well. |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12711 | // |
| 12712 | // If this array section refers to the whole dimension we can still |
| 12713 | // accept other array sections before this one, except if the base is a |
| 12714 | // pointer. Otherwise, only unitary sections are accepted. |
| 12715 | if (NotWhole || IsPointer) |
| 12716 | AllowWholeSizeArraySection = false; |
| Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 12717 | } else if (AllowUnitySizeArraySection && NotUnity) { |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12718 | // A unity or whole array section is not allowed and that is not |
| 12719 | // compatible with the properties of the current array section. |
| 12720 | SemaRef.Diag( |
| 12721 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 12722 | << CurE->getSourceRange(); |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12723 | return nullptr; |
| Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 12724 | } |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12725 | |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 12726 | if (const auto *TE = dyn_cast<CXXThisExpr>(E)) { |
| 12727 | Expr::EvalResult ResultR; |
| 12728 | Expr::EvalResult ResultL; |
| 12729 | if (CurE->getLength()->EvaluateAsInt(ResultR, |
| 12730 | SemaRef.getASTContext())) { |
| 12731 | if (!ResultR.Val.getInt().isOneValue()) { |
| 12732 | SemaRef.Diag(CurE->getLength()->getExprLoc(), |
| 12733 | diag::err_omp_invalid_map_this_expr); |
| 12734 | SemaRef.Diag(CurE->getLength()->getExprLoc(), |
| 12735 | diag::note_omp_invalid_length_on_this_ptr_mapping); |
| 12736 | } |
| 12737 | } |
| 12738 | if (CurE->getLowerBound() && CurE->getLowerBound()->EvaluateAsInt( |
| 12739 | ResultL, SemaRef.getASTContext())) { |
| 12740 | if (!ResultL.Val.getInt().isNullValue()) { |
| 12741 | SemaRef.Diag(CurE->getLowerBound()->getExprLoc(), |
| 12742 | diag::err_omp_invalid_map_this_expr); |
| 12743 | SemaRef.Diag(CurE->getLowerBound()->getExprLoc(), |
| 12744 | diag::note_omp_invalid_lower_bound_on_this_ptr_mapping); |
| 12745 | } |
| 12746 | } |
| 12747 | RelevantExpr = TE; |
| 12748 | } |
| 12749 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12750 | // Record the component - we don't have any declaration associated. |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12751 | CurComponents.emplace_back(CurE, nullptr); |
| 12752 | } else { |
| Alexey Bataev | b7a9b74 | 2017-12-05 19:20:09 +0000 | [diff] [blame] | 12753 | if (!NoDiagnose) { |
| 12754 | // If nothing else worked, this is not a valid map clause expression. |
| 12755 | SemaRef.Diag( |
| 12756 | ELoc, diag::err_omp_expected_named_var_member_or_array_expression) |
| 12757 | << ERange; |
| 12758 | } |
| Alexey Bataev | 27041fa | 2017-12-05 15:22:49 +0000 | [diff] [blame] | 12759 | return nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12760 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12761 | } |
| 12762 | |
| 12763 | return RelevantExpr; |
| 12764 | } |
| 12765 | |
| 12766 | // Return true if expression E associated with value VD has conflicts with other |
| 12767 | // map information. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12768 | static bool checkMapConflicts( |
| 12769 | Sema &SemaRef, DSAStackTy *DSAS, const ValueDecl *VD, const Expr *E, |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12770 | bool CurrentRegionOnly, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12771 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 12772 | OpenMPClauseKind CKind) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12773 | assert(VD && E); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12774 | SourceLocation ELoc = E->getExprLoc(); |
| 12775 | SourceRange ERange = E->getSourceRange(); |
| 12776 | |
| 12777 | // In order to easily check the conflicts we need to match each component of |
| 12778 | // the expression under test with the components of the expressions that are |
| 12779 | // already in the stack. |
| 12780 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12781 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12782 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12783 | "Map clause expression with unexpected base!"); |
| 12784 | |
| 12785 | // Variables to help detecting enclosing problems in data environment nests. |
| 12786 | bool IsEnclosedByDataEnvironmentExpr = false; |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12787 | const Expr *EnclosingExpr = nullptr; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12788 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12789 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 12790 | VD, CurrentRegionOnly, |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12791 | [&IsEnclosedByDataEnvironmentExpr, &SemaRef, VD, CurrentRegionOnly, ELoc, |
| 12792 | ERange, CKind, &EnclosingExpr, |
| 12793 | CurComponents](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 12794 | StackComponents, |
| 12795 | OpenMPClauseKind) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12796 | assert(!StackComponents.empty() && |
| 12797 | "Map clause expression with no components!"); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12798 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12799 | "Map clause expression with unexpected base!"); |
| Fangrui Song | 16fe49a | 2018-04-18 19:32:01 +0000 | [diff] [blame] | 12800 | (void)VD; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12801 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12802 | // The whole expression in the stack. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12803 | const Expr *RE = StackComponents.front().getAssociatedExpression(); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12804 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12805 | // Expressions must start from the same base. Here we detect at which |
| 12806 | // point both expressions diverge from each other and see if we can |
| 12807 | // detect if the memory referred to both expressions is contiguous and |
| 12808 | // do not overlap. |
| 12809 | auto CI = CurComponents.rbegin(); |
| 12810 | auto CE = CurComponents.rend(); |
| 12811 | auto SI = StackComponents.rbegin(); |
| 12812 | auto SE = StackComponents.rend(); |
| 12813 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 12814 | |
| 12815 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 12816 | // At most one list item can be an array item derived from a given |
| 12817 | // variable in map clauses of the same construct. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12818 | if (CurrentRegionOnly && |
| 12819 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 12820 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 12821 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 12822 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 12823 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12824 | diag::err_omp_multiple_array_items_in_map_clause) |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12825 | << CI->getAssociatedExpression()->getSourceRange(); |
| 12826 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 12827 | diag::note_used_here) |
| 12828 | << SI->getAssociatedExpression()->getSourceRange(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12829 | return true; |
| 12830 | } |
| 12831 | |
| 12832 | // Do both expressions have the same kind? |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12833 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 12834 | SI->getAssociatedExpression()->getStmtClass()) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12835 | break; |
| 12836 | |
| 12837 | // Are we dealing with different variables/fields? |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12838 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12839 | break; |
| 12840 | } |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 12841 | // Check if the extra components of the expressions in the enclosing |
| 12842 | // data environment are redundant for the current base declaration. |
| 12843 | // If they are, the maps completely overlap, which is legal. |
| 12844 | for (; SI != SE; ++SI) { |
| 12845 | QualType Type; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12846 | if (const auto *ASE = |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12847 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 12848 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12849 | } else if (const auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12850 | SI->getAssociatedExpression())) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12851 | const Expr *E = OASE->getBase()->IgnoreParenImpCasts(); |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 12852 | Type = |
| 12853 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 12854 | } |
| 12855 | if (Type.isNull() || Type->isAnyPointerType() || |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12856 | checkArrayExpressionDoesNotReferToWholeSize( |
| Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 12857 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 12858 | break; |
| 12859 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12860 | |
| 12861 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 12862 | // List items of map clauses in the same construct must not share |
| 12863 | // original storage. |
| 12864 | // |
| 12865 | // If the expressions are exactly the same or one is a subset of the |
| 12866 | // other, it means they are sharing storage. |
| 12867 | if (CI == CE && SI == SE) { |
| 12868 | if (CurrentRegionOnly) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12869 | if (CKind == OMPC_map) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12870 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12871 | } else { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12872 | assert(CKind == OMPC_to || CKind == OMPC_from); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12873 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 12874 | << ERange; |
| 12875 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12876 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 12877 | << RE->getSourceRange(); |
| 12878 | return true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12879 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12880 | // If we find the same expression in the enclosing data environment, |
| 12881 | // that is legal. |
| 12882 | IsEnclosedByDataEnvironmentExpr = true; |
| 12883 | return false; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12884 | } |
| 12885 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12886 | QualType DerivedType = |
| 12887 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 12888 | SourceLocation DerivedLoc = |
| 12889 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12890 | |
| 12891 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 12892 | // If the type of a list item is a reference to a type T then the type |
| 12893 | // will be considered to be T for all purposes of this clause. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12894 | DerivedType = DerivedType.getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12895 | |
| 12896 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 12897 | // A variable for which the type is pointer and an array section |
| 12898 | // derived from that variable must not appear as list items of map |
| 12899 | // clauses of the same construct. |
| 12900 | // |
| 12901 | // Also, cover one of the cases in: |
| 12902 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 12903 | // If any part of the original storage of a list item has corresponding |
| 12904 | // storage in the device data environment, all of the original storage |
| 12905 | // must have corresponding storage in the device data environment. |
| 12906 | // |
| 12907 | if (DerivedType->isAnyPointerType()) { |
| 12908 | if (CI == CE || SI == SE) { |
| 12909 | SemaRef.Diag( |
| 12910 | DerivedLoc, |
| 12911 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 12912 | << DerivedLoc; |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 12913 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 12914 | << RE->getSourceRange(); |
| 12915 | return true; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12916 | } |
| 12917 | if (CI->getAssociatedExpression()->getStmtClass() != |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 12918 | SI->getAssociatedExpression()->getStmtClass() || |
| 12919 | CI->getAssociatedDeclaration()->getCanonicalDecl() == |
| 12920 | SI->getAssociatedDeclaration()->getCanonicalDecl()) { |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12921 | assert(CI != CE && SI != SE); |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 12922 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_dereferenced) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12923 | << DerivedLoc; |
| Alexey Bataev | 2819260b | 2018-02-27 17:42:00 +0000 | [diff] [blame] | 12924 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 12925 | << RE->getSourceRange(); |
| 12926 | return true; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12927 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12928 | } |
| 12929 | |
| 12930 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 12931 | // List items of map clauses in the same construct must not share |
| 12932 | // original storage. |
| 12933 | // |
| 12934 | // An expression is a subset of the other. |
| 12935 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12936 | if (CKind == OMPC_map) { |
| Alexey Bataev | e82445f | 2018-09-20 13:54:02 +0000 | [diff] [blame] | 12937 | if (CI != CE || SI != SE) { |
| 12938 | // Allow constructs like this: map(s, s.ptr[0:1]), where s.ptr is |
| 12939 | // a pointer. |
| 12940 | auto Begin = |
| 12941 | CI != CE ? CurComponents.begin() : StackComponents.begin(); |
| 12942 | auto End = CI != CE ? CurComponents.end() : StackComponents.end(); |
| 12943 | auto It = Begin; |
| 12944 | while (It != End && !It->getAssociatedDeclaration()) |
| 12945 | std::advance(It, 1); |
| 12946 | assert(It != End && |
| 12947 | "Expected at least one component with the declaration."); |
| 12948 | if (It != Begin && It->getAssociatedDeclaration() |
| 12949 | ->getType() |
| 12950 | .getCanonicalType() |
| 12951 | ->isAnyPointerType()) { |
| 12952 | IsEnclosedByDataEnvironmentExpr = false; |
| 12953 | EnclosingExpr = nullptr; |
| 12954 | return false; |
| 12955 | } |
| 12956 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12957 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 12958 | } else { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 12959 | assert(CKind == OMPC_to || CKind == OMPC_from); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 12960 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 12961 | << ERange; |
| 12962 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12963 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 12964 | << RE->getSourceRange(); |
| 12965 | return true; |
| 12966 | } |
| 12967 | |
| 12968 | // The current expression uses the same base as other expression in the |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12969 | // data environment but does not contain it completely. |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 12970 | if (!CurrentRegionOnly && SI != SE) |
| 12971 | EnclosingExpr = RE; |
| 12972 | |
| 12973 | // The current expression is a subset of the expression in the data |
| 12974 | // environment. |
| 12975 | IsEnclosedByDataEnvironmentExpr |= |
| 12976 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 12977 | |
| 12978 | return false; |
| 12979 | }); |
| 12980 | |
| 12981 | if (CurrentRegionOnly) |
| 12982 | return FoundError; |
| 12983 | |
| 12984 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 12985 | // If any part of the original storage of a list item has corresponding |
| 12986 | // storage in the device data environment, all of the original storage must |
| 12987 | // have corresponding storage in the device data environment. |
| 12988 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 12989 | // If a list item is an element of a structure, and a different element of |
| 12990 | // the structure has a corresponding list item in the device data environment |
| 12991 | // prior to a task encountering the construct associated with the map clause, |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 12992 | // 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] | 12993 | // data environment prior to the task encountering the construct. |
| 12994 | // |
| 12995 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 12996 | SemaRef.Diag(ELoc, |
| 12997 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 12998 | << ERange; |
| 12999 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 13000 | << EnclosingExpr->getSourceRange(); |
| 13001 | return true; |
| 13002 | } |
| 13003 | |
| 13004 | return FoundError; |
| 13005 | } |
| 13006 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13007 | // Look up the user-defined mapper given the mapper name and mapped type, and |
| 13008 | // build a reference to it. |
| 13009 | ExprResult buildUserDefinedMapperRef(Sema &SemaRef, Scope *S, |
| 13010 | CXXScopeSpec &MapperIdScopeSpec, |
| 13011 | const DeclarationNameInfo &MapperId, |
| 13012 | QualType Type, Expr *UnresolvedMapper) { |
| 13013 | if (MapperIdScopeSpec.isInvalid()) |
| 13014 | return ExprError(); |
| 13015 | // Find all user-defined mappers with the given MapperId. |
| 13016 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 13017 | LookupResult Lookup(SemaRef, MapperId, Sema::LookupOMPMapperName); |
| 13018 | Lookup.suppressDiagnostics(); |
| 13019 | if (S) { |
| 13020 | while (S && SemaRef.LookupParsedName(Lookup, S, &MapperIdScopeSpec)) { |
| 13021 | NamedDecl *D = Lookup.getRepresentativeDecl(); |
| 13022 | while (S && !S->isDeclScope(D)) |
| 13023 | S = S->getParent(); |
| 13024 | if (S) |
| 13025 | S = S->getParent(); |
| 13026 | Lookups.emplace_back(); |
| 13027 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 13028 | Lookup.clear(); |
| 13029 | } |
| 13030 | } else if (auto *ULE = cast_or_null<UnresolvedLookupExpr>(UnresolvedMapper)) { |
| 13031 | // Extract the user-defined mappers with the given MapperId. |
| 13032 | Lookups.push_back(UnresolvedSet<8>()); |
| 13033 | for (NamedDecl *D : ULE->decls()) { |
| 13034 | auto *DMD = cast<OMPDeclareMapperDecl>(D); |
| 13035 | assert(DMD && "Expect valid OMPDeclareMapperDecl during instantiation."); |
| 13036 | Lookups.back().addDecl(DMD); |
| 13037 | } |
| 13038 | } |
| 13039 | // Defer the lookup for dependent types. The results will be passed through |
| 13040 | // UnresolvedMapper on instantiation. |
| 13041 | if (SemaRef.CurContext->isDependentContext() || Type->isDependentType() || |
| 13042 | Type->isInstantiationDependentType() || |
| 13043 | Type->containsUnexpandedParameterPack() || |
| 13044 | filterLookupForUDReductionAndMapper<bool>(Lookups, [](ValueDecl *D) { |
| 13045 | return !D->isInvalidDecl() && |
| 13046 | (D->getType()->isDependentType() || |
| 13047 | D->getType()->isInstantiationDependentType() || |
| 13048 | D->getType()->containsUnexpandedParameterPack()); |
| 13049 | })) { |
| 13050 | UnresolvedSet<8> URS; |
| 13051 | for (const UnresolvedSet<8> &Set : Lookups) { |
| 13052 | if (Set.empty()) |
| 13053 | continue; |
| 13054 | URS.append(Set.begin(), Set.end()); |
| 13055 | } |
| 13056 | return UnresolvedLookupExpr::Create( |
| 13057 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 13058 | MapperIdScopeSpec.getWithLocInContext(SemaRef.Context), MapperId, |
| 13059 | /*ADL=*/false, /*Overloaded=*/true, URS.begin(), URS.end()); |
| 13060 | } |
| 13061 | // [OpenMP 5.0], 2.19.7.3 declare mapper Directive, Restrictions |
| 13062 | // The type must be of struct, union or class type in C and C++ |
| 13063 | if (!Type->isStructureOrClassType() && !Type->isUnionType()) |
| 13064 | return ExprEmpty(); |
| 13065 | SourceLocation Loc = MapperId.getLoc(); |
| 13066 | // Perform argument dependent lookup. |
| 13067 | if (SemaRef.getLangOpts().CPlusPlus && !MapperIdScopeSpec.isSet()) |
| 13068 | argumentDependentLookup(SemaRef, MapperId, Loc, Type, Lookups); |
| 13069 | // Return the first user-defined mapper with the desired type. |
| 13070 | if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>( |
| 13071 | Lookups, [&SemaRef, Type](ValueDecl *D) -> ValueDecl * { |
| 13072 | if (!D->isInvalidDecl() && |
| 13073 | SemaRef.Context.hasSameType(D->getType(), Type)) |
| 13074 | return D; |
| 13075 | return nullptr; |
| 13076 | })) |
| 13077 | return SemaRef.BuildDeclRefExpr(VD, Type, VK_LValue, Loc); |
| 13078 | // Find the first user-defined mapper with a type derived from the desired |
| 13079 | // type. |
| 13080 | if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>( |
| 13081 | Lookups, [&SemaRef, Type, Loc](ValueDecl *D) -> ValueDecl * { |
| 13082 | if (!D->isInvalidDecl() && |
| 13083 | SemaRef.IsDerivedFrom(Loc, Type, D->getType()) && |
| 13084 | !Type.isMoreQualifiedThan(D->getType())) |
| 13085 | return D; |
| 13086 | return nullptr; |
| 13087 | })) { |
| 13088 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 13089 | /*DetectVirtual=*/false); |
| 13090 | if (SemaRef.IsDerivedFrom(Loc, Type, VD->getType(), Paths)) { |
| 13091 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 13092 | VD->getType().getUnqualifiedType()))) { |
| 13093 | if (SemaRef.CheckBaseClassAccess( |
| 13094 | Loc, VD->getType(), Type, Paths.front(), |
| 13095 | /*DiagID=*/0) != Sema::AR_inaccessible) { |
| 13096 | return SemaRef.BuildDeclRefExpr(VD, Type, VK_LValue, Loc); |
| 13097 | } |
| 13098 | } |
| 13099 | } |
| 13100 | } |
| 13101 | // Report error if a mapper is specified, but cannot be found. |
| 13102 | if (MapperIdScopeSpec.isSet() || MapperId.getAsString() != "default") { |
| 13103 | SemaRef.Diag(Loc, diag::err_omp_invalid_mapper) |
| 13104 | << Type << MapperId.getName(); |
| 13105 | return ExprError(); |
| 13106 | } |
| 13107 | return ExprEmpty(); |
| 13108 | } |
| 13109 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13110 | namespace { |
| 13111 | // Utility struct that gathers all the related lists associated with a mappable |
| 13112 | // expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13113 | struct MappableVarListInfo { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13114 | // The list of expressions. |
| 13115 | ArrayRef<Expr *> VarList; |
| 13116 | // The list of processed expressions. |
| 13117 | SmallVector<Expr *, 16> ProcessedVarList; |
| 13118 | // The mappble components for each expression. |
| 13119 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 13120 | // The base declaration of the variable. |
| 13121 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13122 | // The reference to the user-defined mapper associated with every expression. |
| 13123 | SmallVector<Expr *, 16> UDMapperList; |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13124 | |
| 13125 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 13126 | // We have a list of components and base declarations for each entry in the |
| 13127 | // variable list. |
| 13128 | VarComponents.reserve(VarList.size()); |
| 13129 | VarBaseDeclarations.reserve(VarList.size()); |
| 13130 | } |
| 13131 | }; |
| 13132 | } |
| 13133 | |
| 13134 | // Check the validity of the provided variable list for the provided clause kind |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13135 | // \a CKind. In the check process the valid expressions, mappable expression |
| 13136 | // components, variables, and user-defined mappers are extracted and used to |
| 13137 | // fill \a ProcessedVarList, \a VarComponents, \a VarBaseDeclarations, and \a |
| 13138 | // UDMapperList in MVLI. \a MapType, \a IsMapTypeImplicit, \a MapperIdScopeSpec, |
| 13139 | // and \a MapperId are expected to be valid if the clause kind is 'map'. |
| 13140 | static void checkMappableExpressionList( |
| 13141 | Sema &SemaRef, DSAStackTy *DSAS, OpenMPClauseKind CKind, |
| 13142 | MappableVarListInfo &MVLI, SourceLocation StartLoc, |
| 13143 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 13144 | bool IsMapTypeImplicit = false, CXXScopeSpec *MapperIdScopeSpec = nullptr, |
| 13145 | const DeclarationNameInfo *MapperId = nullptr, |
| 13146 | ArrayRef<Expr *> UnresolvedMappers = llvm::None) { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 13147 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 13148 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13149 | "Unexpected clause kind with mappable expressions!"); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13150 | assert( |
| 13151 | ((CKind == OMPC_map && MapperIdScopeSpec && MapperId) || |
| 13152 | (CKind != OMPC_map && !MapperIdScopeSpec && !MapperId)) && |
| 13153 | "Map clauses and only map clauses have user-defined mapper identifiers."); |
| 13154 | |
| 13155 | // Iterators to find the current unresolved mapper expression. |
| 13156 | auto UMIt = UnresolvedMappers.begin(), UMEnd = UnresolvedMappers.end(); |
| 13157 | bool UpdateUMIt = false; |
| 13158 | Expr *UnresolvedMapper = nullptr; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13159 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 13160 | // Keep track of the mappable components and base declarations in this clause. |
| 13161 | // Each entry in the list is going to have a list of components associated. We |
| 13162 | // record each set of the components so that we can build the clause later on. |
| 13163 | // In the end we should have the same amount of declarations and component |
| 13164 | // lists. |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 13165 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13166 | for (Expr *RE : MVLI.VarList) { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 13167 | assert(RE && "Null expr in omp to/from/map clause"); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13168 | SourceLocation ELoc = RE->getExprLoc(); |
| 13169 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13170 | // Find the current unresolved mapper expression. |
| 13171 | if (UpdateUMIt && UMIt != UMEnd) { |
| 13172 | UMIt++; |
| 13173 | assert( |
| 13174 | UMIt != UMEnd && |
| 13175 | "Expect the size of UnresolvedMappers to match with that of VarList"); |
| 13176 | } |
| 13177 | UpdateUMIt = true; |
| 13178 | if (UMIt != UMEnd) |
| 13179 | UnresolvedMapper = *UMIt; |
| 13180 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13181 | const Expr *VE = RE->IgnoreParenLValueCasts(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13182 | |
| 13183 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 13184 | VE->isInstantiationDependent() || |
| 13185 | VE->containsUnexpandedParameterPack()) { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13186 | if (CKind == OMPC_map) { |
| 13187 | // Try to find the associated user-defined mapper. |
| 13188 | ExprResult ER = buildUserDefinedMapperRef( |
| 13189 | SemaRef, DSAS->getCurScope(), *MapperIdScopeSpec, *MapperId, |
| 13190 | VE->getType().getCanonicalType(), UnresolvedMapper); |
| 13191 | if (ER.isInvalid()) |
| 13192 | continue; |
| 13193 | MVLI.UDMapperList.push_back(ER.get()); |
| 13194 | } else { |
| 13195 | MVLI.UDMapperList.push_back(nullptr); |
| 13196 | } |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13197 | // We can only analyze this information once the missing information is |
| 13198 | // resolved. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13199 | MVLI.ProcessedVarList.push_back(RE); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13200 | continue; |
| 13201 | } |
| 13202 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13203 | Expr *SimpleExpr = RE->IgnoreParenCasts(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13204 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13205 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13206 | SemaRef.Diag(ELoc, |
| 13207 | diag::err_omp_expected_named_var_member_or_array_expression) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13208 | << RE->getSourceRange(); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13209 | continue; |
| 13210 | } |
| 13211 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 13212 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 13213 | ValueDecl *CurDeclaration = nullptr; |
| 13214 | |
| 13215 | // Obtain the array or member expression bases if required. Also, fill the |
| 13216 | // components array with all the components identified in the process. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13217 | const Expr *BE = checkMapClauseExpressionBase( |
| 13218 | SemaRef, SimpleExpr, CurComponents, CKind, /*NoDiagnose=*/false); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13219 | if (!BE) |
| 13220 | continue; |
| 13221 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 13222 | assert(!CurComponents.empty() && |
| 13223 | "Invalid mappable expression information."); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13224 | |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 13225 | if (const auto *TE = dyn_cast<CXXThisExpr>(BE)) { |
| 13226 | // Add store "this" pointer to class in DSAStackTy for future checking |
| 13227 | DSAS->addMappedClassesQualTypes(TE->getType()); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13228 | if (CKind == OMPC_map) { |
| 13229 | // Try to find the associated user-defined mapper. |
| 13230 | ExprResult ER = buildUserDefinedMapperRef( |
| 13231 | SemaRef, DSAS->getCurScope(), *MapperIdScopeSpec, *MapperId, |
| 13232 | VE->getType().getCanonicalType(), UnresolvedMapper); |
| 13233 | if (ER.isInvalid()) |
| 13234 | continue; |
| 13235 | MVLI.UDMapperList.push_back(ER.get()); |
| 13236 | } else { |
| 13237 | MVLI.UDMapperList.push_back(nullptr); |
| 13238 | } |
| Patrick Lyster | e13b1e3 | 2019-01-02 19:28:48 +0000 | [diff] [blame] | 13239 | // Skip restriction checking for variable or field declarations |
| 13240 | MVLI.ProcessedVarList.push_back(RE); |
| 13241 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 13242 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 13243 | CurComponents.end()); |
| 13244 | MVLI.VarBaseDeclarations.push_back(nullptr); |
| 13245 | continue; |
| 13246 | } |
| 13247 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 13248 | // For the following checks, we rely on the base declaration which is |
| 13249 | // expected to be associated with the last component. The declaration is |
| 13250 | // expected to be a variable or a field (if 'this' is being mapped). |
| 13251 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 13252 | assert(CurDeclaration && "Null decl on map clause."); |
| 13253 | assert( |
| 13254 | CurDeclaration->isCanonicalDecl() && |
| 13255 | "Expecting components to have associated only canonical declarations."); |
| 13256 | |
| 13257 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13258 | const auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13259 | |
| 13260 | assert((VD || FD) && "Only variables or fields are expected here!"); |
| NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 13261 | (void)FD; |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13262 | |
| 13263 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13264 | // threadprivate variables cannot appear in a map clause. |
| 13265 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 13266 | // threadprivate variables cannot appear in a from clause. |
| 13267 | if (VD && DSAS->isThreadPrivate(VD)) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13268 | DSAStackTy::DSAVarData DVar = DSAS->getTopDSA(VD, /*FromParent=*/false); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13269 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 13270 | << getOpenMPClauseName(CKind); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13271 | reportOriginalDsa(SemaRef, DSAS, VD, DVar); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13272 | continue; |
| 13273 | } |
| 13274 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13275 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 13276 | // A list item cannot appear in both a map clause and a data-sharing |
| 13277 | // attribute clause on the same construct. |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13278 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13279 | // Check conflicts with other map clause expressions. We check the conflicts |
| 13280 | // with the current construct separately from the enclosing data |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13281 | // environment, because the restrictions are different. We only have to |
| 13282 | // check conflicts across regions for the map clauses. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13283 | if (checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13284 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13285 | break; |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13286 | if (CKind == OMPC_map && |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13287 | checkMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13288 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13289 | break; |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13290 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13291 | // OpenMP 4.5 [2.10.5, target update Construct] |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13292 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 13293 | // If the type of a list item is a reference to a type T then the type will |
| 13294 | // be considered to be T for all purposes of this clause. |
| Alexey Bataev | 354df2e | 2018-05-02 18:44:10 +0000 | [diff] [blame] | 13295 | auto I = llvm::find_if( |
| 13296 | CurComponents, |
| 13297 | [](const OMPClauseMappableExprCommon::MappableComponent &MC) { |
| 13298 | return MC.getAssociatedDeclaration(); |
| 13299 | }); |
| 13300 | assert(I != CurComponents.end() && "Null decl on map clause."); |
| 13301 | QualType Type = |
| 13302 | I->getAssociatedDeclaration()->getType().getNonReferenceType(); |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13303 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13304 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 13305 | // 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] | 13306 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13307 | // A list item must have a mappable type. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13308 | if (!checkTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13309 | DSAS, Type)) |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13310 | continue; |
| 13311 | |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13312 | if (CKind == OMPC_map) { |
| 13313 | // target enter data |
| 13314 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 13315 | // A map-type must be specified in all map clauses and must be either |
| 13316 | // to or alloc. |
| 13317 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 13318 | if (DKind == OMPD_target_enter_data && |
| 13319 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 13320 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 13321 | << (IsMapTypeImplicit ? 1 : 0) |
| 13322 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 13323 | << getOpenMPDirectiveName(DKind); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 13324 | continue; |
| 13325 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13326 | |
| 13327 | // target exit_data |
| 13328 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 13329 | // A map-type must be specified in all map clauses and must be either |
| 13330 | // from, release, or delete. |
| 13331 | if (DKind == OMPD_target_exit_data && |
| 13332 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 13333 | MapType == OMPC_MAP_delete)) { |
| 13334 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 13335 | << (IsMapTypeImplicit ? 1 : 0) |
| 13336 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 13337 | << getOpenMPDirectiveName(DKind); |
| 13338 | continue; |
| 13339 | } |
| 13340 | |
| 13341 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 13342 | // A list item cannot appear in both a map clause and a data-sharing |
| 13343 | // attribute clause on the same construct |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13344 | if (VD && isOpenMPTargetExecutionDirective(DKind)) { |
| 13345 | DSAStackTy::DSAVarData DVar = DSAS->getTopDSA(VD, /*FromParent=*/false); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13346 | if (isOpenMPPrivate(DVar.CKind)) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13347 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13348 | << getOpenMPClauseName(DVar.CKind) |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13349 | << getOpenMPClauseName(OMPC_map) |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13350 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13351 | reportOriginalDsa(SemaRef, DSAS, CurDeclaration, DVar); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13352 | continue; |
| 13353 | } |
| 13354 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13355 | |
| 13356 | // Try to find the associated user-defined mapper. |
| 13357 | ExprResult ER = buildUserDefinedMapperRef( |
| 13358 | SemaRef, DSAS->getCurScope(), *MapperIdScopeSpec, *MapperId, |
| 13359 | Type.getCanonicalType(), UnresolvedMapper); |
| 13360 | if (ER.isInvalid()) |
| 13361 | continue; |
| 13362 | MVLI.UDMapperList.push_back(ER.get()); |
| 13363 | } else { |
| 13364 | MVLI.UDMapperList.push_back(nullptr); |
| Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 13365 | } |
| 13366 | |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 13367 | // Save the current expression. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13368 | MVLI.ProcessedVarList.push_back(RE); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 13369 | |
| 13370 | // Store the components in the stack so that they can be used to check |
| 13371 | // against other clauses later on. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 13372 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 13373 | /*WhereFoundClauseKind=*/OMPC_map); |
| Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 13374 | |
| 13375 | // Save the components and declaration to create the clause. For purposes of |
| 13376 | // the clause creation, any component list that has has base 'this' uses |
| Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 13377 | // null as base declaration. |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13378 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 13379 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 13380 | CurComponents.end()); |
| 13381 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 13382 | : CurDeclaration); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13383 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 13384 | } |
| 13385 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13386 | OMPClause *Sema::ActOnOpenMPMapClause( |
| 13387 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
| 13388 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
| 13389 | CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, |
| 13390 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, |
| 13391 | SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 13392 | const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) { |
| 13393 | OpenMPMapModifierKind Modifiers[] = {OMPC_MAP_MODIFIER_unknown, |
| 13394 | OMPC_MAP_MODIFIER_unknown, |
| 13395 | OMPC_MAP_MODIFIER_unknown}; |
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 13396 | SourceLocation ModifiersLoc[OMPMapClause::NumberOfModifiers]; |
| 13397 | |
| 13398 | // Process map-type-modifiers, flag errors for duplicate modifiers. |
| 13399 | unsigned Count = 0; |
| 13400 | for (unsigned I = 0, E = MapTypeModifiers.size(); I < E; ++I) { |
| 13401 | if (MapTypeModifiers[I] != OMPC_MAP_MODIFIER_unknown && |
| 13402 | llvm::find(Modifiers, MapTypeModifiers[I]) != std::end(Modifiers)) { |
| 13403 | Diag(MapTypeModifiersLoc[I], diag::err_omp_duplicate_map_type_modifier); |
| 13404 | continue; |
| 13405 | } |
| 13406 | assert(Count < OMPMapClause::NumberOfModifiers && |
| Gheorghe-Teodor Bercea | a3afcf2 | 2019-01-09 20:38:35 +0000 | [diff] [blame] | 13407 | "Modifiers exceed the allowed number of map type modifiers"); |
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 13408 | Modifiers[Count] = MapTypeModifiers[I]; |
| 13409 | ModifiersLoc[Count] = MapTypeModifiersLoc[I]; |
| 13410 | ++Count; |
| 13411 | } |
| 13412 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13413 | // If the identifier of user-defined mapper is not specified, it is "default". |
| 13414 | if (!MapperId.getName() || MapperId.getName().isEmpty()) { |
| 13415 | auto &DeclNames = getASTContext().DeclarationNames; |
| 13416 | MapperId.setName( |
| 13417 | DeclNames.getIdentifier(&getASTContext().Idents.get("default"))); |
| 13418 | } |
| 13419 | |
| 13420 | MappableVarListInfo MVLI(VarList); |
| 13421 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, Locs.StartLoc, |
| 13422 | MapType, IsMapTypeImplicit, &MapperIdScopeSpec, |
| 13423 | &MapperId, UnresolvedMappers); |
| 13424 | |
| Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 13425 | // We need to produce a map clause even if we don't have variables so that |
| 13426 | // other diagnostics related with non-existing map clauses are accurate. |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 13427 | return OMPMapClause::Create(Context, Locs, MVLI.ProcessedVarList, |
| 13428 | MVLI.VarBaseDeclarations, MVLI.VarComponents, |
| 13429 | MVLI.UDMapperList, Modifiers, ModifiersLoc, |
| 13430 | MapperIdScopeSpec.getWithLocInContext(Context), |
| 13431 | MapperId, MapType, IsMapTypeImplicit, MapLoc); |
| Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 13432 | } |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 13433 | |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13434 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 13435 | TypeResult ParsedType) { |
| 13436 | assert(ParsedType.isUsable()); |
| 13437 | |
| 13438 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 13439 | if (ReductionType.isNull()) |
| 13440 | return QualType(); |
| 13441 | |
| 13442 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 13443 | // A type name in a declare reduction directive cannot be a function type, an |
| 13444 | // array type, a reference type, or a type qualified with const, volatile or |
| 13445 | // restrict. |
| 13446 | if (ReductionType.hasQualifiers()) { |
| 13447 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 13448 | return QualType(); |
| 13449 | } |
| 13450 | |
| 13451 | if (ReductionType->isFunctionType()) { |
| 13452 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 13453 | return QualType(); |
| 13454 | } |
| 13455 | if (ReductionType->isReferenceType()) { |
| 13456 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 13457 | return QualType(); |
| 13458 | } |
| 13459 | if (ReductionType->isArrayType()) { |
| 13460 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 13461 | return QualType(); |
| 13462 | } |
| 13463 | return ReductionType; |
| 13464 | } |
| 13465 | |
| 13466 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 13467 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 13468 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 13469 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 13470 | SmallVector<Decl *, 8> Decls; |
| 13471 | Decls.reserve(ReductionTypes.size()); |
| 13472 | |
| 13473 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| Richard Smith | becb92d | 2017-10-10 22:33:17 +0000 | [diff] [blame] | 13474 | forRedeclarationInCurContext()); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13475 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 13476 | // A reduction-identifier may not be re-declared in the current scope for the |
| 13477 | // same type or for a type that is compatible according to the base language |
| 13478 | // rules. |
| 13479 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 13480 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 13481 | bool InCompoundScope = true; |
| 13482 | if (S != nullptr) { |
| 13483 | // Find previous declaration with the same name not referenced in other |
| 13484 | // declarations. |
| 13485 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 13486 | InCompoundScope = |
| 13487 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 13488 | LookupName(Lookup, S); |
| 13489 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 13490 | /*AllowInlineNamespace=*/false); |
| 13491 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13492 | LookupResult::Filter Filter = Lookup.makeFilter(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13493 | while (Filter.hasNext()) { |
| 13494 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 13495 | if (InCompoundScope) { |
| 13496 | auto I = UsedAsPrevious.find(PrevDecl); |
| 13497 | if (I == UsedAsPrevious.end()) |
| 13498 | UsedAsPrevious[PrevDecl] = false; |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13499 | if (OMPDeclareReductionDecl *D = PrevDecl->getPrevDeclInScope()) |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13500 | UsedAsPrevious[D] = true; |
| 13501 | } |
| 13502 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 13503 | PrevDecl->getLocation(); |
| 13504 | } |
| 13505 | Filter.done(); |
| 13506 | if (InCompoundScope) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13507 | for (const auto &PrevData : UsedAsPrevious) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13508 | if (!PrevData.second) { |
| 13509 | PrevDRD = PrevData.first; |
| 13510 | break; |
| 13511 | } |
| 13512 | } |
| 13513 | } |
| 13514 | } else if (PrevDeclInScope != nullptr) { |
| 13515 | auto *PrevDRDInScope = PrevDRD = |
| 13516 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 13517 | do { |
| 13518 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 13519 | PrevDRDInScope->getLocation(); |
| 13520 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 13521 | } while (PrevDRDInScope != nullptr); |
| 13522 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13523 | for (const auto &TyData : ReductionTypes) { |
| 13524 | const auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13525 | bool Invalid = false; |
| 13526 | if (I != PreviousRedeclTypes.end()) { |
| 13527 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 13528 | << TyData.first; |
| 13529 | Diag(I->second, diag::note_previous_definition); |
| 13530 | Invalid = true; |
| 13531 | } |
| 13532 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 13533 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 13534 | Name, TyData.first, PrevDRD); |
| 13535 | DC->addDecl(DRD); |
| 13536 | DRD->setAccess(AS); |
| 13537 | Decls.push_back(DRD); |
| 13538 | if (Invalid) |
| 13539 | DRD->setInvalidDecl(); |
| 13540 | else |
| 13541 | PrevDRD = DRD; |
| 13542 | } |
| 13543 | |
| 13544 | return DeclGroupPtrTy::make( |
| 13545 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 13546 | } |
| 13547 | |
| 13548 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 13549 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 13550 | |
| 13551 | // Enter new function scope. |
| 13552 | PushFunctionScope(); |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 13553 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13554 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 13555 | |
| 13556 | if (S != nullptr) |
| 13557 | PushDeclContext(S, DRD); |
| 13558 | else |
| 13559 | CurContext = DRD; |
| 13560 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 13561 | PushExpressionEvaluationContext( |
| 13562 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13563 | |
| 13564 | QualType ReductionType = DRD->getType(); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13565 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 13566 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 13567 | // uses semantics of argument handles by value, but it should be passed by |
| 13568 | // reference. C lang does not support references, so pass all parameters as |
| 13569 | // pointers. |
| 13570 | // Create 'T omp_in;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13571 | VarDecl *OmpInParm = |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13572 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13573 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 13574 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 13575 | // uses semantics of argument handles by value, but it should be passed by |
| 13576 | // reference. C lang does not support references, so pass all parameters as |
| 13577 | // pointers. |
| 13578 | // Create 'T omp_out;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13579 | VarDecl *OmpOutParm = |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13580 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 13581 | if (S != nullptr) { |
| 13582 | PushOnScopeChains(OmpInParm, S); |
| 13583 | PushOnScopeChains(OmpOutParm, S); |
| 13584 | } else { |
| 13585 | DRD->addDecl(OmpInParm); |
| 13586 | DRD->addDecl(OmpOutParm); |
| 13587 | } |
| Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 13588 | Expr *InE = |
| 13589 | ::buildDeclRefExpr(*this, OmpInParm, ReductionType, D->getLocation()); |
| 13590 | Expr *OutE = |
| 13591 | ::buildDeclRefExpr(*this, OmpOutParm, ReductionType, D->getLocation()); |
| 13592 | DRD->setCombinerData(InE, OutE); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13593 | } |
| 13594 | |
| 13595 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 13596 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 13597 | DiscardCleanupsInEvaluationContext(); |
| 13598 | PopExpressionEvaluationContext(); |
| 13599 | |
| 13600 | PopDeclContext(); |
| 13601 | PopFunctionScopeInfo(); |
| 13602 | |
| 13603 | if (Combiner != nullptr) |
| 13604 | DRD->setCombiner(Combiner); |
| 13605 | else |
| 13606 | DRD->setInvalidDecl(); |
| 13607 | } |
| 13608 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 13609 | VarDecl *Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13610 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 13611 | |
| 13612 | // Enter new function scope. |
| 13613 | PushFunctionScope(); |
| Reid Kleckner | 87a3180 | 2018-03-12 21:43:02 +0000 | [diff] [blame] | 13614 | setFunctionHasBranchProtectedScope(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13615 | |
| 13616 | if (S != nullptr) |
| 13617 | PushDeclContext(S, DRD); |
| 13618 | else |
| 13619 | CurContext = DRD; |
| 13620 | |
| Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 13621 | PushExpressionEvaluationContext( |
| 13622 | ExpressionEvaluationContext::PotentiallyEvaluated); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13623 | |
| 13624 | QualType ReductionType = DRD->getType(); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13625 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 13626 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 13627 | // uses semantics of argument handles by value, but it should be passed by |
| 13628 | // reference. C lang does not support references, so pass all parameters as |
| 13629 | // pointers. |
| 13630 | // Create 'T omp_priv;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13631 | VarDecl *OmpPrivParm = |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13632 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13633 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 13634 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 13635 | // uses semantics of argument handles by value, but it should be passed by |
| 13636 | // reference. C lang does not support references, so pass all parameters as |
| 13637 | // pointers. |
| 13638 | // Create 'T omp_orig;' variable. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13639 | VarDecl *OmpOrigParm = |
| Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 13640 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13641 | if (S != nullptr) { |
| 13642 | PushOnScopeChains(OmpPrivParm, S); |
| 13643 | PushOnScopeChains(OmpOrigParm, S); |
| 13644 | } else { |
| 13645 | DRD->addDecl(OmpPrivParm); |
| 13646 | DRD->addDecl(OmpOrigParm); |
| 13647 | } |
| Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 13648 | Expr *OrigE = |
| 13649 | ::buildDeclRefExpr(*this, OmpOrigParm, ReductionType, D->getLocation()); |
| 13650 | Expr *PrivE = |
| 13651 | ::buildDeclRefExpr(*this, OmpPrivParm, ReductionType, D->getLocation()); |
| 13652 | DRD->setInitializerData(OrigE, PrivE); |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 13653 | return OmpPrivParm; |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13654 | } |
| 13655 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 13656 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
| 13657 | VarDecl *OmpPrivParm) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13658 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 13659 | DiscardCleanupsInEvaluationContext(); |
| 13660 | PopExpressionEvaluationContext(); |
| 13661 | |
| 13662 | PopDeclContext(); |
| 13663 | PopFunctionScopeInfo(); |
| 13664 | |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 13665 | if (Initializer != nullptr) { |
| 13666 | DRD->setInitializer(Initializer, OMPDeclareReductionDecl::CallInit); |
| 13667 | } else if (OmpPrivParm->hasInit()) { |
| 13668 | DRD->setInitializer(OmpPrivParm->getInit(), |
| 13669 | OmpPrivParm->isDirectInit() |
| 13670 | ? OMPDeclareReductionDecl::DirectInit |
| 13671 | : OMPDeclareReductionDecl::CopyInit); |
| 13672 | } else { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13673 | DRD->setInvalidDecl(); |
| Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 13674 | } |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13675 | } |
| 13676 | |
| 13677 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 13678 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13679 | for (Decl *D : DeclReductions.get()) { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13680 | if (IsValid) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13681 | if (S) |
| 13682 | PushOnScopeChains(cast<OMPDeclareReductionDecl>(D), S, |
| 13683 | /*AddToContext=*/false); |
| 13684 | } else { |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13685 | D->setInvalidDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13686 | } |
| Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 13687 | } |
| 13688 | return DeclReductions; |
| 13689 | } |
| 13690 | |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 13691 | TypeResult Sema::ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D) { |
| 13692 | TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S); |
| 13693 | QualType T = TInfo->getType(); |
| 13694 | if (D.isInvalidType()) |
| 13695 | return true; |
| 13696 | |
| 13697 | if (getLangOpts().CPlusPlus) { |
| 13698 | // Check that there are no default arguments (C++ only). |
| 13699 | CheckExtraCXXDefaultArguments(D); |
| 13700 | } |
| 13701 | |
| 13702 | return CreateParsedType(T, TInfo); |
| 13703 | } |
| 13704 | |
| 13705 | QualType Sema::ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, |
| 13706 | TypeResult ParsedType) { |
| 13707 | assert(ParsedType.isUsable() && "Expect usable parsed mapper type"); |
| 13708 | |
| 13709 | QualType MapperType = GetTypeFromParser(ParsedType.get()); |
| 13710 | assert(!MapperType.isNull() && "Expect valid mapper type"); |
| 13711 | |
| 13712 | // [OpenMP 5.0], 2.19.7.3 declare mapper Directive, Restrictions |
| 13713 | // The type must be of struct, union or class type in C and C++ |
| 13714 | if (!MapperType->isStructureOrClassType() && !MapperType->isUnionType()) { |
| 13715 | Diag(TyLoc, diag::err_omp_mapper_wrong_type); |
| 13716 | return QualType(); |
| 13717 | } |
| 13718 | return MapperType; |
| 13719 | } |
| 13720 | |
| 13721 | OMPDeclareMapperDecl *Sema::ActOnOpenMPDeclareMapperDirectiveStart( |
| 13722 | Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, |
| 13723 | SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, |
| 13724 | Decl *PrevDeclInScope) { |
| 13725 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPMapperName, |
| 13726 | forRedeclarationInCurContext()); |
| 13727 | // [OpenMP 5.0], 2.19.7.3 declare mapper Directive, Restrictions |
| 13728 | // A mapper-identifier may not be redeclared in the current scope for the |
| 13729 | // same type or for a type that is compatible according to the base language |
| 13730 | // rules. |
| 13731 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 13732 | OMPDeclareMapperDecl *PrevDMD = nullptr; |
| 13733 | bool InCompoundScope = true; |
| 13734 | if (S != nullptr) { |
| 13735 | // Find previous declaration with the same name not referenced in other |
| 13736 | // declarations. |
| 13737 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 13738 | InCompoundScope = |
| 13739 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 13740 | LookupName(Lookup, S); |
| 13741 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 13742 | /*AllowInlineNamespace=*/false); |
| 13743 | llvm::DenseMap<OMPDeclareMapperDecl *, bool> UsedAsPrevious; |
| 13744 | LookupResult::Filter Filter = Lookup.makeFilter(); |
| 13745 | while (Filter.hasNext()) { |
| 13746 | auto *PrevDecl = cast<OMPDeclareMapperDecl>(Filter.next()); |
| 13747 | if (InCompoundScope) { |
| 13748 | auto I = UsedAsPrevious.find(PrevDecl); |
| 13749 | if (I == UsedAsPrevious.end()) |
| 13750 | UsedAsPrevious[PrevDecl] = false; |
| 13751 | if (OMPDeclareMapperDecl *D = PrevDecl->getPrevDeclInScope()) |
| 13752 | UsedAsPrevious[D] = true; |
| 13753 | } |
| 13754 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 13755 | PrevDecl->getLocation(); |
| 13756 | } |
| 13757 | Filter.done(); |
| 13758 | if (InCompoundScope) { |
| 13759 | for (const auto &PrevData : UsedAsPrevious) { |
| 13760 | if (!PrevData.second) { |
| 13761 | PrevDMD = PrevData.first; |
| 13762 | break; |
| 13763 | } |
| 13764 | } |
| 13765 | } |
| 13766 | } else if (PrevDeclInScope) { |
| 13767 | auto *PrevDMDInScope = PrevDMD = |
| 13768 | cast<OMPDeclareMapperDecl>(PrevDeclInScope); |
| 13769 | do { |
| 13770 | PreviousRedeclTypes[PrevDMDInScope->getType().getCanonicalType()] = |
| 13771 | PrevDMDInScope->getLocation(); |
| 13772 | PrevDMDInScope = PrevDMDInScope->getPrevDeclInScope(); |
| 13773 | } while (PrevDMDInScope != nullptr); |
| 13774 | } |
| 13775 | const auto I = PreviousRedeclTypes.find(MapperType.getCanonicalType()); |
| 13776 | bool Invalid = false; |
| 13777 | if (I != PreviousRedeclTypes.end()) { |
| 13778 | Diag(StartLoc, diag::err_omp_declare_mapper_redefinition) |
| 13779 | << MapperType << Name; |
| 13780 | Diag(I->second, diag::note_previous_definition); |
| 13781 | Invalid = true; |
| 13782 | } |
| 13783 | auto *DMD = OMPDeclareMapperDecl::Create(Context, DC, StartLoc, Name, |
| 13784 | MapperType, VN, PrevDMD); |
| 13785 | DC->addDecl(DMD); |
| 13786 | DMD->setAccess(AS); |
| 13787 | if (Invalid) |
| 13788 | DMD->setInvalidDecl(); |
| 13789 | |
| 13790 | // Enter new function scope. |
| 13791 | PushFunctionScope(); |
| 13792 | setFunctionHasBranchProtectedScope(); |
| 13793 | |
| 13794 | CurContext = DMD; |
| 13795 | |
| 13796 | return DMD; |
| 13797 | } |
| 13798 | |
| 13799 | void Sema::ActOnOpenMPDeclareMapperDirectiveVarDecl(OMPDeclareMapperDecl *DMD, |
| 13800 | Scope *S, |
| 13801 | QualType MapperType, |
| 13802 | SourceLocation StartLoc, |
| 13803 | DeclarationName VN) { |
| 13804 | VarDecl *VD = buildVarDecl(*this, StartLoc, MapperType, VN.getAsString()); |
| 13805 | if (S) |
| 13806 | PushOnScopeChains(VD, S); |
| 13807 | else |
| 13808 | DMD->addDecl(VD); |
| 13809 | Expr *MapperVarRefExpr = buildDeclRefExpr(*this, VD, MapperType, StartLoc); |
| 13810 | DMD->setMapperVarRef(MapperVarRefExpr); |
| 13811 | } |
| 13812 | |
| 13813 | Sema::DeclGroupPtrTy |
| 13814 | Sema::ActOnOpenMPDeclareMapperDirectiveEnd(OMPDeclareMapperDecl *D, Scope *S, |
| 13815 | ArrayRef<OMPClause *> ClauseList) { |
| 13816 | PopDeclContext(); |
| 13817 | PopFunctionScopeInfo(); |
| 13818 | |
| 13819 | if (D) { |
| 13820 | if (S) |
| 13821 | PushOnScopeChains(D, S, /*AddToContext=*/false); |
| 13822 | D->CreateClauses(Context, ClauseList); |
| 13823 | } |
| 13824 | |
| 13825 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 13826 | } |
| 13827 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 13828 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 13829 | SourceLocation StartLoc, |
| 13830 | SourceLocation LParenLoc, |
| 13831 | SourceLocation EndLoc) { |
| 13832 | Expr *ValExpr = NumTeams; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 13833 | Stmt *HelperValStmt = nullptr; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 13834 | |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 13835 | // OpenMP [teams Constrcut, Restrictions] |
| 13836 | // The num_teams expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13837 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 13838 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 13839 | return nullptr; |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 13840 | |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 13841 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 13842 | OpenMPDirectiveKind CaptureRegion = |
| 13843 | getOpenMPCaptureRegionForClause(DKind, OMPC_num_teams); |
| 13844 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 13845 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13846 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 13847 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 13848 | HelperValStmt = buildPreInits(Context, Captures); |
| 13849 | } |
| 13850 | |
| 13851 | return new (Context) OMPNumTeamsClause(ValExpr, HelperValStmt, CaptureRegion, |
| 13852 | StartLoc, LParenLoc, EndLoc); |
| Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 13853 | } |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 13854 | |
| 13855 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 13856 | SourceLocation StartLoc, |
| 13857 | SourceLocation LParenLoc, |
| 13858 | SourceLocation EndLoc) { |
| 13859 | Expr *ValExpr = ThreadLimit; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 13860 | Stmt *HelperValStmt = nullptr; |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 13861 | |
| 13862 | // OpenMP [teams Constrcut, Restrictions] |
| 13863 | // The thread_limit expression must evaluate to a positive integer value. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13864 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 13865 | /*StrictlyPositive=*/true)) |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 13866 | return nullptr; |
| 13867 | |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 13868 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 13869 | OpenMPDirectiveKind CaptureRegion = |
| 13870 | getOpenMPCaptureRegionForClause(DKind, OMPC_thread_limit); |
| 13871 | if (CaptureRegion != OMPD_unknown && !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 13872 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13873 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 13874 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 13875 | HelperValStmt = buildPreInits(Context, Captures); |
| 13876 | } |
| 13877 | |
| 13878 | return new (Context) OMPThreadLimitClause( |
| 13879 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
| Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 13880 | } |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 13881 | |
| 13882 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 13883 | SourceLocation StartLoc, |
| 13884 | SourceLocation LParenLoc, |
| 13885 | SourceLocation EndLoc) { |
| 13886 | Expr *ValExpr = Priority; |
| 13887 | |
| 13888 | // OpenMP [2.9.1, task Constrcut] |
| 13889 | // The priority-value is a non-negative numerical scalar expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13890 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 13891 | /*StrictlyPositive=*/false)) |
| 13892 | return nullptr; |
| 13893 | |
| 13894 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 13895 | } |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 13896 | |
| 13897 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 13898 | SourceLocation StartLoc, |
| 13899 | SourceLocation LParenLoc, |
| 13900 | SourceLocation EndLoc) { |
| 13901 | Expr *ValExpr = Grainsize; |
| 13902 | |
| 13903 | // OpenMP [2.9.2, taskloop Constrcut] |
| 13904 | // The parameter of the grainsize clause must be a positive integer |
| 13905 | // expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13906 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 13907 | /*StrictlyPositive=*/true)) |
| 13908 | return nullptr; |
| 13909 | |
| 13910 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 13911 | } |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 13912 | |
| 13913 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 13914 | SourceLocation StartLoc, |
| 13915 | SourceLocation LParenLoc, |
| 13916 | SourceLocation EndLoc) { |
| 13917 | Expr *ValExpr = NumTasks; |
| 13918 | |
| 13919 | // OpenMP [2.9.2, taskloop Constrcut] |
| 13920 | // The parameter of the num_tasks clause must be a positive integer |
| 13921 | // expression. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13922 | if (!isNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 13923 | /*StrictlyPositive=*/true)) |
| 13924 | return nullptr; |
| 13925 | |
| 13926 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 13927 | } |
| 13928 | |
| Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 13929 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 13930 | SourceLocation LParenLoc, |
| 13931 | SourceLocation EndLoc) { |
| 13932 | // OpenMP [2.13.2, critical construct, Description] |
| 13933 | // ... where hint-expression is an integer constant expression that evaluates |
| 13934 | // to a valid lock hint. |
| 13935 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 13936 | if (HintExpr.isInvalid()) |
| 13937 | return nullptr; |
| 13938 | return new (Context) |
| 13939 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 13940 | } |
| 13941 | |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 13942 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 13943 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 13944 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 13945 | SourceLocation EndLoc) { |
| 13946 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 13947 | std::string Values; |
| 13948 | Values += "'"; |
| 13949 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 13950 | Values += "'"; |
| 13951 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 13952 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 13953 | return nullptr; |
| 13954 | } |
| 13955 | Expr *ValExpr = ChunkSize; |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 13956 | Stmt *HelperValStmt = nullptr; |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 13957 | if (ChunkSize) { |
| 13958 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 13959 | !ChunkSize->isInstantiationDependent() && |
| 13960 | !ChunkSize->containsUnexpandedParameterPack()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 13961 | SourceLocation ChunkSizeLoc = ChunkSize->getBeginLoc(); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 13962 | ExprResult Val = |
| 13963 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 13964 | if (Val.isInvalid()) |
| 13965 | return nullptr; |
| 13966 | |
| 13967 | ValExpr = Val.get(); |
| 13968 | |
| 13969 | // OpenMP [2.7.1, Restrictions] |
| 13970 | // chunk_size must be a loop invariant integer expression with a positive |
| 13971 | // value. |
| 13972 | llvm::APSInt Result; |
| 13973 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 13974 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 13975 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 13976 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 13977 | return nullptr; |
| 13978 | } |
| Alexey Bataev | 2ba6704 | 2017-11-28 21:11:44 +0000 | [diff] [blame] | 13979 | } else if (getOpenMPCaptureRegionForClause( |
| 13980 | DSAStack->getCurrentDirective(), OMPC_dist_schedule) != |
| 13981 | OMPD_unknown && |
| Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 13982 | !CurContext->isDependentContext()) { |
| Alexey Bataev | 8e769ee | 2017-12-22 21:01:52 +0000 | [diff] [blame] | 13983 | ValExpr = MakeFullExpr(ValExpr).get(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 13984 | llvm::MapVector<const Expr *, DeclRefExpr *> Captures; |
| Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 13985 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 13986 | HelperValStmt = buildPreInits(Context, Captures); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 13987 | } |
| 13988 | } |
| 13989 | } |
| 13990 | |
| 13991 | return new (Context) |
| 13992 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
| Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 13993 | Kind, ValExpr, HelperValStmt); |
| Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 13994 | } |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 13995 | |
| 13996 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 13997 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 13998 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 13999 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 14000 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 14001 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || Kind != OMPC_DEFAULTMAP_scalar) { |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 14002 | std::string Value; |
| 14003 | SourceLocation Loc; |
| 14004 | Value += "'"; |
| 14005 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 14006 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 14007 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 14008 | Loc = MLoc; |
| 14009 | } else { |
| 14010 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 14011 | OMPC_DEFAULTMAP_scalar); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 14012 | Loc = KindLoc; |
| 14013 | } |
| 14014 | Value += "'"; |
| 14015 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 14016 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 14017 | return nullptr; |
| 14018 | } |
| Alexey Bataev | 2fd0cb2 | 2017-10-05 17:51:39 +0000 | [diff] [blame] | 14019 | DSAStack->setDefaultDMAToFromScalar(StartLoc); |
| Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 14020 | |
| 14021 | return new (Context) |
| 14022 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 14023 | } |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14024 | |
| 14025 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 14026 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 14027 | if (!CurLexicalContext->isFileContext() && |
| 14028 | !CurLexicalContext->isExternCContext() && |
| Alexey Bataev | 502ec49 | 2017-10-03 20:00:00 +0000 | [diff] [blame] | 14029 | !CurLexicalContext->isExternCXXContext() && |
| 14030 | !isa<CXXRecordDecl>(CurLexicalContext) && |
| 14031 | !isa<ClassTemplateDecl>(CurLexicalContext) && |
| 14032 | !isa<ClassTemplatePartialSpecializationDecl>(CurLexicalContext) && |
| 14033 | !isa<ClassTemplateSpecializationDecl>(CurLexicalContext)) { |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14034 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 14035 | return false; |
| 14036 | } |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 14037 | ++DeclareTargetNestingLevel; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14038 | return true; |
| 14039 | } |
| 14040 | |
| 14041 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 14042 | assert(DeclareTargetNestingLevel > 0 && |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14043 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 14044 | --DeclareTargetNestingLevel; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14045 | } |
| 14046 | |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 14047 | void Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, |
| 14048 | CXXScopeSpec &ScopeSpec, |
| 14049 | const DeclarationNameInfo &Id, |
| 14050 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 14051 | NamedDeclSetType &SameDirectiveDecls) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 14052 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 14053 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 14054 | |
| 14055 | if (Lookup.isAmbiguous()) |
| 14056 | return; |
| 14057 | Lookup.suppressDiagnostics(); |
| 14058 | |
| 14059 | if (!Lookup.isSingleResult()) { |
| 14060 | if (TypoCorrection Corrected = |
| 14061 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 14062 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 14063 | CTK_ErrorRecovery)) { |
| 14064 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 14065 | << Id.getName()); |
| 14066 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 14067 | return; |
| 14068 | } |
| 14069 | |
| 14070 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 14071 | return; |
| 14072 | } |
| 14073 | |
| 14074 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14075 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND) || |
| 14076 | isa<FunctionTemplateDecl>(ND)) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 14077 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 14078 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14079 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| 14080 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( |
| 14081 | cast<ValueDecl>(ND)); |
| 14082 | if (!Res) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14083 | auto *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 14084 | ND->addAttr(A); |
| 14085 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 14086 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 14087 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND, Id.getLoc()); |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14088 | } else if (*Res != MT) { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 14089 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 14090 | << Id.getName(); |
| 14091 | } |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14092 | } else { |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 14093 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14094 | } |
| Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 14095 | } |
| 14096 | |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14097 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 14098 | Sema &SemaRef, Decl *D) { |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14099 | if (!D || !isa<VarDecl>(D)) |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14100 | return; |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14101 | auto *VD = cast<VarDecl>(D); |
| 14102 | if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
| 14103 | return; |
| 14104 | SemaRef.Diag(VD->getLocation(), diag::warn_omp_not_in_target_context); |
| 14105 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14106 | } |
| 14107 | |
| 14108 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 14109 | Sema &SemaRef, DSAStackTy *Stack, |
| 14110 | ValueDecl *VD) { |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14111 | return VD->hasAttr<OMPDeclareTargetDeclAttr>() || |
| 14112 | checkTypeMappable(SL, SR, SemaRef, Stack, VD->getType(), |
| 14113 | /*FullCheck=*/false); |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14114 | } |
| 14115 | |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 14116 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
| 14117 | SourceLocation IdLoc) { |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14118 | if (!D || D->isInvalidDecl()) |
| 14119 | return; |
| 14120 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 14121 | SourceLocation SL = E ? E->getBeginLoc() : D->getLocation(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14122 | if (auto *VD = dyn_cast<VarDecl>(D)) { |
| Alexey Bataev | c1943e7 | 2018-07-09 19:58:08 +0000 | [diff] [blame] | 14123 | // Only global variables can be marked as declare target. |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14124 | if (!VD->isFileVarDecl() && !VD->isStaticLocal() && |
| 14125 | !VD->isStaticDataMember()) |
| Alexey Bataev | c1943e7 | 2018-07-09 19:58:08 +0000 | [diff] [blame] | 14126 | return; |
| 14127 | // 2.10.6: threadprivate variable cannot appear in a declare target |
| 14128 | // directive. |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14129 | if (DSAStack->isThreadPrivate(VD)) { |
| 14130 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14131 | reportOriginalDsa(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14132 | return; |
| 14133 | } |
| 14134 | } |
| Alexey Bataev | 97b7221 | 2018-08-14 18:31:20 +0000 | [diff] [blame] | 14135 | if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 14136 | D = FTD->getTemplatedDecl(); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14137 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14138 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
| 14139 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(FD); |
| 14140 | if (Res && *Res == OMPDeclareTargetDeclAttr::MT_Link) { |
| Kelvin Li | 1ce87c7 | 2017-12-12 20:08:12 +0000 | [diff] [blame] | 14141 | assert(IdLoc.isValid() && "Source location is expected"); |
| 14142 | Diag(IdLoc, diag::err_omp_function_in_link_clause); |
| 14143 | Diag(FD->getLocation(), diag::note_defined_here) << FD; |
| 14144 | return; |
| 14145 | } |
| 14146 | } |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14147 | if (auto *VD = dyn_cast<ValueDecl>(D)) { |
| 14148 | // Problem if any with var declared with incomplete type will be reported |
| 14149 | // as normal, so no need to check it here. |
| 14150 | if ((E || !VD->getType()->isIncompleteType()) && |
| 14151 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) |
| 14152 | return; |
| 14153 | if (!E && !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) { |
| 14154 | // Checking declaration inside declare target region. |
| 14155 | if (isa<VarDecl>(D) || isa<FunctionDecl>(D) || |
| 14156 | isa<FunctionTemplateDecl>(D)) { |
| 14157 | auto *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 14158 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 14159 | D->addAttr(A); |
| 14160 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 14161 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
| 14162 | } |
| 14163 | return; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14164 | } |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14165 | } |
| Alexey Bataev | 30a7821 | 2018-09-11 13:59:10 +0000 | [diff] [blame] | 14166 | if (!E) |
| 14167 | return; |
| Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 14168 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 14169 | } |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 14170 | |
| 14171 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14172 | const OMPVarListLocTy &Locs) { |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 14173 | MappableVarListInfo MVLI(VarList); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14174 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, Locs.StartLoc); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 14175 | if (MVLI.ProcessedVarList.empty()) |
| 14176 | return nullptr; |
| 14177 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14178 | return OMPToClause::Create(Context, Locs, MVLI.ProcessedVarList, |
| 14179 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
| Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 14180 | } |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 14181 | |
| 14182 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14183 | const OMPVarListLocTy &Locs) { |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 14184 | MappableVarListInfo MVLI(VarList); |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14185 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, Locs.StartLoc); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 14186 | if (MVLI.ProcessedVarList.empty()) |
| 14187 | return nullptr; |
| 14188 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14189 | return OMPFromClause::Create(Context, Locs, MVLI.ProcessedVarList, |
| 14190 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
| Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 14191 | } |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 14192 | |
| 14193 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14194 | const OMPVarListLocTy &Locs) { |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14195 | MappableVarListInfo MVLI(VarList); |
| 14196 | SmallVector<Expr *, 8> PrivateCopies; |
| 14197 | SmallVector<Expr *, 8> Inits; |
| 14198 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14199 | for (Expr *RefExpr : VarList) { |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 14200 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 14201 | SourceLocation ELoc; |
| 14202 | SourceRange ERange; |
| 14203 | Expr *SimpleRefExpr = RefExpr; |
| 14204 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 14205 | if (Res.second) { |
| 14206 | // It will be analyzed later. |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14207 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 14208 | PrivateCopies.push_back(nullptr); |
| 14209 | Inits.push_back(nullptr); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 14210 | } |
| 14211 | ValueDecl *D = Res.first; |
| 14212 | if (!D) |
| 14213 | continue; |
| 14214 | |
| 14215 | QualType Type = D->getType(); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14216 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 14217 | |
| 14218 | auto *VD = dyn_cast<VarDecl>(D); |
| 14219 | |
| 14220 | // Item should be a pointer or reference to pointer. |
| 14221 | if (!Type->isPointerType()) { |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 14222 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 14223 | << 0 << RefExpr->getSourceRange(); |
| 14224 | continue; |
| 14225 | } |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14226 | |
| 14227 | // Build the private variable and the expression that refers to it. |
| Alexey Bataev | 63cc8e9 | 2018-03-20 14:45:59 +0000 | [diff] [blame] | 14228 | auto VDPrivate = |
| 14229 | buildVarDecl(*this, ELoc, Type, D->getName(), |
| 14230 | D->hasAttrs() ? &D->getAttrs() : nullptr, |
| 14231 | VD ? cast<DeclRefExpr>(SimpleRefExpr) : nullptr); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14232 | if (VDPrivate->isInvalidDecl()) |
| 14233 | continue; |
| 14234 | |
| 14235 | CurContext->addDecl(VDPrivate); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14236 | DeclRefExpr *VDPrivateRefExpr = buildDeclRefExpr( |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14237 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 14238 | |
| 14239 | // Add temporary variable to initialize the private copy of the pointer. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14240 | VarDecl *VDInit = |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14241 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14242 | DeclRefExpr *VDInitRefExpr = buildDeclRefExpr( |
| 14243 | *this, VDInit, RefExpr->getType(), RefExpr->getExprLoc()); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14244 | AddInitializerToDecl(VDPrivate, |
| 14245 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 14246 | /*DirectInit=*/false); |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14247 | |
| 14248 | // If required, build a capture to implement the privatization initialized |
| 14249 | // with the current list item value. |
| 14250 | DeclRefExpr *Ref = nullptr; |
| 14251 | if (!VD) |
| 14252 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 14253 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 14254 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 14255 | Inits.push_back(VDInitRefExpr); |
| 14256 | |
| 14257 | // We need to add a data sharing attribute for this variable to make sure it |
| 14258 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 14259 | // similar properties of a first private variable. |
| 14260 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 14261 | |
| 14262 | // Create a mappable component for the list item. List items in this clause |
| 14263 | // only need a component. |
| 14264 | MVLI.VarBaseDeclarations.push_back(D); |
| 14265 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 14266 | MVLI.VarComponents.back().push_back( |
| 14267 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 14268 | } |
| 14269 | |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14270 | if (MVLI.ProcessedVarList.empty()) |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 14271 | return nullptr; |
| 14272 | |
| Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 14273 | return OMPUseDevicePtrClause::Create( |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14274 | Context, Locs, MVLI.ProcessedVarList, PrivateCopies, Inits, |
| 14275 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
| Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 14276 | } |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 14277 | |
| 14278 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14279 | const OMPVarListLocTy &Locs) { |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 14280 | MappableVarListInfo MVLI(VarList); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14281 | for (Expr *RefExpr : VarList) { |
| Kelvin Li | 8437625 | 2016-12-14 15:39:58 +0000 | [diff] [blame] | 14282 | assert(RefExpr && "NULL expr in OpenMP is_device_ptr clause."); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 14283 | SourceLocation ELoc; |
| 14284 | SourceRange ERange; |
| 14285 | Expr *SimpleRefExpr = RefExpr; |
| 14286 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 14287 | if (Res.second) { |
| 14288 | // It will be analyzed later. |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 14289 | MVLI.ProcessedVarList.push_back(RefExpr); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 14290 | } |
| 14291 | ValueDecl *D = Res.first; |
| 14292 | if (!D) |
| 14293 | continue; |
| 14294 | |
| 14295 | QualType Type = D->getType(); |
| 14296 | // item should be a pointer or array or reference to pointer or array |
| 14297 | if (!Type.getNonReferenceType()->isPointerType() && |
| 14298 | !Type.getNonReferenceType()->isArrayType()) { |
| 14299 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 14300 | << 0 << RefExpr->getSourceRange(); |
| 14301 | continue; |
| 14302 | } |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 14303 | |
| 14304 | // Check if the declaration in the clause does not show up in any data |
| 14305 | // sharing attribute. |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14306 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, /*FromParent=*/false); |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 14307 | if (isOpenMPPrivate(DVar.CKind)) { |
| 14308 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 14309 | << getOpenMPClauseName(DVar.CKind) |
| 14310 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 14311 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14312 | reportOriginalDsa(*this, DSAStack, D, DVar); |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 14313 | continue; |
| 14314 | } |
| 14315 | |
| Alexey Bataev | e372710 | 2018-04-18 15:57:46 +0000 | [diff] [blame] | 14316 | const Expr *ConflictExpr; |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 14317 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 14318 | D, /*CurrentRegionOnly=*/true, |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 14319 | [&ConflictExpr]( |
| 14320 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 14321 | OpenMPClauseKind) -> bool { |
| 14322 | ConflictExpr = R.front().getAssociatedExpression(); |
| 14323 | return true; |
| 14324 | })) { |
| 14325 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 14326 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 14327 | << ConflictExpr->getSourceRange(); |
| 14328 | continue; |
| 14329 | } |
| 14330 | |
| 14331 | // Store the components in the stack so that they can be used to check |
| 14332 | // against other clauses later on. |
| 14333 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 14334 | DSAStack->addMappableExpressionComponents( |
| 14335 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 14336 | |
| 14337 | // Record the expression we've just processed. |
| 14338 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 14339 | |
| 14340 | // Create a mappable component for the list item. List items in this clause |
| 14341 | // only need a component. We use a null declaration to signal fields in |
| 14342 | // 'this'. |
| 14343 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 14344 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 14345 | "Unexpected device pointer expression!"); |
| 14346 | MVLI.VarBaseDeclarations.push_back( |
| 14347 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 14348 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 14349 | MVLI.VarComponents.back().push_back(MC); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 14350 | } |
| 14351 | |
| Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 14352 | if (MVLI.ProcessedVarList.empty()) |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 14353 | return nullptr; |
| 14354 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 14355 | return OMPIsDevicePtrClause::Create(Context, Locs, MVLI.ProcessedVarList, |
| 14356 | MVLI.VarBaseDeclarations, |
| 14357 | MVLI.VarComponents); |
| Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 14358 | } |