File: | clang/lib/Sema/SemaOpenMP.cpp |
Warning: | line 8137, column 18 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | /// \file |
9 | /// This file implements semantic analysis for OpenMP directives and |
10 | /// clauses. |
11 | /// |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #include "TreeTransform.h" |
15 | #include "clang/AST/ASTContext.h" |
16 | #include "clang/AST/ASTMutationListener.h" |
17 | #include "clang/AST/CXXInheritance.h" |
18 | #include "clang/AST/Decl.h" |
19 | #include "clang/AST/DeclCXX.h" |
20 | #include "clang/AST/DeclOpenMP.h" |
21 | #include "clang/AST/OpenMPClause.h" |
22 | #include "clang/AST/StmtCXX.h" |
23 | #include "clang/AST/StmtOpenMP.h" |
24 | #include "clang/AST/StmtVisitor.h" |
25 | #include "clang/AST/TypeOrdering.h" |
26 | #include "clang/Basic/DiagnosticSema.h" |
27 | #include "clang/Basic/OpenMPKinds.h" |
28 | #include "clang/Basic/PartialDiagnostic.h" |
29 | #include "clang/Basic/TargetInfo.h" |
30 | #include "clang/Sema/Initialization.h" |
31 | #include "clang/Sema/Lookup.h" |
32 | #include "clang/Sema/Scope.h" |
33 | #include "clang/Sema/ScopeInfo.h" |
34 | #include "clang/Sema/SemaInternal.h" |
35 | #include "llvm/ADT/IndexedMap.h" |
36 | #include "llvm/ADT/PointerEmbeddedInt.h" |
37 | #include "llvm/ADT/STLExtras.h" |
38 | #include "llvm/ADT/StringExtras.h" |
39 | #include "llvm/Frontend/OpenMP/OMPConstants.h" |
40 | #include <set> |
41 | |
42 | using namespace clang; |
43 | using namespace llvm::omp; |
44 | |
45 | //===----------------------------------------------------------------------===// |
46 | // Stack of data-sharing attributes for variables |
47 | //===----------------------------------------------------------------------===// |
48 | |
49 | static const Expr *checkMapClauseExpressionBase( |
50 | Sema &SemaRef, Expr *E, |
51 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
52 | OpenMPClauseKind CKind, OpenMPDirectiveKind DKind, bool NoDiagnose); |
53 | |
54 | namespace { |
55 | /// Default data sharing attributes, which can be applied to directive. |
56 | enum DefaultDataSharingAttributes { |
57 | DSA_unspecified = 0, /// Data sharing attribute not specified. |
58 | DSA_none = 1 << 0, /// Default data sharing attribute 'none'. |
59 | DSA_shared = 1 << 1, /// Default data sharing attribute 'shared'. |
60 | DSA_firstprivate = 1 << 2, /// Default data sharing attribute 'firstprivate'. |
61 | }; |
62 | |
63 | /// Stack for tracking declarations used in OpenMP directives and |
64 | /// clauses and their data-sharing attributes. |
65 | class DSAStackTy { |
66 | public: |
67 | struct DSAVarData { |
68 | OpenMPDirectiveKind DKind = OMPD_unknown; |
69 | OpenMPClauseKind CKind = OMPC_unknown; |
70 | unsigned Modifier = 0; |
71 | const Expr *RefExpr = nullptr; |
72 | DeclRefExpr *PrivateCopy = nullptr; |
73 | SourceLocation ImplicitDSALoc; |
74 | bool AppliedToPointee = false; |
75 | DSAVarData() = default; |
76 | DSAVarData(OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
77 | const Expr *RefExpr, DeclRefExpr *PrivateCopy, |
78 | SourceLocation ImplicitDSALoc, unsigned Modifier, |
79 | bool AppliedToPointee) |
80 | : DKind(DKind), CKind(CKind), Modifier(Modifier), RefExpr(RefExpr), |
81 | PrivateCopy(PrivateCopy), ImplicitDSALoc(ImplicitDSALoc), |
82 | AppliedToPointee(AppliedToPointee) {} |
83 | }; |
84 | using OperatorOffsetTy = |
85 | llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4>; |
86 | using DoacrossDependMapTy = |
87 | llvm::DenseMap<OMPDependClause *, OperatorOffsetTy>; |
88 | /// Kind of the declaration used in the uses_allocators clauses. |
89 | enum class UsesAllocatorsDeclKind { |
90 | /// Predefined allocator |
91 | PredefinedAllocator, |
92 | /// User-defined allocator |
93 | UserDefinedAllocator, |
94 | /// The declaration that represent allocator trait |
95 | AllocatorTrait, |
96 | }; |
97 | |
98 | private: |
99 | struct DSAInfo { |
100 | OpenMPClauseKind Attributes = OMPC_unknown; |
101 | unsigned Modifier = 0; |
102 | /// Pointer to a reference expression and a flag which shows that the |
103 | /// variable is marked as lastprivate(true) or not (false). |
104 | llvm::PointerIntPair<const Expr *, 1, bool> RefExpr; |
105 | DeclRefExpr *PrivateCopy = nullptr; |
106 | /// true if the attribute is applied to the pointee, not the variable |
107 | /// itself. |
108 | bool AppliedToPointee = false; |
109 | }; |
110 | using DeclSAMapTy = llvm::SmallDenseMap<const ValueDecl *, DSAInfo, 8>; |
111 | using UsedRefMapTy = llvm::SmallDenseMap<const ValueDecl *, const Expr *, 8>; |
112 | using LCDeclInfo = std::pair<unsigned, VarDecl *>; |
113 | using LoopControlVariablesMapTy = |
114 | llvm::SmallDenseMap<const ValueDecl *, LCDeclInfo, 8>; |
115 | /// Struct that associates a component with the clause kind where they are |
116 | /// found. |
117 | struct MappedExprComponentTy { |
118 | OMPClauseMappableExprCommon::MappableExprComponentLists Components; |
119 | OpenMPClauseKind Kind = OMPC_unknown; |
120 | }; |
121 | using MappedExprComponentsTy = |
122 | llvm::DenseMap<const ValueDecl *, MappedExprComponentTy>; |
123 | using CriticalsWithHintsTy = |
124 | llvm::StringMap<std::pair<const OMPCriticalDirective *, llvm::APSInt>>; |
125 | struct ReductionData { |
126 | using BOKPtrType = llvm::PointerEmbeddedInt<BinaryOperatorKind, 16>; |
127 | SourceRange ReductionRange; |
128 | llvm::PointerUnion<const Expr *, BOKPtrType> ReductionOp; |
129 | ReductionData() = default; |
130 | void set(BinaryOperatorKind BO, SourceRange RR) { |
131 | ReductionRange = RR; |
132 | ReductionOp = BO; |
133 | } |
134 | void set(const Expr *RefExpr, SourceRange RR) { |
135 | ReductionRange = RR; |
136 | ReductionOp = RefExpr; |
137 | } |
138 | }; |
139 | using DeclReductionMapTy = |
140 | llvm::SmallDenseMap<const ValueDecl *, ReductionData, 4>; |
141 | struct DefaultmapInfo { |
142 | OpenMPDefaultmapClauseModifier ImplicitBehavior = |
143 | OMPC_DEFAULTMAP_MODIFIER_unknown; |
144 | SourceLocation SLoc; |
145 | DefaultmapInfo() = default; |
146 | DefaultmapInfo(OpenMPDefaultmapClauseModifier M, SourceLocation Loc) |
147 | : ImplicitBehavior(M), SLoc(Loc) {} |
148 | }; |
149 | |
150 | struct SharingMapTy { |
151 | DeclSAMapTy SharingMap; |
152 | DeclReductionMapTy ReductionMap; |
153 | UsedRefMapTy AlignedMap; |
154 | UsedRefMapTy NontemporalMap; |
155 | MappedExprComponentsTy MappedExprComponents; |
156 | LoopControlVariablesMapTy LCVMap; |
157 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
158 | SourceLocation DefaultAttrLoc; |
159 | DefaultmapInfo DefaultmapMap[OMPC_DEFAULTMAP_unknown]; |
160 | OpenMPDirectiveKind Directive = OMPD_unknown; |
161 | DeclarationNameInfo DirectiveName; |
162 | Scope *CurScope = nullptr; |
163 | DeclContext *Context = nullptr; |
164 | SourceLocation ConstructLoc; |
165 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
166 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
167 | /// This data is required during codegen. |
168 | DoacrossDependMapTy DoacrossDepends; |
169 | /// First argument (Expr *) contains optional argument of the |
170 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
171 | /// clause, false otherwise. |
172 | llvm::Optional<std::pair<const Expr *, OMPOrderedClause *>> OrderedRegion; |
173 | unsigned AssociatedLoops = 1; |
174 | bool HasMutipleLoops = false; |
175 | const Decl *PossiblyLoopCounter = nullptr; |
176 | bool NowaitRegion = false; |
177 | bool CancelRegion = false; |
178 | bool LoopStart = false; |
179 | bool BodyComplete = false; |
180 | SourceLocation PrevScanLocation; |
181 | SourceLocation PrevOrderedLocation; |
182 | SourceLocation InnerTeamsRegionLoc; |
183 | /// Reference to the taskgroup task_reduction reference expression. |
184 | Expr *TaskgroupReductionRef = nullptr; |
185 | llvm::DenseSet<QualType> MappedClassesQualTypes; |
186 | SmallVector<Expr *, 4> InnerUsedAllocators; |
187 | llvm::DenseSet<CanonicalDeclPtr<Decl>> ImplicitTaskFirstprivates; |
188 | /// List of globals marked as declare target link in this target region |
189 | /// (isOpenMPTargetExecutionDirective(Directive) == true). |
190 | llvm::SmallVector<DeclRefExpr *, 4> DeclareTargetLinkVarDecls; |
191 | /// List of decls used in inclusive/exclusive clauses of the scan directive. |
192 | llvm::DenseSet<CanonicalDeclPtr<Decl>> UsedInScanDirective; |
193 | llvm::DenseMap<CanonicalDeclPtr<const Decl>, UsesAllocatorsDeclKind> |
194 | UsesAllocatorsDecls; |
195 | Expr *DeclareMapperVar = nullptr; |
196 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
197 | Scope *CurScope, SourceLocation Loc) |
198 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
199 | ConstructLoc(Loc) {} |
200 | SharingMapTy() = default; |
201 | }; |
202 | |
203 | using StackTy = SmallVector<SharingMapTy, 4>; |
204 | |
205 | /// Stack of used declaration and their data-sharing attributes. |
206 | DeclSAMapTy Threadprivates; |
207 | const FunctionScopeInfo *CurrentNonCapturingFunctionScope = nullptr; |
208 | SmallVector<std::pair<StackTy, const FunctionScopeInfo *>, 4> Stack; |
209 | /// true, if check for DSA must be from parent directive, false, if |
210 | /// from current directive. |
211 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
212 | Sema &SemaRef; |
213 | bool ForceCapturing = false; |
214 | /// true if all the variables in the target executable directives must be |
215 | /// captured by reference. |
216 | bool ForceCaptureByReferenceInTargetExecutable = false; |
217 | CriticalsWithHintsTy Criticals; |
218 | unsigned IgnoredStackElements = 0; |
219 | |
220 | /// Iterators over the stack iterate in order from innermost to outermost |
221 | /// directive. |
222 | using const_iterator = StackTy::const_reverse_iterator; |
223 | const_iterator begin() const { |
224 | return Stack.empty() ? const_iterator() |
225 | : Stack.back().first.rbegin() + IgnoredStackElements; |
226 | } |
227 | const_iterator end() const { |
228 | return Stack.empty() ? const_iterator() : Stack.back().first.rend(); |
229 | } |
230 | using iterator = StackTy::reverse_iterator; |
231 | iterator begin() { |
232 | return Stack.empty() ? iterator() |
233 | : Stack.back().first.rbegin() + IgnoredStackElements; |
234 | } |
235 | iterator end() { |
236 | return Stack.empty() ? iterator() : Stack.back().first.rend(); |
237 | } |
238 | |
239 | // Convenience operations to get at the elements of the stack. |
240 | |
241 | bool isStackEmpty() const { |
242 | return Stack.empty() || |
243 | Stack.back().second != CurrentNonCapturingFunctionScope || |
244 | Stack.back().first.size() <= IgnoredStackElements; |
245 | } |
246 | size_t getStackSize() const { |
247 | return isStackEmpty() ? 0 |
248 | : Stack.back().first.size() - IgnoredStackElements; |
249 | } |
250 | |
251 | SharingMapTy *getTopOfStackOrNull() { |
252 | size_t Size = getStackSize(); |
253 | if (Size == 0) |
254 | return nullptr; |
255 | return &Stack.back().first[Size - 1]; |
256 | } |
257 | const SharingMapTy *getTopOfStackOrNull() const { |
258 | return const_cast<DSAStackTy&>(*this).getTopOfStackOrNull(); |
259 | } |
260 | SharingMapTy &getTopOfStack() { |
261 | assert(!isStackEmpty() && "no current directive")((!isStackEmpty() && "no current directive") ? static_cast <void> (0) : __assert_fail ("!isStackEmpty() && \"no current directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 261, __PRETTY_FUNCTION__)); |
262 | return *getTopOfStackOrNull(); |
263 | } |
264 | const SharingMapTy &getTopOfStack() const { |
265 | return const_cast<DSAStackTy&>(*this).getTopOfStack(); |
266 | } |
267 | |
268 | SharingMapTy *getSecondOnStackOrNull() { |
269 | size_t Size = getStackSize(); |
270 | if (Size <= 1) |
271 | return nullptr; |
272 | return &Stack.back().first[Size - 2]; |
273 | } |
274 | const SharingMapTy *getSecondOnStackOrNull() const { |
275 | return const_cast<DSAStackTy&>(*this).getSecondOnStackOrNull(); |
276 | } |
277 | |
278 | /// Get the stack element at a certain level (previously returned by |
279 | /// \c getNestingLevel). |
280 | /// |
281 | /// Note that nesting levels count from outermost to innermost, and this is |
282 | /// the reverse of our iteration order where new inner levels are pushed at |
283 | /// the front of the stack. |
284 | SharingMapTy &getStackElemAtLevel(unsigned Level) { |
285 | assert(Level < getStackSize() && "no such stack element")((Level < getStackSize() && "no such stack element" ) ? static_cast<void> (0) : __assert_fail ("Level < getStackSize() && \"no such stack element\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 285, __PRETTY_FUNCTION__)); |
286 | return Stack.back().first[Level]; |
287 | } |
288 | const SharingMapTy &getStackElemAtLevel(unsigned Level) const { |
289 | return const_cast<DSAStackTy&>(*this).getStackElemAtLevel(Level); |
290 | } |
291 | |
292 | DSAVarData getDSA(const_iterator &Iter, ValueDecl *D) const; |
293 | |
294 | /// Checks if the variable is a local for OpenMP region. |
295 | bool isOpenMPLocal(VarDecl *D, const_iterator Iter) const; |
296 | |
297 | /// Vector of previously declared requires directives |
298 | SmallVector<const OMPRequiresDecl *, 2> RequiresDecls; |
299 | /// omp_allocator_handle_t type. |
300 | QualType OMPAllocatorHandleT; |
301 | /// omp_depend_t type. |
302 | QualType OMPDependT; |
303 | /// omp_event_handle_t type. |
304 | QualType OMPEventHandleT; |
305 | /// omp_alloctrait_t type. |
306 | QualType OMPAlloctraitT; |
307 | /// Expression for the predefined allocators. |
308 | Expr *OMPPredefinedAllocators[OMPAllocateDeclAttr::OMPUserDefinedMemAlloc] = { |
309 | nullptr}; |
310 | /// Vector of previously encountered target directives |
311 | SmallVector<SourceLocation, 2> TargetLocations; |
312 | SourceLocation AtomicLocation; |
313 | |
314 | public: |
315 | explicit DSAStackTy(Sema &S) : SemaRef(S) {} |
316 | |
317 | /// Sets omp_allocator_handle_t type. |
318 | void setOMPAllocatorHandleT(QualType Ty) { OMPAllocatorHandleT = Ty; } |
319 | /// Gets omp_allocator_handle_t type. |
320 | QualType getOMPAllocatorHandleT() const { return OMPAllocatorHandleT; } |
321 | /// Sets omp_alloctrait_t type. |
322 | void setOMPAlloctraitT(QualType Ty) { OMPAlloctraitT = Ty; } |
323 | /// Gets omp_alloctrait_t type. |
324 | QualType getOMPAlloctraitT() const { return OMPAlloctraitT; } |
325 | /// Sets the given default allocator. |
326 | void setAllocator(OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind, |
327 | Expr *Allocator) { |
328 | OMPPredefinedAllocators[AllocatorKind] = Allocator; |
329 | } |
330 | /// Returns the specified default allocator. |
331 | Expr *getAllocator(OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind) const { |
332 | return OMPPredefinedAllocators[AllocatorKind]; |
333 | } |
334 | /// Sets omp_depend_t type. |
335 | void setOMPDependT(QualType Ty) { OMPDependT = Ty; } |
336 | /// Gets omp_depend_t type. |
337 | QualType getOMPDependT() const { return OMPDependT; } |
338 | |
339 | /// Sets omp_event_handle_t type. |
340 | void setOMPEventHandleT(QualType Ty) { OMPEventHandleT = Ty; } |
341 | /// Gets omp_event_handle_t type. |
342 | QualType getOMPEventHandleT() const { return OMPEventHandleT; } |
343 | |
344 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
345 | OpenMPClauseKind getClauseParsingMode() const { |
346 | assert(isClauseParsingMode() && "Must be in clause parsing mode.")((isClauseParsingMode() && "Must be in clause parsing mode." ) ? static_cast<void> (0) : __assert_fail ("isClauseParsingMode() && \"Must be in clause parsing mode.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 346, __PRETTY_FUNCTION__)); |
347 | return ClauseKindMode; |
348 | } |
349 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
350 | |
351 | bool isBodyComplete() const { |
352 | const SharingMapTy *Top = getTopOfStackOrNull(); |
353 | return Top && Top->BodyComplete; |
354 | } |
355 | void setBodyComplete() { |
356 | getTopOfStack().BodyComplete = true; |
357 | } |
358 | |
359 | bool isForceVarCapturing() const { return ForceCapturing; } |
360 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
361 | |
362 | void setForceCaptureByReferenceInTargetExecutable(bool V) { |
363 | ForceCaptureByReferenceInTargetExecutable = V; |
364 | } |
365 | bool isForceCaptureByReferenceInTargetExecutable() const { |
366 | return ForceCaptureByReferenceInTargetExecutable; |
367 | } |
368 | |
369 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
370 | Scope *CurScope, SourceLocation Loc) { |
371 | assert(!IgnoredStackElements &&((!IgnoredStackElements && "cannot change stack while ignoring elements" ) ? static_cast<void> (0) : __assert_fail ("!IgnoredStackElements && \"cannot change stack while ignoring elements\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 372, __PRETTY_FUNCTION__)) |
372 | "cannot change stack while ignoring elements")((!IgnoredStackElements && "cannot change stack while ignoring elements" ) ? static_cast<void> (0) : __assert_fail ("!IgnoredStackElements && \"cannot change stack while ignoring elements\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 372, __PRETTY_FUNCTION__)); |
373 | if (Stack.empty() || |
374 | Stack.back().second != CurrentNonCapturingFunctionScope) |
375 | Stack.emplace_back(StackTy(), CurrentNonCapturingFunctionScope); |
376 | Stack.back().first.emplace_back(DKind, DirName, CurScope, Loc); |
377 | Stack.back().first.back().DefaultAttrLoc = Loc; |
378 | } |
379 | |
380 | void pop() { |
381 | assert(!IgnoredStackElements &&((!IgnoredStackElements && "cannot change stack while ignoring elements" ) ? static_cast<void> (0) : __assert_fail ("!IgnoredStackElements && \"cannot change stack while ignoring elements\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 382, __PRETTY_FUNCTION__)) |
382 | "cannot change stack while ignoring elements")((!IgnoredStackElements && "cannot change stack while ignoring elements" ) ? static_cast<void> (0) : __assert_fail ("!IgnoredStackElements && \"cannot change stack while ignoring elements\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 382, __PRETTY_FUNCTION__)); |
383 | assert(!Stack.back().first.empty() &&((!Stack.back().first.empty() && "Data-sharing attributes stack is empty!" ) ? static_cast<void> (0) : __assert_fail ("!Stack.back().first.empty() && \"Data-sharing attributes stack is empty!\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 384, __PRETTY_FUNCTION__)) |
384 | "Data-sharing attributes stack is empty!")((!Stack.back().first.empty() && "Data-sharing attributes stack is empty!" ) ? static_cast<void> (0) : __assert_fail ("!Stack.back().first.empty() && \"Data-sharing attributes stack is empty!\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 384, __PRETTY_FUNCTION__)); |
385 | Stack.back().first.pop_back(); |
386 | } |
387 | |
388 | /// RAII object to temporarily leave the scope of a directive when we want to |
389 | /// logically operate in its parent. |
390 | class ParentDirectiveScope { |
391 | DSAStackTy &Self; |
392 | bool Active; |
393 | public: |
394 | ParentDirectiveScope(DSAStackTy &Self, bool Activate) |
395 | : Self(Self), Active(false) { |
396 | if (Activate) |
397 | enable(); |
398 | } |
399 | ~ParentDirectiveScope() { disable(); } |
400 | void disable() { |
401 | if (Active) { |
402 | --Self.IgnoredStackElements; |
403 | Active = false; |
404 | } |
405 | } |
406 | void enable() { |
407 | if (!Active) { |
408 | ++Self.IgnoredStackElements; |
409 | Active = true; |
410 | } |
411 | } |
412 | }; |
413 | |
414 | /// Marks that we're started loop parsing. |
415 | void loopInit() { |
416 | assert(isOpenMPLoopDirective(getCurrentDirective()) &&((isOpenMPLoopDirective(getCurrentDirective()) && "Expected loop-based directive." ) ? static_cast<void> (0) : __assert_fail ("isOpenMPLoopDirective(getCurrentDirective()) && \"Expected loop-based directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 417, __PRETTY_FUNCTION__)) |
417 | "Expected loop-based directive.")((isOpenMPLoopDirective(getCurrentDirective()) && "Expected loop-based directive." ) ? static_cast<void> (0) : __assert_fail ("isOpenMPLoopDirective(getCurrentDirective()) && \"Expected loop-based directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 417, __PRETTY_FUNCTION__)); |
418 | getTopOfStack().LoopStart = true; |
419 | } |
420 | /// Start capturing of the variables in the loop context. |
421 | void loopStart() { |
422 | assert(isOpenMPLoopDirective(getCurrentDirective()) &&((isOpenMPLoopDirective(getCurrentDirective()) && "Expected loop-based directive." ) ? static_cast<void> (0) : __assert_fail ("isOpenMPLoopDirective(getCurrentDirective()) && \"Expected loop-based directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 423, __PRETTY_FUNCTION__)) |
423 | "Expected loop-based directive.")((isOpenMPLoopDirective(getCurrentDirective()) && "Expected loop-based directive." ) ? static_cast<void> (0) : __assert_fail ("isOpenMPLoopDirective(getCurrentDirective()) && \"Expected loop-based directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 423, __PRETTY_FUNCTION__)); |
424 | getTopOfStack().LoopStart = false; |
425 | } |
426 | /// true, if variables are captured, false otherwise. |
427 | bool isLoopStarted() const { |
428 | assert(isOpenMPLoopDirective(getCurrentDirective()) &&((isOpenMPLoopDirective(getCurrentDirective()) && "Expected loop-based directive." ) ? static_cast<void> (0) : __assert_fail ("isOpenMPLoopDirective(getCurrentDirective()) && \"Expected loop-based directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 429, __PRETTY_FUNCTION__)) |
429 | "Expected loop-based directive.")((isOpenMPLoopDirective(getCurrentDirective()) && "Expected loop-based directive." ) ? static_cast<void> (0) : __assert_fail ("isOpenMPLoopDirective(getCurrentDirective()) && \"Expected loop-based directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 429, __PRETTY_FUNCTION__)); |
430 | return !getTopOfStack().LoopStart; |
431 | } |
432 | /// Marks (or clears) declaration as possibly loop counter. |
433 | void resetPossibleLoopCounter(const Decl *D = nullptr) { |
434 | getTopOfStack().PossiblyLoopCounter = |
435 | D ? D->getCanonicalDecl() : D; |
436 | } |
437 | /// Gets the possible loop counter decl. |
438 | const Decl *getPossiblyLoopCunter() const { |
439 | return getTopOfStack().PossiblyLoopCounter; |
440 | } |
441 | /// Start new OpenMP region stack in new non-capturing function. |
442 | void pushFunction() { |
443 | assert(!IgnoredStackElements &&((!IgnoredStackElements && "cannot change stack while ignoring elements" ) ? static_cast<void> (0) : __assert_fail ("!IgnoredStackElements && \"cannot change stack while ignoring elements\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 444, __PRETTY_FUNCTION__)) |
444 | "cannot change stack while ignoring elements")((!IgnoredStackElements && "cannot change stack while ignoring elements" ) ? static_cast<void> (0) : __assert_fail ("!IgnoredStackElements && \"cannot change stack while ignoring elements\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 444, __PRETTY_FUNCTION__)); |
445 | const FunctionScopeInfo *CurFnScope = SemaRef.getCurFunction(); |
446 | assert(!isa<CapturingScopeInfo>(CurFnScope))((!isa<CapturingScopeInfo>(CurFnScope)) ? static_cast< void> (0) : __assert_fail ("!isa<CapturingScopeInfo>(CurFnScope)" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 446, __PRETTY_FUNCTION__)); |
447 | CurrentNonCapturingFunctionScope = CurFnScope; |
448 | } |
449 | /// Pop region stack for non-capturing function. |
450 | void popFunction(const FunctionScopeInfo *OldFSI) { |
451 | assert(!IgnoredStackElements &&((!IgnoredStackElements && "cannot change stack while ignoring elements" ) ? static_cast<void> (0) : __assert_fail ("!IgnoredStackElements && \"cannot change stack while ignoring elements\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 452, __PRETTY_FUNCTION__)) |
452 | "cannot change stack while ignoring elements")((!IgnoredStackElements && "cannot change stack while ignoring elements" ) ? static_cast<void> (0) : __assert_fail ("!IgnoredStackElements && \"cannot change stack while ignoring elements\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 452, __PRETTY_FUNCTION__)); |
453 | if (!Stack.empty() && Stack.back().second == OldFSI) { |
454 | assert(Stack.back().first.empty())((Stack.back().first.empty()) ? static_cast<void> (0) : __assert_fail ("Stack.back().first.empty()", "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 454, __PRETTY_FUNCTION__)); |
455 | Stack.pop_back(); |
456 | } |
457 | CurrentNonCapturingFunctionScope = nullptr; |
458 | for (const FunctionScopeInfo *FSI : llvm::reverse(SemaRef.FunctionScopes)) { |
459 | if (!isa<CapturingScopeInfo>(FSI)) { |
460 | CurrentNonCapturingFunctionScope = FSI; |
461 | break; |
462 | } |
463 | } |
464 | } |
465 | |
466 | void addCriticalWithHint(const OMPCriticalDirective *D, llvm::APSInt Hint) { |
467 | Criticals.try_emplace(D->getDirectiveName().getAsString(), D, Hint); |
468 | } |
469 | const std::pair<const OMPCriticalDirective *, llvm::APSInt> |
470 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
471 | auto I = Criticals.find(Name.getAsString()); |
472 | if (I != Criticals.end()) |
473 | return I->second; |
474 | return std::make_pair(nullptr, llvm::APSInt()); |
475 | } |
476 | /// If 'aligned' declaration for given variable \a D was not seen yet, |
477 | /// add it and return NULL; otherwise return previous occurrence's expression |
478 | /// for diagnostics. |
479 | const Expr *addUniqueAligned(const ValueDecl *D, const Expr *NewDE); |
480 | /// If 'nontemporal' declaration for given variable \a D was not seen yet, |
481 | /// add it and return NULL; otherwise return previous occurrence's expression |
482 | /// for diagnostics. |
483 | const Expr *addUniqueNontemporal(const ValueDecl *D, const Expr *NewDE); |
484 | |
485 | /// Register specified variable as loop control variable. |
486 | void addLoopControlVariable(const ValueDecl *D, VarDecl *Capture); |
487 | /// Check if the specified variable is a loop control variable for |
488 | /// current region. |
489 | /// \return The index of the loop control variable in the list of associated |
490 | /// for-loops (from outer to inner). |
491 | const LCDeclInfo isLoopControlVariable(const ValueDecl *D) const; |
492 | /// Check if the specified variable is a loop control variable for |
493 | /// parent region. |
494 | /// \return The index of the loop control variable in the list of associated |
495 | /// for-loops (from outer to inner). |
496 | const LCDeclInfo isParentLoopControlVariable(const ValueDecl *D) const; |
497 | /// Check if the specified variable is a loop control variable for |
498 | /// current region. |
499 | /// \return The index of the loop control variable in the list of associated |
500 | /// for-loops (from outer to inner). |
501 | const LCDeclInfo isLoopControlVariable(const ValueDecl *D, |
502 | unsigned Level) const; |
503 | /// Get the loop control variable for the I-th loop (or nullptr) in |
504 | /// parent directive. |
505 | const ValueDecl *getParentLoopControlVariable(unsigned I) const; |
506 | |
507 | /// Marks the specified decl \p D as used in scan directive. |
508 | void markDeclAsUsedInScanDirective(ValueDecl *D) { |
509 | if (SharingMapTy *Stack = getSecondOnStackOrNull()) |
510 | Stack->UsedInScanDirective.insert(D); |
511 | } |
512 | |
513 | /// Checks if the specified declaration was used in the inner scan directive. |
514 | bool isUsedInScanDirective(ValueDecl *D) const { |
515 | if (const SharingMapTy *Stack = getTopOfStackOrNull()) |
516 | return Stack->UsedInScanDirective.count(D) > 0; |
517 | return false; |
518 | } |
519 | |
520 | /// Adds explicit data sharing attribute to the specified declaration. |
521 | void addDSA(const ValueDecl *D, const Expr *E, OpenMPClauseKind A, |
522 | DeclRefExpr *PrivateCopy = nullptr, unsigned Modifier = 0, |
523 | bool AppliedToPointee = false); |
524 | |
525 | /// Adds additional information for the reduction items with the reduction id |
526 | /// represented as an operator. |
527 | void addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
528 | BinaryOperatorKind BOK); |
529 | /// Adds additional information for the reduction items with the reduction id |
530 | /// represented as reduction identifier. |
531 | void addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
532 | const Expr *ReductionRef); |
533 | /// Returns the location and reduction operation from the innermost parent |
534 | /// region for the given \p D. |
535 | const DSAVarData |
536 | getTopMostTaskgroupReductionData(const ValueDecl *D, SourceRange &SR, |
537 | BinaryOperatorKind &BOK, |
538 | Expr *&TaskgroupDescriptor) const; |
539 | /// Returns the location and reduction operation from the innermost parent |
540 | /// region for the given \p D. |
541 | const DSAVarData |
542 | getTopMostTaskgroupReductionData(const ValueDecl *D, SourceRange &SR, |
543 | const Expr *&ReductionRef, |
544 | Expr *&TaskgroupDescriptor) const; |
545 | /// Return reduction reference expression for the current taskgroup or |
546 | /// parallel/worksharing directives with task reductions. |
547 | Expr *getTaskgroupReductionRef() const { |
548 | assert((getTopOfStack().Directive == OMPD_taskgroup ||(((getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "taskgroup reference expression requested for non taskgroup or " "parallel/worksharing directive.") ? static_cast<void> (0) : __assert_fail ("(getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"taskgroup reference expression requested for non taskgroup or \" \"parallel/worksharing directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 553, __PRETTY_FUNCTION__)) |
549 | ((isOpenMPParallelDirective(getTopOfStack().Directive) ||(((getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "taskgroup reference expression requested for non taskgroup or " "parallel/worksharing directive.") ? static_cast<void> (0) : __assert_fail ("(getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"taskgroup reference expression requested for non taskgroup or \" \"parallel/worksharing directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 553, __PRETTY_FUNCTION__)) |
550 | isOpenMPWorksharingDirective(getTopOfStack().Directive)) &&(((getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "taskgroup reference expression requested for non taskgroup or " "parallel/worksharing directive.") ? static_cast<void> (0) : __assert_fail ("(getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"taskgroup reference expression requested for non taskgroup or \" \"parallel/worksharing directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 553, __PRETTY_FUNCTION__)) |
551 | !isOpenMPSimdDirective(getTopOfStack().Directive))) &&(((getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "taskgroup reference expression requested for non taskgroup or " "parallel/worksharing directive.") ? static_cast<void> (0) : __assert_fail ("(getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"taskgroup reference expression requested for non taskgroup or \" \"parallel/worksharing directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 553, __PRETTY_FUNCTION__)) |
552 | "taskgroup reference expression requested for non taskgroup or "(((getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "taskgroup reference expression requested for non taskgroup or " "parallel/worksharing directive.") ? static_cast<void> (0) : __assert_fail ("(getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"taskgroup reference expression requested for non taskgroup or \" \"parallel/worksharing directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 553, __PRETTY_FUNCTION__)) |
553 | "parallel/worksharing directive.")(((getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "taskgroup reference expression requested for non taskgroup or " "parallel/worksharing directive.") ? static_cast<void> (0) : __assert_fail ("(getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"taskgroup reference expression requested for non taskgroup or \" \"parallel/worksharing directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 553, __PRETTY_FUNCTION__)); |
554 | return getTopOfStack().TaskgroupReductionRef; |
555 | } |
556 | /// Checks if the given \p VD declaration is actually a taskgroup reduction |
557 | /// descriptor variable at the \p Level of OpenMP regions. |
558 | bool isTaskgroupReductionRef(const ValueDecl *VD, unsigned Level) const { |
559 | return getStackElemAtLevel(Level).TaskgroupReductionRef && |
560 | cast<DeclRefExpr>(getStackElemAtLevel(Level).TaskgroupReductionRef) |
561 | ->getDecl() == VD; |
562 | } |
563 | |
564 | /// Returns data sharing attributes from top of the stack for the |
565 | /// specified declaration. |
566 | const DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
567 | /// Returns data-sharing attributes for the specified declaration. |
568 | const DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent) const; |
569 | /// Returns data-sharing attributes for the specified declaration. |
570 | const DSAVarData getImplicitDSA(ValueDecl *D, unsigned Level) const; |
571 | /// Checks if the specified variables has data-sharing attributes which |
572 | /// match specified \a CPred predicate in any directive which matches \a DPred |
573 | /// predicate. |
574 | const DSAVarData |
575 | hasDSA(ValueDecl *D, |
576 | const llvm::function_ref<bool(OpenMPClauseKind, bool)> CPred, |
577 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
578 | bool FromParent) const; |
579 | /// Checks if the specified variables has data-sharing attributes which |
580 | /// match specified \a CPred predicate in any innermost directive which |
581 | /// matches \a DPred predicate. |
582 | const DSAVarData |
583 | hasInnermostDSA(ValueDecl *D, |
584 | const llvm::function_ref<bool(OpenMPClauseKind, bool)> CPred, |
585 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
586 | bool FromParent) const; |
587 | /// Checks if the specified variables has explicit data-sharing |
588 | /// attributes which match specified \a CPred predicate at the specified |
589 | /// OpenMP region. |
590 | bool |
591 | hasExplicitDSA(const ValueDecl *D, |
592 | const llvm::function_ref<bool(OpenMPClauseKind, bool)> CPred, |
593 | unsigned Level, bool NotLastprivate = false) const; |
594 | |
595 | /// Returns true if the directive at level \Level matches in the |
596 | /// specified \a DPred predicate. |
597 | bool hasExplicitDirective( |
598 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
599 | unsigned Level) const; |
600 | |
601 | /// Finds a directive which matches specified \a DPred predicate. |
602 | bool hasDirective( |
603 | const llvm::function_ref<bool( |
604 | OpenMPDirectiveKind, const DeclarationNameInfo &, SourceLocation)> |
605 | DPred, |
606 | bool FromParent) const; |
607 | |
608 | /// Returns currently analyzed directive. |
609 | OpenMPDirectiveKind getCurrentDirective() const { |
610 | const SharingMapTy *Top = getTopOfStackOrNull(); |
611 | return Top ? Top->Directive : OMPD_unknown; |
612 | } |
613 | /// Returns directive kind at specified level. |
614 | OpenMPDirectiveKind getDirective(unsigned Level) const { |
615 | assert(!isStackEmpty() && "No directive at specified level.")((!isStackEmpty() && "No directive at specified level." ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"No directive at specified level.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 615, __PRETTY_FUNCTION__)); |
616 | return getStackElemAtLevel(Level).Directive; |
617 | } |
618 | /// Returns the capture region at the specified level. |
619 | OpenMPDirectiveKind getCaptureRegion(unsigned Level, |
620 | unsigned OpenMPCaptureLevel) const { |
621 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
622 | getOpenMPCaptureRegions(CaptureRegions, getDirective(Level)); |
623 | return CaptureRegions[OpenMPCaptureLevel]; |
624 | } |
625 | /// Returns parent directive. |
626 | OpenMPDirectiveKind getParentDirective() const { |
627 | const SharingMapTy *Parent = getSecondOnStackOrNull(); |
628 | return Parent ? Parent->Directive : OMPD_unknown; |
629 | } |
630 | |
631 | /// Add requires decl to internal vector |
632 | void addRequiresDecl(OMPRequiresDecl *RD) { |
633 | RequiresDecls.push_back(RD); |
634 | } |
635 | |
636 | /// Checks if the defined 'requires' directive has specified type of clause. |
637 | template <typename ClauseType> |
638 | bool hasRequiresDeclWithClause() const { |
639 | return llvm::any_of(RequiresDecls, [](const OMPRequiresDecl *D) { |
640 | return llvm::any_of(D->clauselists(), [](const OMPClause *C) { |
641 | return isa<ClauseType>(C); |
642 | }); |
643 | }); |
644 | } |
645 | |
646 | /// Checks for a duplicate clause amongst previously declared requires |
647 | /// directives |
648 | bool hasDuplicateRequiresClause(ArrayRef<OMPClause *> ClauseList) const { |
649 | bool IsDuplicate = false; |
650 | for (OMPClause *CNew : ClauseList) { |
651 | for (const OMPRequiresDecl *D : RequiresDecls) { |
652 | for (const OMPClause *CPrev : D->clauselists()) { |
653 | if (CNew->getClauseKind() == CPrev->getClauseKind()) { |
654 | SemaRef.Diag(CNew->getBeginLoc(), |
655 | diag::err_omp_requires_clause_redeclaration) |
656 | << getOpenMPClauseName(CNew->getClauseKind()); |
657 | SemaRef.Diag(CPrev->getBeginLoc(), |
658 | diag::note_omp_requires_previous_clause) |
659 | << getOpenMPClauseName(CPrev->getClauseKind()); |
660 | IsDuplicate = true; |
661 | } |
662 | } |
663 | } |
664 | } |
665 | return IsDuplicate; |
666 | } |
667 | |
668 | /// Add location of previously encountered target to internal vector |
669 | void addTargetDirLocation(SourceLocation LocStart) { |
670 | TargetLocations.push_back(LocStart); |
671 | } |
672 | |
673 | /// Add location for the first encountered atomicc directive. |
674 | void addAtomicDirectiveLoc(SourceLocation Loc) { |
675 | if (AtomicLocation.isInvalid()) |
676 | AtomicLocation = Loc; |
677 | } |
678 | |
679 | /// Returns the location of the first encountered atomic directive in the |
680 | /// module. |
681 | SourceLocation getAtomicDirectiveLoc() const { |
682 | return AtomicLocation; |
683 | } |
684 | |
685 | // Return previously encountered target region locations. |
686 | ArrayRef<SourceLocation> getEncounteredTargetLocs() const { |
687 | return TargetLocations; |
688 | } |
689 | |
690 | /// Set default data sharing attribute to none. |
691 | void setDefaultDSANone(SourceLocation Loc) { |
692 | getTopOfStack().DefaultAttr = DSA_none; |
693 | getTopOfStack().DefaultAttrLoc = Loc; |
694 | } |
695 | /// Set default data sharing attribute to shared. |
696 | void setDefaultDSAShared(SourceLocation Loc) { |
697 | getTopOfStack().DefaultAttr = DSA_shared; |
698 | getTopOfStack().DefaultAttrLoc = Loc; |
699 | } |
700 | /// Set default data sharing attribute to firstprivate. |
701 | void setDefaultDSAFirstPrivate(SourceLocation Loc) { |
702 | getTopOfStack().DefaultAttr = DSA_firstprivate; |
703 | getTopOfStack().DefaultAttrLoc = Loc; |
704 | } |
705 | /// Set default data mapping attribute to Modifier:Kind |
706 | void setDefaultDMAAttr(OpenMPDefaultmapClauseModifier M, |
707 | OpenMPDefaultmapClauseKind Kind, |
708 | SourceLocation Loc) { |
709 | DefaultmapInfo &DMI = getTopOfStack().DefaultmapMap[Kind]; |
710 | DMI.ImplicitBehavior = M; |
711 | DMI.SLoc = Loc; |
712 | } |
713 | /// Check whether the implicit-behavior has been set in defaultmap |
714 | bool checkDefaultmapCategory(OpenMPDefaultmapClauseKind VariableCategory) { |
715 | if (VariableCategory == OMPC_DEFAULTMAP_unknown) |
716 | return getTopOfStack() |
717 | .DefaultmapMap[OMPC_DEFAULTMAP_aggregate] |
718 | .ImplicitBehavior != OMPC_DEFAULTMAP_MODIFIER_unknown || |
719 | getTopOfStack() |
720 | .DefaultmapMap[OMPC_DEFAULTMAP_scalar] |
721 | .ImplicitBehavior != OMPC_DEFAULTMAP_MODIFIER_unknown || |
722 | getTopOfStack() |
723 | .DefaultmapMap[OMPC_DEFAULTMAP_pointer] |
724 | .ImplicitBehavior != OMPC_DEFAULTMAP_MODIFIER_unknown; |
725 | return getTopOfStack().DefaultmapMap[VariableCategory].ImplicitBehavior != |
726 | OMPC_DEFAULTMAP_MODIFIER_unknown; |
727 | } |
728 | |
729 | DefaultDataSharingAttributes getDefaultDSA(unsigned Level) const { |
730 | return getStackSize() <= Level ? DSA_unspecified |
731 | : getStackElemAtLevel(Level).DefaultAttr; |
732 | } |
733 | DefaultDataSharingAttributes getDefaultDSA() const { |
734 | return isStackEmpty() ? DSA_unspecified |
735 | : getTopOfStack().DefaultAttr; |
736 | } |
737 | SourceLocation getDefaultDSALocation() const { |
738 | return isStackEmpty() ? SourceLocation() |
739 | : getTopOfStack().DefaultAttrLoc; |
740 | } |
741 | OpenMPDefaultmapClauseModifier |
742 | getDefaultmapModifier(OpenMPDefaultmapClauseKind Kind) const { |
743 | return isStackEmpty() |
744 | ? OMPC_DEFAULTMAP_MODIFIER_unknown |
745 | : getTopOfStack().DefaultmapMap[Kind].ImplicitBehavior; |
746 | } |
747 | OpenMPDefaultmapClauseModifier |
748 | getDefaultmapModifierAtLevel(unsigned Level, |
749 | OpenMPDefaultmapClauseKind Kind) const { |
750 | return getStackElemAtLevel(Level).DefaultmapMap[Kind].ImplicitBehavior; |
751 | } |
752 | bool isDefaultmapCapturedByRef(unsigned Level, |
753 | OpenMPDefaultmapClauseKind Kind) const { |
754 | OpenMPDefaultmapClauseModifier M = |
755 | getDefaultmapModifierAtLevel(Level, Kind); |
756 | if (Kind == OMPC_DEFAULTMAP_scalar || Kind == OMPC_DEFAULTMAP_pointer) { |
757 | return (M == OMPC_DEFAULTMAP_MODIFIER_alloc) || |
758 | (M == OMPC_DEFAULTMAP_MODIFIER_to) || |
759 | (M == OMPC_DEFAULTMAP_MODIFIER_from) || |
760 | (M == OMPC_DEFAULTMAP_MODIFIER_tofrom); |
761 | } |
762 | return true; |
763 | } |
764 | static bool mustBeFirstprivateBase(OpenMPDefaultmapClauseModifier M, |
765 | OpenMPDefaultmapClauseKind Kind) { |
766 | switch (Kind) { |
767 | case OMPC_DEFAULTMAP_scalar: |
768 | case OMPC_DEFAULTMAP_pointer: |
769 | return (M == OMPC_DEFAULTMAP_MODIFIER_unknown) || |
770 | (M == OMPC_DEFAULTMAP_MODIFIER_firstprivate) || |
771 | (M == OMPC_DEFAULTMAP_MODIFIER_default); |
772 | case OMPC_DEFAULTMAP_aggregate: |
773 | return M == OMPC_DEFAULTMAP_MODIFIER_firstprivate; |
774 | default: |
775 | break; |
776 | } |
777 | llvm_unreachable("Unexpected OpenMPDefaultmapClauseKind enum")::llvm::llvm_unreachable_internal("Unexpected OpenMPDefaultmapClauseKind enum" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 777); |
778 | } |
779 | bool mustBeFirstprivateAtLevel(unsigned Level, |
780 | OpenMPDefaultmapClauseKind Kind) const { |
781 | OpenMPDefaultmapClauseModifier M = |
782 | getDefaultmapModifierAtLevel(Level, Kind); |
783 | return mustBeFirstprivateBase(M, Kind); |
784 | } |
785 | bool mustBeFirstprivate(OpenMPDefaultmapClauseKind Kind) const { |
786 | OpenMPDefaultmapClauseModifier M = getDefaultmapModifier(Kind); |
787 | return mustBeFirstprivateBase(M, Kind); |
788 | } |
789 | |
790 | /// Checks if the specified variable is a threadprivate. |
791 | bool isThreadPrivate(VarDecl *D) { |
792 | const DSAVarData DVar = getTopDSA(D, false); |
793 | return isOpenMPThreadPrivate(DVar.CKind); |
794 | } |
795 | |
796 | /// Marks current region as ordered (it has an 'ordered' clause). |
797 | void setOrderedRegion(bool IsOrdered, const Expr *Param, |
798 | OMPOrderedClause *Clause) { |
799 | if (IsOrdered) |
800 | getTopOfStack().OrderedRegion.emplace(Param, Clause); |
801 | else |
802 | getTopOfStack().OrderedRegion.reset(); |
803 | } |
804 | /// Returns true, if region is ordered (has associated 'ordered' clause), |
805 | /// false - otherwise. |
806 | bool isOrderedRegion() const { |
807 | if (const SharingMapTy *Top = getTopOfStackOrNull()) |
808 | return Top->OrderedRegion.hasValue(); |
809 | return false; |
810 | } |
811 | /// Returns optional parameter for the ordered region. |
812 | std::pair<const Expr *, OMPOrderedClause *> getOrderedRegionParam() const { |
813 | if (const SharingMapTy *Top = getTopOfStackOrNull()) |
814 | if (Top->OrderedRegion.hasValue()) |
815 | return Top->OrderedRegion.getValue(); |
816 | return std::make_pair(nullptr, nullptr); |
817 | } |
818 | /// Returns true, if parent region is ordered (has associated |
819 | /// 'ordered' clause), false - otherwise. |
820 | bool isParentOrderedRegion() const { |
821 | if (const SharingMapTy *Parent = getSecondOnStackOrNull()) |
822 | return Parent->OrderedRegion.hasValue(); |
823 | return false; |
824 | } |
825 | /// Returns optional parameter for the ordered region. |
826 | std::pair<const Expr *, OMPOrderedClause *> |
827 | getParentOrderedRegionParam() const { |
828 | if (const SharingMapTy *Parent = getSecondOnStackOrNull()) |
829 | if (Parent->OrderedRegion.hasValue()) |
830 | return Parent->OrderedRegion.getValue(); |
831 | return std::make_pair(nullptr, nullptr); |
832 | } |
833 | /// Marks current region as nowait (it has a 'nowait' clause). |
834 | void setNowaitRegion(bool IsNowait = true) { |
835 | getTopOfStack().NowaitRegion = IsNowait; |
836 | } |
837 | /// Returns true, if parent region is nowait (has associated |
838 | /// 'nowait' clause), false - otherwise. |
839 | bool isParentNowaitRegion() const { |
840 | if (const SharingMapTy *Parent = getSecondOnStackOrNull()) |
841 | return Parent->NowaitRegion; |
842 | return false; |
843 | } |
844 | /// Marks parent region as cancel region. |
845 | void setParentCancelRegion(bool Cancel = true) { |
846 | if (SharingMapTy *Parent = getSecondOnStackOrNull()) |
847 | Parent->CancelRegion |= Cancel; |
848 | } |
849 | /// Return true if current region has inner cancel construct. |
850 | bool isCancelRegion() const { |
851 | const SharingMapTy *Top = getTopOfStackOrNull(); |
852 | return Top ? Top->CancelRegion : false; |
853 | } |
854 | |
855 | /// Mark that parent region already has scan directive. |
856 | void setParentHasScanDirective(SourceLocation Loc) { |
857 | if (SharingMapTy *Parent = getSecondOnStackOrNull()) |
858 | Parent->PrevScanLocation = Loc; |
859 | } |
860 | /// Return true if current region has inner cancel construct. |
861 | bool doesParentHasScanDirective() const { |
862 | const SharingMapTy *Top = getSecondOnStackOrNull(); |
863 | return Top ? Top->PrevScanLocation.isValid() : false; |
864 | } |
865 | /// Return true if current region has inner cancel construct. |
866 | SourceLocation getParentScanDirectiveLoc() const { |
867 | const SharingMapTy *Top = getSecondOnStackOrNull(); |
868 | return Top ? Top->PrevScanLocation : SourceLocation(); |
869 | } |
870 | /// Mark that parent region already has ordered directive. |
871 | void setParentHasOrderedDirective(SourceLocation Loc) { |
872 | if (SharingMapTy *Parent = getSecondOnStackOrNull()) |
873 | Parent->PrevOrderedLocation = Loc; |
874 | } |
875 | /// Return true if current region has inner ordered construct. |
876 | bool doesParentHasOrderedDirective() const { |
877 | const SharingMapTy *Top = getSecondOnStackOrNull(); |
878 | return Top ? Top->PrevOrderedLocation.isValid() : false; |
879 | } |
880 | /// Returns the location of the previously specified ordered directive. |
881 | SourceLocation getParentOrderedDirectiveLoc() const { |
882 | const SharingMapTy *Top = getSecondOnStackOrNull(); |
883 | return Top ? Top->PrevOrderedLocation : SourceLocation(); |
884 | } |
885 | |
886 | /// Set collapse value for the region. |
887 | void setAssociatedLoops(unsigned Val) { |
888 | getTopOfStack().AssociatedLoops = Val; |
889 | if (Val > 1) |
890 | getTopOfStack().HasMutipleLoops = true; |
891 | } |
892 | /// Return collapse value for region. |
893 | unsigned getAssociatedLoops() const { |
894 | const SharingMapTy *Top = getTopOfStackOrNull(); |
895 | return Top ? Top->AssociatedLoops : 0; |
896 | } |
897 | /// Returns true if the construct is associated with multiple loops. |
898 | bool hasMutipleLoops() const { |
899 | const SharingMapTy *Top = getTopOfStackOrNull(); |
900 | return Top ? Top->HasMutipleLoops : false; |
901 | } |
902 | |
903 | /// Marks current target region as one with closely nested teams |
904 | /// region. |
905 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
906 | if (SharingMapTy *Parent = getSecondOnStackOrNull()) |
907 | Parent->InnerTeamsRegionLoc = TeamsRegionLoc; |
908 | } |
909 | /// Returns true, if current region has closely nested teams region. |
910 | bool hasInnerTeamsRegion() const { |
911 | return getInnerTeamsRegionLoc().isValid(); |
912 | } |
913 | /// Returns location of the nested teams region (if any). |
914 | SourceLocation getInnerTeamsRegionLoc() const { |
915 | const SharingMapTy *Top = getTopOfStackOrNull(); |
916 | return Top ? Top->InnerTeamsRegionLoc : SourceLocation(); |
917 | } |
918 | |
919 | Scope *getCurScope() const { |
920 | const SharingMapTy *Top = getTopOfStackOrNull(); |
921 | return Top ? Top->CurScope : nullptr; |
922 | } |
923 | void setContext(DeclContext *DC) { getTopOfStack().Context = DC; } |
924 | SourceLocation getConstructLoc() const { |
925 | const SharingMapTy *Top = getTopOfStackOrNull(); |
926 | return Top ? Top->ConstructLoc : SourceLocation(); |
927 | } |
928 | |
929 | /// Do the check specified in \a Check to all component lists and return true |
930 | /// if any issue is found. |
931 | bool checkMappableExprComponentListsForDecl( |
932 | const ValueDecl *VD, bool CurrentRegionOnly, |
933 | const llvm::function_ref< |
934 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
935 | OpenMPClauseKind)> |
936 | Check) const { |
937 | if (isStackEmpty()) |
938 | return false; |
939 | auto SI = begin(); |
940 | auto SE = end(); |
941 | |
942 | if (SI == SE) |
943 | return false; |
944 | |
945 | if (CurrentRegionOnly) |
946 | SE = std::next(SI); |
947 | else |
948 | std::advance(SI, 1); |
949 | |
950 | for (; SI != SE; ++SI) { |
951 | auto MI = SI->MappedExprComponents.find(VD); |
952 | if (MI != SI->MappedExprComponents.end()) |
953 | for (OMPClauseMappableExprCommon::MappableExprComponentListRef L : |
954 | MI->second.Components) |
955 | if (Check(L, MI->second.Kind)) |
956 | return true; |
957 | } |
958 | return false; |
959 | } |
960 | |
961 | /// Do the check specified in \a Check to all component lists at a given level |
962 | /// and return true if any issue is found. |
963 | bool checkMappableExprComponentListsForDeclAtLevel( |
964 | const ValueDecl *VD, unsigned Level, |
965 | const llvm::function_ref< |
966 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
967 | OpenMPClauseKind)> |
968 | Check) const { |
969 | if (getStackSize() <= Level) |
970 | return false; |
971 | |
972 | const SharingMapTy &StackElem = getStackElemAtLevel(Level); |
973 | auto MI = StackElem.MappedExprComponents.find(VD); |
974 | if (MI != StackElem.MappedExprComponents.end()) |
975 | for (OMPClauseMappableExprCommon::MappableExprComponentListRef L : |
976 | MI->second.Components) |
977 | if (Check(L, MI->second.Kind)) |
978 | return true; |
979 | return false; |
980 | } |
981 | |
982 | /// Create a new mappable expression component list associated with a given |
983 | /// declaration and initialize it with the provided list of components. |
984 | void addMappableExpressionComponents( |
985 | const ValueDecl *VD, |
986 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components, |
987 | OpenMPClauseKind WhereFoundClauseKind) { |
988 | MappedExprComponentTy &MEC = getTopOfStack().MappedExprComponents[VD]; |
989 | // Create new entry and append the new components there. |
990 | MEC.Components.resize(MEC.Components.size() + 1); |
991 | MEC.Components.back().append(Components.begin(), Components.end()); |
992 | MEC.Kind = WhereFoundClauseKind; |
993 | } |
994 | |
995 | unsigned getNestingLevel() const { |
996 | assert(!isStackEmpty())((!isStackEmpty()) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty()", "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 996, __PRETTY_FUNCTION__)); |
997 | return getStackSize() - 1; |
998 | } |
999 | void addDoacrossDependClause(OMPDependClause *C, |
1000 | const OperatorOffsetTy &OpsOffs) { |
1001 | SharingMapTy *Parent = getSecondOnStackOrNull(); |
1002 | assert(Parent && isOpenMPWorksharingDirective(Parent->Directive))((Parent && isOpenMPWorksharingDirective(Parent->Directive )) ? static_cast<void> (0) : __assert_fail ("Parent && isOpenMPWorksharingDirective(Parent->Directive)" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1002, __PRETTY_FUNCTION__)); |
1003 | Parent->DoacrossDepends.try_emplace(C, OpsOffs); |
1004 | } |
1005 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
1006 | getDoacrossDependClauses() const { |
1007 | const SharingMapTy &StackElem = getTopOfStack(); |
1008 | if (isOpenMPWorksharingDirective(StackElem.Directive)) { |
1009 | const DoacrossDependMapTy &Ref = StackElem.DoacrossDepends; |
1010 | return llvm::make_range(Ref.begin(), Ref.end()); |
1011 | } |
1012 | return llvm::make_range(StackElem.DoacrossDepends.end(), |
1013 | StackElem.DoacrossDepends.end()); |
1014 | } |
1015 | |
1016 | // Store types of classes which have been explicitly mapped |
1017 | void addMappedClassesQualTypes(QualType QT) { |
1018 | SharingMapTy &StackElem = getTopOfStack(); |
1019 | StackElem.MappedClassesQualTypes.insert(QT); |
1020 | } |
1021 | |
1022 | // Return set of mapped classes types |
1023 | bool isClassPreviouslyMapped(QualType QT) const { |
1024 | const SharingMapTy &StackElem = getTopOfStack(); |
1025 | return StackElem.MappedClassesQualTypes.count(QT) != 0; |
1026 | } |
1027 | |
1028 | /// Adds global declare target to the parent target region. |
1029 | void addToParentTargetRegionLinkGlobals(DeclRefExpr *E) { |
1030 | assert(*OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(((*OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( E-> getDecl()) == OMPDeclareTargetDeclAttr::MT_Link && "Expected declare target link global." ) ? static_cast<void> (0) : __assert_fail ("*OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( E->getDecl()) == OMPDeclareTargetDeclAttr::MT_Link && \"Expected declare target link global.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1032, __PRETTY_FUNCTION__)) |
1031 | E->getDecl()) == OMPDeclareTargetDeclAttr::MT_Link &&((*OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( E-> getDecl()) == OMPDeclareTargetDeclAttr::MT_Link && "Expected declare target link global." ) ? static_cast<void> (0) : __assert_fail ("*OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( E->getDecl()) == OMPDeclareTargetDeclAttr::MT_Link && \"Expected declare target link global.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1032, __PRETTY_FUNCTION__)) |
1032 | "Expected declare target link global.")((*OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( E-> getDecl()) == OMPDeclareTargetDeclAttr::MT_Link && "Expected declare target link global." ) ? static_cast<void> (0) : __assert_fail ("*OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration( E->getDecl()) == OMPDeclareTargetDeclAttr::MT_Link && \"Expected declare target link global.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1032, __PRETTY_FUNCTION__)); |
1033 | for (auto &Elem : *this) { |
1034 | if (isOpenMPTargetExecutionDirective(Elem.Directive)) { |
1035 | Elem.DeclareTargetLinkVarDecls.push_back(E); |
1036 | return; |
1037 | } |
1038 | } |
1039 | } |
1040 | |
1041 | /// Returns the list of globals with declare target link if current directive |
1042 | /// is target. |
1043 | ArrayRef<DeclRefExpr *> getLinkGlobals() const { |
1044 | assert(isOpenMPTargetExecutionDirective(getCurrentDirective()) &&((isOpenMPTargetExecutionDirective(getCurrentDirective()) && "Expected target executable directive.") ? static_cast<void > (0) : __assert_fail ("isOpenMPTargetExecutionDirective(getCurrentDirective()) && \"Expected target executable directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1045, __PRETTY_FUNCTION__)) |
1045 | "Expected target executable directive.")((isOpenMPTargetExecutionDirective(getCurrentDirective()) && "Expected target executable directive.") ? static_cast<void > (0) : __assert_fail ("isOpenMPTargetExecutionDirective(getCurrentDirective()) && \"Expected target executable directive.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1045, __PRETTY_FUNCTION__)); |
1046 | return getTopOfStack().DeclareTargetLinkVarDecls; |
1047 | } |
1048 | |
1049 | /// Adds list of allocators expressions. |
1050 | void addInnerAllocatorExpr(Expr *E) { |
1051 | getTopOfStack().InnerUsedAllocators.push_back(E); |
1052 | } |
1053 | /// Return list of used allocators. |
1054 | ArrayRef<Expr *> getInnerAllocators() const { |
1055 | return getTopOfStack().InnerUsedAllocators; |
1056 | } |
1057 | /// Marks the declaration as implicitly firstprivate nin the task-based |
1058 | /// regions. |
1059 | void addImplicitTaskFirstprivate(unsigned Level, Decl *D) { |
1060 | getStackElemAtLevel(Level).ImplicitTaskFirstprivates.insert(D); |
1061 | } |
1062 | /// Checks if the decl is implicitly firstprivate in the task-based region. |
1063 | bool isImplicitTaskFirstprivate(Decl *D) const { |
1064 | return getTopOfStack().ImplicitTaskFirstprivates.count(D) > 0; |
1065 | } |
1066 | |
1067 | /// Marks decl as used in uses_allocators clause as the allocator. |
1068 | void addUsesAllocatorsDecl(const Decl *D, UsesAllocatorsDeclKind Kind) { |
1069 | getTopOfStack().UsesAllocatorsDecls.try_emplace(D, Kind); |
1070 | } |
1071 | /// Checks if specified decl is used in uses allocator clause as the |
1072 | /// allocator. |
1073 | Optional<UsesAllocatorsDeclKind> isUsesAllocatorsDecl(unsigned Level, |
1074 | const Decl *D) const { |
1075 | const SharingMapTy &StackElem = getTopOfStack(); |
1076 | auto I = StackElem.UsesAllocatorsDecls.find(D); |
1077 | if (I == StackElem.UsesAllocatorsDecls.end()) |
1078 | return None; |
1079 | return I->getSecond(); |
1080 | } |
1081 | Optional<UsesAllocatorsDeclKind> isUsesAllocatorsDecl(const Decl *D) const { |
1082 | const SharingMapTy &StackElem = getTopOfStack(); |
1083 | auto I = StackElem.UsesAllocatorsDecls.find(D); |
1084 | if (I == StackElem.UsesAllocatorsDecls.end()) |
1085 | return None; |
1086 | return I->getSecond(); |
1087 | } |
1088 | |
1089 | void addDeclareMapperVarRef(Expr *Ref) { |
1090 | SharingMapTy &StackElem = getTopOfStack(); |
1091 | StackElem.DeclareMapperVar = Ref; |
1092 | } |
1093 | const Expr *getDeclareMapperVarRef() const { |
1094 | const SharingMapTy *Top = getTopOfStackOrNull(); |
1095 | return Top ? Top->DeclareMapperVar : nullptr; |
1096 | } |
1097 | }; |
1098 | |
1099 | bool isImplicitTaskingRegion(OpenMPDirectiveKind DKind) { |
1100 | return isOpenMPParallelDirective(DKind) || isOpenMPTeamsDirective(DKind); |
1101 | } |
1102 | |
1103 | bool isImplicitOrExplicitTaskingRegion(OpenMPDirectiveKind DKind) { |
1104 | return isImplicitTaskingRegion(DKind) || isOpenMPTaskingDirective(DKind) || |
1105 | DKind == OMPD_unknown; |
1106 | } |
1107 | |
1108 | } // namespace |
1109 | |
1110 | static const Expr *getExprAsWritten(const Expr *E) { |
1111 | if (const auto *FE = dyn_cast<FullExpr>(E)) |
1112 | E = FE->getSubExpr(); |
1113 | |
1114 | if (const auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
1115 | E = MTE->getSubExpr(); |
1116 | |
1117 | while (const auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
1118 | E = Binder->getSubExpr(); |
1119 | |
1120 | if (const auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
1121 | E = ICE->getSubExprAsWritten(); |
1122 | return E->IgnoreParens(); |
1123 | } |
1124 | |
1125 | static Expr *getExprAsWritten(Expr *E) { |
1126 | return const_cast<Expr *>(getExprAsWritten(const_cast<const Expr *>(E))); |
1127 | } |
1128 | |
1129 | static const ValueDecl *getCanonicalDecl(const ValueDecl *D) { |
1130 | if (const auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) |
1131 | if (const auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
1132 | D = ME->getMemberDecl(); |
1133 | const auto *VD = dyn_cast<VarDecl>(D); |
1134 | const auto *FD = dyn_cast<FieldDecl>(D); |
1135 | if (VD != nullptr) { |
1136 | VD = VD->getCanonicalDecl(); |
1137 | D = VD; |
1138 | } else { |
1139 | assert(FD)((FD) ? static_cast<void> (0) : __assert_fail ("FD", "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1139, __PRETTY_FUNCTION__)); |
1140 | FD = FD->getCanonicalDecl(); |
1141 | D = FD; |
1142 | } |
1143 | return D; |
1144 | } |
1145 | |
1146 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
1147 | return const_cast<ValueDecl *>( |
1148 | getCanonicalDecl(const_cast<const ValueDecl *>(D))); |
1149 | } |
1150 | |
1151 | DSAStackTy::DSAVarData DSAStackTy::getDSA(const_iterator &Iter, |
1152 | ValueDecl *D) const { |
1153 | D = getCanonicalDecl(D); |
1154 | auto *VD = dyn_cast<VarDecl>(D); |
1155 | const auto *FD = dyn_cast<FieldDecl>(D); |
1156 | DSAVarData DVar; |
1157 | if (Iter == end()) { |
1158 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1159 | // in a region but not in construct] |
1160 | // File-scope or namespace-scope variables referenced in called routines |
1161 | // in the region are shared unless they appear in a threadprivate |
1162 | // directive. |
1163 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(VD)) |
1164 | DVar.CKind = OMPC_shared; |
1165 | |
1166 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
1167 | // in a region but not in construct] |
1168 | // Variables with static storage duration that are declared in called |
1169 | // routines in the region are shared. |
1170 | if (VD && VD->hasGlobalStorage()) |
1171 | DVar.CKind = OMPC_shared; |
1172 | |
1173 | // Non-static data members are shared by default. |
1174 | if (FD) |
1175 | DVar.CKind = OMPC_shared; |
1176 | |
1177 | return DVar; |
1178 | } |
1179 | |
1180 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1181 | // in a Construct, C/C++, predetermined, p.1] |
1182 | // Variables with automatic storage duration that are declared in a scope |
1183 | // inside the construct are private. |
1184 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
1185 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
1186 | DVar.CKind = OMPC_private; |
1187 | return DVar; |
1188 | } |
1189 | |
1190 | DVar.DKind = Iter->Directive; |
1191 | // Explicitly specified attributes and local variables with predetermined |
1192 | // attributes. |
1193 | if (Iter->SharingMap.count(D)) { |
1194 | const DSAInfo &Data = Iter->SharingMap.lookup(D); |
1195 | DVar.RefExpr = Data.RefExpr.getPointer(); |
1196 | DVar.PrivateCopy = Data.PrivateCopy; |
1197 | DVar.CKind = Data.Attributes; |
1198 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
1199 | DVar.Modifier = Data.Modifier; |
1200 | DVar.AppliedToPointee = Data.AppliedToPointee; |
1201 | return DVar; |
1202 | } |
1203 | |
1204 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1205 | // in a Construct, C/C++, implicitly determined, p.1] |
1206 | // In a parallel or task construct, the data-sharing attributes of these |
1207 | // variables are determined by the default clause, if present. |
1208 | switch (Iter->DefaultAttr) { |
1209 | case DSA_shared: |
1210 | DVar.CKind = OMPC_shared; |
1211 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
1212 | return DVar; |
1213 | case DSA_none: |
1214 | return DVar; |
1215 | case DSA_firstprivate: |
1216 | if (VD->getStorageDuration() == SD_Static && |
1217 | VD->getDeclContext()->isFileContext()) { |
1218 | DVar.CKind = OMPC_unknown; |
1219 | } else { |
1220 | DVar.CKind = OMPC_firstprivate; |
1221 | } |
1222 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
1223 | return DVar; |
1224 | case DSA_unspecified: |
1225 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1226 | // in a Construct, implicitly determined, p.2] |
1227 | // In a parallel construct, if no default clause is present, these |
1228 | // variables are shared. |
1229 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
1230 | if ((isOpenMPParallelDirective(DVar.DKind) && |
1231 | !isOpenMPTaskLoopDirective(DVar.DKind)) || |
1232 | isOpenMPTeamsDirective(DVar.DKind)) { |
1233 | DVar.CKind = OMPC_shared; |
1234 | return DVar; |
1235 | } |
1236 | |
1237 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1238 | // in a Construct, implicitly determined, p.4] |
1239 | // In a task construct, if no default clause is present, a variable that in |
1240 | // the enclosing context is determined to be shared by all implicit tasks |
1241 | // bound to the current team is shared. |
1242 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
1243 | DSAVarData DVarTemp; |
1244 | const_iterator I = Iter, E = end(); |
1245 | do { |
1246 | ++I; |
1247 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
1248 | // Referenced in a Construct, implicitly determined, p.6] |
1249 | // In a task construct, if no default clause is present, a variable |
1250 | // whose data-sharing attribute is not determined by the rules above is |
1251 | // firstprivate. |
1252 | DVarTemp = getDSA(I, D); |
1253 | if (DVarTemp.CKind != OMPC_shared) { |
1254 | DVar.RefExpr = nullptr; |
1255 | DVar.CKind = OMPC_firstprivate; |
1256 | return DVar; |
1257 | } |
1258 | } while (I != E && !isImplicitTaskingRegion(I->Directive)); |
1259 | DVar.CKind = |
1260 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
1261 | return DVar; |
1262 | } |
1263 | } |
1264 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1265 | // in a Construct, implicitly determined, p.3] |
1266 | // For constructs other than task, if no default clause is present, these |
1267 | // variables inherit their data-sharing attributes from the enclosing |
1268 | // context. |
1269 | return getDSA(++Iter, D); |
1270 | } |
1271 | |
1272 | const Expr *DSAStackTy::addUniqueAligned(const ValueDecl *D, |
1273 | const Expr *NewDE) { |
1274 | assert(!isStackEmpty() && "Data sharing attributes stack is empty")((!isStackEmpty() && "Data sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1274, __PRETTY_FUNCTION__)); |
1275 | D = getCanonicalDecl(D); |
1276 | SharingMapTy &StackElem = getTopOfStack(); |
1277 | auto It = StackElem.AlignedMap.find(D); |
1278 | if (It == StackElem.AlignedMap.end()) { |
1279 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map")((NewDE && "Unexpected nullptr expr to be added into aligned map" ) ? static_cast<void> (0) : __assert_fail ("NewDE && \"Unexpected nullptr expr to be added into aligned map\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1279, __PRETTY_FUNCTION__)); |
1280 | StackElem.AlignedMap[D] = NewDE; |
1281 | return nullptr; |
1282 | } |
1283 | assert(It->second && "Unexpected nullptr expr in the aligned map")((It->second && "Unexpected nullptr expr in the aligned map" ) ? static_cast<void> (0) : __assert_fail ("It->second && \"Unexpected nullptr expr in the aligned map\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1283, __PRETTY_FUNCTION__)); |
1284 | return It->second; |
1285 | } |
1286 | |
1287 | const Expr *DSAStackTy::addUniqueNontemporal(const ValueDecl *D, |
1288 | const Expr *NewDE) { |
1289 | assert(!isStackEmpty() && "Data sharing attributes stack is empty")((!isStackEmpty() && "Data sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1289, __PRETTY_FUNCTION__)); |
1290 | D = getCanonicalDecl(D); |
1291 | SharingMapTy &StackElem = getTopOfStack(); |
1292 | auto It = StackElem.NontemporalMap.find(D); |
1293 | if (It == StackElem.NontemporalMap.end()) { |
1294 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map")((NewDE && "Unexpected nullptr expr to be added into aligned map" ) ? static_cast<void> (0) : __assert_fail ("NewDE && \"Unexpected nullptr expr to be added into aligned map\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1294, __PRETTY_FUNCTION__)); |
1295 | StackElem.NontemporalMap[D] = NewDE; |
1296 | return nullptr; |
1297 | } |
1298 | assert(It->second && "Unexpected nullptr expr in the aligned map")((It->second && "Unexpected nullptr expr in the aligned map" ) ? static_cast<void> (0) : __assert_fail ("It->second && \"Unexpected nullptr expr in the aligned map\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1298, __PRETTY_FUNCTION__)); |
1299 | return It->second; |
1300 | } |
1301 | |
1302 | void DSAStackTy::addLoopControlVariable(const ValueDecl *D, VarDecl *Capture) { |
1303 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty")((!isStackEmpty() && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data-sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1303, __PRETTY_FUNCTION__)); |
1304 | D = getCanonicalDecl(D); |
1305 | SharingMapTy &StackElem = getTopOfStack(); |
1306 | StackElem.LCVMap.try_emplace( |
1307 | D, LCDeclInfo(StackElem.LCVMap.size() + 1, Capture)); |
1308 | } |
1309 | |
1310 | const DSAStackTy::LCDeclInfo |
1311 | DSAStackTy::isLoopControlVariable(const ValueDecl *D) const { |
1312 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty")((!isStackEmpty() && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data-sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1312, __PRETTY_FUNCTION__)); |
1313 | D = getCanonicalDecl(D); |
1314 | const SharingMapTy &StackElem = getTopOfStack(); |
1315 | auto It = StackElem.LCVMap.find(D); |
1316 | if (It != StackElem.LCVMap.end()) |
1317 | return It->second; |
1318 | return {0, nullptr}; |
1319 | } |
1320 | |
1321 | const DSAStackTy::LCDeclInfo |
1322 | DSAStackTy::isLoopControlVariable(const ValueDecl *D, unsigned Level) const { |
1323 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty")((!isStackEmpty() && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data-sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1323, __PRETTY_FUNCTION__)); |
1324 | D = getCanonicalDecl(D); |
1325 | for (unsigned I = Level + 1; I > 0; --I) { |
1326 | const SharingMapTy &StackElem = getStackElemAtLevel(I - 1); |
1327 | auto It = StackElem.LCVMap.find(D); |
1328 | if (It != StackElem.LCVMap.end()) |
1329 | return It->second; |
1330 | } |
1331 | return {0, nullptr}; |
1332 | } |
1333 | |
1334 | const DSAStackTy::LCDeclInfo |
1335 | DSAStackTy::isParentLoopControlVariable(const ValueDecl *D) const { |
1336 | const SharingMapTy *Parent = getSecondOnStackOrNull(); |
1337 | assert(Parent && "Data-sharing attributes stack is empty")((Parent && "Data-sharing attributes stack is empty") ? static_cast<void> (0) : __assert_fail ("Parent && \"Data-sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1337, __PRETTY_FUNCTION__)); |
1338 | D = getCanonicalDecl(D); |
1339 | auto It = Parent->LCVMap.find(D); |
1340 | if (It != Parent->LCVMap.end()) |
1341 | return It->second; |
1342 | return {0, nullptr}; |
1343 | } |
1344 | |
1345 | const ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) const { |
1346 | const SharingMapTy *Parent = getSecondOnStackOrNull(); |
1347 | assert(Parent && "Data-sharing attributes stack is empty")((Parent && "Data-sharing attributes stack is empty") ? static_cast<void> (0) : __assert_fail ("Parent && \"Data-sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1347, __PRETTY_FUNCTION__)); |
1348 | if (Parent->LCVMap.size() < I) |
1349 | return nullptr; |
1350 | for (const auto &Pair : Parent->LCVMap) |
1351 | if (Pair.second.first == I) |
1352 | return Pair.first; |
1353 | return nullptr; |
1354 | } |
1355 | |
1356 | void DSAStackTy::addDSA(const ValueDecl *D, const Expr *E, OpenMPClauseKind A, |
1357 | DeclRefExpr *PrivateCopy, unsigned Modifier, |
1358 | bool AppliedToPointee) { |
1359 | D = getCanonicalDecl(D); |
1360 | if (A == OMPC_threadprivate) { |
1361 | DSAInfo &Data = Threadprivates[D]; |
1362 | Data.Attributes = A; |
1363 | Data.RefExpr.setPointer(E); |
1364 | Data.PrivateCopy = nullptr; |
1365 | Data.Modifier = Modifier; |
1366 | } else { |
1367 | DSAInfo &Data = getTopOfStack().SharingMap[D]; |
1368 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) ||((Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate ) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate ) || (isLoopControlVariable(D).first && A == OMPC_private )) ? static_cast<void> (0) : __assert_fail ("Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || (isLoopControlVariable(D).first && A == OMPC_private)" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1371, __PRETTY_FUNCTION__)) |
1369 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) ||((Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate ) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate ) || (isLoopControlVariable(D).first && A == OMPC_private )) ? static_cast<void> (0) : __assert_fail ("Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || (isLoopControlVariable(D).first && A == OMPC_private)" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1371, __PRETTY_FUNCTION__)) |
1370 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) ||((Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate ) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate ) || (isLoopControlVariable(D).first && A == OMPC_private )) ? static_cast<void> (0) : __assert_fail ("Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || (isLoopControlVariable(D).first && A == OMPC_private)" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1371, __PRETTY_FUNCTION__)) |
1371 | (isLoopControlVariable(D).first && A == OMPC_private))((Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate ) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate ) || (isLoopControlVariable(D).first && A == OMPC_private )) ? static_cast<void> (0) : __assert_fail ("Data.Attributes == OMPC_unknown || (A == Data.Attributes) || (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || (isLoopControlVariable(D).first && A == OMPC_private)" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1371, __PRETTY_FUNCTION__)); |
1372 | Data.Modifier = Modifier; |
1373 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
1374 | Data.RefExpr.setInt(/*IntVal=*/true); |
1375 | return; |
1376 | } |
1377 | const bool IsLastprivate = |
1378 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
1379 | Data.Attributes = A; |
1380 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
1381 | Data.PrivateCopy = PrivateCopy; |
1382 | Data.AppliedToPointee = AppliedToPointee; |
1383 | if (PrivateCopy) { |
1384 | DSAInfo &Data = getTopOfStack().SharingMap[PrivateCopy->getDecl()]; |
1385 | Data.Modifier = Modifier; |
1386 | Data.Attributes = A; |
1387 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
1388 | Data.PrivateCopy = nullptr; |
1389 | Data.AppliedToPointee = AppliedToPointee; |
1390 | } |
1391 | } |
1392 | } |
1393 | |
1394 | /// Build a variable declaration for OpenMP loop iteration variable. |
1395 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
1396 | StringRef Name, const AttrVec *Attrs = nullptr, |
1397 | DeclRefExpr *OrigRef = nullptr) { |
1398 | DeclContext *DC = SemaRef.CurContext; |
1399 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
1400 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
1401 | auto *Decl = |
1402 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
1403 | if (Attrs) { |
1404 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
1405 | I != E; ++I) |
1406 | Decl->addAttr(*I); |
1407 | } |
1408 | Decl->setImplicit(); |
1409 | if (OrigRef) { |
1410 | Decl->addAttr( |
1411 | OMPReferencedVarAttr::CreateImplicit(SemaRef.Context, OrigRef)); |
1412 | } |
1413 | return Decl; |
1414 | } |
1415 | |
1416 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
1417 | SourceLocation Loc, |
1418 | bool RefersToCapture = false) { |
1419 | D->setReferenced(); |
1420 | D->markUsed(S.Context); |
1421 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
1422 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
1423 | VK_LValue); |
1424 | } |
1425 | |
1426 | void DSAStackTy::addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
1427 | BinaryOperatorKind BOK) { |
1428 | D = getCanonicalDecl(D); |
1429 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty")((!isStackEmpty() && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data-sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1429, __PRETTY_FUNCTION__)); |
1430 | assert(((getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && "Additional reduction info may be specified only for reduction items." ) ? static_cast<void> (0) : __assert_fail ("getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && \"Additional reduction info may be specified only for reduction items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1432, __PRETTY_FUNCTION__)) |
1431 | getTopOfStack().SharingMap[D].Attributes == OMPC_reduction &&((getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && "Additional reduction info may be specified only for reduction items." ) ? static_cast<void> (0) : __assert_fail ("getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && \"Additional reduction info may be specified only for reduction items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1432, __PRETTY_FUNCTION__)) |
1432 | "Additional reduction info may be specified only for reduction items.")((getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && "Additional reduction info may be specified only for reduction items." ) ? static_cast<void> (0) : __assert_fail ("getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && \"Additional reduction info may be specified only for reduction items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1432, __PRETTY_FUNCTION__)); |
1433 | ReductionData &ReductionData = getTopOfStack().ReductionMap[D]; |
1434 | assert(ReductionData.ReductionRange.isInvalid() &&((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1440, __PRETTY_FUNCTION__)) |
1435 | (getTopOfStack().Directive == OMPD_taskgroup ||((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1440, __PRETTY_FUNCTION__)) |
1436 | ((isOpenMPParallelDirective(getTopOfStack().Directive) ||((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1440, __PRETTY_FUNCTION__)) |
1437 | isOpenMPWorksharingDirective(getTopOfStack().Directive)) &&((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1440, __PRETTY_FUNCTION__)) |
1438 | !isOpenMPSimdDirective(getTopOfStack().Directive))) &&((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1440, __PRETTY_FUNCTION__)) |
1439 | "Additional reduction info may be specified only once for reduction "((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1440, __PRETTY_FUNCTION__)) |
1440 | "items.")((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1440, __PRETTY_FUNCTION__)); |
1441 | ReductionData.set(BOK, SR); |
1442 | Expr *&TaskgroupReductionRef = |
1443 | getTopOfStack().TaskgroupReductionRef; |
1444 | if (!TaskgroupReductionRef) { |
1445 | VarDecl *VD = buildVarDecl(SemaRef, SR.getBegin(), |
1446 | SemaRef.Context.VoidPtrTy, ".task_red."); |
1447 | TaskgroupReductionRef = |
1448 | buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, SR.getBegin()); |
1449 | } |
1450 | } |
1451 | |
1452 | void DSAStackTy::addTaskgroupReductionData(const ValueDecl *D, SourceRange SR, |
1453 | const Expr *ReductionRef) { |
1454 | D = getCanonicalDecl(D); |
1455 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty")((!isStackEmpty() && "Data-sharing attributes stack is empty" ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data-sharing attributes stack is empty\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1455, __PRETTY_FUNCTION__)); |
1456 | assert(((getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && "Additional reduction info may be specified only for reduction items." ) ? static_cast<void> (0) : __assert_fail ("getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && \"Additional reduction info may be specified only for reduction items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1458, __PRETTY_FUNCTION__)) |
1457 | getTopOfStack().SharingMap[D].Attributes == OMPC_reduction &&((getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && "Additional reduction info may be specified only for reduction items." ) ? static_cast<void> (0) : __assert_fail ("getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && \"Additional reduction info may be specified only for reduction items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1458, __PRETTY_FUNCTION__)) |
1458 | "Additional reduction info may be specified only for reduction items.")((getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && "Additional reduction info may be specified only for reduction items." ) ? static_cast<void> (0) : __assert_fail ("getTopOfStack().SharingMap[D].Attributes == OMPC_reduction && \"Additional reduction info may be specified only for reduction items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1458, __PRETTY_FUNCTION__)); |
1459 | ReductionData &ReductionData = getTopOfStack().ReductionMap[D]; |
1460 | assert(ReductionData.ReductionRange.isInvalid() &&((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1466, __PRETTY_FUNCTION__)) |
1461 | (getTopOfStack().Directive == OMPD_taskgroup ||((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1466, __PRETTY_FUNCTION__)) |
1462 | ((isOpenMPParallelDirective(getTopOfStack().Directive) ||((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1466, __PRETTY_FUNCTION__)) |
1463 | isOpenMPWorksharingDirective(getTopOfStack().Directive)) &&((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1466, __PRETTY_FUNCTION__)) |
1464 | !isOpenMPSimdDirective(getTopOfStack().Directive))) &&((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1466, __PRETTY_FUNCTION__)) |
1465 | "Additional reduction info may be specified only once for reduction "((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1466, __PRETTY_FUNCTION__)) |
1466 | "items.")((ReductionData.ReductionRange.isInvalid() && (getTopOfStack ().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective (getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack ().Directive)) && !isOpenMPSimdDirective(getTopOfStack ().Directive))) && "Additional reduction info may be specified only once for reduction " "items.") ? static_cast<void> (0) : __assert_fail ("ReductionData.ReductionRange.isInvalid() && (getTopOfStack().Directive == OMPD_taskgroup || ((isOpenMPParallelDirective(getTopOfStack().Directive) || isOpenMPWorksharingDirective(getTopOfStack().Directive)) && !isOpenMPSimdDirective(getTopOfStack().Directive))) && \"Additional reduction info may be specified only once for reduction \" \"items.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1466, __PRETTY_FUNCTION__)); |
1467 | ReductionData.set(ReductionRef, SR); |
1468 | Expr *&TaskgroupReductionRef = |
1469 | getTopOfStack().TaskgroupReductionRef; |
1470 | if (!TaskgroupReductionRef) { |
1471 | VarDecl *VD = buildVarDecl(SemaRef, SR.getBegin(), |
1472 | SemaRef.Context.VoidPtrTy, ".task_red."); |
1473 | TaskgroupReductionRef = |
1474 | buildDeclRefExpr(SemaRef, VD, SemaRef.Context.VoidPtrTy, SR.getBegin()); |
1475 | } |
1476 | } |
1477 | |
1478 | const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData( |
1479 | const ValueDecl *D, SourceRange &SR, BinaryOperatorKind &BOK, |
1480 | Expr *&TaskgroupDescriptor) const { |
1481 | D = getCanonicalDecl(D); |
1482 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty.")((!isStackEmpty() && "Data-sharing attributes stack is empty." ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data-sharing attributes stack is empty.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1482, __PRETTY_FUNCTION__)); |
1483 | for (const_iterator I = begin() + 1, E = end(); I != E; ++I) { |
1484 | const DSAInfo &Data = I->SharingMap.lookup(D); |
1485 | if (Data.Attributes != OMPC_reduction || |
1486 | Data.Modifier != OMPC_REDUCTION_task) |
1487 | continue; |
1488 | const ReductionData &ReductionData = I->ReductionMap.lookup(D); |
1489 | if (!ReductionData.ReductionOp || |
1490 | ReductionData.ReductionOp.is<const Expr *>()) |
1491 | return DSAVarData(); |
1492 | SR = ReductionData.ReductionRange; |
1493 | BOK = ReductionData.ReductionOp.get<ReductionData::BOKPtrType>(); |
1494 | assert(I->TaskgroupReductionRef && "taskgroup reduction reference "((I->TaskgroupReductionRef && "taskgroup reduction reference " "expression for the descriptor is not " "set.") ? static_cast <void> (0) : __assert_fail ("I->TaskgroupReductionRef && \"taskgroup reduction reference \" \"expression for the descriptor is not \" \"set.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1496, __PRETTY_FUNCTION__)) |
1495 | "expression for the descriptor is not "((I->TaskgroupReductionRef && "taskgroup reduction reference " "expression for the descriptor is not " "set.") ? static_cast <void> (0) : __assert_fail ("I->TaskgroupReductionRef && \"taskgroup reduction reference \" \"expression for the descriptor is not \" \"set.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1496, __PRETTY_FUNCTION__)) |
1496 | "set.")((I->TaskgroupReductionRef && "taskgroup reduction reference " "expression for the descriptor is not " "set.") ? static_cast <void> (0) : __assert_fail ("I->TaskgroupReductionRef && \"taskgroup reduction reference \" \"expression for the descriptor is not \" \"set.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1496, __PRETTY_FUNCTION__)); |
1497 | TaskgroupDescriptor = I->TaskgroupReductionRef; |
1498 | return DSAVarData(I->Directive, OMPC_reduction, Data.RefExpr.getPointer(), |
1499 | Data.PrivateCopy, I->DefaultAttrLoc, OMPC_REDUCTION_task, |
1500 | /*AppliedToPointee=*/false); |
1501 | } |
1502 | return DSAVarData(); |
1503 | } |
1504 | |
1505 | const DSAStackTy::DSAVarData DSAStackTy::getTopMostTaskgroupReductionData( |
1506 | const ValueDecl *D, SourceRange &SR, const Expr *&ReductionRef, |
1507 | Expr *&TaskgroupDescriptor) const { |
1508 | D = getCanonicalDecl(D); |
1509 | assert(!isStackEmpty() && "Data-sharing attributes stack is empty.")((!isStackEmpty() && "Data-sharing attributes stack is empty." ) ? static_cast<void> (0) : __assert_fail ("!isStackEmpty() && \"Data-sharing attributes stack is empty.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1509, __PRETTY_FUNCTION__)); |
1510 | for (const_iterator I = begin() + 1, E = end(); I != E; ++I) { |
1511 | const DSAInfo &Data = I->SharingMap.lookup(D); |
1512 | if (Data.Attributes != OMPC_reduction || |
1513 | Data.Modifier != OMPC_REDUCTION_task) |
1514 | continue; |
1515 | const ReductionData &ReductionData = I->ReductionMap.lookup(D); |
1516 | if (!ReductionData.ReductionOp || |
1517 | !ReductionData.ReductionOp.is<const Expr *>()) |
1518 | return DSAVarData(); |
1519 | SR = ReductionData.ReductionRange; |
1520 | ReductionRef = ReductionData.ReductionOp.get<const Expr *>(); |
1521 | assert(I->TaskgroupReductionRef && "taskgroup reduction reference "((I->TaskgroupReductionRef && "taskgroup reduction reference " "expression for the descriptor is not " "set.") ? static_cast <void> (0) : __assert_fail ("I->TaskgroupReductionRef && \"taskgroup reduction reference \" \"expression for the descriptor is not \" \"set.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1523, __PRETTY_FUNCTION__)) |
1522 | "expression for the descriptor is not "((I->TaskgroupReductionRef && "taskgroup reduction reference " "expression for the descriptor is not " "set.") ? static_cast <void> (0) : __assert_fail ("I->TaskgroupReductionRef && \"taskgroup reduction reference \" \"expression for the descriptor is not \" \"set.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1523, __PRETTY_FUNCTION__)) |
1523 | "set.")((I->TaskgroupReductionRef && "taskgroup reduction reference " "expression for the descriptor is not " "set.") ? static_cast <void> (0) : __assert_fail ("I->TaskgroupReductionRef && \"taskgroup reduction reference \" \"expression for the descriptor is not \" \"set.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1523, __PRETTY_FUNCTION__)); |
1524 | TaskgroupDescriptor = I->TaskgroupReductionRef; |
1525 | return DSAVarData(I->Directive, OMPC_reduction, Data.RefExpr.getPointer(), |
1526 | Data.PrivateCopy, I->DefaultAttrLoc, OMPC_REDUCTION_task, |
1527 | /*AppliedToPointee=*/false); |
1528 | } |
1529 | return DSAVarData(); |
1530 | } |
1531 | |
1532 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, const_iterator I) const { |
1533 | D = D->getCanonicalDecl(); |
1534 | for (const_iterator E = end(); I != E; ++I) { |
1535 | if (isImplicitOrExplicitTaskingRegion(I->Directive) || |
1536 | isOpenMPTargetExecutionDirective(I->Directive)) { |
1537 | if (I->CurScope) { |
1538 | Scope *TopScope = I->CurScope->getParent(); |
1539 | Scope *CurScope = getCurScope(); |
1540 | while (CurScope && CurScope != TopScope && !CurScope->isDeclScope(D)) |
1541 | CurScope = CurScope->getParent(); |
1542 | return CurScope != TopScope; |
1543 | } |
1544 | for (DeclContext *DC = D->getDeclContext(); DC; DC = DC->getParent()) |
1545 | if (I->Context == DC) |
1546 | return true; |
1547 | return false; |
1548 | } |
1549 | } |
1550 | return false; |
1551 | } |
1552 | |
1553 | static bool isConstNotMutableType(Sema &SemaRef, QualType Type, |
1554 | bool AcceptIfMutable = true, |
1555 | bool *IsClassType = nullptr) { |
1556 | ASTContext &Context = SemaRef.getASTContext(); |
1557 | Type = Type.getNonReferenceType().getCanonicalType(); |
1558 | bool IsConstant = Type.isConstant(Context); |
1559 | Type = Context.getBaseElementType(Type); |
1560 | const CXXRecordDecl *RD = AcceptIfMutable && SemaRef.getLangOpts().CPlusPlus |
1561 | ? Type->getAsCXXRecordDecl() |
1562 | : nullptr; |
1563 | if (const auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
1564 | if (const ClassTemplateDecl *CTD = CTSD->getSpecializedTemplate()) |
1565 | RD = CTD->getTemplatedDecl(); |
1566 | if (IsClassType) |
1567 | *IsClassType = RD; |
1568 | return IsConstant && !(SemaRef.getLangOpts().CPlusPlus && RD && |
1569 | RD->hasDefinition() && RD->hasMutableFields()); |
1570 | } |
1571 | |
1572 | static bool rejectConstNotMutableType(Sema &SemaRef, const ValueDecl *D, |
1573 | QualType Type, OpenMPClauseKind CKind, |
1574 | SourceLocation ELoc, |
1575 | bool AcceptIfMutable = true, |
1576 | bool ListItemNotVar = false) { |
1577 | ASTContext &Context = SemaRef.getASTContext(); |
1578 | bool IsClassType; |
1579 | if (isConstNotMutableType(SemaRef, Type, AcceptIfMutable, &IsClassType)) { |
1580 | unsigned Diag = ListItemNotVar |
1581 | ? diag::err_omp_const_list_item |
1582 | : IsClassType ? diag::err_omp_const_not_mutable_variable |
1583 | : diag::err_omp_const_variable; |
1584 | SemaRef.Diag(ELoc, Diag) << getOpenMPClauseName(CKind); |
1585 | if (!ListItemNotVar && D) { |
1586 | const VarDecl *VD = dyn_cast<VarDecl>(D); |
1587 | bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) == |
1588 | VarDecl::DeclarationOnly; |
1589 | SemaRef.Diag(D->getLocation(), |
1590 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
1591 | << D; |
1592 | } |
1593 | return true; |
1594 | } |
1595 | return false; |
1596 | } |
1597 | |
1598 | const DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, |
1599 | bool FromParent) { |
1600 | D = getCanonicalDecl(D); |
1601 | DSAVarData DVar; |
1602 | |
1603 | auto *VD = dyn_cast<VarDecl>(D); |
1604 | auto TI = Threadprivates.find(D); |
1605 | if (TI != Threadprivates.end()) { |
1606 | DVar.RefExpr = TI->getSecond().RefExpr.getPointer(); |
1607 | DVar.CKind = OMPC_threadprivate; |
1608 | DVar.Modifier = TI->getSecond().Modifier; |
1609 | return DVar; |
1610 | } |
1611 | if (VD && VD->hasAttr<OMPThreadPrivateDeclAttr>()) { |
1612 | DVar.RefExpr = buildDeclRefExpr( |
1613 | SemaRef, VD, D->getType().getNonReferenceType(), |
1614 | VD->getAttr<OMPThreadPrivateDeclAttr>()->getLocation()); |
1615 | DVar.CKind = OMPC_threadprivate; |
1616 | addDSA(D, DVar.RefExpr, OMPC_threadprivate); |
1617 | return DVar; |
1618 | } |
1619 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1620 | // in a Construct, C/C++, predetermined, p.1] |
1621 | // Variables appearing in threadprivate directives are threadprivate. |
1622 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
1623 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
1624 | SemaRef.getLangOpts().OpenMPUseTLS && |
1625 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
1626 | (VD && VD->getStorageClass() == SC_Register && |
1627 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
1628 | DVar.RefExpr = buildDeclRefExpr( |
1629 | SemaRef, VD, D->getType().getNonReferenceType(), D->getLocation()); |
1630 | DVar.CKind = OMPC_threadprivate; |
1631 | addDSA(D, DVar.RefExpr, OMPC_threadprivate); |
1632 | return DVar; |
1633 | } |
1634 | if (SemaRef.getLangOpts().OpenMPCUDAMode && VD && |
1635 | VD->isLocalVarDeclOrParm() && !isStackEmpty() && |
1636 | !isLoopControlVariable(D).first) { |
1637 | const_iterator IterTarget = |
1638 | std::find_if(begin(), end(), [](const SharingMapTy &Data) { |
1639 | return isOpenMPTargetExecutionDirective(Data.Directive); |
1640 | }); |
1641 | if (IterTarget != end()) { |
1642 | const_iterator ParentIterTarget = IterTarget + 1; |
1643 | for (const_iterator Iter = begin(); |
1644 | Iter != ParentIterTarget; ++Iter) { |
1645 | if (isOpenMPLocal(VD, Iter)) { |
1646 | DVar.RefExpr = |
1647 | buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
1648 | D->getLocation()); |
1649 | DVar.CKind = OMPC_threadprivate; |
1650 | return DVar; |
1651 | } |
1652 | } |
1653 | if (!isClauseParsingMode() || IterTarget != begin()) { |
1654 | auto DSAIter = IterTarget->SharingMap.find(D); |
1655 | if (DSAIter != IterTarget->SharingMap.end() && |
1656 | isOpenMPPrivate(DSAIter->getSecond().Attributes)) { |
1657 | DVar.RefExpr = DSAIter->getSecond().RefExpr.getPointer(); |
1658 | DVar.CKind = OMPC_threadprivate; |
1659 | return DVar; |
1660 | } |
1661 | const_iterator End = end(); |
1662 | if (!SemaRef.isOpenMPCapturedByRef( |
1663 | D, std::distance(ParentIterTarget, End), |
1664 | /*OpenMPCaptureLevel=*/0)) { |
1665 | DVar.RefExpr = |
1666 | buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
1667 | IterTarget->ConstructLoc); |
1668 | DVar.CKind = OMPC_threadprivate; |
1669 | return DVar; |
1670 | } |
1671 | } |
1672 | } |
1673 | } |
1674 | |
1675 | if (isStackEmpty()) |
1676 | // Not in OpenMP execution region and top scope was already checked. |
1677 | return DVar; |
1678 | |
1679 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1680 | // in a Construct, C/C++, predetermined, p.4] |
1681 | // Static data members are shared. |
1682 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1683 | // in a Construct, C/C++, predetermined, p.7] |
1684 | // Variables with static storage duration that are declared in a scope |
1685 | // inside the construct are shared. |
1686 | if (VD && VD->isStaticDataMember()) { |
1687 | // Check for explicitly specified attributes. |
1688 | const_iterator I = begin(); |
1689 | const_iterator EndI = end(); |
1690 | if (FromParent && I != EndI) |
1691 | ++I; |
1692 | if (I != EndI) { |
1693 | auto It = I->SharingMap.find(D); |
1694 | if (It != I->SharingMap.end()) { |
1695 | const DSAInfo &Data = It->getSecond(); |
1696 | DVar.RefExpr = Data.RefExpr.getPointer(); |
1697 | DVar.PrivateCopy = Data.PrivateCopy; |
1698 | DVar.CKind = Data.Attributes; |
1699 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
1700 | DVar.DKind = I->Directive; |
1701 | DVar.Modifier = Data.Modifier; |
1702 | DVar.AppliedToPointee = Data.AppliedToPointee; |
1703 | return DVar; |
1704 | } |
1705 | } |
1706 | |
1707 | DVar.CKind = OMPC_shared; |
1708 | return DVar; |
1709 | } |
1710 | |
1711 | auto &&MatchesAlways = [](OpenMPDirectiveKind) { return true; }; |
1712 | // The predetermined shared attribute for const-qualified types having no |
1713 | // mutable members was removed after OpenMP 3.1. |
1714 | if (SemaRef.LangOpts.OpenMP <= 31) { |
1715 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
1716 | // in a Construct, C/C++, predetermined, p.6] |
1717 | // Variables with const qualified type having no mutable member are |
1718 | // shared. |
1719 | if (isConstNotMutableType(SemaRef, D->getType())) { |
1720 | // Variables with const-qualified type having no mutable member may be |
1721 | // listed in a firstprivate clause, even if they are static data members. |
1722 | DSAVarData DVarTemp = hasInnermostDSA( |
1723 | D, |
1724 | [](OpenMPClauseKind C, bool) { |
1725 | return C == OMPC_firstprivate || C == OMPC_shared; |
1726 | }, |
1727 | MatchesAlways, FromParent); |
1728 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
1729 | return DVarTemp; |
1730 | |
1731 | DVar.CKind = OMPC_shared; |
1732 | return DVar; |
1733 | } |
1734 | } |
1735 | |
1736 | // Explicitly specified attributes and local variables with predetermined |
1737 | // attributes. |
1738 | const_iterator I = begin(); |
1739 | const_iterator EndI = end(); |
1740 | if (FromParent && I != EndI) |
1741 | ++I; |
1742 | if (I == EndI) |
1743 | return DVar; |
1744 | auto It = I->SharingMap.find(D); |
1745 | if (It != I->SharingMap.end()) { |
1746 | const DSAInfo &Data = It->getSecond(); |
1747 | DVar.RefExpr = Data.RefExpr.getPointer(); |
1748 | DVar.PrivateCopy = Data.PrivateCopy; |
1749 | DVar.CKind = Data.Attributes; |
1750 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
1751 | DVar.DKind = I->Directive; |
1752 | DVar.Modifier = Data.Modifier; |
1753 | DVar.AppliedToPointee = Data.AppliedToPointee; |
1754 | } |
1755 | |
1756 | return DVar; |
1757 | } |
1758 | |
1759 | const DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
1760 | bool FromParent) const { |
1761 | if (isStackEmpty()) { |
1762 | const_iterator I; |
1763 | return getDSA(I, D); |
1764 | } |
1765 | D = getCanonicalDecl(D); |
1766 | const_iterator StartI = begin(); |
1767 | const_iterator EndI = end(); |
1768 | if (FromParent && StartI != EndI) |
1769 | ++StartI; |
1770 | return getDSA(StartI, D); |
1771 | } |
1772 | |
1773 | const DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
1774 | unsigned Level) const { |
1775 | if (getStackSize() <= Level) |
1776 | return DSAVarData(); |
1777 | D = getCanonicalDecl(D); |
1778 | const_iterator StartI = std::next(begin(), getStackSize() - 1 - Level); |
1779 | return getDSA(StartI, D); |
1780 | } |
1781 | |
1782 | const DSAStackTy::DSAVarData |
1783 | DSAStackTy::hasDSA(ValueDecl *D, |
1784 | const llvm::function_ref<bool(OpenMPClauseKind, bool)> CPred, |
1785 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
1786 | bool FromParent) const { |
1787 | if (isStackEmpty()) |
1788 | return {}; |
1789 | D = getCanonicalDecl(D); |
1790 | const_iterator I = begin(); |
1791 | const_iterator EndI = end(); |
1792 | if (FromParent && I != EndI) |
1793 | ++I; |
1794 | for (; I != EndI; ++I) { |
1795 | if (!DPred(I->Directive) && |
1796 | !isImplicitOrExplicitTaskingRegion(I->Directive)) |
1797 | continue; |
1798 | const_iterator NewI = I; |
1799 | DSAVarData DVar = getDSA(NewI, D); |
1800 | if (I == NewI && CPred(DVar.CKind, DVar.AppliedToPointee)) |
1801 | return DVar; |
1802 | } |
1803 | return {}; |
1804 | } |
1805 | |
1806 | const DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
1807 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind, bool)> CPred, |
1808 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
1809 | bool FromParent) const { |
1810 | if (isStackEmpty()) |
1811 | return {}; |
1812 | D = getCanonicalDecl(D); |
1813 | const_iterator StartI = begin(); |
1814 | const_iterator EndI = end(); |
1815 | if (FromParent && StartI != EndI) |
1816 | ++StartI; |
1817 | if (StartI == EndI || !DPred(StartI->Directive)) |
1818 | return {}; |
1819 | const_iterator NewI = StartI; |
1820 | DSAVarData DVar = getDSA(NewI, D); |
1821 | return (NewI == StartI && CPred(DVar.CKind, DVar.AppliedToPointee)) |
1822 | ? DVar |
1823 | : DSAVarData(); |
1824 | } |
1825 | |
1826 | bool DSAStackTy::hasExplicitDSA( |
1827 | const ValueDecl *D, |
1828 | const llvm::function_ref<bool(OpenMPClauseKind, bool)> CPred, |
1829 | unsigned Level, bool NotLastprivate) const { |
1830 | if (getStackSize() <= Level) |
1831 | return false; |
1832 | D = getCanonicalDecl(D); |
1833 | const SharingMapTy &StackElem = getStackElemAtLevel(Level); |
1834 | auto I = StackElem.SharingMap.find(D); |
1835 | if (I != StackElem.SharingMap.end() && I->getSecond().RefExpr.getPointer() && |
1836 | CPred(I->getSecond().Attributes, I->getSecond().AppliedToPointee) && |
1837 | (!NotLastprivate || !I->getSecond().RefExpr.getInt())) |
1838 | return true; |
1839 | // Check predetermined rules for the loop control variables. |
1840 | auto LI = StackElem.LCVMap.find(D); |
1841 | if (LI != StackElem.LCVMap.end()) |
1842 | return CPred(OMPC_private, /*AppliedToPointee=*/false); |
1843 | return false; |
1844 | } |
1845 | |
1846 | bool DSAStackTy::hasExplicitDirective( |
1847 | const llvm::function_ref<bool(OpenMPDirectiveKind)> DPred, |
1848 | unsigned Level) const { |
1849 | if (getStackSize() <= Level) |
1850 | return false; |
1851 | const SharingMapTy &StackElem = getStackElemAtLevel(Level); |
1852 | return DPred(StackElem.Directive); |
1853 | } |
1854 | |
1855 | bool DSAStackTy::hasDirective( |
1856 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
1857 | const DeclarationNameInfo &, SourceLocation)> |
1858 | DPred, |
1859 | bool FromParent) const { |
1860 | // We look only in the enclosing region. |
1861 | size_t Skip = FromParent ? 2 : 1; |
1862 | for (const_iterator I = begin() + std::min(Skip, getStackSize()), E = end(); |
1863 | I != E; ++I) { |
1864 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
1865 | return true; |
1866 | } |
1867 | return false; |
1868 | } |
1869 | |
1870 | void Sema::InitDataSharingAttributesStack() { |
1871 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
1872 | } |
1873 | |
1874 | #define DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ) static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
1875 | |
1876 | void Sema::pushOpenMPFunctionRegion() { |
1877 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->pushFunction(); |
1878 | } |
1879 | |
1880 | void Sema::popOpenMPFunctionRegion(const FunctionScopeInfo *OldFSI) { |
1881 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->popFunction(OldFSI); |
1882 | } |
1883 | |
1884 | static bool isOpenMPDeviceDelayedContext(Sema &S) { |
1885 | assert(S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice &&((S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice && "Expected OpenMP device compilation.") ? static_cast<void > (0) : __assert_fail ("S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice && \"Expected OpenMP device compilation.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1886, __PRETTY_FUNCTION__)) |
1886 | "Expected OpenMP device compilation.")((S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice && "Expected OpenMP device compilation.") ? static_cast<void > (0) : __assert_fail ("S.LangOpts.OpenMP && S.LangOpts.OpenMPIsDevice && \"Expected OpenMP device compilation.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1886, __PRETTY_FUNCTION__)); |
1887 | return !S.isInOpenMPTargetExecutionDirective(); |
1888 | } |
1889 | |
1890 | namespace { |
1891 | /// Status of the function emission on the host/device. |
1892 | enum class FunctionEmissionStatus { |
1893 | Emitted, |
1894 | Discarded, |
1895 | Unknown, |
1896 | }; |
1897 | } // anonymous namespace |
1898 | |
1899 | Sema::SemaDiagnosticBuilder Sema::diagIfOpenMPDeviceCode(SourceLocation Loc, |
1900 | unsigned DiagID, |
1901 | FunctionDecl *FD) { |
1902 | assert(LangOpts.OpenMP && LangOpts.OpenMPIsDevice &&((LangOpts.OpenMP && LangOpts.OpenMPIsDevice && "Expected OpenMP device compilation.") ? static_cast<void > (0) : __assert_fail ("LangOpts.OpenMP && LangOpts.OpenMPIsDevice && \"Expected OpenMP device compilation.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1903, __PRETTY_FUNCTION__)) |
1903 | "Expected OpenMP device compilation.")((LangOpts.OpenMP && LangOpts.OpenMPIsDevice && "Expected OpenMP device compilation.") ? static_cast<void > (0) : __assert_fail ("LangOpts.OpenMP && LangOpts.OpenMPIsDevice && \"Expected OpenMP device compilation.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1903, __PRETTY_FUNCTION__)); |
1904 | |
1905 | SemaDiagnosticBuilder::Kind Kind = SemaDiagnosticBuilder::K_Nop; |
1906 | if (FD) { |
1907 | FunctionEmissionStatus FES = getEmissionStatus(FD); |
1908 | switch (FES) { |
1909 | case FunctionEmissionStatus::Emitted: |
1910 | Kind = SemaDiagnosticBuilder::K_Immediate; |
1911 | break; |
1912 | case FunctionEmissionStatus::Unknown: |
1913 | // TODO: We should always delay diagnostics here in case a target |
1914 | // region is in a function we do not emit. However, as the |
1915 | // current diagnostics are associated with the function containing |
1916 | // the target region and we do not emit that one, we would miss out |
1917 | // on diagnostics for the target region itself. We need to anchor |
1918 | // the diagnostics with the new generated function *or* ensure we |
1919 | // emit diagnostics associated with the surrounding function. |
1920 | Kind = isOpenMPDeviceDelayedContext(*this) |
1921 | ? SemaDiagnosticBuilder::K_Deferred |
1922 | : SemaDiagnosticBuilder::K_Immediate; |
1923 | break; |
1924 | case FunctionEmissionStatus::TemplateDiscarded: |
1925 | case FunctionEmissionStatus::OMPDiscarded: |
1926 | Kind = SemaDiagnosticBuilder::K_Nop; |
1927 | break; |
1928 | case FunctionEmissionStatus::CUDADiscarded: |
1929 | llvm_unreachable("CUDADiscarded unexpected in OpenMP device compilation")::llvm::llvm_unreachable_internal("CUDADiscarded unexpected in OpenMP device compilation" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1929); |
1930 | break; |
1931 | } |
1932 | } |
1933 | |
1934 | return SemaDiagnosticBuilder(Kind, Loc, DiagID, FD, *this); |
1935 | } |
1936 | |
1937 | Sema::SemaDiagnosticBuilder Sema::diagIfOpenMPHostCode(SourceLocation Loc, |
1938 | unsigned DiagID, |
1939 | FunctionDecl *FD) { |
1940 | assert(LangOpts.OpenMP && !LangOpts.OpenMPIsDevice &&((LangOpts.OpenMP && !LangOpts.OpenMPIsDevice && "Expected OpenMP host compilation.") ? static_cast<void> (0) : __assert_fail ("LangOpts.OpenMP && !LangOpts.OpenMPIsDevice && \"Expected OpenMP host compilation.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1941, __PRETTY_FUNCTION__)) |
1941 | "Expected OpenMP host compilation.")((LangOpts.OpenMP && !LangOpts.OpenMPIsDevice && "Expected OpenMP host compilation.") ? static_cast<void> (0) : __assert_fail ("LangOpts.OpenMP && !LangOpts.OpenMPIsDevice && \"Expected OpenMP host compilation.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1941, __PRETTY_FUNCTION__)); |
1942 | FunctionEmissionStatus FES = getEmissionStatus(FD); |
1943 | SemaDiagnosticBuilder::Kind Kind = SemaDiagnosticBuilder::K_Nop; |
1944 | switch (FES) { |
1945 | case FunctionEmissionStatus::Emitted: |
1946 | Kind = SemaDiagnosticBuilder::K_Immediate; |
1947 | break; |
1948 | case FunctionEmissionStatus::Unknown: |
1949 | Kind = SemaDiagnosticBuilder::K_Deferred; |
1950 | break; |
1951 | case FunctionEmissionStatus::TemplateDiscarded: |
1952 | case FunctionEmissionStatus::OMPDiscarded: |
1953 | case FunctionEmissionStatus::CUDADiscarded: |
1954 | Kind = SemaDiagnosticBuilder::K_Nop; |
1955 | break; |
1956 | } |
1957 | |
1958 | return SemaDiagnosticBuilder(Kind, Loc, DiagID, FD, *this); |
1959 | } |
1960 | |
1961 | static OpenMPDefaultmapClauseKind |
1962 | getVariableCategoryFromDecl(const LangOptions &LO, const ValueDecl *VD) { |
1963 | if (LO.OpenMP <= 45) { |
1964 | if (VD->getType().getNonReferenceType()->isScalarType()) |
1965 | return OMPC_DEFAULTMAP_scalar; |
1966 | return OMPC_DEFAULTMAP_aggregate; |
1967 | } |
1968 | if (VD->getType().getNonReferenceType()->isAnyPointerType()) |
1969 | return OMPC_DEFAULTMAP_pointer; |
1970 | if (VD->getType().getNonReferenceType()->isScalarType()) |
1971 | return OMPC_DEFAULTMAP_scalar; |
1972 | return OMPC_DEFAULTMAP_aggregate; |
1973 | } |
1974 | |
1975 | bool Sema::isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, |
1976 | unsigned OpenMPCaptureLevel) const { |
1977 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 1977, __PRETTY_FUNCTION__)); |
1978 | |
1979 | ASTContext &Ctx = getASTContext(); |
1980 | bool IsByRef = true; |
1981 | |
1982 | // Find the directive that is associated with the provided scope. |
1983 | D = cast<ValueDecl>(D->getCanonicalDecl()); |
1984 | QualType Ty = D->getType(); |
1985 | |
1986 | bool IsVariableUsedInMapClause = false; |
1987 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
1988 | // This table summarizes how a given variable should be passed to the device |
1989 | // given its type and the clauses where it appears. This table is based on |
1990 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
1991 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
1992 | // |
1993 | // ========================================================================= |
1994 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
1995 | // | |(tofrom:scalar)| | pvt | | | | |
1996 | // ========================================================================= |
1997 | // | scl | | | | - | | bycopy| |
1998 | // | scl | | - | x | - | - | bycopy| |
1999 | // | scl | | x | - | - | - | null | |
2000 | // | scl | x | | | - | | byref | |
2001 | // | scl | x | - | x | - | - | bycopy| |
2002 | // | scl | x | x | - | - | - | null | |
2003 | // | scl | | - | - | - | x | byref | |
2004 | // | scl | x | - | - | - | x | byref | |
2005 | // |
2006 | // | agg | n.a. | | | - | | byref | |
2007 | // | agg | n.a. | - | x | - | - | byref | |
2008 | // | agg | n.a. | x | - | - | - | null | |
2009 | // | agg | n.a. | - | - | - | x | byref | |
2010 | // | agg | n.a. | - | - | - | x[] | byref | |
2011 | // |
2012 | // | ptr | n.a. | | | - | | bycopy| |
2013 | // | ptr | n.a. | - | x | - | - | bycopy| |
2014 | // | ptr | n.a. | x | - | - | - | null | |
2015 | // | ptr | n.a. | - | - | - | x | byref | |
2016 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
2017 | // | ptr | n.a. | - | - | x | | bycopy| |
2018 | // | ptr | n.a. | - | - | x | x | bycopy| |
2019 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
2020 | // ========================================================================= |
2021 | // Legend: |
2022 | // scl - scalar |
2023 | // ptr - pointer |
2024 | // agg - aggregate |
2025 | // x - applies |
2026 | // - - invalid in this combination |
2027 | // [] - mapped with an array section |
2028 | // byref - should be mapped by reference |
2029 | // byval - should be mapped by value |
2030 | // null - initialize a local variable to null on the device |
2031 | // |
2032 | // Observations: |
2033 | // - All scalar declarations that show up in a map clause have to be passed |
2034 | // by reference, because they may have been mapped in the enclosing data |
2035 | // environment. |
2036 | // - If the scalar value does not fit the size of uintptr, it has to be |
2037 | // passed by reference, regardless the result in the table above. |
2038 | // - For pointers mapped by value that have either an implicit map or an |
2039 | // array section, the runtime library may pass the NULL value to the |
2040 | // device instead of the value passed to it by the compiler. |
2041 | |
2042 | if (Ty->isReferenceType()) |
2043 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
2044 | |
2045 | // Locate map clauses and see if the variable being captured is referred to |
2046 | // in any of those clauses. Here we only care about variables, not fields, |
2047 | // because fields are part of aggregates. |
2048 | bool IsVariableAssociatedWithSection = false; |
2049 | |
2050 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->checkMappableExprComponentListsForDeclAtLevel( |
2051 | D, Level, |
2052 | [&IsVariableUsedInMapClause, &IsVariableAssociatedWithSection, D]( |
2053 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
2054 | MapExprComponents, |
2055 | OpenMPClauseKind WhereFoundClauseKind) { |
2056 | // Only the map clause information influences how a variable is |
2057 | // captured. E.g. is_device_ptr does not require changing the default |
2058 | // behavior. |
2059 | if (WhereFoundClauseKind != OMPC_map) |
2060 | return false; |
2061 | |
2062 | auto EI = MapExprComponents.rbegin(); |
2063 | auto EE = MapExprComponents.rend(); |
2064 | |
2065 | assert(EI != EE && "Invalid map expression!")((EI != EE && "Invalid map expression!") ? static_cast <void> (0) : __assert_fail ("EI != EE && \"Invalid map expression!\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2065, __PRETTY_FUNCTION__)); |
2066 | |
2067 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
2068 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
2069 | |
2070 | ++EI; |
2071 | if (EI == EE) |
2072 | return false; |
2073 | |
2074 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
2075 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
2076 | isa<MemberExpr>(EI->getAssociatedExpression()) || |
2077 | isa<OMPArrayShapingExpr>(EI->getAssociatedExpression())) { |
2078 | IsVariableAssociatedWithSection = true; |
2079 | // There is nothing more we need to know about this variable. |
2080 | return true; |
2081 | } |
2082 | |
2083 | // Keep looking for more map info. |
2084 | return false; |
2085 | }); |
2086 | |
2087 | if (IsVariableUsedInMapClause) { |
2088 | // If variable is identified in a map clause it is always captured by |
2089 | // reference except if it is a pointer that is dereferenced somehow. |
2090 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
2091 | } else { |
2092 | // By default, all the data that has a scalar type is mapped by copy |
2093 | // (except for reduction variables). |
2094 | // Defaultmap scalar is mutual exclusive to defaultmap pointer |
2095 | IsByRef = (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isForceCaptureByReferenceInTargetExecutable() && |
2096 | !Ty->isAnyPointerType()) || |
2097 | !Ty->isScalarType() || |
2098 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isDefaultmapCapturedByRef( |
2099 | Level, getVariableCategoryFromDecl(LangOpts, D)) || |
2100 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( |
2101 | D, |
2102 | [](OpenMPClauseKind K, bool AppliedToPointee) { |
2103 | return K == OMPC_reduction && !AppliedToPointee; |
2104 | }, |
2105 | Level); |
2106 | } |
2107 | } |
2108 | |
2109 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
2110 | IsByRef = |
2111 | ((IsVariableUsedInMapClause && |
2112 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCaptureRegion(Level, OpenMPCaptureLevel) == |
2113 | OMPD_target) || |
2114 | !(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( |
2115 | D, |
2116 | [](OpenMPClauseKind K, bool AppliedToPointee) -> bool { |
2117 | return K == OMPC_firstprivate || |
2118 | (K == OMPC_reduction && AppliedToPointee); |
2119 | }, |
2120 | Level, /*NotLastprivate=*/true) || |
2121 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isUsesAllocatorsDecl(Level, D))) && |
2122 | // If the variable is artificial and must be captured by value - try to |
2123 | // capture by value. |
2124 | !(isa<OMPCapturedExprDecl>(D) && !D->hasAttr<OMPCaptureNoInitAttr>() && |
2125 | !cast<OMPCapturedExprDecl>(D)->getInit()->isGLValue()) && |
2126 | // If the variable is implicitly firstprivate and scalar - capture by |
2127 | // copy |
2128 | !(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDefaultDSA() == DSA_firstprivate && |
2129 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( |
2130 | D, [](OpenMPClauseKind K, bool) { return K != OMPC_unknown; }, |
2131 | Level) && |
2132 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isLoopControlVariable(D, Level).first); |
2133 | } |
2134 | |
2135 | // When passing data by copy, we need to make sure it fits the uintptr size |
2136 | // and alignment, because the runtime library only deals with uintptr types. |
2137 | // If it does not fit the uintptr size, we need to pass the data by reference |
2138 | // instead. |
2139 | if (!IsByRef && |
2140 | (Ctx.getTypeSizeInChars(Ty) > |
2141 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
2142 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
2143 | IsByRef = true; |
2144 | } |
2145 | |
2146 | return IsByRef; |
2147 | } |
2148 | |
2149 | unsigned Sema::getOpenMPNestingLevel() const { |
2150 | assert(getLangOpts().OpenMP)((getLangOpts().OpenMP) ? static_cast<void> (0) : __assert_fail ("getLangOpts().OpenMP", "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2150, __PRETTY_FUNCTION__)); |
2151 | return DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getNestingLevel(); |
2152 | } |
2153 | |
2154 | bool Sema::isInOpenMPTargetExecutionDirective() const { |
2155 | return (isOpenMPTargetExecutionDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()) && |
2156 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode()) || |
2157 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasDirective( |
2158 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
2159 | SourceLocation) -> bool { |
2160 | return isOpenMPTargetExecutionDirective(K); |
2161 | }, |
2162 | false); |
2163 | } |
2164 | |
2165 | VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo, |
2166 | unsigned StopAt) { |
2167 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2167, __PRETTY_FUNCTION__)); |
2168 | D = getCanonicalDecl(D); |
2169 | |
2170 | auto *VD = dyn_cast<VarDecl>(D); |
2171 | // Do not capture constexpr variables. |
2172 | if (VD && VD->isConstexpr()) |
2173 | return nullptr; |
2174 | |
2175 | // If we want to determine whether the variable should be captured from the |
2176 | // perspective of the current capturing scope, and we've already left all the |
2177 | // capturing scopes of the top directive on the stack, check from the |
2178 | // perspective of its parent directive (if any) instead. |
2179 | DSAStackTy::ParentDirectiveScope InParentDirectiveRAII( |
2180 | *DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), CheckScopeInfo && DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isBodyComplete()); |
2181 | |
2182 | // If we are attempting to capture a global variable in a directive with |
2183 | // 'target' we return true so that this global is also mapped to the device. |
2184 | // |
2185 | if (VD && !VD->hasLocalStorage() && |
2186 | (getCurCapturedRegion() || getCurBlock() || getCurLambda())) { |
2187 | if (isInOpenMPDeclareTargetContext()) { |
2188 | // Try to mark variable as declare target if it is used in capturing |
2189 | // regions. |
2190 | if (LangOpts.OpenMP <= 45 && |
2191 | !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
2192 | checkDeclIsAllowedInOpenMPTarget(nullptr, VD); |
2193 | return nullptr; |
2194 | } |
2195 | if (isInOpenMPTargetExecutionDirective()) { |
2196 | // If the declaration is enclosed in a 'declare target' directive, |
2197 | // then it should not be captured. |
2198 | // |
2199 | if (OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) |
2200 | return nullptr; |
2201 | CapturedRegionScopeInfo *CSI = nullptr; |
2202 | for (FunctionScopeInfo *FSI : llvm::drop_begin( |
2203 | llvm::reverse(FunctionScopes), |
2204 | CheckScopeInfo ? (FunctionScopes.size() - (StopAt + 1)) : 0)) { |
2205 | if (!isa<CapturingScopeInfo>(FSI)) |
2206 | return nullptr; |
2207 | if (auto *RSI = dyn_cast<CapturedRegionScopeInfo>(FSI)) |
2208 | if (RSI->CapRegionKind == CR_OpenMP) { |
2209 | CSI = RSI; |
2210 | break; |
2211 | } |
2212 | } |
2213 | assert(CSI && "Failed to find CapturedRegionScopeInfo")((CSI && "Failed to find CapturedRegionScopeInfo") ? static_cast <void> (0) : __assert_fail ("CSI && \"Failed to find CapturedRegionScopeInfo\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2213, __PRETTY_FUNCTION__)); |
2214 | SmallVector<OpenMPDirectiveKind, 4> Regions; |
2215 | getOpenMPCaptureRegions(Regions, |
2216 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDirective(CSI->OpenMPLevel)); |
2217 | if (Regions[CSI->OpenMPCaptureLevel] != OMPD_task) |
2218 | return VD; |
2219 | } |
2220 | } |
2221 | |
2222 | if (CheckScopeInfo) { |
2223 | bool OpenMPFound = false; |
2224 | for (unsigned I = StopAt + 1; I > 0; --I) { |
2225 | FunctionScopeInfo *FSI = FunctionScopes[I - 1]; |
2226 | if(!isa<CapturingScopeInfo>(FSI)) |
2227 | return nullptr; |
2228 | if (auto *RSI = dyn_cast<CapturedRegionScopeInfo>(FSI)) |
2229 | if (RSI->CapRegionKind == CR_OpenMP) { |
2230 | OpenMPFound = true; |
2231 | break; |
2232 | } |
2233 | } |
2234 | if (!OpenMPFound) |
2235 | return nullptr; |
2236 | } |
2237 | |
2238 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() != OMPD_unknown && |
2239 | (!DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode() || |
2240 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getParentDirective() != OMPD_unknown)) { |
2241 | auto &&Info = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isLoopControlVariable(D); |
2242 | if (Info.first || |
2243 | (VD && VD->hasLocalStorage() && |
2244 | isImplicitOrExplicitTaskingRegion(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) || |
2245 | (VD && DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isForceVarCapturing())) |
2246 | return VD ? VD : Info.second; |
2247 | DSAStackTy::DSAVarData DVarTop = |
2248 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode()); |
2249 | if (DVarTop.CKind != OMPC_unknown && isOpenMPPrivate(DVarTop.CKind) && |
2250 | (!VD || VD->hasLocalStorage() || !DVarTop.AppliedToPointee)) |
2251 | return VD ? VD : cast<VarDecl>(DVarTop.PrivateCopy->getDecl()); |
2252 | // Threadprivate variables must not be captured. |
2253 | if (isOpenMPThreadPrivate(DVarTop.CKind)) |
2254 | return nullptr; |
2255 | // The variable is not private or it is the variable in the directive with |
2256 | // default(none) clause and not used in any clause. |
2257 | DSAStackTy::DSAVarData DVarPrivate = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasDSA( |
2258 | D, |
2259 | [](OpenMPClauseKind C, bool AppliedToPointee) { |
2260 | return isOpenMPPrivate(C) && !AppliedToPointee; |
2261 | }, |
2262 | [](OpenMPDirectiveKind) { return true; }, |
2263 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode()); |
2264 | // Global shared must not be captured. |
2265 | if (VD && !VD->hasLocalStorage() && DVarPrivate.CKind == OMPC_unknown && |
2266 | ((DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDefaultDSA() != DSA_none && |
2267 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDefaultDSA() != DSA_firstprivate) || |
2268 | DVarTop.CKind == OMPC_shared)) |
2269 | return nullptr; |
2270 | if (DVarPrivate.CKind != OMPC_unknown || |
2271 | (VD && (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDefaultDSA() == DSA_none || |
2272 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDefaultDSA() == DSA_firstprivate))) |
2273 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
2274 | } |
2275 | return nullptr; |
2276 | } |
2277 | |
2278 | void Sema::adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
2279 | unsigned Level) const { |
2280 | FunctionScopesIndex -= getOpenMPCaptureLevels(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDirective(Level)); |
2281 | } |
2282 | |
2283 | void Sema::startOpenMPLoop() { |
2284 | assert(LangOpts.OpenMP && "OpenMP must be enabled.")((LangOpts.OpenMP && "OpenMP must be enabled.") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP must be enabled.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2284, __PRETTY_FUNCTION__)); |
2285 | if (isOpenMPLoopDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) |
2286 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->loopInit(); |
2287 | } |
2288 | |
2289 | void Sema::startOpenMPCXXRangeFor() { |
2290 | assert(LangOpts.OpenMP && "OpenMP must be enabled.")((LangOpts.OpenMP && "OpenMP must be enabled.") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP must be enabled.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2290, __PRETTY_FUNCTION__)); |
2291 | if (isOpenMPLoopDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { |
2292 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->resetPossibleLoopCounter(); |
2293 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->loopStart(); |
2294 | } |
2295 | } |
2296 | |
2297 | OpenMPClauseKind Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level, |
2298 | unsigned CapLevel) const { |
2299 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2299, __PRETTY_FUNCTION__)); |
2300 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDirective( |
2301 | [](OpenMPDirectiveKind K) { return isOpenMPTaskingDirective(K); }, |
2302 | Level)) { |
2303 | bool IsTriviallyCopyable = |
2304 | D->getType().getNonReferenceType().isTriviallyCopyableType(Context) && |
2305 | !D->getType() |
2306 | .getNonReferenceType() |
2307 | .getCanonicalType() |
2308 | ->getAsCXXRecordDecl(); |
2309 | OpenMPDirectiveKind DKind = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDirective(Level); |
2310 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
2311 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
2312 | if (isOpenMPTaskingDirective(CaptureRegions[CapLevel]) && |
2313 | (IsTriviallyCopyable || |
2314 | !isOpenMPTaskLoopDirective(CaptureRegions[CapLevel]))) { |
2315 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( |
2316 | D, |
2317 | [](OpenMPClauseKind K, bool) { return K == OMPC_firstprivate; }, |
2318 | Level, /*NotLastprivate=*/true)) |
2319 | return OMPC_firstprivate; |
2320 | DSAStackTy::DSAVarData DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getImplicitDSA(D, Level); |
2321 | if (DVar.CKind != OMPC_shared && |
2322 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isLoopControlVariable(D, Level).first && !DVar.RefExpr) { |
2323 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addImplicitTaskFirstprivate(Level, D); |
2324 | return OMPC_firstprivate; |
2325 | } |
2326 | } |
2327 | } |
2328 | if (isOpenMPLoopDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { |
2329 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getAssociatedLoops() > 0 && |
2330 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isLoopStarted()) { |
2331 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->resetPossibleLoopCounter(D); |
2332 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->loopStart(); |
2333 | return OMPC_private; |
2334 | } |
2335 | if ((DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getPossiblyLoopCunter() == D->getCanonicalDecl() || |
2336 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isLoopControlVariable(D).first) && |
2337 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( |
2338 | D, [](OpenMPClauseKind K, bool) { return K != OMPC_private; }, |
2339 | Level) && |
2340 | !isOpenMPSimdDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) |
2341 | return OMPC_private; |
2342 | } |
2343 | if (const auto *VD = dyn_cast<VarDecl>(D)) { |
2344 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isThreadPrivate(const_cast<VarDecl *>(VD)) && |
2345 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isForceVarCapturing() && |
2346 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( |
2347 | D, [](OpenMPClauseKind K, bool) { return K == OMPC_copyin; }, |
2348 | Level)) |
2349 | return OMPC_private; |
2350 | } |
2351 | // User-defined allocators are private since they must be defined in the |
2352 | // context of target region. |
2353 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level) && |
2354 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isUsesAllocatorsDecl(Level, D).getValueOr( |
2355 | DSAStackTy::UsesAllocatorsDeclKind::AllocatorTrait) == |
2356 | DSAStackTy::UsesAllocatorsDeclKind::UserDefinedAllocator) |
2357 | return OMPC_private; |
2358 | return (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( |
2359 | D, [](OpenMPClauseKind K, bool) { return K == OMPC_private; }, |
2360 | Level) || |
2361 | (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isClauseParsingMode() && |
2362 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getClauseParsingMode() == OMPC_private) || |
2363 | // Consider taskgroup reduction descriptor variable a private |
2364 | // to avoid possible capture in the region. |
2365 | (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDirective( |
2366 | [](OpenMPDirectiveKind K) { |
2367 | return K == OMPD_taskgroup || |
2368 | ((isOpenMPParallelDirective(K) || |
2369 | isOpenMPWorksharingDirective(K)) && |
2370 | !isOpenMPSimdDirective(K)); |
2371 | }, |
2372 | Level) && |
2373 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isTaskgroupReductionRef(D, Level))) |
2374 | ? OMPC_private |
2375 | : OMPC_unknown; |
2376 | } |
2377 | |
2378 | void Sema::setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, |
2379 | unsigned Level) { |
2380 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2380, __PRETTY_FUNCTION__)); |
2381 | D = getCanonicalDecl(D); |
2382 | OpenMPClauseKind OMPC = OMPC_unknown; |
2383 | for (unsigned I = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getNestingLevel() + 1; I > Level; --I) { |
2384 | const unsigned NewLevel = I - 1; |
2385 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDSA( |
2386 | D, |
2387 | [&OMPC](const OpenMPClauseKind K, bool AppliedToPointee) { |
2388 | if (isOpenMPPrivate(K) && !AppliedToPointee) { |
2389 | OMPC = K; |
2390 | return true; |
2391 | } |
2392 | return false; |
2393 | }, |
2394 | NewLevel)) |
2395 | break; |
2396 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->checkMappableExprComponentListsForDeclAtLevel( |
2397 | D, NewLevel, |
2398 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
2399 | OpenMPClauseKind) { return true; })) { |
2400 | OMPC = OMPC_map; |
2401 | break; |
2402 | } |
2403 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
2404 | NewLevel)) { |
2405 | OMPC = OMPC_map; |
2406 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->mustBeFirstprivateAtLevel( |
2407 | NewLevel, getVariableCategoryFromDecl(LangOpts, D))) |
2408 | OMPC = OMPC_firstprivate; |
2409 | break; |
2410 | } |
2411 | } |
2412 | if (OMPC != OMPC_unknown) |
2413 | FD->addAttr(OMPCaptureKindAttr::CreateImplicit(Context, unsigned(OMPC))); |
2414 | } |
2415 | |
2416 | bool Sema::isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, |
2417 | unsigned CaptureLevel) const { |
2418 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2418, __PRETTY_FUNCTION__)); |
2419 | // Return true if the current level is no longer enclosed in a target region. |
2420 | |
2421 | SmallVector<OpenMPDirectiveKind, 4> Regions; |
2422 | getOpenMPCaptureRegions(Regions, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDirective(Level)); |
2423 | const auto *VD = dyn_cast<VarDecl>(D); |
2424 | return VD && !VD->hasLocalStorage() && |
2425 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
2426 | Level) && |
2427 | Regions[CaptureLevel] != OMPD_task; |
2428 | } |
2429 | |
2430 | bool Sema::isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level, |
2431 | unsigned CaptureLevel) const { |
2432 | assert(LangOpts.OpenMP && "OpenMP is not allowed")((LangOpts.OpenMP && "OpenMP is not allowed") ? static_cast <void> (0) : __assert_fail ("LangOpts.OpenMP && \"OpenMP is not allowed\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2432, __PRETTY_FUNCTION__)); |
2433 | // Return true if the current level is no longer enclosed in a target region. |
2434 | |
2435 | if (const auto *VD = dyn_cast<VarDecl>(D)) { |
2436 | if (!VD->hasLocalStorage()) { |
2437 | if (isInOpenMPTargetExecutionDirective()) |
2438 | return true; |
2439 | DSAStackTy::DSAVarData TopDVar = |
2440 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, /*FromParent=*/false); |
2441 | unsigned NumLevels = |
2442 | getOpenMPCaptureLevels(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDirective(Level)); |
2443 | if (Level == 0) |
2444 | return (NumLevels == CaptureLevel + 1) && TopDVar.CKind != OMPC_shared; |
2445 | do { |
2446 | --Level; |
2447 | DSAStackTy::DSAVarData DVar = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getImplicitDSA(D, Level); |
2448 | if (DVar.CKind != OMPC_shared) |
2449 | return true; |
2450 | } while (Level > 0); |
2451 | } |
2452 | } |
2453 | return true; |
2454 | } |
2455 | |
2456 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ); } |
2457 | |
2458 | void Sema::ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, |
2459 | OMPTraitInfo &TI) { |
2460 | OMPDeclareVariantScopes.push_back(OMPDeclareVariantScope(TI)); |
2461 | } |
2462 | |
2463 | void Sema::ActOnOpenMPEndDeclareVariant() { |
2464 | assert(isInOpenMPDeclareVariantScope() &&((isInOpenMPDeclareVariantScope() && "Not in OpenMP declare variant scope!" ) ? static_cast<void> (0) : __assert_fail ("isInOpenMPDeclareVariantScope() && \"Not in OpenMP declare variant scope!\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2465, __PRETTY_FUNCTION__)) |
2465 | "Not in OpenMP declare variant scope!")((isInOpenMPDeclareVariantScope() && "Not in OpenMP declare variant scope!" ) ? static_cast<void> (0) : __assert_fail ("isInOpenMPDeclareVariantScope() && \"Not in OpenMP declare variant scope!\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2465, __PRETTY_FUNCTION__)); |
2466 | |
2467 | OMPDeclareVariantScopes.pop_back(); |
2468 | } |
2469 | |
2470 | void Sema::finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, |
2471 | const FunctionDecl *Callee, |
2472 | SourceLocation Loc) { |
2473 | assert(LangOpts.OpenMP && "Expected OpenMP compilation mode.")((LangOpts.OpenMP && "Expected OpenMP compilation mode." ) ? static_cast<void> (0) : __assert_fail ("LangOpts.OpenMP && \"Expected OpenMP compilation mode.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2473, __PRETTY_FUNCTION__)); |
2474 | Optional<OMPDeclareTargetDeclAttr::DevTypeTy> DevTy = |
2475 | OMPDeclareTargetDeclAttr::getDeviceType(Caller->getMostRecentDecl()); |
2476 | // Ignore host functions during device analyzis. |
2477 | if (LangOpts.OpenMPIsDevice && DevTy && |
2478 | *DevTy == OMPDeclareTargetDeclAttr::DT_Host) |
2479 | return; |
2480 | // Ignore nohost functions during host analyzis. |
2481 | if (!LangOpts.OpenMPIsDevice && DevTy && |
2482 | *DevTy == OMPDeclareTargetDeclAttr::DT_NoHost) |
2483 | return; |
2484 | const FunctionDecl *FD = Callee->getMostRecentDecl(); |
2485 | DevTy = OMPDeclareTargetDeclAttr::getDeviceType(FD); |
2486 | if (LangOpts.OpenMPIsDevice && DevTy && |
2487 | *DevTy == OMPDeclareTargetDeclAttr::DT_Host) { |
2488 | // Diagnose host function called during device codegen. |
2489 | StringRef HostDevTy = |
2490 | getOpenMPSimpleClauseTypeName(OMPC_device_type, OMPC_DEVICE_TYPE_host); |
2491 | Diag(Loc, diag::err_omp_wrong_device_function_call) << HostDevTy << 0; |
2492 | Diag(*OMPDeclareTargetDeclAttr::getLocation(FD), |
2493 | diag::note_omp_marked_device_type_here) |
2494 | << HostDevTy; |
2495 | return; |
2496 | } |
2497 | if (!LangOpts.OpenMPIsDevice && DevTy && |
2498 | *DevTy == OMPDeclareTargetDeclAttr::DT_NoHost) { |
2499 | // Diagnose nohost function called during host codegen. |
2500 | StringRef NoHostDevTy = getOpenMPSimpleClauseTypeName( |
2501 | OMPC_device_type, OMPC_DEVICE_TYPE_nohost); |
2502 | Diag(Loc, diag::err_omp_wrong_device_function_call) << NoHostDevTy << 1; |
2503 | Diag(*OMPDeclareTargetDeclAttr::getLocation(FD), |
2504 | diag::note_omp_marked_device_type_here) |
2505 | << NoHostDevTy; |
2506 | } |
2507 | } |
2508 | |
2509 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
2510 | const DeclarationNameInfo &DirName, |
2511 | Scope *CurScope, SourceLocation Loc) { |
2512 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->push(DKind, DirName, CurScope, Loc); |
2513 | PushExpressionEvaluationContext( |
2514 | ExpressionEvaluationContext::PotentiallyEvaluated); |
2515 | } |
2516 | |
2517 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
2518 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setClauseParsingMode(K); |
2519 | } |
2520 | |
2521 | void Sema::EndOpenMPClause() { |
2522 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setClauseParsingMode(/*K=*/OMPC_unknown); |
2523 | } |
2524 | |
2525 | static std::pair<ValueDecl *, bool> |
2526 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
2527 | SourceRange &ERange, bool AllowArraySection = false); |
2528 | |
2529 | /// Check consistency of the reduction clauses. |
2530 | static void checkReductionClauses(Sema &S, DSAStackTy *Stack, |
2531 | ArrayRef<OMPClause *> Clauses) { |
2532 | bool InscanFound = false; |
2533 | SourceLocation InscanLoc; |
2534 | // OpenMP 5.0, 2.19.5.4 reduction Clause, Restrictions. |
2535 | // A reduction clause without the inscan reduction-modifier may not appear on |
2536 | // a construct on which a reduction clause with the inscan reduction-modifier |
2537 | // appears. |
2538 | for (OMPClause *C : Clauses) { |
2539 | if (C->getClauseKind() != OMPC_reduction) |
2540 | continue; |
2541 | auto *RC = cast<OMPReductionClause>(C); |
2542 | if (RC->getModifier() == OMPC_REDUCTION_inscan) { |
2543 | InscanFound = true; |
2544 | InscanLoc = RC->getModifierLoc(); |
2545 | continue; |
2546 | } |
2547 | if (RC->getModifier() == OMPC_REDUCTION_task) { |
2548 | // OpenMP 5.0, 2.19.5.4 reduction Clause. |
2549 | // A reduction clause with the task reduction-modifier may only appear on |
2550 | // a parallel construct, a worksharing construct or a combined or |
2551 | // composite construct for which any of the aforementioned constructs is a |
2552 | // constituent construct and simd or loop are not constituent constructs. |
2553 | OpenMPDirectiveKind CurDir = Stack->getCurrentDirective(); |
2554 | if (!(isOpenMPParallelDirective(CurDir) || |
2555 | isOpenMPWorksharingDirective(CurDir)) || |
2556 | isOpenMPSimdDirective(CurDir)) |
2557 | S.Diag(RC->getModifierLoc(), |
2558 | diag::err_omp_reduction_task_not_parallel_or_worksharing); |
2559 | continue; |
2560 | } |
2561 | } |
2562 | if (InscanFound) { |
2563 | for (OMPClause *C : Clauses) { |
2564 | if (C->getClauseKind() != OMPC_reduction) |
2565 | continue; |
2566 | auto *RC = cast<OMPReductionClause>(C); |
2567 | if (RC->getModifier() != OMPC_REDUCTION_inscan) { |
2568 | S.Diag(RC->getModifier() == OMPC_REDUCTION_unknown |
2569 | ? RC->getBeginLoc() |
2570 | : RC->getModifierLoc(), |
2571 | diag::err_omp_inscan_reduction_expected); |
2572 | S.Diag(InscanLoc, diag::note_omp_previous_inscan_reduction); |
2573 | continue; |
2574 | } |
2575 | for (Expr *Ref : RC->varlists()) { |
2576 | assert(Ref && "NULL expr in OpenMP nontemporal clause.")((Ref && "NULL expr in OpenMP nontemporal clause.") ? static_cast<void> (0) : __assert_fail ("Ref && \"NULL expr in OpenMP nontemporal clause.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2576, __PRETTY_FUNCTION__)); |
2577 | SourceLocation ELoc; |
2578 | SourceRange ERange; |
2579 | Expr *SimpleRefExpr = Ref; |
2580 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange, |
2581 | /*AllowArraySection=*/true); |
2582 | ValueDecl *D = Res.first; |
2583 | if (!D) |
2584 | continue; |
2585 | if (!Stack->isUsedInScanDirective(getCanonicalDecl(D))) { |
2586 | S.Diag(Ref->getExprLoc(), |
2587 | diag::err_omp_reduction_not_inclusive_exclusive) |
2588 | << Ref->getSourceRange(); |
2589 | } |
2590 | } |
2591 | } |
2592 | } |
2593 | } |
2594 | |
2595 | static void checkAllocateClauses(Sema &S, DSAStackTy *Stack, |
2596 | ArrayRef<OMPClause *> Clauses); |
2597 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
2598 | bool WithInit); |
2599 | |
2600 | static void reportOriginalDsa(Sema &SemaRef, const DSAStackTy *Stack, |
2601 | const ValueDecl *D, |
2602 | const DSAStackTy::DSAVarData &DVar, |
2603 | bool IsLoopIterVar = false); |
2604 | |
2605 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
2606 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
2607 | // A variable of class type (or array thereof) that appears in a lastprivate |
2608 | // clause requires an accessible, unambiguous default constructor for the |
2609 | // class type, unless the list item is also specified in a firstprivate |
2610 | // clause. |
2611 | if (const auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
2612 | for (OMPClause *C : D->clauses()) { |
2613 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
2614 | SmallVector<Expr *, 8> PrivateCopies; |
2615 | for (Expr *DE : Clause->varlists()) { |
2616 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
2617 | PrivateCopies.push_back(nullptr); |
2618 | continue; |
2619 | } |
2620 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
2621 | auto *VD = cast<VarDecl>(DRE->getDecl()); |
2622 | QualType Type = VD->getType().getNonReferenceType(); |
2623 | const DSAStackTy::DSAVarData DVar = |
2624 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(VD, /*FromParent=*/false); |
2625 | if (DVar.CKind == OMPC_lastprivate) { |
2626 | // Generate helper private variable and initialize it with the |
2627 | // default value. The address of the original variable is replaced |
2628 | // by the address of the new private variable in CodeGen. This new |
2629 | // variable is not added to IdResolver, so the code in the OpenMP |
2630 | // region uses original variable for proper diagnostics. |
2631 | VarDecl *VDPrivate = buildVarDecl( |
2632 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
2633 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr, DRE); |
2634 | ActOnUninitializedDecl(VDPrivate); |
2635 | if (VDPrivate->isInvalidDecl()) { |
2636 | PrivateCopies.push_back(nullptr); |
2637 | continue; |
2638 | } |
2639 | PrivateCopies.push_back(buildDeclRefExpr( |
2640 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
2641 | } else { |
2642 | // The variable is also a firstprivate, so initialization sequence |
2643 | // for private copy is generated already. |
2644 | PrivateCopies.push_back(nullptr); |
2645 | } |
2646 | } |
2647 | Clause->setPrivateCopies(PrivateCopies); |
2648 | continue; |
2649 | } |
2650 | // Finalize nontemporal clause by handling private copies, if any. |
2651 | if (auto *Clause = dyn_cast<OMPNontemporalClause>(C)) { |
2652 | SmallVector<Expr *, 8> PrivateRefs; |
2653 | for (Expr *RefExpr : Clause->varlists()) { |
2654 | assert(RefExpr && "NULL expr in OpenMP nontemporal clause.")((RefExpr && "NULL expr in OpenMP nontemporal clause." ) ? static_cast<void> (0) : __assert_fail ("RefExpr && \"NULL expr in OpenMP nontemporal clause.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 2654, __PRETTY_FUNCTION__)); |
2655 | SourceLocation ELoc; |
2656 | SourceRange ERange; |
2657 | Expr *SimpleRefExpr = RefExpr; |
2658 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
2659 | if (Res.second) |
2660 | // It will be analyzed later. |
2661 | PrivateRefs.push_back(RefExpr); |
2662 | ValueDecl *D = Res.first; |
2663 | if (!D) |
2664 | continue; |
2665 | |
2666 | const DSAStackTy::DSAVarData DVar = |
2667 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(D, /*FromParent=*/false); |
2668 | PrivateRefs.push_back(DVar.PrivateCopy ? DVar.PrivateCopy |
2669 | : SimpleRefExpr); |
2670 | } |
2671 | Clause->setPrivateRefs(PrivateRefs); |
2672 | continue; |
2673 | } |
2674 | if (auto *Clause = dyn_cast<OMPUsesAllocatorsClause>(C)) { |
2675 | for (unsigned I = 0, E = Clause->getNumberOfAllocators(); I < E; ++I) { |
2676 | OMPUsesAllocatorsClause::Data D = Clause->getAllocatorData(I); |
2677 | auto *DRE = dyn_cast<DeclRefExpr>(D.Allocator->IgnoreParenImpCasts()); |
2678 | if (!DRE) |
2679 | continue; |
2680 | ValueDecl *VD = DRE->getDecl(); |
2681 | if (!VD || !isa<VarDecl>(VD)) |
2682 | continue; |
2683 | DSAStackTy::DSAVarData DVar = |
2684 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getTopDSA(VD, /*FromParent=*/false); |
2685 | // OpenMP [2.12.5, target Construct] |
2686 | // Memory allocators that appear in a uses_allocators clause cannot |
2687 | // appear in other data-sharing attribute clauses or data-mapping |
2688 | // attribute clauses in the same construct. |
2689 | Expr *MapExpr = nullptr; |
2690 | if (DVar.RefExpr || |
2691 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->checkMappableExprComponentListsForDecl( |
2692 | VD, /*CurrentRegionOnly=*/true, |
2693 | [VD, &MapExpr]( |
2694 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
2695 | MapExprComponents, |
2696 | OpenMPClauseKind C) { |
2697 | auto MI = MapExprComponents.rbegin(); |
2698 | auto ME = MapExprComponents.rend(); |
2699 | if (MI != ME && |
2700 | MI->getAssociatedDeclaration()->getCanonicalDecl() == |
2701 | VD->getCanonicalDecl()) { |
2702 | MapExpr = MI->getAssociatedExpression(); |
2703 | return true; |
2704 | } |
2705 | return false; |
2706 | })) { |
2707 | Diag(D.Allocator->getExprLoc(), |
2708 | diag::err_omp_allocator_used_in_clauses) |
2709 | << D.Allocator->getSourceRange(); |
2710 | if (DVar.RefExpr) |
2711 | reportOriginalDsa(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), VD, DVar); |
2712 | else |
2713 | Diag(MapExpr->getExprLoc(), diag::note_used_here) |
2714 | << MapExpr->getSourceRange(); |
2715 | } |
2716 | } |
2717 | continue; |
2718 | } |
2719 | } |
2720 | // Check allocate clauses. |
2721 | if (!CurContext->isDependentContext()) |
2722 | checkAllocateClauses(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D->clauses()); |
2723 | checkReductionClauses(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), D->clauses()); |
2724 | } |
2725 | |
2726 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->pop(); |
2727 | DiscardCleanupsInEvaluationContext(); |
2728 | PopExpressionEvaluationContext(); |
2729 | } |
2730 | |
2731 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
2732 | Expr *NumIterations, Sema &SemaRef, |
2733 | Scope *S, DSAStackTy *Stack); |
2734 | |
2735 | namespace { |
2736 | |
2737 | class VarDeclFilterCCC final : public CorrectionCandidateCallback { |
2738 | private: |
2739 | Sema &SemaRef; |
2740 | |
2741 | public: |
2742 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
2743 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
2744 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
2745 | if (const auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
2746 | return VD->hasGlobalStorage() && |
2747 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
2748 | SemaRef.getCurScope()); |
2749 | } |
2750 | return false; |
2751 | } |
2752 | |
2753 | std::unique_ptr<CorrectionCandidateCallback> clone() override { |
2754 | return std::make_unique<VarDeclFilterCCC>(*this); |
2755 | } |
2756 | |
2757 | }; |
2758 | |
2759 | class VarOrFuncDeclFilterCCC final : public CorrectionCandidateCallback { |
2760 | private: |
2761 | Sema &SemaRef; |
2762 | |
2763 | public: |
2764 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
2765 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
2766 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
2767 | if (ND && ((isa<VarDecl>(ND) && ND->getKind() == Decl::Var) || |
2768 | isa<FunctionDecl>(ND))) { |
2769 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
2770 | SemaRef.getCurScope()); |
2771 | } |
2772 | return false; |
2773 | } |
2774 | |
2775 | std::unique_ptr<CorrectionCandidateCallback> clone() override { |
2776 | return std::make_unique<VarOrFuncDeclFilterCCC>(*this); |
2777 | } |
2778 | }; |
2779 | |
2780 | } // namespace |
2781 | |
2782 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
2783 | CXXScopeSpec &ScopeSpec, |
2784 | const DeclarationNameInfo &Id, |
2785 | OpenMPDirectiveKind Kind) { |
2786 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
2787 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
2788 | |
2789 | if (Lookup.isAmbiguous()) |
2790 | return ExprError(); |
2791 | |
2792 | VarDecl *VD; |
2793 | if (!Lookup.isSingleResult()) { |
2794 | VarDeclFilterCCC CCC(*this); |
2795 | if (TypoCorrection Corrected = |
2796 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, CCC, |
2797 | CTK_ErrorRecovery)) { |
2798 | diagnoseTypo(Corrected, |
2799 | PDiag(Lookup.empty() |
2800 | ? diag::err_undeclared_var_use_suggest |
2801 | : diag::err_omp_expected_var_arg_suggest) |
2802 | << Id.getName()); |
2803 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
2804 | } else { |
2805 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
2806 | : diag::err_omp_expected_var_arg) |
2807 | << Id.getName(); |
2808 | return ExprError(); |
2809 | } |
2810 | } else if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
2811 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
2812 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
2813 | return ExprError(); |
2814 | } |
2815 | Lookup.suppressDiagnostics(); |
2816 | |
2817 | // OpenMP [2.9.2, Syntax, C/C++] |
2818 | // Variables must be file-scope, namespace-scope, or static block-scope. |
2819 | if (Kind == OMPD_threadprivate && !VD->hasGlobalStorage()) { |
2820 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
2821 | << getOpenMPDirectiveName(Kind) << !VD->isStaticLocal(); |
2822 | bool IsDecl = |
2823 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
2824 | Diag(VD->getLocation(), |
2825 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
2826 | << VD; |
2827 | return ExprError(); |
2828 | } |
2829 | |
2830 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
2831 | NamedDecl *ND = CanonicalVD; |
2832 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
2833 | // A threadprivate directive for file-scope variables must appear outside |
2834 | // any definition or declaration. |
2835 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
2836 | !getCurLexicalContext()->isTranslationUnit()) { |
2837 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
2838 | << getOpenMPDirectiveName(Kind) << VD; |
2839 | bool IsDecl = |
2840 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
2841 | Diag(VD->getLocation(), |
2842 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
2843 | << VD; |
2844 | return ExprError(); |
2845 | } |
2846 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
2847 | // A threadprivate directive for static class member variables must appear |
2848 | // in the class definition, in the same scope in which the member |
2849 | // variables are declared. |
2850 | if (CanonicalVD->isStaticDataMember() && |
2851 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
2852 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
2853 | << getOpenMPDirectiveName(Kind) << VD; |
2854 | bool IsDecl = |
2855 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
2856 | Diag(VD->getLocation(), |
2857 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
2858 | << VD; |
2859 | return ExprError(); |
2860 | } |
2861 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
2862 | // A threadprivate directive for namespace-scope variables must appear |
2863 | // outside any definition or declaration other than the namespace |
2864 | // definition itself. |
2865 | if (CanonicalVD->getDeclContext()->isNamespace() && |
2866 | (!getCurLexicalContext()->isFileContext() || |
2867 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
2868 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
2869 | << getOpenMPDirectiveName(Kind) << VD; |
2870 | bool IsDecl = |
2871 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
2872 | Diag(VD->getLocation(), |
2873 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
2874 | << VD; |
2875 | return ExprError(); |
2876 | } |
2877 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
2878 | // A threadprivate directive for static block-scope variables must appear |
2879 | // in the scope of the variable and not in a nested scope. |
2880 | if (CanonicalVD->isLocalVarDecl() && CurScope && |
2881 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
2882 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
2883 | << getOpenMPDirectiveName(Kind) << VD; |
2884 | bool IsDecl = |
2885 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
2886 | Diag(VD->getLocation(), |
2887 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
2888 | << VD; |
2889 | return ExprError(); |
2890 | } |
2891 | |
2892 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
2893 | // A threadprivate directive must lexically precede all references to any |
2894 | // of the variables in its list. |
2895 | if (Kind == OMPD_threadprivate && VD->isUsed() && |
2896 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isThreadPrivate(VD)) { |
2897 | Diag(Id.getLoc(), diag::err_omp_var_used) |
2898 | << getOpenMPDirectiveName(Kind) << VD; |
2899 | return ExprError(); |
2900 | } |
2901 | |
2902 | QualType ExprType = VD->getType().getNonReferenceType(); |
2903 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
2904 | SourceLocation(), VD, |
2905 | /*RefersToEnclosingVariableOrCapture=*/false, |
2906 | Id.getLoc(), ExprType, VK_LValue); |
2907 | } |
2908 | |
2909 | Sema::DeclGroupPtrTy |
2910 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
2911 | ArrayRef<Expr *> VarList) { |
2912 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
2913 | CurContext->addDecl(D); |
2914 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
2915 | } |
2916 | return nullptr; |
2917 | } |
2918 | |
2919 | namespace { |
2920 | class LocalVarRefChecker final |
2921 | : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
2922 | Sema &SemaRef; |
2923 | |
2924 | public: |
2925 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
2926 | if (const auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
2927 | if (VD->hasLocalStorage()) { |
2928 | SemaRef.Diag(E->getBeginLoc(), |
2929 | diag::err_omp_local_var_in_threadprivate_init) |
2930 | << E->getSourceRange(); |
2931 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
2932 | << VD << VD->getSourceRange(); |
2933 | return true; |
2934 | } |
2935 | } |
2936 | return false; |
2937 | } |
2938 | bool VisitStmt(const Stmt *S) { |
2939 | for (const Stmt *Child : S->children()) { |
2940 | if (Child && Visit(Child)) |
2941 | return true; |
2942 | } |
2943 | return false; |
2944 | } |
2945 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
2946 | }; |
2947 | } // namespace |
2948 | |
2949 | OMPThreadPrivateDecl * |
2950 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
2951 | SmallVector<Expr *, 8> Vars; |
2952 | for (Expr *RefExpr : VarList) { |
2953 | auto *DE = cast<DeclRefExpr>(RefExpr); |
2954 | auto *VD = cast<VarDecl>(DE->getDecl()); |
2955 | SourceLocation ILoc = DE->getExprLoc(); |
2956 | |
2957 | // Mark variable as used. |
2958 | VD->setReferenced(); |
2959 | VD->markUsed(Context); |
2960 | |
2961 | QualType QType = VD->getType(); |
2962 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
2963 | // It will be analyzed later. |
2964 | Vars.push_back(DE); |
2965 | continue; |
2966 | } |
2967 | |
2968 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
2969 | // A threadprivate variable must not have an incomplete type. |
2970 | if (RequireCompleteType(ILoc, VD->getType(), |
2971 | diag::err_omp_threadprivate_incomplete_type)) { |
2972 | continue; |
2973 | } |
2974 | |
2975 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
2976 | // A threadprivate variable must not have a reference type. |
2977 | if (VD->getType()->isReferenceType()) { |
2978 | Diag(ILoc, diag::err_omp_ref_type_arg) |
2979 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
2980 | bool IsDecl = |
2981 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
2982 | Diag(VD->getLocation(), |
2983 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
2984 | << VD; |
2985 | continue; |
2986 | } |
2987 | |
2988 | // Check if this is a TLS variable. If TLS is not being supported, produce |
2989 | // the corresponding diagnostic. |
2990 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
2991 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
2992 | getLangOpts().OpenMPUseTLS && |
2993 | getASTContext().getTargetInfo().isTLSSupported())) || |
2994 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
2995 | !VD->isLocalVarDecl())) { |
2996 | Diag(ILoc, diag::err_omp_var_thread_local) |
2997 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
2998 | bool IsDecl = |
2999 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
3000 | Diag(VD->getLocation(), |
3001 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
3002 | << VD; |
3003 | continue; |
3004 | } |
3005 | |
3006 | // Check if initial value of threadprivate variable reference variable with |
3007 | // local storage (it is not supported by runtime). |
3008 | if (const Expr *Init = VD->getAnyInitializer()) { |
3009 | LocalVarRefChecker Checker(*this); |
3010 | if (Checker.Visit(Init)) |
3011 | continue; |
3012 | } |
3013 | |
3014 | Vars.push_back(RefExpr); |
3015 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addDSA(VD, DE, OMPC_threadprivate); |
3016 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
3017 | Context, SourceRange(Loc, Loc))); |
3018 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
3019 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
3020 | } |
3021 | OMPThreadPrivateDecl *D = nullptr; |
3022 | if (!Vars.empty()) { |
3023 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
3024 | Vars); |
3025 | D->setAccess(AS_public); |
3026 | } |
3027 | return D; |
3028 | } |
3029 | |
3030 | static OMPAllocateDeclAttr::AllocatorTypeTy |
3031 | getAllocatorKind(Sema &S, DSAStackTy *Stack, Expr *Allocator) { |
3032 | if (!Allocator) |
3033 | return OMPAllocateDeclAttr::OMPNullMemAlloc; |
3034 | if (Allocator->isTypeDependent() || Allocator->isValueDependent() || |
3035 | Allocator->isInstantiationDependent() || |
3036 | Allocator->containsUnexpandedParameterPack()) |
3037 | return OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; |
3038 | auto AllocatorKindRes = OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; |
3039 | const Expr *AE = Allocator->IgnoreParenImpCasts(); |
3040 | for (int I = 0; I < OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; ++I) { |
3041 | auto AllocatorKind = static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(I); |
3042 | const Expr *DefAllocator = Stack->getAllocator(AllocatorKind); |
3043 | llvm::FoldingSetNodeID AEId, DAEId; |
3044 | AE->Profile(AEId, S.getASTContext(), /*Canonical=*/true); |
3045 | DefAllocator->Profile(DAEId, S.getASTContext(), /*Canonical=*/true); |
3046 | if (AEId == DAEId) { |
3047 | AllocatorKindRes = AllocatorKind; |
3048 | break; |
3049 | } |
3050 | } |
3051 | return AllocatorKindRes; |
3052 | } |
3053 | |
3054 | static bool checkPreviousOMPAllocateAttribute( |
3055 | Sema &S, DSAStackTy *Stack, Expr *RefExpr, VarDecl *VD, |
3056 | OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind, Expr *Allocator) { |
3057 | if (!VD->hasAttr<OMPAllocateDeclAttr>()) |
3058 | return false; |
3059 | const auto *A = VD->getAttr<OMPAllocateDeclAttr>(); |
3060 | Expr *PrevAllocator = A->getAllocator(); |
3061 | OMPAllocateDeclAttr::AllocatorTypeTy PrevAllocatorKind = |
3062 | getAllocatorKind(S, Stack, PrevAllocator); |
3063 | bool AllocatorsMatch = AllocatorKind == PrevAllocatorKind; |
3064 | if (AllocatorsMatch && |
3065 | AllocatorKind == OMPAllocateDeclAttr::OMPUserDefinedMemAlloc && |
3066 | Allocator && PrevAllocator) { |
3067 | const Expr *AE = Allocator->IgnoreParenImpCasts(); |
3068 | const Expr *PAE = PrevAllocator->IgnoreParenImpCasts(); |
3069 | llvm::FoldingSetNodeID AEId, PAEId; |
3070 | AE->Profile(AEId, S.Context, /*Canonical=*/true); |
3071 | PAE->Profile(PAEId, S.Context, /*Canonical=*/true); |
3072 | AllocatorsMatch = AEId == PAEId; |
3073 | } |
3074 | if (!AllocatorsMatch) { |
3075 | SmallString<256> AllocatorBuffer; |
3076 | llvm::raw_svector_ostream AllocatorStream(AllocatorBuffer); |
3077 | if (Allocator) |
3078 | Allocator->printPretty(AllocatorStream, nullptr, S.getPrintingPolicy()); |
3079 | SmallString<256> PrevAllocatorBuffer; |
3080 | llvm::raw_svector_ostream PrevAllocatorStream(PrevAllocatorBuffer); |
3081 | if (PrevAllocator) |
3082 | PrevAllocator->printPretty(PrevAllocatorStream, nullptr, |
3083 | S.getPrintingPolicy()); |
3084 | |
3085 | SourceLocation AllocatorLoc = |
3086 | Allocator ? Allocator->getExprLoc() : RefExpr->getExprLoc(); |
3087 | SourceRange AllocatorRange = |
3088 | Allocator ? Allocator->getSourceRange() : RefExpr->getSourceRange(); |
3089 | SourceLocation PrevAllocatorLoc = |
3090 | PrevAllocator ? PrevAllocator->getExprLoc() : A->getLocation(); |
3091 | SourceRange PrevAllocatorRange = |
3092 | PrevAllocator ? PrevAllocator->getSourceRange() : A->getRange(); |
3093 | S.Diag(AllocatorLoc, diag::warn_omp_used_different_allocator) |
3094 | << (Allocator ? 1 : 0) << AllocatorStream.str() |
3095 | << (PrevAllocator ? 1 : 0) << PrevAllocatorStream.str() |
3096 | << AllocatorRange; |
3097 | S.Diag(PrevAllocatorLoc, diag::note_omp_previous_allocator) |
3098 | << PrevAllocatorRange; |
3099 | return true; |
3100 | } |
3101 | return false; |
3102 | } |
3103 | |
3104 | static void |
3105 | applyOMPAllocateAttribute(Sema &S, VarDecl *VD, |
3106 | OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind, |
3107 | Expr *Allocator, SourceRange SR) { |
3108 | if (VD->hasAttr<OMPAllocateDeclAttr>()) |
3109 | return; |
3110 | if (Allocator && |
3111 | (Allocator->isTypeDependent() || Allocator->isValueDependent() || |
3112 | Allocator->isInstantiationDependent() || |
3113 | Allocator->containsUnexpandedParameterPack())) |
3114 | return; |
3115 | auto *A = OMPAllocateDeclAttr::CreateImplicit(S.Context, AllocatorKind, |
3116 | Allocator, SR); |
3117 | VD->addAttr(A); |
3118 | if (ASTMutationListener *ML = S.Context.getASTMutationListener()) |
3119 | ML->DeclarationMarkedOpenMPAllocate(VD, A); |
3120 | } |
3121 | |
3122 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPAllocateDirective( |
3123 | SourceLocation Loc, ArrayRef<Expr *> VarList, |
3124 | ArrayRef<OMPClause *> Clauses, DeclContext *Owner) { |
3125 | assert(Clauses.size() <= 1 && "Expected at most one clause.")((Clauses.size() <= 1 && "Expected at most one clause." ) ? static_cast<void> (0) : __assert_fail ("Clauses.size() <= 1 && \"Expected at most one clause.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 3125, __PRETTY_FUNCTION__)); |
3126 | Expr *Allocator = nullptr; |
3127 | if (Clauses.empty()) { |
3128 | // OpenMP 5.0, 2.11.3 allocate Directive, Restrictions. |
3129 | // allocate directives that appear in a target region must specify an |
3130 | // allocator clause unless a requires directive with the dynamic_allocators |
3131 | // clause is present in the same compilation unit. |
3132 | if (LangOpts.OpenMPIsDevice && |
3133 | !DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>()) |
3134 | targetDiag(Loc, diag::err_expected_allocator_clause); |
3135 | } else { |
3136 | Allocator = cast<OMPAllocatorClause>(Clauses.back())->getAllocator(); |
3137 | } |
3138 | OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind = |
3139 | getAllocatorKind(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), Allocator); |
3140 | SmallVector<Expr *, 8> Vars; |
3141 | for (Expr *RefExpr : VarList) { |
3142 | auto *DE = cast<DeclRefExpr>(RefExpr); |
3143 | auto *VD = cast<VarDecl>(DE->getDecl()); |
3144 | |
3145 | // Check if this is a TLS variable or global register. |
3146 | if (VD->getTLSKind() != VarDecl::TLS_None || |
3147 | VD->hasAttr<OMPThreadPrivateDeclAttr>() || |
3148 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
3149 | !VD->isLocalVarDecl())) |
3150 | continue; |
3151 | |
3152 | // If the used several times in the allocate directive, the same allocator |
3153 | // must be used. |
3154 | if (checkPreviousOMPAllocateAttribute(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), RefExpr, VD, |
3155 | AllocatorKind, Allocator)) |
3156 | continue; |
3157 | |
3158 | // OpenMP, 2.11.3 allocate Directive, Restrictions, C / C++ |
3159 | // If a list item has a static storage type, the allocator expression in the |
3160 | // allocator clause must be a constant expression that evaluates to one of |
3161 | // the predefined memory allocator values. |
3162 | if (Allocator && VD->hasGlobalStorage()) { |
3163 | if (AllocatorKind == OMPAllocateDeclAttr::OMPUserDefinedMemAlloc) { |
3164 | Diag(Allocator->getExprLoc(), |
3165 | diag::err_omp_expected_predefined_allocator) |
3166 | << Allocator->getSourceRange(); |
3167 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
3168 | VarDecl::DeclarationOnly; |
3169 | Diag(VD->getLocation(), |
3170 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
3171 | << VD; |
3172 | continue; |
3173 | } |
3174 | } |
3175 | |
3176 | Vars.push_back(RefExpr); |
3177 | applyOMPAllocateAttribute(*this, VD, AllocatorKind, Allocator, |
3178 | DE->getSourceRange()); |
3179 | } |
3180 | if (Vars.empty()) |
3181 | return nullptr; |
3182 | if (!Owner) |
3183 | Owner = getCurLexicalContext(); |
3184 | auto *D = OMPAllocateDecl::Create(Context, Owner, Loc, Vars, Clauses); |
3185 | D->setAccess(AS_public); |
3186 | Owner->addDecl(D); |
3187 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
3188 | } |
3189 | |
3190 | Sema::DeclGroupPtrTy |
3191 | Sema::ActOnOpenMPRequiresDirective(SourceLocation Loc, |
3192 | ArrayRef<OMPClause *> ClauseList) { |
3193 | OMPRequiresDecl *D = nullptr; |
3194 | if (!CurContext->isFileContext()) { |
3195 | Diag(Loc, diag::err_omp_invalid_scope) << "requires"; |
3196 | } else { |
3197 | D = CheckOMPRequiresDecl(Loc, ClauseList); |
3198 | if (D) { |
3199 | CurContext->addDecl(D); |
3200 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->addRequiresDecl(D); |
3201 | } |
3202 | } |
3203 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
3204 | } |
3205 | |
3206 | void Sema::ActOnOpenMPAssumesDirective(SourceLocation Loc, |
3207 | OpenMPDirectiveKind DKind, |
3208 | ArrayRef<StringRef> Assumptions, |
3209 | bool SkippedClauses) { |
3210 | if (!SkippedClauses && Assumptions.empty()) |
3211 | Diag(Loc, diag::err_omp_no_clause_for_directive) |
3212 | << llvm::omp::getAllAssumeClauseOptions() |
3213 | << llvm::omp::getOpenMPDirectiveName(DKind); |
3214 | |
3215 | auto *AA = AssumptionAttr::Create(Context, llvm::join(Assumptions, ","), Loc); |
3216 | if (DKind == llvm::omp::Directive::OMPD_begin_assumes) { |
3217 | OMPAssumeScoped.push_back(AA); |
3218 | return; |
3219 | } |
3220 | |
3221 | // Global assumes without assumption clauses are ignored. |
3222 | if (Assumptions.empty()) |
3223 | return; |
3224 | |
3225 | assert(DKind == llvm::omp::Directive::OMPD_assumes &&((DKind == llvm::omp::Directive::OMPD_assumes && "Unexpected omp assumption directive!" ) ? static_cast<void> (0) : __assert_fail ("DKind == llvm::omp::Directive::OMPD_assumes && \"Unexpected omp assumption directive!\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 3226, __PRETTY_FUNCTION__)) |
3226 | "Unexpected omp assumption directive!")((DKind == llvm::omp::Directive::OMPD_assumes && "Unexpected omp assumption directive!" ) ? static_cast<void> (0) : __assert_fail ("DKind == llvm::omp::Directive::OMPD_assumes && \"Unexpected omp assumption directive!\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 3226, __PRETTY_FUNCTION__)); |
3227 | OMPAssumeGlobal.push_back(AA); |
3228 | |
3229 | // The OMPAssumeGlobal scope above will take care of new declarations but |
3230 | // we also want to apply the assumption to existing ones, e.g., to |
3231 | // declarations in included headers. To this end, we traverse all existing |
3232 | // declaration contexts and annotate function declarations here. |
3233 | SmallVector<DeclContext *, 8> DeclContexts; |
3234 | auto *Ctx = CurContext; |
3235 | while (Ctx->getLexicalParent()) |
3236 | Ctx = Ctx->getLexicalParent(); |
3237 | DeclContexts.push_back(Ctx); |
3238 | while (!DeclContexts.empty()) { |
3239 | DeclContext *DC = DeclContexts.pop_back_val(); |
3240 | for (auto *SubDC : DC->decls()) { |
3241 | if (SubDC->isInvalidDecl()) |
3242 | continue; |
3243 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(SubDC)) { |
3244 | DeclContexts.push_back(CTD->getTemplatedDecl()); |
3245 | for (auto *S : CTD->specializations()) |
3246 | DeclContexts.push_back(S); |
3247 | continue; |
3248 | } |
3249 | if (auto *DC = dyn_cast<DeclContext>(SubDC)) |
3250 | DeclContexts.push_back(DC); |
3251 | if (auto *F = dyn_cast<FunctionDecl>(SubDC)) { |
3252 | F->addAttr(AA); |
3253 | continue; |
3254 | } |
3255 | } |
3256 | } |
3257 | } |
3258 | |
3259 | void Sema::ActOnOpenMPEndAssumesDirective() { |
3260 | assert(isInOpenMPAssumeScope() && "Not in OpenMP assumes scope!")((isInOpenMPAssumeScope() && "Not in OpenMP assumes scope!" ) ? static_cast<void> (0) : __assert_fail ("isInOpenMPAssumeScope() && \"Not in OpenMP assumes scope!\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 3260, __PRETTY_FUNCTION__)); |
3261 | OMPAssumeScoped.pop_back(); |
3262 | } |
3263 | |
3264 | OMPRequiresDecl *Sema::CheckOMPRequiresDecl(SourceLocation Loc, |
3265 | ArrayRef<OMPClause *> ClauseList) { |
3266 | /// For target specific clauses, the requires directive cannot be |
3267 | /// specified after the handling of any of the target regions in the |
3268 | /// current compilation unit. |
3269 | ArrayRef<SourceLocation> TargetLocations = |
3270 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getEncounteredTargetLocs(); |
3271 | SourceLocation AtomicLoc = DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getAtomicDirectiveLoc(); |
3272 | if (!TargetLocations.empty() || !AtomicLoc.isInvalid()) { |
3273 | for (const OMPClause *CNew : ClauseList) { |
3274 | // Check if any of the requires clauses affect target regions. |
3275 | if (isa<OMPUnifiedSharedMemoryClause>(CNew) || |
3276 | isa<OMPUnifiedAddressClause>(CNew) || |
3277 | isa<OMPReverseOffloadClause>(CNew) || |
3278 | isa<OMPDynamicAllocatorsClause>(CNew)) { |
3279 | Diag(Loc, diag::err_omp_directive_before_requires) |
3280 | << "target" << getOpenMPClauseName(CNew->getClauseKind()); |
3281 | for (SourceLocation TargetLoc : TargetLocations) { |
3282 | Diag(TargetLoc, diag::note_omp_requires_encountered_directive) |
3283 | << "target"; |
3284 | } |
3285 | } else if (!AtomicLoc.isInvalid() && |
3286 | isa<OMPAtomicDefaultMemOrderClause>(CNew)) { |
3287 | Diag(Loc, diag::err_omp_directive_before_requires) |
3288 | << "atomic" << getOpenMPClauseName(CNew->getClauseKind()); |
3289 | Diag(AtomicLoc, diag::note_omp_requires_encountered_directive) |
3290 | << "atomic"; |
3291 | } |
3292 | } |
3293 | } |
3294 | |
3295 | if (!DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->hasDuplicateRequiresClause(ClauseList)) |
3296 | return OMPRequiresDecl::Create(Context, getCurLexicalContext(), Loc, |
3297 | ClauseList); |
3298 | return nullptr; |
3299 | } |
3300 | |
3301 | static void reportOriginalDsa(Sema &SemaRef, const DSAStackTy *Stack, |
3302 | const ValueDecl *D, |
3303 | const DSAStackTy::DSAVarData &DVar, |
3304 | bool IsLoopIterVar) { |
3305 | if (DVar.RefExpr) { |
3306 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
3307 | << getOpenMPClauseName(DVar.CKind); |
3308 | return; |
3309 | } |
3310 | enum { |
3311 | PDSA_StaticMemberShared, |
3312 | PDSA_StaticLocalVarShared, |
3313 | PDSA_LoopIterVarPrivate, |
3314 | PDSA_LoopIterVarLinear, |
3315 | PDSA_LoopIterVarLastprivate, |
3316 | PDSA_ConstVarShared, |
3317 | PDSA_GlobalVarShared, |
3318 | PDSA_TaskVarFirstprivate, |
3319 | PDSA_LocalVarPrivate, |
3320 | PDSA_Implicit |
3321 | } Reason = PDSA_Implicit; |
3322 | bool ReportHint = false; |
3323 | auto ReportLoc = D->getLocation(); |
3324 | auto *VD = dyn_cast<VarDecl>(D); |
3325 | if (IsLoopIterVar) { |
3326 | if (DVar.CKind == OMPC_private) |
3327 | Reason = PDSA_LoopIterVarPrivate; |
3328 | else if (DVar.CKind == OMPC_lastprivate) |
3329 | Reason = PDSA_LoopIterVarLastprivate; |
3330 | else |
3331 | Reason = PDSA_LoopIterVarLinear; |
3332 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
3333 | DVar.CKind == OMPC_firstprivate) { |
3334 | Reason = PDSA_TaskVarFirstprivate; |
3335 | ReportLoc = DVar.ImplicitDSALoc; |
3336 | } else if (VD && VD->isStaticLocal()) |
3337 | Reason = PDSA_StaticLocalVarShared; |
3338 | else if (VD && VD->isStaticDataMember()) |
3339 | Reason = PDSA_StaticMemberShared; |
3340 | else if (VD && VD->isFileVarDecl()) |
3341 | Reason = PDSA_GlobalVarShared; |
3342 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
3343 | Reason = PDSA_ConstVarShared; |
3344 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
3345 | ReportHint = true; |
3346 | Reason = PDSA_LocalVarPrivate; |
3347 | } |
3348 | if (Reason != PDSA_Implicit) { |
3349 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
3350 | << Reason << ReportHint |
3351 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
3352 | } else if (DVar.ImplicitDSALoc.isValid()) { |
3353 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
3354 | << getOpenMPClauseName(DVar.CKind); |
3355 | } |
3356 | } |
3357 | |
3358 | static OpenMPMapClauseKind |
3359 | getMapClauseKindFromModifier(OpenMPDefaultmapClauseModifier M, |
3360 | bool IsAggregateOrDeclareTarget) { |
3361 | OpenMPMapClauseKind Kind = OMPC_MAP_unknown; |
3362 | switch (M) { |
3363 | case OMPC_DEFAULTMAP_MODIFIER_alloc: |
3364 | Kind = OMPC_MAP_alloc; |
3365 | break; |
3366 | case OMPC_DEFAULTMAP_MODIFIER_to: |
3367 | Kind = OMPC_MAP_to; |
3368 | break; |
3369 | case OMPC_DEFAULTMAP_MODIFIER_from: |
3370 | Kind = OMPC_MAP_from; |
3371 | break; |
3372 | case OMPC_DEFAULTMAP_MODIFIER_tofrom: |
3373 | Kind = OMPC_MAP_tofrom; |
3374 | break; |
3375 | case OMPC_DEFAULTMAP_MODIFIER_present: |
3376 | // OpenMP 5.1 [2.21.7.3] defaultmap clause, Description] |
3377 | // If implicit-behavior is present, each variable referenced in the |
3378 | // construct in the category specified by variable-category is treated as if |
3379 | // it had been listed in a map clause with the map-type of alloc and |
3380 | // map-type-modifier of present. |
3381 | Kind = OMPC_MAP_alloc; |
3382 | break; |
3383 | case OMPC_DEFAULTMAP_MODIFIER_firstprivate: |
3384 | case OMPC_DEFAULTMAP_MODIFIER_last: |
3385 | llvm_unreachable("Unexpected defaultmap implicit behavior")::llvm::llvm_unreachable_internal("Unexpected defaultmap implicit behavior" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 3385); |
3386 | case OMPC_DEFAULTMAP_MODIFIER_none: |
3387 | case OMPC_DEFAULTMAP_MODIFIER_default: |
3388 | case OMPC_DEFAULTMAP_MODIFIER_unknown: |
3389 | // IsAggregateOrDeclareTarget could be true if: |
3390 | // 1. the implicit behavior for aggregate is tofrom |
3391 | // 2. it's a declare target link |
3392 | if (IsAggregateOrDeclareTarget) { |
3393 | Kind = OMPC_MAP_tofrom; |
3394 | break; |
3395 | } |
3396 | llvm_unreachable("Unexpected defaultmap implicit behavior")::llvm::llvm_unreachable_internal("Unexpected defaultmap implicit behavior" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 3396); |
3397 | } |
3398 | assert(Kind != OMPC_MAP_unknown && "Expect map kind to be known")((Kind != OMPC_MAP_unknown && "Expect map kind to be known" ) ? static_cast<void> (0) : __assert_fail ("Kind != OMPC_MAP_unknown && \"Expect map kind to be known\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 3398, __PRETTY_FUNCTION__)); |
3399 | return Kind; |
3400 | } |
3401 | |
3402 | namespace { |
3403 | class DSAAttrChecker final : public StmtVisitor<DSAAttrChecker, void> { |
3404 | DSAStackTy *Stack; |
3405 | Sema &SemaRef; |
3406 | bool ErrorFound = false; |
3407 | bool TryCaptureCXXThisMembers = false; |
3408 | CapturedStmt *CS = nullptr; |
3409 | const static unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1; |
3410 | llvm::SmallVector<Expr *, 4> ImplicitFirstprivate; |
3411 | llvm::SmallVector<Expr *, 4> ImplicitMap[DefaultmapKindNum][OMPC_MAP_delete]; |
3412 | llvm::SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers> |
3413 | ImplicitMapModifier[DefaultmapKindNum]; |
3414 | Sema::VarsWithInheritedDSAType VarsWithInheritedDSA; |
3415 | llvm::SmallDenseSet<const ValueDecl *, 4> ImplicitDeclarations; |
3416 | |
3417 | void VisitSubCaptures(OMPExecutableDirective *S) { |
3418 | // Check implicitly captured variables. |
3419 | if (!S->hasAssociatedStmt() || !S->getAssociatedStmt()) |
3420 | return; |
3421 | if (S->getDirectiveKind() == OMPD_atomic || |
3422 | S->getDirectiveKind() == OMPD_critical || |
3423 | S->getDirectiveKind() == OMPD_section || |
3424 | S->getDirectiveKind() == OMPD_master || |
3425 | isOpenMPLoopTransformationDirective(S->getDirectiveKind())) { |
3426 | Visit(S->getAssociatedStmt()); |
3427 | return; |
3428 | } |
3429 | visitSubCaptures(S->getInnermostCapturedStmt()); |
3430 | // Try to capture inner this->member references to generate correct mappings |
3431 | // and diagnostics. |
3432 | if (TryCaptureCXXThisMembers || |
3433 | (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) && |
3434 | llvm::any_of(S->getInnermostCapturedStmt()->captures(), |
3435 | [](const CapturedStmt::Capture &C) { |
3436 | return C.capturesThis(); |
3437 | }))) { |
3438 | bool SavedTryCaptureCXXThisMembers = TryCaptureCXXThisMembers; |
3439 | TryCaptureCXXThisMembers = true; |
3440 | Visit(S->getInnermostCapturedStmt()->getCapturedStmt()); |
3441 | TryCaptureCXXThisMembers = SavedTryCaptureCXXThisMembers; |
3442 | } |
3443 | // In tasks firstprivates are not captured anymore, need to analyze them |
3444 | // explicitly. |
3445 | if (isOpenMPTaskingDirective(S->getDirectiveKind()) && |
3446 | !isOpenMPTaskLoopDirective(S->getDirectiveKind())) { |
3447 | for (OMPClause *C : S->clauses()) |
3448 | if (auto *FC = dyn_cast<OMPFirstprivateClause>(C)) { |
3449 | for (Expr *Ref : FC->varlists()) |
3450 | Visit(Ref); |
3451 | } |
3452 | } |
3453 | } |
3454 | |
3455 | public: |
3456 | void VisitDeclRefExpr(DeclRefExpr *E) { |
3457 | if (TryCaptureCXXThisMembers || E->isTypeDependent() || |
3458 | E->isValueDependent() || E->containsUnexpandedParameterPack() || |
3459 | E->isInstantiationDependent()) |
3460 | return; |
3461 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
3462 | // Check the datasharing rules for the expressions in the clauses. |
3463 | if (!CS) { |
3464 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
3465 | if (!CED->hasAttr<OMPCaptureNoInitAttr>()) { |
3466 | Visit(CED->getInit()); |
3467 | return; |
3468 | } |
3469 | } else if (VD->isImplicit() || isa<OMPCapturedExprDecl>(VD)) |
3470 | // Do not analyze internal variables and do not enclose them into |
3471 | // implicit clauses. |
3472 | return; |
3473 | VD = VD->getCanonicalDecl(); |
3474 | // Skip internally declared variables. |
3475 | if (VD->hasLocalStorage() && CS && !CS->capturesVariable(VD) && |
3476 | !Stack->isImplicitTaskFirstprivate(VD)) |
3477 | return; |
3478 | // Skip allocators in uses_allocators clauses. |
3479 | if (Stack->isUsesAllocatorsDecl(VD).hasValue()) |
3480 | return; |
3481 | |
3482 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, /*FromParent=*/false); |
3483 | // Check if the variable has explicit DSA set and stop analysis if it so. |
3484 | if (DVar.RefExpr || !ImplicitDeclarations.insert(VD).second) |
3485 | return; |
3486 | |
3487 | // Skip internally declared static variables. |
3488 | llvm::Optional<OMPDeclareTargetDeclAttr::MapTypeTy> Res = |
3489 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD); |
3490 | if (VD->hasGlobalStorage() && CS && !CS->capturesVariable(VD) && |
3491 | (Stack->hasRequiresDeclWithClause<OMPUnifiedSharedMemoryClause>() || |
3492 | !Res || *Res != OMPDeclareTargetDeclAttr::MT_Link) && |
3493 | !Stack->isImplicitTaskFirstprivate(VD)) |
3494 | return; |
3495 | |
3496 | SourceLocation ELoc = E->getExprLoc(); |
3497 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
3498 | // The default(none) clause requires that each variable that is referenced |
3499 | // in the construct, and does not have a predetermined data-sharing |
3500 | // attribute, must have its data-sharing attribute explicitly determined |
3501 | // by being listed in a data-sharing attribute clause. |
3502 | if (DVar.CKind == OMPC_unknown && |
3503 | (Stack->getDefaultDSA() == DSA_none || |
3504 | Stack->getDefaultDSA() == DSA_firstprivate) && |
3505 | isImplicitOrExplicitTaskingRegion(DKind) && |
3506 | VarsWithInheritedDSA.count(VD) == 0) { |
3507 | bool InheritedDSA = Stack->getDefaultDSA() == DSA_none; |
3508 | if (!InheritedDSA && Stack->getDefaultDSA() == DSA_firstprivate) { |
3509 | DSAStackTy::DSAVarData DVar = |
3510 | Stack->getImplicitDSA(VD, /*FromParent=*/false); |
3511 | InheritedDSA = DVar.CKind == OMPC_unknown; |
3512 | } |
3513 | if (InheritedDSA) |
3514 | VarsWithInheritedDSA[VD] = E; |
3515 | return; |
3516 | } |
3517 | |
3518 | // OpenMP 5.0 [2.19.7.2, defaultmap clause, Description] |
3519 | // If implicit-behavior is none, each variable referenced in the |
3520 | // construct that does not have a predetermined data-sharing attribute |
3521 | // and does not appear in a to or link clause on a declare target |
3522 | // directive must be listed in a data-mapping attribute clause, a |
3523 | // data-haring attribute clause (including a data-sharing attribute |
3524 | // clause on a combined construct where target. is one of the |
3525 | // constituent constructs), or an is_device_ptr clause. |
3526 | OpenMPDefaultmapClauseKind ClauseKind = |
3527 | getVariableCategoryFromDecl(SemaRef.getLangOpts(), VD); |
3528 | if (SemaRef.getLangOpts().OpenMP >= 50) { |
3529 | bool IsModifierNone = Stack->getDefaultmapModifier(ClauseKind) == |
3530 | OMPC_DEFAULTMAP_MODIFIER_none; |
3531 | if (DVar.CKind == OMPC_unknown && IsModifierNone && |
3532 | VarsWithInheritedDSA.count(VD) == 0 && !Res) { |
3533 | // Only check for data-mapping attribute and is_device_ptr here |
3534 | // since we have already make sure that the declaration does not |
3535 | // have a data-sharing attribute above |
3536 | if (!Stack->checkMappableExprComponentListsForDecl( |
3537 | VD, /*CurrentRegionOnly=*/true, |
3538 | [VD](OMPClauseMappableExprCommon::MappableExprComponentListRef |
3539 | MapExprComponents, |
3540 | OpenMPClauseKind) { |
3541 | auto MI = MapExprComponents.rbegin(); |
3542 | auto ME = MapExprComponents.rend(); |
3543 | return MI != ME && MI->getAssociatedDeclaration() == VD; |
3544 | })) { |
3545 | VarsWithInheritedDSA[VD] = E; |
3546 | return; |
3547 | } |
3548 | } |
3549 | } |
3550 | if (SemaRef.getLangOpts().OpenMP > 50) { |
3551 | bool IsModifierPresent = Stack->getDefaultmapModifier(ClauseKind) == |
3552 | OMPC_DEFAULTMAP_MODIFIER_present; |
3553 | if (IsModifierPresent) { |
3554 | if (llvm::find(ImplicitMapModifier[ClauseKind], |
3555 | OMPC_MAP_MODIFIER_present) == |
3556 | std::end(ImplicitMapModifier[ClauseKind])) { |
3557 | ImplicitMapModifier[ClauseKind].push_back( |
3558 | OMPC_MAP_MODIFIER_present); |
3559 | } |
3560 | } |
3561 | } |
3562 | |
3563 | if (isOpenMPTargetExecutionDirective(DKind) && |
3564 | !Stack->isLoopControlVariable(VD).first) { |
3565 | if (!Stack->checkMappableExprComponentListsForDecl( |
3566 | VD, /*CurrentRegionOnly=*/true, |
3567 | [this](OMPClauseMappableExprCommon::MappableExprComponentListRef |
3568 | StackComponents, |
3569 | OpenMPClauseKind) { |
3570 | if (SemaRef.LangOpts.OpenMP >= 50) |
3571 | return !StackComponents.empty(); |
3572 | // Variable is used if it has been marked as an array, array |
3573 | // section, array shaping or the variable iself. |
3574 | return StackComponents.size() == 1 || |
3575 | std::all_of( |
3576 | std::next(StackComponents.rbegin()), |
3577 | StackComponents.rend(), |
3578 | [](const OMPClauseMappableExprCommon:: |
3579 | MappableComponent &MC) { |
3580 | return MC.getAssociatedDeclaration() == |
3581 | nullptr && |
3582 | (isa<OMPArraySectionExpr>( |
3583 | MC.getAssociatedExpression()) || |
3584 | isa<OMPArrayShapingExpr>( |
3585 | MC.getAssociatedExpression()) || |
3586 | isa<ArraySubscriptExpr>( |
3587 | MC.getAssociatedExpression())); |
3588 | }); |
3589 | })) { |
3590 | bool IsFirstprivate = false; |
3591 | // By default lambdas are captured as firstprivates. |
3592 | if (const auto *RD = |
3593 | VD->getType().getNonReferenceType()->getAsCXXRecordDecl()) |
3594 | IsFirstprivate = RD->isLambda(); |
3595 | IsFirstprivate = |
3596 | IsFirstprivate || (Stack->mustBeFirstprivate(ClauseKind) && !Res); |
3597 | if (IsFirstprivate) { |
3598 | ImplicitFirstprivate.emplace_back(E); |
3599 | } else { |
3600 | OpenMPDefaultmapClauseModifier M = |
3601 | Stack->getDefaultmapModifier(ClauseKind); |
3602 | OpenMPMapClauseKind Kind = getMapClauseKindFromModifier( |
3603 | M, ClauseKind == OMPC_DEFAULTMAP_aggregate || Res); |
3604 | ImplicitMap[ClauseKind][Kind].emplace_back(E); |
3605 | } |
3606 | return; |
3607 | } |
3608 | } |
3609 | |
3610 | // OpenMP [2.9.3.6, Restrictions, p.2] |
3611 | // A list item that appears in a reduction clause of the innermost |
3612 | // enclosing worksharing or parallel construct may not be accessed in an |
3613 | // explicit task. |
3614 | DVar = Stack->hasInnermostDSA( |
3615 | VD, |
3616 | [](OpenMPClauseKind C, bool AppliedToPointee) { |
3617 | return C == OMPC_reduction && !AppliedToPointee; |
3618 | }, |
3619 | [](OpenMPDirectiveKind K) { |
3620 | return isOpenMPParallelDirective(K) || |
3621 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
3622 | }, |
3623 | /*FromParent=*/true); |
3624 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
3625 | ErrorFound = true; |
3626 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
3627 | reportOriginalDsa(SemaRef, Stack, VD, DVar); |
3628 | return; |
3629 | } |
3630 | |
3631 | // Define implicit data-sharing attributes for task. |
3632 | DVar = Stack->getImplicitDSA(VD, /*FromParent=*/false); |
3633 | if (((isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared) || |
3634 | (Stack->getDefaultDSA() == DSA_firstprivate && |
3635 | DVar.CKind == OMPC_firstprivate && !DVar.RefExpr)) && |
3636 | !Stack->isLoopControlVariable(VD).first) { |
3637 | ImplicitFirstprivate.push_back(E); |
3638 | return; |
3639 | } |
3640 | |
3641 | // Store implicitly used globals with declare target link for parent |
3642 | // target. |
3643 | if (!isOpenMPTargetExecutionDirective(DKind) && Res && |
3644 | *Res == OMPDeclareTargetDeclAttr::MT_Link) { |
3645 | Stack->addToParentTargetRegionLinkGlobals(E); |
3646 | return; |
3647 | } |
3648 | } |
3649 | } |
3650 | void VisitMemberExpr(MemberExpr *E) { |
3651 | if (E->isTypeDependent() || E->isValueDependent() || |
3652 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
3653 | return; |
3654 | auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl()); |
3655 | OpenMPDirectiveKind DKind = Stack->getCurrentDirective(); |
3656 | if (auto *TE = dyn_cast<CXXThisExpr>(E->getBase()->IgnoreParenCasts())) { |
3657 | if (!FD) |
3658 | return; |
3659 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(FD, /*FromParent=*/false); |
3660 | // Check if the variable has explicit DSA set and stop analysis if it |
3661 | // so. |
3662 | if (DVar.RefExpr || !ImplicitDeclarations.insert(FD).second) |
3663 | return; |
3664 | |
3665 | if (isOpenMPTargetExecutionDirective(DKind) && |
3666 | !Stack->isLoopControlVariable(FD).first && |
3667 | !Stack->checkMappableExprComponentListsForDecl( |
3668 | FD, /*CurrentRegionOnly=*/true, |
3669 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef |
3670 | StackComponents, |
3671 | OpenMPClauseKind) { |
3672 | return isa<CXXThisExpr>( |
3673 | cast<MemberExpr>( |
3674 | StackComponents.back().getAssociatedExpression()) |
3675 | ->getBase() |
3676 | ->IgnoreParens()); |
3677 | })) { |
3678 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
3679 | // A bit-field cannot appear in a map clause. |
3680 | // |
3681 | if (FD->isBitField()) |
3682 | return; |
3683 | |
3684 | // Check to see if the member expression is referencing a class that |
3685 | // has already been explicitly mapped |
3686 | if (Stack->isClassPreviouslyMapped(TE->getType())) |
3687 | return; |
3688 | |
3689 | OpenMPDefaultmapClauseModifier Modifier = |
3690 | Stack->getDefaultmapModifier(OMPC_DEFAULTMAP_aggregate); |
3691 | OpenMPDefaultmapClauseKind ClauseKind = |
3692 | getVariableCategoryFromDecl(SemaRef.getLangOpts(), FD); |
3693 | OpenMPMapClauseKind Kind = getMapClauseKindFromModifier( |
3694 | Modifier, /*IsAggregateOrDeclareTarget*/ true); |
3695 | ImplicitMap[ClauseKind][Kind].emplace_back(E); |
3696 | return; |
3697 | } |
3698 | |
3699 | SourceLocation ELoc = E->getExprLoc(); |
3700 | // OpenMP [2.9.3.6, Restrictions, p.2] |
3701 | // A list item that appears in a reduction clause of the innermost |
3702 | // enclosing worksharing or parallel construct may not be accessed in |
3703 | // an explicit task. |
3704 | DVar = Stack->hasInnermostDSA( |
3705 | FD, |
3706 | [](OpenMPClauseKind C, bool AppliedToPointee) { |
3707 | return C == OMPC_reduction && !AppliedToPointee; |
3708 | }, |
3709 | [](OpenMPDirectiveKind K) { |
3710 | return isOpenMPParallelDirective(K) || |
3711 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
3712 | }, |
3713 | /*FromParent=*/true); |
3714 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
3715 | ErrorFound = true; |
3716 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
3717 | reportOriginalDsa(SemaRef, Stack, FD, DVar); |
3718 | return; |
3719 | } |
3720 | |
3721 | // Define implicit data-sharing attributes for task. |
3722 | DVar = Stack->getImplicitDSA(FD, /*FromParent=*/false); |
3723 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
3724 | !Stack->isLoopControlVariable(FD).first) { |
3725 | // Check if there is a captured expression for the current field in the |
3726 | // region. Do not mark it as firstprivate unless there is no captured |
3727 | // expression. |
3728 | // TODO: try to make it firstprivate. |
3729 | if (DVar.CKind != OMPC_unknown) |
3730 | ImplicitFirstprivate.push_back(E); |
3731 | } |
3732 | return; |
3733 | } |
3734 | if (isOpenMPTargetExecutionDirective(DKind)) { |
3735 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
3736 | if (!checkMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map, |
3737 | Stack->getCurrentDirective(), |
3738 | /*NoDiagnose=*/true)) |
3739 | return; |
3740 | const auto *VD = cast<ValueDecl>( |
3741 | CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl()); |
3742 | if (!Stack->checkMappableExprComponentListsForDecl( |
3743 | VD, /*CurrentRegionOnly=*/true, |
3744 | [&CurComponents]( |
3745 | OMPClauseMappableExprCommon::MappableExprComponentListRef |
3746 | StackComponents, |
3747 | OpenMPClauseKind) { |
3748 | auto CCI = CurComponents.rbegin(); |
3749 | auto CCE = CurComponents.rend(); |
3750 | for (const auto &SC : llvm::reverse(StackComponents)) { |
3751 | // Do both expressions have the same kind? |
3752 | if (CCI->getAssociatedExpression()->getStmtClass() != |
3753 | SC.getAssociatedExpression()->getStmtClass()) |
3754 | if (!((isa<OMPArraySectionExpr>( |
3755 | SC.getAssociatedExpression()) || |
3756 | isa<OMPArrayShapingExpr>( |
3757 | SC.getAssociatedExpression())) && |
3758 | isa<ArraySubscriptExpr>( |
3759 | CCI->getAssociatedExpression()))) |
3760 | return false; |
3761 | |
3762 | const Decl *CCD = CCI->getAssociatedDeclaration(); |
3763 | const Decl *SCD = SC.getAssociatedDeclaration(); |
3764 | CCD = CCD ? CCD->getCanonicalDecl() : nullptr; |
3765 | SCD = SCD ? SCD->getCanonicalDecl() : nullptr; |
3766 | if (SCD != CCD) |
3767 | return false; |
3768 | std::advance(CCI, 1); |
3769 | if (CCI == CCE) |
3770 | break; |
3771 | } |
3772 | return true; |
3773 | })) { |
3774 | Visit(E->getBase()); |
3775 | } |
3776 | } else if (!TryCaptureCXXThisMembers) { |
3777 | Visit(E->getBase()); |
3778 | } |
3779 | } |
3780 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
3781 | for (OMPClause *C : S->clauses()) { |
3782 | // Skip analysis of arguments of implicitly defined firstprivate clause |
3783 | // for task|target directives. |
3784 | // Skip analysis of arguments of implicitly defined map clause for target |
3785 | // directives. |
3786 | if (C && !((isa<OMPFirstprivateClause>(C) || isa<OMPMapClause>(C)) && |
3787 | C->isImplicit() && |
3788 | !isOpenMPTaskingDirective(Stack->getCurrentDirective()))) { |
3789 | for (Stmt *CC : C->children()) { |
3790 | if (CC) |
3791 | Visit(CC); |
3792 | } |
3793 | } |
3794 | } |
3795 | // Check implicitly captured variables. |
3796 | VisitSubCaptures(S); |
3797 | } |
3798 | |
3799 | void VisitOMPTileDirective(OMPTileDirective *S) { |
3800 | // #pragma omp tile does not introduce data sharing. |
3801 | VisitStmt(S); |
3802 | } |
3803 | |
3804 | void VisitStmt(Stmt *S) { |
3805 | for (Stmt *C : S->children()) { |
3806 | if (C) { |
3807 | // Check implicitly captured variables in the task-based directives to |
3808 | // check if they must be firstprivatized. |
3809 | Visit(C); |
3810 | } |
3811 | } |
3812 | } |
3813 | |
3814 | void visitSubCaptures(CapturedStmt *S) { |
3815 | for (const CapturedStmt::Capture &Cap : S->captures()) { |
3816 | if (!Cap.capturesVariable() && !Cap.capturesVariableByCopy()) |
3817 | continue; |
3818 | VarDecl *VD = Cap.getCapturedVar(); |
3819 | // Do not try to map the variable if it or its sub-component was mapped |
3820 | // already. |
3821 | if (isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) && |
3822 | Stack->checkMappableExprComponentListsForDecl( |
3823 | VD, /*CurrentRegionOnly=*/true, |
3824 | [](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
3825 | OpenMPClauseKind) { return true; })) |
3826 | continue; |
3827 | DeclRefExpr *DRE = buildDeclRefExpr( |
3828 | SemaRef, VD, VD->getType().getNonLValueExprType(SemaRef.Context), |
3829 | Cap.getLocation(), /*RefersToCapture=*/true); |
3830 | Visit(DRE); |
3831 | } |
3832 | } |
3833 | bool isErrorFound() const { return ErrorFound; } |
3834 | ArrayRef<Expr *> getImplicitFirstprivate() const { |
3835 | return ImplicitFirstprivate; |
3836 | } |
3837 | ArrayRef<Expr *> getImplicitMap(OpenMPDefaultmapClauseKind DK, |
3838 | OpenMPMapClauseKind MK) const { |
3839 | return ImplicitMap[DK][MK]; |
3840 | } |
3841 | ArrayRef<OpenMPMapModifierKind> |
3842 | getImplicitMapModifier(OpenMPDefaultmapClauseKind Kind) const { |
3843 | return ImplicitMapModifier[Kind]; |
3844 | } |
3845 | const Sema::VarsWithInheritedDSAType &getVarsWithInheritedDSA() const { |
3846 | return VarsWithInheritedDSA; |
3847 | } |
3848 | |
3849 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
3850 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) { |
3851 | // Process declare target link variables for the target directives. |
3852 | if (isOpenMPTargetExecutionDirective(S->getCurrentDirective())) { |
3853 | for (DeclRefExpr *E : Stack->getLinkGlobals()) |
3854 | Visit(E); |
3855 | } |
3856 | } |
3857 | }; |
3858 | } // namespace |
3859 | |
3860 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
3861 | switch (DKind) { |
3862 | case OMPD_parallel: |
3863 | case OMPD_parallel_for: |
3864 | case OMPD_parallel_for_simd: |
3865 | case OMPD_parallel_sections: |
3866 | case OMPD_parallel_master: |
3867 | case OMPD_teams: |
3868 | case OMPD_teams_distribute: |
3869 | case OMPD_teams_distribute_simd: { |
3870 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
3871 | QualType KmpInt32PtrTy = |
3872 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
3873 | Sema::CapturedParamNameType Params[] = { |
3874 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
3875 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
3876 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
3877 | }; |
3878 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
3879 | Params); |
3880 | break; |
3881 | } |
3882 | case OMPD_target_teams: |
3883 | case OMPD_target_parallel: |
3884 | case OMPD_target_parallel_for: |
3885 | case OMPD_target_parallel_for_simd: |
3886 | case OMPD_target_teams_distribute: |
3887 | case OMPD_target_teams_distribute_simd: { |
3888 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
3889 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
3890 | QualType KmpInt32PtrTy = |
3891 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
3892 | QualType Args[] = {VoidPtrTy}; |
3893 | FunctionProtoType::ExtProtoInfo EPI; |
3894 | EPI.Variadic = true; |
3895 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
3896 | Sema::CapturedParamNameType Params[] = { |
3897 | std::make_pair(".global_tid.", KmpInt32Ty), |
3898 | std::make_pair(".part_id.", KmpInt32PtrTy), |
3899 | std::make_pair(".privates.", VoidPtrTy), |
3900 | std::make_pair( |
3901 | ".copy_fn.", |
3902 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
3903 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
3904 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
3905 | }; |
3906 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
3907 | Params, /*OpenMPCaptureLevel=*/0); |
3908 | // Mark this captured region as inlined, because we don't use outlined |
3909 | // function directly. |
3910 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
3911 | AlwaysInlineAttr::CreateImplicit( |
3912 | Context, {}, AttributeCommonInfo::AS_Keyword, |
3913 | AlwaysInlineAttr::Keyword_forceinline)); |
3914 | Sema::CapturedParamNameType ParamsTarget[] = { |
3915 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
3916 | }; |
3917 | // Start a captured region for 'target' with no implicit parameters. |
3918 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
3919 | ParamsTarget, /*OpenMPCaptureLevel=*/1); |
3920 | Sema::CapturedParamNameType ParamsTeamsOrParallel[] = { |
3921 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
3922 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
3923 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
3924 | }; |
3925 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
3926 | // the same implicit parameters. |
3927 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
3928 | ParamsTeamsOrParallel, /*OpenMPCaptureLevel=*/2); |
3929 | break; |
3930 | } |
3931 | case OMPD_target: |
3932 | case OMPD_target_simd: { |
3933 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
3934 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
3935 | QualType KmpInt32PtrTy = |
3936 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
3937 | QualType Args[] = {VoidPtrTy}; |
3938 | FunctionProtoType::ExtProtoInfo EPI; |
3939 | EPI.Variadic = true; |
3940 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
3941 | Sema::CapturedParamNameType Params[] = { |
3942 | std::make_pair(".global_tid.", KmpInt32Ty), |
3943 | std::make_pair(".part_id.", KmpInt32PtrTy), |
3944 | std::make_pair(".privates.", VoidPtrTy), |
3945 | std::make_pair( |
3946 | ".copy_fn.", |
3947 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
3948 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
3949 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
3950 | }; |
3951 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
3952 | Params, /*OpenMPCaptureLevel=*/0); |
3953 | // Mark this captured region as inlined, because we don't use outlined |
3954 | // function directly. |
3955 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
3956 | AlwaysInlineAttr::CreateImplicit( |
3957 | Context, {}, AttributeCommonInfo::AS_Keyword, |
3958 | AlwaysInlineAttr::Keyword_forceinline)); |
3959 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
3960 | std::make_pair(StringRef(), QualType()), |
3961 | /*OpenMPCaptureLevel=*/1); |
3962 | break; |
3963 | } |
3964 | case OMPD_atomic: |
3965 | case OMPD_critical: |
3966 | case OMPD_section: |
3967 | case OMPD_master: |
3968 | case OMPD_tile: |
3969 | break; |
3970 | case OMPD_simd: |
3971 | case OMPD_for: |
3972 | case OMPD_for_simd: |
3973 | case OMPD_sections: |
3974 | case OMPD_single: |
3975 | case OMPD_taskgroup: |
3976 | case OMPD_distribute: |
3977 | case OMPD_distribute_simd: |
3978 | case OMPD_ordered: |
3979 | case OMPD_target_data: { |
3980 | Sema::CapturedParamNameType Params[] = { |
3981 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
3982 | }; |
3983 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
3984 | Params); |
3985 | break; |
3986 | } |
3987 | case OMPD_task: { |
3988 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
3989 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
3990 | QualType KmpInt32PtrTy = |
3991 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
3992 | QualType Args[] = {VoidPtrTy}; |
3993 | FunctionProtoType::ExtProtoInfo EPI; |
3994 | EPI.Variadic = true; |
3995 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
3996 | Sema::CapturedParamNameType Params[] = { |
3997 | std::make_pair(".global_tid.", KmpInt32Ty), |
3998 | std::make_pair(".part_id.", KmpInt32PtrTy), |
3999 | std::make_pair(".privates.", VoidPtrTy), |
4000 | std::make_pair( |
4001 | ".copy_fn.", |
4002 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
4003 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
4004 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4005 | }; |
4006 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4007 | Params); |
4008 | // Mark this captured region as inlined, because we don't use outlined |
4009 | // function directly. |
4010 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
4011 | AlwaysInlineAttr::CreateImplicit( |
4012 | Context, {}, AttributeCommonInfo::AS_Keyword, |
4013 | AlwaysInlineAttr::Keyword_forceinline)); |
4014 | break; |
4015 | } |
4016 | case OMPD_taskloop: |
4017 | case OMPD_taskloop_simd: |
4018 | case OMPD_master_taskloop: |
4019 | case OMPD_master_taskloop_simd: { |
4020 | QualType KmpInt32Ty = |
4021 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1) |
4022 | .withConst(); |
4023 | QualType KmpUInt64Ty = |
4024 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0) |
4025 | .withConst(); |
4026 | QualType KmpInt64Ty = |
4027 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1) |
4028 | .withConst(); |
4029 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
4030 | QualType KmpInt32PtrTy = |
4031 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
4032 | QualType Args[] = {VoidPtrTy}; |
4033 | FunctionProtoType::ExtProtoInfo EPI; |
4034 | EPI.Variadic = true; |
4035 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
4036 | Sema::CapturedParamNameType Params[] = { |
4037 | std::make_pair(".global_tid.", KmpInt32Ty), |
4038 | std::make_pair(".part_id.", KmpInt32PtrTy), |
4039 | std::make_pair(".privates.", VoidPtrTy), |
4040 | std::make_pair( |
4041 | ".copy_fn.", |
4042 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
4043 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
4044 | std::make_pair(".lb.", KmpUInt64Ty), |
4045 | std::make_pair(".ub.", KmpUInt64Ty), |
4046 | std::make_pair(".st.", KmpInt64Ty), |
4047 | std::make_pair(".liter.", KmpInt32Ty), |
4048 | std::make_pair(".reductions.", VoidPtrTy), |
4049 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4050 | }; |
4051 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4052 | Params); |
4053 | // Mark this captured region as inlined, because we don't use outlined |
4054 | // function directly. |
4055 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
4056 | AlwaysInlineAttr::CreateImplicit( |
4057 | Context, {}, AttributeCommonInfo::AS_Keyword, |
4058 | AlwaysInlineAttr::Keyword_forceinline)); |
4059 | break; |
4060 | } |
4061 | case OMPD_parallel_master_taskloop: |
4062 | case OMPD_parallel_master_taskloop_simd: { |
4063 | QualType KmpInt32Ty = |
4064 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1) |
4065 | .withConst(); |
4066 | QualType KmpUInt64Ty = |
4067 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0) |
4068 | .withConst(); |
4069 | QualType KmpInt64Ty = |
4070 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1) |
4071 | .withConst(); |
4072 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
4073 | QualType KmpInt32PtrTy = |
4074 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
4075 | Sema::CapturedParamNameType ParamsParallel[] = { |
4076 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
4077 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
4078 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4079 | }; |
4080 | // Start a captured region for 'parallel'. |
4081 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4082 | ParamsParallel, /*OpenMPCaptureLevel=*/0); |
4083 | QualType Args[] = {VoidPtrTy}; |
4084 | FunctionProtoType::ExtProtoInfo EPI; |
4085 | EPI.Variadic = true; |
4086 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
4087 | Sema::CapturedParamNameType Params[] = { |
4088 | std::make_pair(".global_tid.", KmpInt32Ty), |
4089 | std::make_pair(".part_id.", KmpInt32PtrTy), |
4090 | std::make_pair(".privates.", VoidPtrTy), |
4091 | std::make_pair( |
4092 | ".copy_fn.", |
4093 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
4094 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
4095 | std::make_pair(".lb.", KmpUInt64Ty), |
4096 | std::make_pair(".ub.", KmpUInt64Ty), |
4097 | std::make_pair(".st.", KmpInt64Ty), |
4098 | std::make_pair(".liter.", KmpInt32Ty), |
4099 | std::make_pair(".reductions.", VoidPtrTy), |
4100 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4101 | }; |
4102 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4103 | Params, /*OpenMPCaptureLevel=*/1); |
4104 | // Mark this captured region as inlined, because we don't use outlined |
4105 | // function directly. |
4106 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
4107 | AlwaysInlineAttr::CreateImplicit( |
4108 | Context, {}, AttributeCommonInfo::AS_Keyword, |
4109 | AlwaysInlineAttr::Keyword_forceinline)); |
4110 | break; |
4111 | } |
4112 | case OMPD_distribute_parallel_for_simd: |
4113 | case OMPD_distribute_parallel_for: { |
4114 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
4115 | QualType KmpInt32PtrTy = |
4116 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
4117 | Sema::CapturedParamNameType Params[] = { |
4118 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
4119 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
4120 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
4121 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
4122 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4123 | }; |
4124 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4125 | Params); |
4126 | break; |
4127 | } |
4128 | case OMPD_target_teams_distribute_parallel_for: |
4129 | case OMPD_target_teams_distribute_parallel_for_simd: { |
4130 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
4131 | QualType KmpInt32PtrTy = |
4132 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
4133 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
4134 | |
4135 | QualType Args[] = {VoidPtrTy}; |
4136 | FunctionProtoType::ExtProtoInfo EPI; |
4137 | EPI.Variadic = true; |
4138 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
4139 | Sema::CapturedParamNameType Params[] = { |
4140 | std::make_pair(".global_tid.", KmpInt32Ty), |
4141 | std::make_pair(".part_id.", KmpInt32PtrTy), |
4142 | std::make_pair(".privates.", VoidPtrTy), |
4143 | std::make_pair( |
4144 | ".copy_fn.", |
4145 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
4146 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
4147 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4148 | }; |
4149 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4150 | Params, /*OpenMPCaptureLevel=*/0); |
4151 | // Mark this captured region as inlined, because we don't use outlined |
4152 | // function directly. |
4153 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
4154 | AlwaysInlineAttr::CreateImplicit( |
4155 | Context, {}, AttributeCommonInfo::AS_Keyword, |
4156 | AlwaysInlineAttr::Keyword_forceinline)); |
4157 | Sema::CapturedParamNameType ParamsTarget[] = { |
4158 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4159 | }; |
4160 | // Start a captured region for 'target' with no implicit parameters. |
4161 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4162 | ParamsTarget, /*OpenMPCaptureLevel=*/1); |
4163 | |
4164 | Sema::CapturedParamNameType ParamsTeams[] = { |
4165 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
4166 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
4167 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4168 | }; |
4169 | // Start a captured region for 'target' with no implicit parameters. |
4170 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4171 | ParamsTeams, /*OpenMPCaptureLevel=*/2); |
4172 | |
4173 | Sema::CapturedParamNameType ParamsParallel[] = { |
4174 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
4175 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
4176 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
4177 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
4178 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4179 | }; |
4180 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
4181 | // the same implicit parameters. |
4182 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4183 | ParamsParallel, /*OpenMPCaptureLevel=*/3); |
4184 | break; |
4185 | } |
4186 | |
4187 | case OMPD_teams_distribute_parallel_for: |
4188 | case OMPD_teams_distribute_parallel_for_simd: { |
4189 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
4190 | QualType KmpInt32PtrTy = |
4191 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
4192 | |
4193 | Sema::CapturedParamNameType ParamsTeams[] = { |
4194 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
4195 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
4196 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4197 | }; |
4198 | // Start a captured region for 'target' with no implicit parameters. |
4199 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4200 | ParamsTeams, /*OpenMPCaptureLevel=*/0); |
4201 | |
4202 | Sema::CapturedParamNameType ParamsParallel[] = { |
4203 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
4204 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
4205 | std::make_pair(".previous.lb.", Context.getSizeType().withConst()), |
4206 | std::make_pair(".previous.ub.", Context.getSizeType().withConst()), |
4207 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4208 | }; |
4209 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
4210 | // the same implicit parameters. |
4211 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4212 | ParamsParallel, /*OpenMPCaptureLevel=*/1); |
4213 | break; |
4214 | } |
4215 | case OMPD_target_update: |
4216 | case OMPD_target_enter_data: |
4217 | case OMPD_target_exit_data: { |
4218 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1).withConst(); |
4219 | QualType VoidPtrTy = Context.VoidPtrTy.withConst().withRestrict(); |
4220 | QualType KmpInt32PtrTy = |
4221 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
4222 | QualType Args[] = {VoidPtrTy}; |
4223 | FunctionProtoType::ExtProtoInfo EPI; |
4224 | EPI.Variadic = true; |
4225 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
4226 | Sema::CapturedParamNameType Params[] = { |
4227 | std::make_pair(".global_tid.", KmpInt32Ty), |
4228 | std::make_pair(".part_id.", KmpInt32PtrTy), |
4229 | std::make_pair(".privates.", VoidPtrTy), |
4230 | std::make_pair( |
4231 | ".copy_fn.", |
4232 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
4233 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
4234 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
4235 | }; |
4236 | ActOnCapturedRegionStart(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getConstructLoc(), CurScope, CR_OpenMP, |
4237 | Params); |
4238 | // Mark this captured region as inlined, because we don't use outlined |
4239 | // function directly. |
4240 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
4241 | AlwaysInlineAttr::CreateImplicit( |
4242 | Context, {}, AttributeCommonInfo::AS_Keyword, |
4243 | AlwaysInlineAttr::Keyword_forceinline)); |
4244 | break; |
4245 | } |
4246 | case OMPD_threadprivate: |
4247 | case OMPD_allocate: |
4248 | case OMPD_taskyield: |
4249 | case OMPD_barrier: |
4250 | case OMPD_taskwait: |
4251 | case OMPD_cancellation_point: |
4252 | case OMPD_cancel: |
4253 | case OMPD_flush: |
4254 | case OMPD_depobj: |
4255 | case OMPD_scan: |
4256 | case OMPD_declare_reduction: |
4257 | case OMPD_declare_mapper: |
4258 | case OMPD_declare_simd: |
4259 | case OMPD_declare_target: |
4260 | case OMPD_end_declare_target: |
4261 | case OMPD_requires: |
4262 | case OMPD_declare_variant: |
4263 | case OMPD_begin_declare_variant: |
4264 | case OMPD_end_declare_variant: |
4265 | llvm_unreachable("OpenMP Directive is not allowed")::llvm::llvm_unreachable_internal("OpenMP Directive is not allowed" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 4265); |
4266 | case OMPD_unknown: |
4267 | default: |
4268 | llvm_unreachable("Unknown OpenMP directive")::llvm::llvm_unreachable_internal("Unknown OpenMP directive", "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 4268); |
4269 | } |
4270 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setContext(CurContext); |
4271 | } |
4272 | |
4273 | int Sema::getNumberOfConstructScopes(unsigned Level) const { |
4274 | return getOpenMPCaptureLevels(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getDirective(Level)); |
4275 | } |
4276 | |
4277 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
4278 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
4279 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
4280 | return CaptureRegions.size(); |
4281 | } |
4282 | |
4283 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
4284 | Expr *CaptureExpr, bool WithInit, |
4285 | bool AsExpression) { |
4286 | assert(CaptureExpr)((CaptureExpr) ? static_cast<void> (0) : __assert_fail ( "CaptureExpr", "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 4286, __PRETTY_FUNCTION__)); |
4287 | ASTContext &C = S.getASTContext(); |
4288 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
4289 | QualType Ty = Init->getType(); |
4290 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
4291 | if (S.getLangOpts().CPlusPlus) { |
4292 | Ty = C.getLValueReferenceType(Ty); |
4293 | } else { |
4294 | Ty = C.getPointerType(Ty); |
4295 | ExprResult Res = |
4296 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
4297 | if (!Res.isUsable()) |
4298 | return nullptr; |
4299 | Init = Res.get(); |
4300 | } |
4301 | WithInit = true; |
4302 | } |
4303 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
4304 | CaptureExpr->getBeginLoc()); |
4305 | if (!WithInit) |
4306 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C)); |
4307 | S.CurContext->addHiddenDecl(CED); |
4308 | Sema::TentativeAnalysisScope Trap(S); |
4309 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
4310 | return CED; |
4311 | } |
4312 | |
4313 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
4314 | bool WithInit) { |
4315 | OMPCapturedExprDecl *CD; |
4316 | if (VarDecl *VD = S.isOpenMPCapturedDecl(D)) |
4317 | CD = cast<OMPCapturedExprDecl>(VD); |
4318 | else |
4319 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
4320 | /*AsExpression=*/false); |
4321 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
4322 | CaptureExpr->getExprLoc()); |
4323 | } |
4324 | |
4325 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
4326 | CaptureExpr = S.DefaultLvalueConversion(CaptureExpr).get(); |
4327 | if (!Ref) { |
4328 | OMPCapturedExprDecl *CD = buildCaptureDecl( |
4329 | S, &S.getASTContext().Idents.get(".capture_expr."), CaptureExpr, |
4330 | /*WithInit=*/true, /*AsExpression=*/true); |
4331 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
4332 | CaptureExpr->getExprLoc()); |
4333 | } |
4334 | ExprResult Res = Ref; |
4335 | if (!S.getLangOpts().CPlusPlus && |
4336 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
4337 | Ref->getType()->isPointerType()) { |
4338 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
4339 | if (!Res.isUsable()) |
4340 | return ExprError(); |
4341 | } |
4342 | return S.DefaultLvalueConversion(Res.get()); |
4343 | } |
4344 | |
4345 | namespace { |
4346 | // OpenMP directives parsed in this section are represented as a |
4347 | // CapturedStatement with an associated statement. If a syntax error |
4348 | // is detected during the parsing of the associated statement, the |
4349 | // compiler must abort processing and close the CapturedStatement. |
4350 | // |
4351 | // Combined directives such as 'target parallel' have more than one |
4352 | // nested CapturedStatements. This RAII ensures that we unwind out |
4353 | // of all the nested CapturedStatements when an error is found. |
4354 | class CaptureRegionUnwinderRAII { |
4355 | private: |
4356 | Sema &S; |
4357 | bool &ErrorFound; |
4358 | OpenMPDirectiveKind DKind = OMPD_unknown; |
4359 | |
4360 | public: |
4361 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
4362 | OpenMPDirectiveKind DKind) |
4363 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
4364 | ~CaptureRegionUnwinderRAII() { |
4365 | if (ErrorFound) { |
4366 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
4367 | while (--ThisCaptureLevel >= 0) |
4368 | S.ActOnCapturedRegionError(); |
4369 | } |
4370 | } |
4371 | }; |
4372 | } // namespace |
4373 | |
4374 | void Sema::tryCaptureOpenMPLambdas(ValueDecl *V) { |
4375 | // Capture variables captured by reference in lambdas for target-based |
4376 | // directives. |
4377 | if (!CurContext->isDependentContext() && |
4378 | (isOpenMPTargetExecutionDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()) || |
4379 | isOpenMPTargetDataManagementDirective( |
4380 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()))) { |
4381 | QualType Type = V->getType(); |
4382 | if (const auto *RD = Type.getCanonicalType() |
4383 | .getNonReferenceType() |
4384 | ->getAsCXXRecordDecl()) { |
4385 | bool SavedForceCaptureByReferenceInTargetExecutable = |
4386 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->isForceCaptureByReferenceInTargetExecutable(); |
4387 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setForceCaptureByReferenceInTargetExecutable( |
4388 | /*V=*/true); |
4389 | if (RD->isLambda()) { |
4390 | llvm::DenseMap<const VarDecl *, FieldDecl *> Captures; |
4391 | FieldDecl *ThisCapture; |
4392 | RD->getCaptureFields(Captures, ThisCapture); |
4393 | for (const LambdaCapture &LC : RD->captures()) { |
4394 | if (LC.getCaptureKind() == LCK_ByRef) { |
4395 | VarDecl *VD = LC.getCapturedVar(); |
4396 | DeclContext *VDC = VD->getDeclContext(); |
4397 | if (!VDC->Encloses(CurContext)) |
4398 | continue; |
4399 | MarkVariableReferenced(LC.getLocation(), VD); |
4400 | } else if (LC.getCaptureKind() == LCK_This) { |
4401 | QualType ThisTy = getCurrentThisType(); |
4402 | if (!ThisTy.isNull() && |
4403 | Context.typesAreCompatible(ThisTy, ThisCapture->getType())) |
4404 | CheckCXXThisCapture(LC.getLocation()); |
4405 | } |
4406 | } |
4407 | } |
4408 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setForceCaptureByReferenceInTargetExecutable( |
4409 | SavedForceCaptureByReferenceInTargetExecutable); |
4410 | } |
4411 | } |
4412 | } |
4413 | |
4414 | static bool checkOrderedOrderSpecified(Sema &S, |
4415 | const ArrayRef<OMPClause *> Clauses) { |
4416 | const OMPOrderedClause *Ordered = nullptr; |
4417 | const OMPOrderClause *Order = nullptr; |
4418 | |
4419 | for (const OMPClause *Clause : Clauses) { |
4420 | if (Clause->getClauseKind() == OMPC_ordered) |
4421 | Ordered = cast<OMPOrderedClause>(Clause); |
4422 | else if (Clause->getClauseKind() == OMPC_order) { |
4423 | Order = cast<OMPOrderClause>(Clause); |
4424 | if (Order->getKind() != OMPC_ORDER_concurrent) |
4425 | Order = nullptr; |
4426 | } |
4427 | if (Ordered && Order) |
4428 | break; |
4429 | } |
4430 | |
4431 | if (Ordered && Order) { |
4432 | S.Diag(Order->getKindKwLoc(), |
4433 | diag::err_omp_simple_clause_incompatible_with_ordered) |
4434 | << getOpenMPClauseName(OMPC_order) |
4435 | << getOpenMPSimpleClauseTypeName(OMPC_order, OMPC_ORDER_concurrent) |
4436 | << SourceRange(Order->getBeginLoc(), Order->getEndLoc()); |
4437 | S.Diag(Ordered->getBeginLoc(), diag::note_omp_ordered_param) |
4438 | << 0 << SourceRange(Ordered->getBeginLoc(), Ordered->getEndLoc()); |
4439 | return true; |
4440 | } |
4441 | return false; |
4442 | } |
4443 | |
4444 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
4445 | ArrayRef<OMPClause *> Clauses) { |
4446 | if (DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() == OMPD_atomic || |
4447 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() == OMPD_critical || |
4448 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() == OMPD_section || |
4449 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective() == OMPD_master) |
4450 | return S; |
4451 | |
4452 | bool ErrorFound = false; |
4453 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
4454 | *this, ErrorFound, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); |
4455 | if (!S.isUsable()) { |
4456 | ErrorFound = true; |
4457 | return StmtError(); |
4458 | } |
4459 | |
4460 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
4461 | getOpenMPCaptureRegions(CaptureRegions, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); |
4462 | OMPOrderedClause *OC = nullptr; |
4463 | OMPScheduleClause *SC = nullptr; |
4464 | SmallVector<const OMPLinearClause *, 4> LCs; |
4465 | SmallVector<const OMPClauseWithPreInit *, 4> PICs; |
4466 | // This is required for proper codegen. |
4467 | for (OMPClause *Clause : Clauses) { |
4468 | if (!LangOpts.OpenMPSimd && |
4469 | isOpenMPTaskingDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()) && |
4470 | Clause->getClauseKind() == OMPC_in_reduction) { |
4471 | // Capture taskgroup task_reduction descriptors inside the tasking regions |
4472 | // with the corresponding in_reduction items. |
4473 | auto *IRC = cast<OMPInReductionClause>(Clause); |
4474 | for (Expr *E : IRC->taskgroup_descriptors()) |
4475 | if (E) |
4476 | MarkDeclarationsReferencedInExpr(E); |
4477 | } |
4478 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
4479 | Clause->getClauseKind() == OMPC_copyprivate || |
4480 | (getLangOpts().OpenMPUseTLS && |
4481 | getASTContext().getTargetInfo().isTLSSupported() && |
4482 | Clause->getClauseKind() == OMPC_copyin)) { |
4483 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
4484 | // Mark all variables in private list clauses as used in inner region. |
4485 | for (Stmt *VarRef : Clause->children()) { |
4486 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
4487 | MarkDeclarationsReferencedInExpr(E); |
4488 | } |
4489 | } |
4490 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setForceVarCapturing(/*V=*/false); |
4491 | } else if (isOpenMPLoopTransformationDirective( |
4492 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective())) { |
4493 | assert(CaptureRegions.empty() &&((CaptureRegions.empty() && "No captured regions in loop transformation directives." ) ? static_cast<void> (0) : __assert_fail ("CaptureRegions.empty() && \"No captured regions in loop transformation directives.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 4494, __PRETTY_FUNCTION__)) |
4494 | "No captured regions in loop transformation directives.")((CaptureRegions.empty() && "No captured regions in loop transformation directives." ) ? static_cast<void> (0) : __assert_fail ("CaptureRegions.empty() && \"No captured regions in loop transformation directives.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 4494, __PRETTY_FUNCTION__)); |
4495 | } else if (CaptureRegions.size() > 1 || |
4496 | CaptureRegions.back() != OMPD_unknown) { |
4497 | if (auto *C = OMPClauseWithPreInit::get(Clause)) |
4498 | PICs.push_back(C); |
4499 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
4500 | if (Expr *E = C->getPostUpdateExpr()) |
4501 | MarkDeclarationsReferencedInExpr(E); |
4502 | } |
4503 | } |
4504 | if (Clause->getClauseKind() == OMPC_schedule) |
4505 | SC = cast<OMPScheduleClause>(Clause); |
4506 | else if (Clause->getClauseKind() == OMPC_ordered) |
4507 | OC = cast<OMPOrderedClause>(Clause); |
4508 | else if (Clause->getClauseKind() == OMPC_linear) |
4509 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
4510 | } |
4511 | // Capture allocator expressions if used. |
4512 | for (Expr *E : DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getInnerAllocators()) |
4513 | MarkDeclarationsReferencedInExpr(E); |
4514 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
4515 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
4516 | // specified. |
4517 | if (SC && |
4518 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
4519 | SC->getSecondScheduleModifier() == |
4520 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
4521 | OC) { |
4522 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
4523 | ? SC->getFirstScheduleModifierLoc() |
4524 | : SC->getSecondScheduleModifierLoc(), |
4525 | diag::err_omp_simple_clause_incompatible_with_ordered) |
4526 | << getOpenMPClauseName(OMPC_schedule) |
4527 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, |
4528 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
4529 | << SourceRange(OC->getBeginLoc(), OC->getEndLoc()); |
4530 | ErrorFound = true; |
4531 | } |
4532 | // OpenMP 5.0, 2.9.2 Worksharing-Loop Construct, Restrictions. |
4533 | // If an order(concurrent) clause is present, an ordered clause may not appear |
4534 | // on the same directive. |
4535 | if (checkOrderedOrderSpecified(*this, Clauses)) |
4536 | ErrorFound = true; |
4537 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
4538 | for (const OMPLinearClause *C : LCs) { |
4539 | Diag(C->getBeginLoc(), diag::err_omp_linear_ordered) |
4540 | << SourceRange(OC->getBeginLoc(), OC->getEndLoc()); |
4541 | } |
4542 | ErrorFound = true; |
4543 | } |
4544 | if (isOpenMPWorksharingDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()) && |
4545 | isOpenMPSimdDirective(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()) && OC && |
4546 | OC->getNumForLoops()) { |
4547 | Diag(OC->getBeginLoc(), diag::err_omp_ordered_simd) |
4548 | << getOpenMPDirectiveName(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->getCurrentDirective()); |
4549 | ErrorFound = true; |
4550 | } |
4551 | if (ErrorFound) { |
4552 | return StmtError(); |
4553 | } |
4554 | StmtResult SR = S; |
4555 | unsigned CompletedRegions = 0; |
4556 | for (OpenMPDirectiveKind ThisCaptureRegion : llvm::reverse(CaptureRegions)) { |
4557 | // Mark all variables in private list clauses as used in inner region. |
4558 | // Required for proper codegen of combined directives. |
4559 | // TODO: add processing for other clauses. |
4560 | if (ThisCaptureRegion != OMPD_unknown) { |
4561 | for (const clang::OMPClauseWithPreInit *C : PICs) { |
4562 | OpenMPDirectiveKind CaptureRegion = C->getCaptureRegion(); |
4563 | // Find the particular capture region for the clause if the |
4564 | // directive is a combined one with multiple capture regions. |
4565 | // If the directive is not a combined one, the capture region |
4566 | // associated with the clause is OMPD_unknown and is generated |
4567 | // only once. |
4568 | if (CaptureRegion == ThisCaptureRegion || |
4569 | CaptureRegion == OMPD_unknown) { |
4570 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
4571 | for (Decl *D : DS->decls()) |
4572 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
4573 | } |
4574 | } |
4575 | } |
4576 | } |
4577 | if (ThisCaptureRegion == OMPD_target) { |
4578 | // Capture allocator traits in the target region. They are used implicitly |
4579 | // and, thus, are not captured by default. |
4580 | for (OMPClause *C : Clauses) { |
4581 | if (const auto *UAC = dyn_cast<OMPUsesAllocatorsClause>(C)) { |
4582 | for (unsigned I = 0, End = UAC->getNumberOfAllocators(); I < End; |
4583 | ++I) { |
4584 | OMPUsesAllocatorsClause::Data D = UAC->getAllocatorData(I); |
4585 | if (Expr *E = D.AllocatorTraits) |
4586 | MarkDeclarationsReferencedInExpr(E); |
4587 | } |
4588 | continue; |
4589 | } |
4590 | } |
4591 | } |
4592 | if (++CompletedRegions == CaptureRegions.size()) |
4593 | DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack )->setBodyComplete(); |
4594 | SR = ActOnCapturedRegionEnd(SR.get()); |
4595 | } |
4596 | return SR; |
4597 | } |
4598 | |
4599 | static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, |
4600 | OpenMPDirectiveKind CancelRegion, |
4601 | SourceLocation StartLoc) { |
4602 | // CancelRegion is only needed for cancel and cancellation_point. |
4603 | if (CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_cancellation_point) |
4604 | return false; |
4605 | |
4606 | if (CancelRegion == OMPD_parallel || CancelRegion == OMPD_for || |
4607 | CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) |
4608 | return false; |
4609 | |
4610 | SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
4611 | << getOpenMPDirectiveName(CancelRegion); |
4612 | return true; |
4613 | } |
4614 | |
4615 | static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack, |
4616 | OpenMPDirectiveKind CurrentRegion, |
4617 | const DeclarationNameInfo &CurrentName, |
4618 | OpenMPDirectiveKind CancelRegion, |
4619 | SourceLocation StartLoc) { |
4620 | if (Stack->getCurScope()) { |
4621 | OpenMPDirectiveKind ParentRegion = Stack->getParentDirective(); |
4622 | OpenMPDirectiveKind OffendingRegion = ParentRegion; |
4623 | bool NestingProhibited = false; |
4624 | bool CloseNesting = true; |
4625 | bool OrphanSeen = false; |
4626 | enum { |
4627 | NoRecommend, |
4628 | ShouldBeInParallelRegion, |
4629 | ShouldBeInOrderedRegion, |
4630 | ShouldBeInTargetRegion, |
4631 | ShouldBeInTeamsRegion, |
4632 | ShouldBeInLoopSimdRegion, |
4633 | } Recommend = NoRecommend; |
4634 | if (isOpenMPSimdDirective(ParentRegion) && |
4635 | ((SemaRef.LangOpts.OpenMP <= 45 && CurrentRegion != OMPD_ordered) || |
4636 | (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion != OMPD_ordered && |
4637 | CurrentRegion != OMPD_simd && CurrentRegion != OMPD_atomic && |
4638 | CurrentRegion != OMPD_scan))) { |
4639 | // OpenMP [2.16, Nesting of Regions] |
4640 | // OpenMP constructs may not be nested inside a simd region. |
4641 | // OpenMP [2.8.1,simd Construct, Restrictions] |
4642 | // An ordered construct with the simd clause is the only OpenMP |
4643 | // construct that can appear in the simd region. |
4644 | // Allowing a SIMD construct nested in another SIMD construct is an |
4645 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
4646 | // message. |
4647 | // OpenMP 5.0 [2.9.3.1, simd Construct, Restrictions] |
4648 | // The only OpenMP constructs that can be encountered during execution of |
4649 | // a simd region are the atomic construct, the loop construct, the simd |
4650 | // construct and the ordered construct with the simd clause. |
4651 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
4652 | ? diag::err_omp_prohibited_region_simd |
4653 | : diag::warn_omp_nesting_simd) |
4654 | << (SemaRef.LangOpts.OpenMP >= 50 ? 1 : 0); |
4655 | return CurrentRegion != OMPD_simd; |
4656 | } |
4657 | if (ParentRegion == OMPD_atomic) { |
4658 | // OpenMP [2.16, Nesting of Regions] |
4659 | // OpenMP constructs may not be nested inside an atomic region. |
4660 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
4661 | return true; |
4662 | } |
4663 | if (CurrentRegion == OMPD_section) { |
4664 | // OpenMP [2.7.2, sections Construct, Restrictions] |
4665 | // Orphaned section directives are prohibited. That is, the section |
4666 | // directives must appear within the sections construct and must not be |
4667 | // encountered elsewhere in the sections region. |
4668 | if (ParentRegion != OMPD_sections && |
4669 | ParentRegion != OMPD_parallel_sections) { |
4670 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
4671 | << (ParentRegion != OMPD_unknown) |
4672 | << getOpenMPDirectiveName(ParentRegion); |
4673 | return true; |
4674 | } |
4675 | return false; |
4676 | } |
4677 | // Allow some constructs (except teams and cancellation constructs) to be |
4678 | // orphaned (they could be used in functions, called from OpenMP regions |
4679 | // with the required preconditions). |
4680 | if (ParentRegion == OMPD_unknown && |
4681 | !isOpenMPNestingTeamsDirective(CurrentRegion) && |
4682 | CurrentRegion != OMPD_cancellation_point && |
4683 | CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_scan) |
4684 | return false; |
4685 | if (CurrentRegion == OMPD_cancellation_point || |
4686 | CurrentRegion == OMPD_cancel) { |
4687 | // OpenMP [2.16, Nesting of Regions] |
4688 | // A cancellation point construct for which construct-type-clause is |
4689 | // taskgroup must be nested inside a task construct. A cancellation |
4690 | // point construct for which construct-type-clause is not taskgroup must |
4691 | // be closely nested inside an OpenMP construct that matches the type |
4692 | // specified in construct-type-clause. |
4693 | // A cancel construct for which construct-type-clause is taskgroup must be |
4694 | // nested inside a task construct. A cancel construct for which |
4695 | // construct-type-clause is not taskgroup must be closely nested inside an |
4696 | // OpenMP construct that matches the type specified in |
4697 | // construct-type-clause. |
4698 | NestingProhibited = |
4699 | !((CancelRegion == OMPD_parallel && |
4700 | (ParentRegion == OMPD_parallel || |
4701 | ParentRegion == OMPD_target_parallel)) || |
4702 | (CancelRegion == OMPD_for && |
4703 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
4704 | ParentRegion == OMPD_target_parallel_for || |
4705 | ParentRegion == OMPD_distribute_parallel_for || |
4706 | ParentRegion == OMPD_teams_distribute_parallel_for || |
4707 | ParentRegion == OMPD_target_teams_distribute_parallel_for)) || |
4708 | (CancelRegion == OMPD_taskgroup && |
4709 | (ParentRegion == OMPD_task || |
4710 | (SemaRef.getLangOpts().OpenMP >= 50 && |
4711 | (ParentRegion == OMPD_taskloop || |
4712 | ParentRegion == OMPD_master_taskloop || |
4713 | ParentRegion == OMPD_parallel_master_taskloop)))) || |
4714 | (CancelRegion == OMPD_sections && |
4715 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
4716 | ParentRegion == OMPD_parallel_sections))); |
4717 | OrphanSeen = ParentRegion == OMPD_unknown; |
4718 | } else if (CurrentRegion == OMPD_master) { |
4719 | // OpenMP [2.16, Nesting of Regions] |
4720 | // A master region may not be closely nested inside a worksharing, |
4721 | // atomic, or explicit task region. |
4722 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
4723 | isOpenMPTaskingDirective(ParentRegion); |
4724 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
4725 | // OpenMP [2.16, Nesting of Regions] |
4726 | // A critical region may not be nested (closely or otherwise) inside a |
4727 | // critical region with the same name. Note that this restriction is not |
4728 | // sufficient to prevent deadlock. |
4729 | SourceLocation PreviousCriticalLoc; |
4730 | bool DeadLock = Stack->hasDirective( |
4731 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
4732 | const DeclarationNameInfo &DNI, |
4733 | SourceLocation Loc) { |
4734 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
4735 | PreviousCriticalLoc = Loc; |
4736 | return true; |
4737 | } |
4738 | return false; |
4739 | }, |
4740 | false /* skip top directive */); |
4741 | if (DeadLock) { |
4742 | SemaRef.Diag(StartLoc, |
4743 | diag::err_omp_prohibited_region_critical_same_name) |
4744 | << CurrentName.getName(); |
4745 | if (PreviousCriticalLoc.isValid()) |
4746 | SemaRef.Diag(PreviousCriticalLoc, |
4747 | diag::note_omp_previous_critical_region); |
4748 | return true; |
4749 | } |
4750 | } else if (CurrentRegion == OMPD_barrier) { |
4751 | // OpenMP [2.16, Nesting of Regions] |
4752 | // A barrier region may not be closely nested inside a worksharing, |
4753 | // explicit task, critical, ordered, atomic, or master region. |
4754 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
4755 | isOpenMPTaskingDirective(ParentRegion) || |
4756 | ParentRegion == OMPD_master || |
4757 | ParentRegion == OMPD_parallel_master || |
4758 | ParentRegion == OMPD_critical || |
4759 | ParentRegion == OMPD_ordered; |
4760 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
4761 | !isOpenMPParallelDirective(CurrentRegion) && |
4762 | !isOpenMPTeamsDirective(CurrentRegion)) { |
4763 | // OpenMP [2.16, Nesting of Regions] |
4764 | // A worksharing region may not be closely nested inside a worksharing, |
4765 | // explicit task, critical, ordered, atomic, or master region. |
4766 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
4767 | isOpenMPTaskingDirective(ParentRegion) || |
4768 | ParentRegion == OMPD_master || |
4769 | ParentRegion == OMPD_parallel_master || |
4770 | ParentRegion == OMPD_critical || |
4771 | ParentRegion == OMPD_ordered; |
4772 | Recommend = ShouldBeInParallelRegion; |
4773 | } else if (CurrentRegion == OMPD_ordered) { |
4774 | // OpenMP [2.16, Nesting of Regions] |
4775 | // An ordered region may not be closely nested inside a critical, |
4776 | // atomic, or explicit task region. |
4777 | // An ordered region must be closely nested inside a loop region (or |
4778 | // parallel loop region) with an ordered clause. |
4779 | // OpenMP [2.8.1,simd Construct, Restrictions] |
4780 | // An ordered construct with the simd clause is the only OpenMP construct |
4781 | // that can appear in the simd region. |
4782 | NestingProhibited = ParentRegion == OMPD_critical || |
4783 | isOpenMPTaskingDirective(ParentRegion) || |
4784 | !(isOpenMPSimdDirective(ParentRegion) || |
4785 | Stack->isParentOrderedRegion()); |
4786 | Recommend = ShouldBeInOrderedRegion; |
4787 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
4788 | // OpenMP [2.16, Nesting of Regions] |
4789 | // If specified, a teams construct must be contained within a target |
4790 | // construct. |
4791 | NestingProhibited = |
4792 | (SemaRef.LangOpts.OpenMP <= 45 && ParentRegion != OMPD_target) || |
4793 | (SemaRef.LangOpts.OpenMP >= 50 && ParentRegion != OMPD_unknown && |
4794 | ParentRegion != OMPD_target); |
4795 | OrphanSeen = ParentRegion == OMPD_unknown; |
4796 | Recommend = ShouldBeInTargetRegion; |
4797 | } else if (CurrentRegion == OMPD_scan) { |
4798 | // OpenMP [2.16, Nesting of Regions] |
4799 | // If specified, a teams construct must be contained within a target |
4800 | // construct. |
4801 | NestingProhibited = |
4802 | SemaRef.LangOpts.OpenMP < 50 || |
4803 | (ParentRegion != OMPD_simd && ParentRegion != OMPD_for && |
4804 | ParentRegion != OMPD_for_simd && ParentRegion != OMPD_parallel_for && |
4805 | ParentRegion != OMPD_parallel_for_simd); |
4806 | OrphanSeen = ParentRegion == OMPD_unknown; |
4807 | Recommend = ShouldBeInLoopSimdRegion; |
4808 | } |
4809 | if (!NestingProhibited && |
4810 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
4811 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
4812 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
4813 | // OpenMP [2.16, Nesting of Regions] |
4814 | // distribute, parallel, parallel sections, parallel workshare, and the |
4815 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
4816 | // constructs that can be closely nested in the teams region. |
4817 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
4818 | !isOpenMPDistributeDirective(CurrentRegion); |
4819 | Recommend = ShouldBeInParallelRegion; |
4820 | } |
4821 | if (!NestingProhibited && |
4822 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
4823 | // OpenMP 4.5 [2.17 Nesting of Regions] |
4824 | // The region associated with the distribute construct must be strictly |
4825 | // nested inside a teams region |
4826 | NestingProhibited = |
4827 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
4828 | Recommend = ShouldBeInTeamsRegion; |
4829 | } |
4830 | if (!NestingProhibited && |
4831 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
4832 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
4833 | // OpenMP 4.5 [2.17 Nesting of Regions] |
4834 | // If a target, target update, target data, target enter data, or |
4835 | // target exit data construct is encountered during execution of a |
4836 | // target region, the behavior is unspecified. |
4837 | NestingProhibited = Stack->hasDirective( |
4838 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
4839 | SourceLocation) { |
4840 | if (isOpenMPTargetExecutionDirective(K)) { |
4841 | OffendingRegion = K; |
4842 | return true; |
4843 | } |
4844 | return false; |
4845 | }, |
4846 | false /* don't skip top directive */); |
4847 | CloseNesting = false; |
4848 | } |
4849 | if (NestingProhibited) { |
4850 | if (OrphanSeen) { |
4851 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
4852 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
4853 | } else { |
4854 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
4855 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
4856 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
4857 | } |
4858 | return true; |
4859 | } |
4860 | } |
4861 | return false; |
4862 | } |
4863 | |
4864 | struct Kind2Unsigned { |
4865 | using argument_type = OpenMPDirectiveKind; |
4866 | unsigned operator()(argument_type DK) { return unsigned(DK); } |
4867 | }; |
4868 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
4869 | ArrayRef<OMPClause *> Clauses, |
4870 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
4871 | bool ErrorFound = false; |
4872 | unsigned NamedModifiersNumber = 0; |
4873 | llvm::IndexedMap<const OMPIfClause *, Kind2Unsigned> FoundNameModifiers; |
4874 | FoundNameModifiers.resize(llvm::omp::Directive_enumSize + 1); |
4875 | SmallVector<SourceLocation, 4> NameModifierLoc; |
4876 | for (const OMPClause *C : Clauses) { |
4877 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
4878 | // At most one if clause without a directive-name-modifier can appear on |
4879 | // the directive. |
4880 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
4881 | if (FoundNameModifiers[CurNM]) { |
4882 | S.Diag(C->getBeginLoc(), diag::err_omp_more_one_clause) |
4883 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
4884 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
4885 | ErrorFound = true; |
4886 | } else if (CurNM != OMPD_unknown) { |
4887 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
4888 | ++NamedModifiersNumber; |
4889 | } |
4890 | FoundNameModifiers[CurNM] = IC; |
4891 | if (CurNM == OMPD_unknown) |
4892 | continue; |
4893 | // Check if the specified name modifier is allowed for the current |
4894 | // directive. |
4895 | // At most one if clause with the particular directive-name-modifier can |
4896 | // appear on the directive. |
4897 | bool MatchFound = false; |
4898 | for (auto NM : AllowedNameModifiers) { |
4899 | if (CurNM == NM) { |
4900 | MatchFound = true; |
4901 | break; |
4902 | } |
4903 | } |
4904 | if (!MatchFound) { |
4905 | S.Diag(IC->getNameModifierLoc(), |
4906 | diag::err_omp_wrong_if_directive_name_modifier) |
4907 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
4908 | ErrorFound = true; |
4909 | } |
4910 | } |
4911 | } |
4912 | // If any if clause on the directive includes a directive-name-modifier then |
4913 | // all if clauses on the directive must include a directive-name-modifier. |
4914 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
4915 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
4916 | S.Diag(FoundNameModifiers[OMPD_unknown]->getBeginLoc(), |
4917 | diag::err_omp_no_more_if_clause); |
4918 | } else { |
4919 | std::string Values; |
4920 | std::string Sep(", "); |
4921 | unsigned AllowedCnt = 0; |
4922 | unsigned TotalAllowedNum = |
4923 | AllowedNameModifiers.size() - NamedModifiersNumber; |
4924 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
4925 | ++Cnt) { |
4926 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
4927 | if (!FoundNameModifiers[NM]) { |
4928 | Values += "'"; |
4929 | Values += getOpenMPDirectiveName(NM); |
4930 | Values += "'"; |
4931 | if (AllowedCnt + 2 == TotalAllowedNum) |
4932 | Values += " or "; |
4933 | else if (AllowedCnt + 1 != TotalAllowedNum) |
4934 | Values += Sep; |
4935 | ++AllowedCnt; |
4936 | } |
4937 | } |
4938 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getBeginLoc(), |
4939 | diag::err_omp_unnamed_if_clause) |
4940 | << (TotalAllowedNum > 1) << Values; |
4941 | } |
4942 | for (SourceLocation Loc : NameModifierLoc) { |
4943 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
4944 | } |
4945 | ErrorFound = true; |
4946 | } |
4947 | return ErrorFound; |
4948 | } |
4949 | |
4950 | static std::pair<ValueDecl *, bool> getPrivateItem(Sema &S, Expr *&RefExpr, |
4951 | SourceLocation &ELoc, |
4952 | SourceRange &ERange, |
4953 | bool AllowArraySection) { |
4954 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
4955 | RefExpr->containsUnexpandedParameterPack()) |
4956 | return std::make_pair(nullptr, true); |
4957 | |
4958 | // OpenMP [3.1, C/C++] |
4959 | // A list item is a variable name. |
4960 | // OpenMP [2.9.3.3, Restrictions, p.1] |
4961 | // A variable that is part of another variable (as an array or |
4962 | // structure element) cannot appear in a private clause. |
4963 | RefExpr = RefExpr->IgnoreParens(); |
4964 | enum { |
4965 | NoArrayExpr = -1, |
4966 | ArraySubscript = 0, |
4967 | OMPArraySection = 1 |
4968 | } IsArrayExpr = NoArrayExpr; |
4969 | if (AllowArraySection) { |
4970 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
4971 | Expr *Base = ASE->getBase()->IgnoreParenImpCasts(); |
4972 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
4973 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
4974 | RefExpr = Base; |
4975 | IsArrayExpr = ArraySubscript; |
4976 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
4977 | Expr *Base = OASE->getBase()->IgnoreParenImpCasts(); |
4978 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
4979 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
4980 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
4981 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
4982 | RefExpr = Base; |
4983 | IsArrayExpr = OMPArraySection; |
4984 | } |
4985 | } |
4986 | ELoc = RefExpr->getExprLoc(); |
4987 | ERange = RefExpr->getSourceRange(); |
4988 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
4989 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
4990 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
4991 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
4992 | (S.getCurrentThisType().isNull() || !ME || |
4993 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
4994 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
4995 | if (IsArrayExpr != NoArrayExpr) { |
4996 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
4997 | << ERange; |
4998 | } else { |
4999 | S.Diag(ELoc, |
5000 | AllowArraySection |
5001 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
5002 | : diag::err_omp_expected_var_name_member_expr) |
5003 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
5004 | } |
5005 | return std::make_pair(nullptr, false); |
5006 | } |
5007 | return std::make_pair( |
5008 | getCanonicalDecl(DE ? DE->getDecl() : ME->getMemberDecl()), false); |
5009 | } |
5010 | |
5011 | namespace { |
5012 | /// Checks if the allocator is used in uses_allocators clause to be allowed in |
5013 | /// target regions. |
5014 | class AllocatorChecker final : public ConstStmtVisitor<AllocatorChecker, bool> { |
5015 | DSAStackTy *S = nullptr; |
5016 | |
5017 | public: |
5018 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
5019 | return S->isUsesAllocatorsDecl(E->getDecl()) |
5020 | .getValueOr( |
5021 | DSAStackTy::UsesAllocatorsDeclKind::AllocatorTrait) == |
5022 | DSAStackTy::UsesAllocatorsDeclKind::AllocatorTrait; |
5023 | } |
5024 | bool VisitStmt(const Stmt *S) { |
5025 | for (const Stmt *Child : S->children()) { |
5026 | if (Child && Visit(Child)) |
5027 | return true; |
5028 | } |
5029 | return false; |
5030 | } |
5031 | explicit AllocatorChecker(DSAStackTy *S) : S(S) {} |
5032 | }; |
5033 | } // namespace |
5034 | |
5035 | static void checkAllocateClauses(Sema &S, DSAStackTy *Stack, |
5036 | ArrayRef<OMPClause *> Clauses) { |
5037 | assert(!S.CurContext->isDependentContext() &&((!S.CurContext->isDependentContext() && "Expected non-dependent context." ) ? static_cast<void> (0) : __assert_fail ("!S.CurContext->isDependentContext() && \"Expected non-dependent context.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5038, __PRETTY_FUNCTION__)) |
5038 | "Expected non-dependent context.")((!S.CurContext->isDependentContext() && "Expected non-dependent context." ) ? static_cast<void> (0) : __assert_fail ("!S.CurContext->isDependentContext() && \"Expected non-dependent context.\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5038, __PRETTY_FUNCTION__)); |
5039 | auto AllocateRange = |
5040 | llvm::make_filter_range(Clauses, OMPAllocateClause::classof); |
5041 | llvm::DenseMap<CanonicalDeclPtr<Decl>, CanonicalDeclPtr<VarDecl>> |
5042 | DeclToCopy; |
5043 | auto PrivateRange = llvm::make_filter_range(Clauses, [](const OMPClause *C) { |
5044 | return isOpenMPPrivate(C->getClauseKind()); |
5045 | }); |
5046 | for (OMPClause *Cl : PrivateRange) { |
5047 | MutableArrayRef<Expr *>::iterator I, It, Et; |
5048 | if (Cl->getClauseKind() == OMPC_private) { |
5049 | auto *PC = cast<OMPPrivateClause>(Cl); |
5050 | I = PC->private_copies().begin(); |
5051 | It = PC->varlist_begin(); |
5052 | Et = PC->varlist_end(); |
5053 | } else if (Cl->getClauseKind() == OMPC_firstprivate) { |
5054 | auto *PC = cast<OMPFirstprivateClause>(Cl); |
5055 | I = PC->private_copies().begin(); |
5056 | It = PC->varlist_begin(); |
5057 | Et = PC->varlist_end(); |
5058 | } else if (Cl->getClauseKind() == OMPC_lastprivate) { |
5059 | auto *PC = cast<OMPLastprivateClause>(Cl); |
5060 | I = PC->private_copies().begin(); |
5061 | It = PC->varlist_begin(); |
5062 | Et = PC->varlist_end(); |
5063 | } else if (Cl->getClauseKind() == OMPC_linear) { |
5064 | auto *PC = cast<OMPLinearClause>(Cl); |
5065 | I = PC->privates().begin(); |
5066 | It = PC->varlist_begin(); |
5067 | Et = PC->varlist_end(); |
5068 | } else if (Cl->getClauseKind() == OMPC_reduction) { |
5069 | auto *PC = cast<OMPReductionClause>(Cl); |
5070 | I = PC->privates().begin(); |
5071 | It = PC->varlist_begin(); |
5072 | Et = PC->varlist_end(); |
5073 | } else if (Cl->getClauseKind() == OMPC_task_reduction) { |
5074 | auto *PC = cast<OMPTaskReductionClause>(Cl); |
5075 | I = PC->privates().begin(); |
5076 | It = PC->varlist_begin(); |
5077 | Et = PC->varlist_end(); |
5078 | } else if (Cl->getClauseKind() == OMPC_in_reduction) { |
5079 | auto *PC = cast<OMPInReductionClause>(Cl); |
5080 | I = PC->privates().begin(); |
5081 | It = PC->varlist_begin(); |
5082 | Et = PC->varlist_end(); |
5083 | } else { |
5084 | llvm_unreachable("Expected private clause.")::llvm::llvm_unreachable_internal("Expected private clause.", "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5084); |
5085 | } |
5086 | for (Expr *E : llvm::make_range(It, Et)) { |
5087 | if (!*I) { |
5088 | ++I; |
5089 | continue; |
5090 | } |
5091 | SourceLocation ELoc; |
5092 | SourceRange ERange; |
5093 | Expr *SimpleRefExpr = E; |
5094 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange, |
5095 | /*AllowArraySection=*/true); |
5096 | DeclToCopy.try_emplace(Res.first, |
5097 | cast<VarDecl>(cast<DeclRefExpr>(*I)->getDecl())); |
5098 | ++I; |
5099 | } |
5100 | } |
5101 | for (OMPClause *C : AllocateRange) { |
5102 | auto *AC = cast<OMPAllocateClause>(C); |
5103 | if (S.getLangOpts().OpenMP >= 50 && |
5104 | !Stack->hasRequiresDeclWithClause<OMPDynamicAllocatorsClause>() && |
5105 | isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()) && |
5106 | AC->getAllocator()) { |
5107 | Expr *Allocator = AC->getAllocator(); |
5108 | // OpenMP, 2.12.5 target Construct |
5109 | // Memory allocators that do not appear in a uses_allocators clause cannot |
5110 | // appear as an allocator in an allocate clause or be used in the target |
5111 | // region unless a requires directive with the dynamic_allocators clause |
5112 | // is present in the same compilation unit. |
5113 | AllocatorChecker Checker(Stack); |
5114 | if (Checker.Visit(Allocator)) |
5115 | S.Diag(Allocator->getExprLoc(), |
5116 | diag::err_omp_allocator_not_in_uses_allocators) |
5117 | << Allocator->getSourceRange(); |
5118 | } |
5119 | OMPAllocateDeclAttr::AllocatorTypeTy AllocatorKind = |
5120 | getAllocatorKind(S, Stack, AC->getAllocator()); |
5121 | // OpenMP, 2.11.4 allocate Clause, Restrictions. |
5122 | // For task, taskloop or target directives, allocation requests to memory |
5123 | // allocators with the trait access set to thread result in unspecified |
5124 | // behavior. |
5125 | if (AllocatorKind == OMPAllocateDeclAttr::OMPThreadMemAlloc && |
5126 | (isOpenMPTaskingDirective(Stack->getCurrentDirective()) || |
5127 | isOpenMPTargetExecutionDirective(Stack->getCurrentDirective()))) { |
5128 | S.Diag(AC->getAllocator()->getExprLoc(), |
5129 | diag::warn_omp_allocate_thread_on_task_target_directive) |
5130 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
5131 | } |
5132 | for (Expr *E : AC->varlists()) { |
5133 | SourceLocation ELoc; |
5134 | SourceRange ERange; |
5135 | Expr *SimpleRefExpr = E; |
5136 | auto Res = getPrivateItem(S, SimpleRefExpr, ELoc, ERange); |
5137 | ValueDecl *VD = Res.first; |
5138 | DSAStackTy::DSAVarData Data = Stack->getTopDSA(VD, /*FromParent=*/false); |
5139 | if (!isOpenMPPrivate(Data.CKind)) { |
5140 | S.Diag(E->getExprLoc(), |
5141 | diag::err_omp_expected_private_copy_for_allocate); |
5142 | continue; |
5143 | } |
5144 | VarDecl *PrivateVD = DeclToCopy[VD]; |
5145 | if (checkPreviousOMPAllocateAttribute(S, Stack, E, PrivateVD, |
5146 | AllocatorKind, AC->getAllocator())) |
5147 | continue; |
5148 | applyOMPAllocateAttribute(S, PrivateVD, AllocatorKind, AC->getAllocator(), |
5149 | E->getSourceRange()); |
5150 | } |
5151 | } |
5152 | } |
5153 | |
5154 | static ExprResult buildUserDefinedMapperRef(Sema &SemaRef, Scope *S, |
5155 | CXXScopeSpec &MapperIdScopeSpec, |
5156 | const DeclarationNameInfo &MapperId, |
5157 | QualType Type, |
5158 | Expr *UnresolvedMapper); |
5159 | |
5160 | /// Perform DFS through the structure/class data members trying to find |
5161 | /// member(s) with user-defined 'default' mapper and generate implicit map |
5162 | /// clauses for such members with the found 'default' mapper. |
5163 | static void |
5164 | processImplicitMapsWithDefaultMappers(Sema &S, DSAStackTy *Stack, |
5165 | SmallVectorImpl<OMPClause *> &Clauses) { |
5166 | // Check for the deault mapper for data members. |
5167 | if (S.getLangOpts().OpenMP < 50) |
5168 | return; |
5169 | SmallVector<OMPClause *, 4> ImplicitMaps; |
5170 | DeclarationNameInfo DefaultMapperId; |
5171 | DefaultMapperId.setName(S.Context.DeclarationNames.getIdentifier( |
5172 | &S.Context.Idents.get("default"))); |
5173 | for (int Cnt = 0, EndCnt = Clauses.size(); Cnt < EndCnt; ++Cnt) { |
5174 | auto *C = dyn_cast<OMPMapClause>(Clauses[Cnt]); |
5175 | if (!C) |
5176 | continue; |
5177 | SmallVector<Expr *, 4> SubExprs; |
5178 | auto *MI = C->mapperlist_begin(); |
5179 | for (auto I = C->varlist_begin(), End = C->varlist_end(); I != End; |
5180 | ++I, ++MI) { |
5181 | // Expression is mapped using mapper - skip it. |
5182 | if (*MI) |
5183 | continue; |
5184 | Expr *E = *I; |
5185 | // Expression is dependent - skip it, build the mapper when it gets |
5186 | // instantiated. |
5187 | if (E->isTypeDependent() || E->isValueDependent() || |
5188 | E->containsUnexpandedParameterPack()) |
5189 | continue; |
5190 | // Array section - need to check for the mapping of the array section |
5191 | // element. |
5192 | QualType CanonType = E->getType().getCanonicalType(); |
5193 | if (CanonType->isSpecificBuiltinType(BuiltinType::OMPArraySection)) { |
5194 | const auto *OASE = cast<OMPArraySectionExpr>(E->IgnoreParenImpCasts()); |
5195 | QualType BaseType = |
5196 | OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
5197 | QualType ElemType; |
5198 | if (const auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
5199 | ElemType = ATy->getElementType(); |
5200 | else |
5201 | ElemType = BaseType->getPointeeType(); |
5202 | CanonType = ElemType; |
5203 | } |
5204 | |
5205 | // DFS over data members in structures/classes. |
5206 | SmallVector<std::pair<QualType, FieldDecl *>, 4> Types( |
5207 | 1, {CanonType, nullptr}); |
5208 | llvm::DenseMap<const Type *, Expr *> Visited; |
5209 | SmallVector<std::pair<FieldDecl *, unsigned>, 4> ParentChain( |
5210 | 1, {nullptr, 1}); |
5211 | while (!Types.empty()) { |
5212 | QualType BaseType; |
5213 | FieldDecl *CurFD; |
5214 | std::tie(BaseType, CurFD) = Types.pop_back_val(); |
5215 | while (ParentChain.back().second == 0) |
5216 | ParentChain.pop_back(); |
5217 | --ParentChain.back().second; |
5218 | if (BaseType.isNull()) |
5219 | continue; |
5220 | // Only structs/classes are allowed to have mappers. |
5221 | const RecordDecl *RD = BaseType.getCanonicalType()->getAsRecordDecl(); |
5222 | if (!RD) |
5223 | continue; |
5224 | auto It = Visited.find(BaseType.getTypePtr()); |
5225 | if (It == Visited.end()) { |
5226 | // Try to find the associated user-defined mapper. |
5227 | CXXScopeSpec MapperIdScopeSpec; |
5228 | ExprResult ER = buildUserDefinedMapperRef( |
5229 | S, Stack->getCurScope(), MapperIdScopeSpec, DefaultMapperId, |
5230 | BaseType, /*UnresolvedMapper=*/nullptr); |
5231 | if (ER.isInvalid()) |
5232 | continue; |
5233 | It = Visited.try_emplace(BaseType.getTypePtr(), ER.get()).first; |
5234 | } |
5235 | // Found default mapper. |
5236 | if (It->second) { |
5237 | auto *OE = new (S.Context) OpaqueValueExpr(E->getExprLoc(), CanonType, |
5238 | VK_LValue, OK_Ordinary, E); |
5239 | OE->setIsUnique(/*V=*/true); |
5240 | Expr *BaseExpr = OE; |
5241 | for (const auto &P : ParentChain) { |
5242 | if (P.first) { |
5243 | BaseExpr = S.BuildMemberExpr( |
5244 | BaseExpr, /*IsArrow=*/false, E->getExprLoc(), |
5245 | NestedNameSpecifierLoc(), SourceLocation(), P.first, |
5246 | DeclAccessPair::make(P.first, P.first->getAccess()), |
5247 | /*HadMultipleCandidates=*/false, DeclarationNameInfo(), |
5248 | P.first->getType(), VK_LValue, OK_Ordinary); |
5249 | BaseExpr = S.DefaultLvalueConversion(BaseExpr).get(); |
5250 | } |
5251 | } |
5252 | if (CurFD) |
5253 | BaseExpr = S.BuildMemberExpr( |
5254 | BaseExpr, /*IsArrow=*/false, E->getExprLoc(), |
5255 | NestedNameSpecifierLoc(), SourceLocation(), CurFD, |
5256 | DeclAccessPair::make(CurFD, CurFD->getAccess()), |
5257 | /*HadMultipleCandidates=*/false, DeclarationNameInfo(), |
5258 | CurFD->getType(), VK_LValue, OK_Ordinary); |
5259 | SubExprs.push_back(BaseExpr); |
5260 | continue; |
5261 | } |
5262 | // Check for the "default" mapper for data memebers. |
5263 | bool FirstIter = true; |
5264 | for (FieldDecl *FD : RD->fields()) { |
5265 | if (!FD) |
5266 | continue; |
5267 | QualType FieldTy = FD->getType(); |
5268 | if (FieldTy.isNull() || |
5269 | !(FieldTy->isStructureOrClassType() || FieldTy->isUnionType())) |
5270 | continue; |
5271 | if (FirstIter) { |
5272 | FirstIter = false; |
5273 | ParentChain.emplace_back(CurFD, 1); |
5274 | } else { |
5275 | ++ParentChain.back().second; |
5276 | } |
5277 | Types.emplace_back(FieldTy, FD); |
5278 | } |
5279 | } |
5280 | } |
5281 | if (SubExprs.empty()) |
5282 | continue; |
5283 | CXXScopeSpec MapperIdScopeSpec; |
5284 | DeclarationNameInfo MapperId; |
5285 | if (OMPClause *NewClause = S.ActOnOpenMPMapClause( |
5286 | C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), |
5287 | MapperIdScopeSpec, MapperId, C->getMapType(), |
5288 | /*IsMapTypeImplicit=*/true, SourceLocation(), SourceLocation(), |
5289 | SubExprs, OMPVarListLocTy())) |
5290 | Clauses.push_back(NewClause); |
5291 | } |
5292 | } |
5293 | |
5294 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
5295 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
5296 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
5297 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
5298 | StmtResult Res = StmtError(); |
5299 | // First check CancelRegion which is then used in checkNestingOfRegions. |
5300 | if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) || |
5301 | checkNestingOfRegions(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), Kind, DirName, CancelRegion, |
5302 | StartLoc)) |
5303 | return StmtError(); |
5304 | |
5305 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
5306 | VarsWithInheritedDSAType VarsWithInheritedDSA; |
5307 | bool ErrorFound = false; |
5308 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
5309 | if (AStmt && !CurContext->isDependentContext() && Kind != OMPD_atomic && |
5310 | Kind != OMPD_critical && Kind != OMPD_section && Kind != OMPD_master && |
5311 | !isOpenMPLoopTransformationDirective(Kind)) { |
5312 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected")((isa<CapturedStmt>(AStmt) && "Captured statement expected" ) ? static_cast<void> (0) : __assert_fail ("isa<CapturedStmt>(AStmt) && \"Captured statement expected\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5312, __PRETTY_FUNCTION__)); |
5313 | |
5314 | // Check default data sharing attributes for referenced variables. |
5315 | DSAAttrChecker DSAChecker(DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), *this, cast<CapturedStmt>(AStmt)); |
5316 | int ThisCaptureLevel = getOpenMPCaptureLevels(Kind); |
5317 | Stmt *S = AStmt; |
5318 | while (--ThisCaptureLevel >= 0) |
5319 | S = cast<CapturedStmt>(S)->getCapturedStmt(); |
5320 | DSAChecker.Visit(S); |
5321 | if (!isOpenMPTargetDataManagementDirective(Kind) && |
5322 | !isOpenMPTaskingDirective(Kind)) { |
5323 | // Visit subcaptures to generate implicit clauses for captured vars. |
5324 | auto *CS = cast<CapturedStmt>(AStmt); |
5325 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
5326 | getOpenMPCaptureRegions(CaptureRegions, Kind); |
5327 | // Ignore outer tasking regions for target directives. |
5328 | if (CaptureRegions.size() > 1 && CaptureRegions.front() == OMPD_task) |
5329 | CS = cast<CapturedStmt>(CS->getCapturedStmt()); |
5330 | DSAChecker.visitSubCaptures(CS); |
5331 | } |
5332 | if (DSAChecker.isErrorFound()) |
5333 | return StmtError(); |
5334 | // Generate list of implicitly defined firstprivate variables. |
5335 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
5336 | |
5337 | SmallVector<Expr *, 4> ImplicitFirstprivates( |
5338 | DSAChecker.getImplicitFirstprivate().begin(), |
5339 | DSAChecker.getImplicitFirstprivate().end()); |
5340 | const unsigned DefaultmapKindNum = OMPC_DEFAULTMAP_pointer + 1; |
5341 | SmallVector<Expr *, 4> ImplicitMaps[DefaultmapKindNum][OMPC_MAP_delete]; |
5342 | SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers> |
5343 | ImplicitMapModifiers[DefaultmapKindNum]; |
5344 | SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers> |
5345 | ImplicitMapModifiersLoc[DefaultmapKindNum]; |
5346 | // Get the original location of present modifier from Defaultmap clause. |
5347 | SourceLocation PresentModifierLocs[DefaultmapKindNum]; |
5348 | for (OMPClause *C : Clauses) { |
5349 | if (auto *DMC = dyn_cast<OMPDefaultmapClause>(C)) |
5350 | if (DMC->getDefaultmapModifier() == OMPC_DEFAULTMAP_MODIFIER_present) |
5351 | PresentModifierLocs[DMC->getDefaultmapKind()] = |
5352 | DMC->getDefaultmapModifierLoc(); |
5353 | } |
5354 | for (unsigned VC = 0; VC < DefaultmapKindNum; ++VC) { |
5355 | auto Kind = static_cast<OpenMPDefaultmapClauseKind>(VC); |
5356 | for (unsigned I = 0; I < OMPC_MAP_delete; ++I) { |
5357 | ArrayRef<Expr *> ImplicitMap = DSAChecker.getImplicitMap( |
5358 | Kind, static_cast<OpenMPMapClauseKind>(I)); |
5359 | ImplicitMaps[VC][I].append(ImplicitMap.begin(), ImplicitMap.end()); |
5360 | } |
5361 | ArrayRef<OpenMPMapModifierKind> ImplicitModifier = |
5362 | DSAChecker.getImplicitMapModifier(Kind); |
5363 | ImplicitMapModifiers[VC].append(ImplicitModifier.begin(), |
5364 | ImplicitModifier.end()); |
5365 | std::fill_n(std::back_inserter(ImplicitMapModifiersLoc[VC]), |
5366 | ImplicitModifier.size(), PresentModifierLocs[VC]); |
5367 | } |
5368 | // Mark taskgroup task_reduction descriptors as implicitly firstprivate. |
5369 | for (OMPClause *C : Clauses) { |
5370 | if (auto *IRC = dyn_cast<OMPInReductionClause>(C)) { |
5371 | for (Expr *E : IRC->taskgroup_descriptors()) |
5372 | if (E) |
5373 | ImplicitFirstprivates.emplace_back(E); |
5374 | } |
5375 | // OpenMP 5.0, 2.10.1 task Construct |
5376 | // [detach clause]... The event-handle will be considered as if it was |
5377 | // specified on a firstprivate clause. |
5378 | if (auto *DC = dyn_cast<OMPDetachClause>(C)) |
5379 | ImplicitFirstprivates.push_back(DC->getEventHandler()); |
5380 | } |
5381 | if (!ImplicitFirstprivates.empty()) { |
5382 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
5383 | ImplicitFirstprivates, SourceLocation(), SourceLocation(), |
5384 | SourceLocation())) { |
5385 | ClausesWithImplicit.push_back(Implicit); |
5386 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
5387 | ImplicitFirstprivates.size(); |
5388 | } else { |
5389 | ErrorFound = true; |
5390 | } |
5391 | } |
5392 | for (unsigned I = 0, E = DefaultmapKindNum; I < E; ++I) { |
5393 | int ClauseKindCnt = -1; |
5394 | for (ArrayRef<Expr *> ImplicitMap : ImplicitMaps[I]) { |
5395 | ++ClauseKindCnt; |
5396 | if (ImplicitMap.empty()) |
5397 | continue; |
5398 | CXXScopeSpec MapperIdScopeSpec; |
5399 | DeclarationNameInfo MapperId; |
5400 | auto Kind = static_cast<OpenMPMapClauseKind>(ClauseKindCnt); |
5401 | if (OMPClause *Implicit = ActOnOpenMPMapClause( |
5402 | ImplicitMapModifiers[I], ImplicitMapModifiersLoc[I], |
5403 | MapperIdScopeSpec, MapperId, Kind, /*IsMapTypeImplicit=*/true, |
5404 | SourceLocation(), SourceLocation(), ImplicitMap, |
5405 | OMPVarListLocTy())) { |
5406 | ClausesWithImplicit.emplace_back(Implicit); |
5407 | ErrorFound |= cast<OMPMapClause>(Implicit)->varlist_size() != |
5408 | ImplicitMap.size(); |
5409 | } else { |
5410 | ErrorFound = true; |
5411 | } |
5412 | } |
5413 | } |
5414 | // Build expressions for implicit maps of data members with 'default' |
5415 | // mappers. |
5416 | if (LangOpts.OpenMP >= 50) |
5417 | processImplicitMapsWithDefaultMappers(*this, DSAStackstatic_cast<DSAStackTy *>(VarDataSharingAttributesStack ), |
5418 | ClausesWithImplicit); |
5419 | } |
5420 | |
5421 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
5422 | switch (Kind) { |
5423 | case OMPD_parallel: |
5424 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
5425 | EndLoc); |
5426 | AllowedNameModifiers.push_back(OMPD_parallel); |
5427 | break; |
5428 | case OMPD_simd: |
5429 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
5430 | VarsWithInheritedDSA); |
5431 | if (LangOpts.OpenMP >= 50) |
5432 | AllowedNameModifiers.push_back(OMPD_simd); |
5433 | break; |
5434 | case OMPD_tile: |
5435 | Res = |
5436 | ActOnOpenMPTileDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
5437 | break; |
5438 | case OMPD_for: |
5439 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
5440 | VarsWithInheritedDSA); |
5441 | break; |
5442 | case OMPD_for_simd: |
5443 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
5444 | EndLoc, VarsWithInheritedDSA); |
5445 | if (LangOpts.OpenMP >= 50) |
5446 | AllowedNameModifiers.push_back(OMPD_simd); |
5447 | break; |
5448 | case OMPD_sections: |
5449 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
5450 | EndLoc); |
5451 | break; |
5452 | case OMPD_section: |
5453 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp section' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp section' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5454, __PRETTY_FUNCTION__)) |
5454 | "No clauses are allowed for 'omp section' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp section' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp section' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5454, __PRETTY_FUNCTION__)); |
5455 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
5456 | break; |
5457 | case OMPD_single: |
5458 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
5459 | EndLoc); |
5460 | break; |
5461 | case OMPD_master: |
5462 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp master' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp master' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5463, __PRETTY_FUNCTION__)) |
5463 | "No clauses are allowed for 'omp master' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp master' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp master' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5463, __PRETTY_FUNCTION__)); |
5464 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
5465 | break; |
5466 | case OMPD_critical: |
5467 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
5468 | StartLoc, EndLoc); |
5469 | break; |
5470 | case OMPD_parallel_for: |
5471 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
5472 | EndLoc, VarsWithInheritedDSA); |
5473 | AllowedNameModifiers.push_back(OMPD_parallel); |
5474 | break; |
5475 | case OMPD_parallel_for_simd: |
5476 | Res = ActOnOpenMPParallelForSimdDirective( |
5477 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
5478 | AllowedNameModifiers.push_back(OMPD_parallel); |
5479 | if (LangOpts.OpenMP >= 50) |
5480 | AllowedNameModifiers.push_back(OMPD_simd); |
5481 | break; |
5482 | case OMPD_parallel_master: |
5483 | Res = ActOnOpenMPParallelMasterDirective(ClausesWithImplicit, AStmt, |
5484 | StartLoc, EndLoc); |
5485 | AllowedNameModifiers.push_back(OMPD_parallel); |
5486 | break; |
5487 | case OMPD_parallel_sections: |
5488 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
5489 | StartLoc, EndLoc); |
5490 | AllowedNameModifiers.push_back(OMPD_parallel); |
5491 | break; |
5492 | case OMPD_task: |
5493 | Res = |
5494 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
5495 | AllowedNameModifiers.push_back(OMPD_task); |
5496 | break; |
5497 | case OMPD_taskyield: |
5498 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskyield' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskyield' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5499, __PRETTY_FUNCTION__)) |
5499 | "No clauses are allowed for 'omp taskyield' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskyield' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskyield' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5499, __PRETTY_FUNCTION__)); |
5500 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp taskyield' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp taskyield' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5501, __PRETTY_FUNCTION__)) |
5501 | "No associated statement allowed for 'omp taskyield' directive")((AStmt == nullptr && "No associated statement allowed for 'omp taskyield' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp taskyield' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5501, __PRETTY_FUNCTION__)); |
5502 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
5503 | break; |
5504 | case OMPD_barrier: |
5505 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp barrier' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp barrier' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5506, __PRETTY_FUNCTION__)) |
5506 | "No clauses are allowed for 'omp barrier' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp barrier' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp barrier' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5506, __PRETTY_FUNCTION__)); |
5507 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp barrier' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp barrier' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5508, __PRETTY_FUNCTION__)) |
5508 | "No associated statement allowed for 'omp barrier' directive")((AStmt == nullptr && "No associated statement allowed for 'omp barrier' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp barrier' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5508, __PRETTY_FUNCTION__)); |
5509 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
5510 | break; |
5511 | case OMPD_taskwait: |
5512 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskwait' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskwait' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5513, __PRETTY_FUNCTION__)) |
5513 | "No clauses are allowed for 'omp taskwait' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp taskwait' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp taskwait' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5513, __PRETTY_FUNCTION__)); |
5514 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp taskwait' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp taskwait' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5515, __PRETTY_FUNCTION__)) |
5515 | "No associated statement allowed for 'omp taskwait' directive")((AStmt == nullptr && "No associated statement allowed for 'omp taskwait' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp taskwait' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5515, __PRETTY_FUNCTION__)); |
5516 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
5517 | break; |
5518 | case OMPD_taskgroup: |
5519 | Res = ActOnOpenMPTaskgroupDirective(ClausesWithImplicit, AStmt, StartLoc, |
5520 | EndLoc); |
5521 | break; |
5522 | case OMPD_flush: |
5523 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp flush' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp flush' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5524, __PRETTY_FUNCTION__)) |
5524 | "No associated statement allowed for 'omp flush' directive")((AStmt == nullptr && "No associated statement allowed for 'omp flush' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp flush' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5524, __PRETTY_FUNCTION__)); |
5525 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
5526 | break; |
5527 | case OMPD_depobj: |
5528 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp depobj' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp depobj' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5529, __PRETTY_FUNCTION__)) |
5529 | "No associated statement allowed for 'omp depobj' directive")((AStmt == nullptr && "No associated statement allowed for 'omp depobj' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp depobj' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5529, __PRETTY_FUNCTION__)); |
5530 | Res = ActOnOpenMPDepobjDirective(ClausesWithImplicit, StartLoc, EndLoc); |
5531 | break; |
5532 | case OMPD_scan: |
5533 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp scan' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp scan' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5534, __PRETTY_FUNCTION__)) |
5534 | "No associated statement allowed for 'omp scan' directive")((AStmt == nullptr && "No associated statement allowed for 'omp scan' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp scan' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5534, __PRETTY_FUNCTION__)); |
5535 | Res = ActOnOpenMPScanDirective(ClausesWithImplicit, StartLoc, EndLoc); |
5536 | break; |
5537 | case OMPD_ordered: |
5538 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
5539 | EndLoc); |
5540 | break; |
5541 | case OMPD_atomic: |
5542 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
5543 | EndLoc); |
5544 | break; |
5545 | case OMPD_teams: |
5546 | Res = |
5547 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
5548 | break; |
5549 | case OMPD_target: |
5550 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
5551 | EndLoc); |
5552 | AllowedNameModifiers.push_back(OMPD_target); |
5553 | break; |
5554 | case OMPD_target_parallel: |
5555 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
5556 | StartLoc, EndLoc); |
5557 | AllowedNameModifiers.push_back(OMPD_target); |
5558 | AllowedNameModifiers.push_back(OMPD_parallel); |
5559 | break; |
5560 | case OMPD_target_parallel_for: |
5561 | Res = ActOnOpenMPTargetParallelForDirective( |
5562 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
5563 | AllowedNameModifiers.push_back(OMPD_target); |
5564 | AllowedNameModifiers.push_back(OMPD_parallel); |
5565 | break; |
5566 | case OMPD_cancellation_point: |
5567 | assert(ClausesWithImplicit.empty() &&((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp cancellation point' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp cancellation point' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5568, __PRETTY_FUNCTION__)) |
5568 | "No clauses are allowed for 'omp cancellation point' directive")((ClausesWithImplicit.empty() && "No clauses are allowed for 'omp cancellation point' directive" ) ? static_cast<void> (0) : __assert_fail ("ClausesWithImplicit.empty() && \"No clauses are allowed for 'omp cancellation point' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5568, __PRETTY_FUNCTION__)); |
5569 | assert(AStmt == nullptr && "No associated statement allowed for 'omp "((AStmt == nullptr && "No associated statement allowed for 'omp " "cancellation point' directive") ? static_cast<void> ( 0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp \" \"cancellation point' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5570, __PRETTY_FUNCTION__)) |
5570 | "cancellation point' directive")((AStmt == nullptr && "No associated statement allowed for 'omp " "cancellation point' directive") ? static_cast<void> ( 0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp \" \"cancellation point' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5570, __PRETTY_FUNCTION__)); |
5571 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
5572 | break; |
5573 | case OMPD_cancel: |
5574 | assert(AStmt == nullptr &&((AStmt == nullptr && "No associated statement allowed for 'omp cancel' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp cancel' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5575, __PRETTY_FUNCTION__)) |
5575 | "No associated statement allowed for 'omp cancel' directive")((AStmt == nullptr && "No associated statement allowed for 'omp cancel' directive" ) ? static_cast<void> (0) : __assert_fail ("AStmt == nullptr && \"No associated statement allowed for 'omp cancel' directive\"" , "/build/llvm-toolchain-snapshot-13~++20210304100658+2f37cdd5699f/clang/lib/Sema/SemaOpenMP.cpp" , 5575, __PRETTY_FUNCTION__)); |
5576 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
5577 | CancelRegion); |
5578 | AllowedNameModifiers.push_back(OMPD_cancel); |