clang 20.0.0git
DeclOpenMP.cpp
Go to the documentation of this file.
1//===--- DeclOpenMP.cpp - Declaration OpenMP AST Node Implementation ------===//
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 OMPThreadPrivateDecl, OMPCapturedExprDecl
10/// classes.
11///
12//===----------------------------------------------------------------------===//
13
15#include "clang/AST/Decl.h"
16#include "clang/AST/DeclBase.h"
18#include "clang/AST/Expr.h"
19
20using namespace clang;
21
22//===----------------------------------------------------------------------===//
23// OMPThreadPrivateDecl Implementation.
24//===----------------------------------------------------------------------===//
25
26void OMPThreadPrivateDecl::anchor() {}
27
29 DeclContext *DC,
32 auto *D = OMPDeclarativeDirective::createDirective<OMPThreadPrivateDecl>(
33 C, DC, {}, VL.size(), L);
34 D->setVars(VL);
35 return D;
36}
37
39 GlobalDeclID ID,
40 unsigned N) {
41 return OMPDeclarativeDirective::createEmptyDirective<OMPThreadPrivateDecl>(
42 C, ID, 0, N);
43}
44
45void OMPThreadPrivateDecl::setVars(ArrayRef<Expr *> VL) {
46 assert(VL.size() == Data->getNumChildren() &&
47 "Number of variables is not the same as the preallocated buffer");
48 llvm::copy(VL, getVars().begin());
49}
50
51//===----------------------------------------------------------------------===//
52// OMPAllocateDecl Implementation.
53//===----------------------------------------------------------------------===//
54
55void OMPAllocateDecl::anchor() { }
56
60 auto *D = OMPDeclarativeDirective::createDirective<OMPAllocateDecl>(
61 C, DC, CL, VL.size(), L);
62 D->setVars(VL);
63 return D;
64}
65
67 GlobalDeclID ID,
68 unsigned NVars,
69 unsigned NClauses) {
70 return OMPDeclarativeDirective::createEmptyDirective<OMPAllocateDecl>(
71 C, ID, NClauses, NVars, SourceLocation());
72}
73
74void OMPAllocateDecl::setVars(ArrayRef<Expr *> VL) {
75 assert(VL.size() == Data->getNumChildren() &&
76 "Number of variables is not the same as the preallocated buffer");
77 llvm::copy(VL, getVars().begin());
78}
79
80//===----------------------------------------------------------------------===//
81// OMPRequiresDecl Implementation.
82//===----------------------------------------------------------------------===//
83
84void OMPRequiresDecl::anchor() {}
85
89 return OMPDeclarativeDirective::createDirective<OMPRequiresDecl>(C, DC, CL, 0,
90 L);
91}
92
94 GlobalDeclID ID,
95 unsigned N) {
96 return OMPDeclarativeDirective::createEmptyDirective<OMPRequiresDecl>(
97 C, ID, N, 0, SourceLocation());
98}
99
100//===----------------------------------------------------------------------===//
101// OMPDeclareReductionDecl Implementation.
102//===----------------------------------------------------------------------===//
103
104OMPDeclareReductionDecl::OMPDeclareReductionDecl(
105 Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
106 QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
107 : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
108 PrevDeclInScope(PrevDeclInScope) {
109 setInitializer(nullptr, OMPDeclareReductionInitKind::Call);
110}
111
112void OMPDeclareReductionDecl::anchor() {}
113
116 QualType T, OMPDeclareReductionDecl *PrevDeclInScope) {
117 return new (C, DC) OMPDeclareReductionDecl(OMPDeclareReduction, DC, L, Name,
118 T, PrevDeclInScope);
119}
120
123 return new (C, ID) OMPDeclareReductionDecl(
124 OMPDeclareReduction, /*DC=*/nullptr, SourceLocation(), DeclarationName(),
125 QualType(), /*PrevDeclInScope=*/nullptr);
126}
127
129 return cast_or_null<OMPDeclareReductionDecl>(
130 PrevDeclInScope.get(getASTContext().getExternalSource()));
131}
134 return cast_or_null<OMPDeclareReductionDecl>(
135 PrevDeclInScope.get(getASTContext().getExternalSource()));
136}
137
138//===----------------------------------------------------------------------===//
139// OMPDeclareMapperDecl Implementation.
140//===----------------------------------------------------------------------===//
141
142void OMPDeclareMapperDecl::anchor() {}
143
147 OMPDeclareMapperDecl *PrevDeclInScope) {
148 return OMPDeclarativeDirective::createDirective<OMPDeclareMapperDecl>(
149 C, DC, Clauses, 1, L, Name, T, VarName, PrevDeclInScope);