blob: 22b557dadc64c1fc2fccd927db50c0c8b946cb27 [file] [log] [blame]
Chris Lattnerf42cce72006-10-25 04:09:21 +00001//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner5b12ab82007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerf42cce72006-10-25 04:09:21 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt class and statement subclasses.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramer444a1302012-12-01 17:12:56 +000014#include "clang/AST/ASTContext.h"
15#include "clang/AST/ASTDiagnostic.h"
Chris Lattner29375652006-12-04 18:06:35 +000016#include "clang/AST/ExprCXX.h"
Steve Naroff021ca182008-05-29 21:12:08 +000017#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000018#include "clang/AST/ExprOpenMP.h"
Benjamin Kramer444a1302012-12-01 17:12:56 +000019#include "clang/AST/Stmt.h"
Chris Lattnerf0b64d72009-04-26 01:32:48 +000020#include "clang/AST/StmtCXX.h"
21#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000022#include "clang/AST/StmtOpenMP.h"
Sebastian Redl54c04d42008-12-22 19:15:10 +000023#include "clang/AST/Type.h"
Jordan Rosea7d03842013-02-08 22:30:41 +000024#include "clang/Basic/CharInfo.h"
Chris Lattner1a8f3942010-04-23 16:29:58 +000025#include "clang/Basic/TargetInfo.h"
Benjamin Kramer444a1302012-12-01 17:12:56 +000026#include "clang/Lex/Token.h"
Chad Rosier14836ba2012-08-24 17:05:45 +000027#include "llvm/ADT/StringExtras.h"
Chandler Carruthbfb154a2011-07-04 06:13:27 +000028#include "llvm/Support/raw_ostream.h"
Chris Lattnerf42cce72006-10-25 04:09:21 +000029using namespace clang;
30
Steve Narofff84d11f2007-05-23 21:48:04 +000031static struct StmtClassNameTable {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000032 const char *Name;
33 unsigned Counter;
34 unsigned Size;
Alexis Hunt656bb312010-05-05 15:24:00 +000035} StmtClassInfo[Stmt::lastStmtConstant+1];
Chris Lattner4d15a0d2007-08-25 01:42:24 +000036
37static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
38 static bool Initialized = false;
39 if (Initialized)
40 return StmtClassInfo[E];
41
42 // Intialize the table on the first use.
43 Initialized = true;
Alexis Huntabb2ac82010-05-18 06:22:21 +000044#define ABSTRACT_STMT(STMT)
Douglas Gregorbe35ce92008-11-14 12:46:07 +000045#define STMT(CLASS, PARENT) \
46 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
47 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
Alexis Hunt656bb312010-05-05 15:24:00 +000048#include "clang/AST/StmtNodes.inc"
Nico Weberde565e32008-08-05 23:15:29 +000049
Chris Lattner4d15a0d2007-08-25 01:42:24 +000050 return StmtClassInfo[E];
51}
52
Craig Topper37932912013-08-18 10:09:15 +000053void *Stmt::operator new(size_t bytes, const ASTContext& C,
Craig Topper5a050012013-08-18 17:45:38 +000054 unsigned alignment) {
Benjamin Kramerea70eb32012-12-01 15:09:41 +000055 return ::operator new(bytes, C, alignment);
56}
57
Steve Narofff1e53692007-03-23 22:27:02 +000058const char *Stmt::getStmtClassName() const {
John McCall925b16622010-10-26 08:39:16 +000059 return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
Steve Narofff1e53692007-03-23 22:27:02 +000060}
Steve Narofff84d11f2007-05-23 21:48:04 +000061
62void Stmt::PrintStats() {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000063 // Ensure the table is primed.
64 getStmtInfoTableEntry(Stmt::NullStmtClass);
Nico Weberde565e32008-08-05 23:15:29 +000065
Steve Narofff84d11f2007-05-23 21:48:04 +000066 unsigned sum = 0;
Chandler Carruthbfb154a2011-07-04 06:13:27 +000067 llvm::errs() << "\n*** Stmt/Expr Stats:\n";
Alexis Hunt656bb312010-05-05 15:24:00 +000068 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Craig Topper36250ad2014-05-12 05:36:57 +000069 if (StmtClassInfo[i].Name == nullptr) continue;
Chris Lattner4d15a0d2007-08-25 01:42:24 +000070 sum += StmtClassInfo[i].Counter;
Steve Narofff84d11f2007-05-23 21:48:04 +000071 }
Chandler Carruthbfb154a2011-07-04 06:13:27 +000072 llvm::errs() << " " << sum << " stmts/exprs total.\n";
Steve Narofff84d11f2007-05-23 21:48:04 +000073 sum = 0;
Alexis Hunt656bb312010-05-05 15:24:00 +000074 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Craig Topper36250ad2014-05-12 05:36:57 +000075 if (StmtClassInfo[i].Name == nullptr) continue;
Douglas Gregora30d0462009-05-26 14:40:08 +000076 if (StmtClassInfo[i].Counter == 0) continue;
Chandler Carruthbfb154a2011-07-04 06:13:27 +000077 llvm::errs() << " " << StmtClassInfo[i].Counter << " "
78 << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
79 << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
80 << " bytes)\n";
Chris Lattner4d15a0d2007-08-25 01:42:24 +000081 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
Steve Narofff84d11f2007-05-23 21:48:04 +000082 }
Chandler Carruthbfb154a2011-07-04 06:13:27 +000083
84 llvm::errs() << "Total bytes = " << sum << "\n";
Steve Narofff84d11f2007-05-23 21:48:04 +000085}
86
87void Stmt::addStmtClass(StmtClass s) {
Chris Lattner4d15a0d2007-08-25 01:42:24 +000088 ++getStmtInfoTableEntry(s).Counter;
Steve Narofff84d11f2007-05-23 21:48:04 +000089}
90
Daniel Dunbar62905572012-03-05 21:42:49 +000091bool Stmt::StatisticsEnabled = false;
92void Stmt::EnableStatistics() {
93 StatisticsEnabled = true;
Steve Narofff84d11f2007-05-23 21:48:04 +000094}
95
John McCall4db5c3c2011-07-07 06:58:02 +000096Stmt *Stmt::IgnoreImplicit() {
97 Stmt *s = this;
98
Richard Smith520449d2015-02-05 06:15:50 +000099 if (auto *ewc = dyn_cast<ExprWithCleanups>(s))
John McCall4db5c3c2011-07-07 06:58:02 +0000100 s = ewc->getSubExpr();
101
Richard Smith520449d2015-02-05 06:15:50 +0000102 if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s))
103 s = mte->GetTemporaryExpr();
104
105 if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s))
106 s = bte->getSubExpr();
107
108 while (auto *ice = dyn_cast<ImplicitCastExpr>(s))
John McCall4db5c3c2011-07-07 06:58:02 +0000109 s = ice->getSubExpr();
110
111 return s;
112}
113
Alexander Musmana5f070a2014-10-01 06:03:56 +0000114/// \brief Skip no-op (attributed, compound) container stmts and skip captured
115/// stmt at the top, if \a IgnoreCaptured is true.
116Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) {
117 Stmt *S = this;
118 if (IgnoreCaptured)
119 if (auto CapS = dyn_cast_or_null<CapturedStmt>(S))
120 S = CapS->getCapturedStmt();
121 while (true) {
122 if (auto AS = dyn_cast_or_null<AttributedStmt>(S))
123 S = AS->getSubStmt();
124 else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) {
125 if (CS->size() != 1)
126 break;
127 S = CS->body_back();
128 } else
129 break;
130 }
131 return S;
132}
133
Chandler Carrutha626d642011-09-10 00:02:34 +0000134/// \brief Strip off all label-like statements.
135///
Richard Smithc202b282012-04-14 00:33:13 +0000136/// This will strip off label statements, case statements, attributed
137/// statements and default statements recursively.
Chandler Carrutha626d642011-09-10 00:02:34 +0000138const Stmt *Stmt::stripLabelLikeStatements() const {
139 const Stmt *S = this;
140 while (true) {
141 if (const LabelStmt *LS = dyn_cast<LabelStmt>(S))
142 S = LS->getSubStmt();
143 else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S))
144 S = SC->getSubStmt();
Richard Smithc202b282012-04-14 00:33:13 +0000145 else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S))
146 S = AS->getSubStmt();
Chandler Carrutha626d642011-09-10 00:02:34 +0000147 else
148 return S;
149 }
150}
151
John McCallbd066782011-02-09 08:16:59 +0000152namespace {
153 struct good {};
154 struct bad {};
John McCallf75152f2011-02-09 08:31:17 +0000155
156 // These silly little functions have to be static inline to suppress
157 // unused warnings, and they have to be defined to suppress other
158 // warnings.
Nick Lewyckybae992f2011-02-09 08:42:57 +0000159 static inline good is_good(good) { return good(); }
John McCallbd066782011-02-09 08:16:59 +0000160
161 typedef Stmt::child_range children_t();
Nick Lewyckybae992f2011-02-09 08:42:57 +0000162 template <class T> good implements_children(children_t T::*) {
163 return good();
164 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000165 LLVM_ATTRIBUTE_UNUSED
Nick Lewyckybae992f2011-02-09 08:42:57 +0000166 static inline bad implements_children(children_t Stmt::*) {
167 return bad();
168 }
John McCallbd066782011-02-09 08:16:59 +0000169
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000170 typedef SourceLocation getLocStart_t() const;
171 template <class T> good implements_getLocStart(getLocStart_t T::*) {
Nick Lewyckybae992f2011-02-09 08:42:57 +0000172 return good();
173 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000174 LLVM_ATTRIBUTE_UNUSED
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000175 static inline bad implements_getLocStart(getLocStart_t Stmt::*) {
176 return bad();
177 }
178
179 typedef SourceLocation getLocEnd_t() const;
180 template <class T> good implements_getLocEnd(getLocEnd_t T::*) {
181 return good();
182 }
Eli Friedmandc41d792013-09-10 22:57:15 +0000183 LLVM_ATTRIBUTE_UNUSED
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000184 static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) {
Nick Lewyckybae992f2011-02-09 08:42:57 +0000185 return bad();
186 }
John McCallbd066782011-02-09 08:16:59 +0000187
188#define ASSERT_IMPLEMENTS_children(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000189 (void) is_good(implements_children(&type::children))
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000190#define ASSERT_IMPLEMENTS_getLocStart(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000191 (void) is_good(implements_getLocStart(&type::getLocStart))
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000192#define ASSERT_IMPLEMENTS_getLocEnd(type) \
Eli Friedmandc41d792013-09-10 22:57:15 +0000193 (void) is_good(implements_getLocEnd(&type::getLocEnd))
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000194}
John McCallbd066782011-02-09 08:16:59 +0000195
196/// Check whether the various Stmt classes implement their member
197/// functions.
Eli Friedmandc41d792013-09-10 22:57:15 +0000198LLVM_ATTRIBUTE_UNUSED
John McCallbd066782011-02-09 08:16:59 +0000199static inline void check_implementations() {
200#define ABSTRACT_STMT(type)
201#define STMT(type, base) \
202 ASSERT_IMPLEMENTS_children(type); \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000203 ASSERT_IMPLEMENTS_getLocStart(type); \
204 ASSERT_IMPLEMENTS_getLocEnd(type);
John McCallbd066782011-02-09 08:16:59 +0000205#include "clang/AST/StmtNodes.inc"
206}
207
208Stmt::child_range Stmt::children() {
209 switch (getStmtClass()) {
210 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
211#define ABSTRACT_STMT(type)
212#define STMT(type, base) \
213 case Stmt::type##Class: \
214 return static_cast<type*>(this)->children();
215#include "clang/AST/StmtNodes.inc"
216 }
217 llvm_unreachable("unknown statement kind!");
John McCallbd066782011-02-09 08:16:59 +0000218}
219
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000220// Amusing macro metaprogramming hack: check whether a class provides
221// a more specific implementation of getSourceRange.
222//
223// See also Expr.cpp:getExprLoc().
224namespace {
225 /// This implementation is used when a class provides a custom
226 /// implementation of getSourceRange.
227 template <class S, class T>
228 SourceRange getSourceRangeImpl(const Stmt *stmt,
229 SourceRange (T::*v)() const) {
230 return static_cast<const S*>(stmt)->getSourceRange();
231 }
232
233 /// This implementation is used when a class doesn't provide a custom
234 /// implementation of getSourceRange. Overload resolution should pick it over
235 /// the implementation above because it's more specialized according to
236 /// function template partial ordering.
237 template <class S>
238 SourceRange getSourceRangeImpl(const Stmt *stmt,
239 SourceRange (Stmt::*v)() const) {
240 return SourceRange(static_cast<const S*>(stmt)->getLocStart(),
241 static_cast<const S*>(stmt)->getLocEnd());
242 }
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000243}
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000244
John McCallbd066782011-02-09 08:16:59 +0000245SourceRange Stmt::getSourceRange() const {
246 switch (getStmtClass()) {
247 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
248#define ABSTRACT_STMT(type)
249#define STMT(type, base) \
250 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000251 return getSourceRangeImpl<type>(this, &type::getSourceRange);
John McCallbd066782011-02-09 08:16:59 +0000252#include "clang/AST/StmtNodes.inc"
253 }
254 llvm_unreachable("unknown statement kind!");
John McCallbd066782011-02-09 08:16:59 +0000255}
256
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000257SourceLocation Stmt::getLocStart() const {
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000258// llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n";
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000259 switch (getStmtClass()) {
260 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
261#define ABSTRACT_STMT(type)
262#define STMT(type, base) \
263 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000264 return static_cast<const type*>(this)->getLocStart();
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000265#include "clang/AST/StmtNodes.inc"
266 }
267 llvm_unreachable("unknown statement kind");
268}
269
270SourceLocation Stmt::getLocEnd() const {
271 switch (getStmtClass()) {
272 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
273#define ABSTRACT_STMT(type)
274#define STMT(type, base) \
275 case Stmt::type##Class: \
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000276 return static_cast<const type*>(this)->getLocEnd();
Daniel Dunbarb0ab5e92012-03-09 15:39:19 +0000277#include "clang/AST/StmtNodes.inc"
278 }
279 llvm_unreachable("unknown statement kind");
280}
281
Craig Toppere6960e22013-08-22 05:28:54 +0000282CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000283 SourceLocation LB, SourceLocation RB)
Aaron Ballmance6c67e2014-10-22 21:06:18 +0000284 : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) {
Nico Webera2a0eb92012-12-29 20:03:39 +0000285 CompoundStmtBits.NumStmts = Stmts.size();
286 assert(CompoundStmtBits.NumStmts == Stmts.size() &&
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000287 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
288
Nico Webera2a0eb92012-12-29 20:03:39 +0000289 if (Stmts.size() == 0) {
Craig Topper36250ad2014-05-12 05:36:57 +0000290 Body = nullptr;
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000291 return;
292 }
293
Nico Webera2a0eb92012-12-29 20:03:39 +0000294 Body = new (C) Stmt*[Stmts.size()];
295 std::copy(Stmts.begin(), Stmts.end(), Body);
Benjamin Kramere2a929d2012-07-04 17:03:41 +0000296}
297
Craig Topperc571c812013-08-22 06:02:26 +0000298void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts,
299 unsigned NumStmts) {
Douglas Gregora9af1d12009-04-17 00:04:06 +0000300 if (this->Body)
301 C.Deallocate(Body);
John McCall925b16622010-10-26 08:39:16 +0000302 this->CompoundStmtBits.NumStmts = NumStmts;
Douglas Gregora9af1d12009-04-17 00:04:06 +0000303
304 Body = new (C) Stmt*[NumStmts];
305 memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
306}
Steve Narofff84d11f2007-05-23 21:48:04 +0000307
Chris Lattnereefa10e2007-05-28 06:56:27 +0000308const char *LabelStmt::getName() const {
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000309 return getDecl()->getIdentifier()->getNameStart();
Chris Lattnereefa10e2007-05-28 06:56:27 +0000310}
311
Craig Toppere6960e22013-08-22 05:28:54 +0000312AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc,
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000313 ArrayRef<const Attr*> Attrs,
314 Stmt *SubStmt) {
Aaron Ballmanf3d9b092014-05-13 14:55:01 +0000315 assert(!Attrs.empty() && "Attrs should not be empty");
316 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(),
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000317 llvm::alignOf<AttributedStmt>());
318 return new (Mem) AttributedStmt(Loc, Attrs, SubStmt);
319}
320
Craig Toppere6960e22013-08-22 05:28:54 +0000321AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C,
322 unsigned NumAttrs) {
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000323 assert(NumAttrs > 0 && "NumAttrs should be greater than zero");
Aaron Ballmanf3d9b092014-05-13 14:55:01 +0000324 void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs,
Alexander Kornienko20f6fc62012-07-09 10:04:07 +0000325 llvm::alignOf<AttributedStmt>());
326 return new (Mem) AttributedStmt(EmptyShell(), NumAttrs);
327}
328
Craig Topperc571c812013-08-22 06:02:26 +0000329std::string AsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000330 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
331 return gccAsmStmt->generateAsmString(C);
332 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
333 return msAsmStmt->generateAsmString(C);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000334 llvm_unreachable("unknown asm statement kind!");
335}
336
337StringRef AsmStmt::getOutputConstraint(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000338 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
339 return gccAsmStmt->getOutputConstraint(i);
340 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
341 return msAsmStmt->getOutputConstraint(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000342 llvm_unreachable("unknown asm statement kind!");
343}
344
345const Expr *AsmStmt::getOutputExpr(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000346 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
347 return gccAsmStmt->getOutputExpr(i);
348 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
349 return msAsmStmt->getOutputExpr(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000350 llvm_unreachable("unknown asm statement kind!");
351}
352
353StringRef AsmStmt::getInputConstraint(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000354 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
355 return gccAsmStmt->getInputConstraint(i);
356 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
357 return msAsmStmt->getInputConstraint(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000358 llvm_unreachable("unknown asm statement kind!");
359}
360
361const Expr *AsmStmt::getInputExpr(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000362 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
363 return gccAsmStmt->getInputExpr(i);
364 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
365 return msAsmStmt->getInputExpr(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000366 llvm_unreachable("unknown asm statement kind!");
367}
368
369StringRef AsmStmt::getClobber(unsigned i) const {
Chad Rosierf70b7e22012-08-28 18:21:14 +0000370 if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this))
371 return gccAsmStmt->getClobber(i);
372 if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this))
373 return msAsmStmt->getClobber(i);
Chad Rosierbbbe9ab2012-08-28 17:43:23 +0000374 llvm_unreachable("unknown asm statement kind!");
375}
376
Chad Rosiera1b5c8c2012-08-28 00:24:05 +0000377/// getNumPlusOperands - Return the number of output operands that have a "+"
378/// constraint.
379unsigned AsmStmt::getNumPlusOperands() const {
380 unsigned Res = 0;
381 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
382 if (isOutputPlusConstraint(i))
383 ++Res;
384 return Res;
385}
386
Akira Hatanaka987f1862014-08-22 06:05:21 +0000387char GCCAsmStmt::AsmStringPiece::getModifier() const {
388 assert(isOperand() && "Only Operands can have modifiers.");
389 return isLetter(Str[0]) ? Str[0] : '\0';
390}
391
Chad Rosier6100ae12012-08-27 23:47:56 +0000392StringRef GCCAsmStmt::getClobber(unsigned i) const {
393 return getClobberStringLiteral(i)->getString();
394}
395
Chad Rosierde70e0e2012-08-25 00:11:56 +0000396Expr *GCCAsmStmt::getOutputExpr(unsigned i) {
Ted Kremenek5778acf2008-10-27 18:40:21 +0000397 return cast<Expr>(Exprs[i]);
398}
Chris Lattner72bbf172009-03-10 04:59:06 +0000399
400/// getOutputConstraint - Return the constraint string for the specified
401/// output operand. All output constraints are known to be non-empty (either
402/// '=' or '+').
Chad Rosierde70e0e2012-08-25 00:11:56 +0000403StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const {
Anders Carlsson66de0812010-01-30 20:38:10 +0000404 return getOutputConstraintLiteral(i)->getString();
Ted Kremenek5778acf2008-10-27 18:40:21 +0000405}
Chris Lattner72bbf172009-03-10 04:59:06 +0000406
Chad Rosierde70e0e2012-08-25 00:11:56 +0000407Expr *GCCAsmStmt::getInputExpr(unsigned i) {
Ted Kremenek5778acf2008-10-27 18:40:21 +0000408 return cast<Expr>(Exprs[i + NumOutputs]);
409}
Chad Rosierde70e0e2012-08-25 00:11:56 +0000410void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) {
Chris Lattner93ede022011-02-21 22:09:29 +0000411 Exprs[i + NumOutputs] = E;
412}
413
Chris Lattner72bbf172009-03-10 04:59:06 +0000414/// getInputConstraint - Return the specified input constraint. Unlike output
415/// constraints, these can be empty.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000416StringRef GCCAsmStmt::getInputConstraint(unsigned i) const {
Anders Carlsson66de0812010-01-30 20:38:10 +0000417 return getInputConstraintLiteral(i)->getString();
Ted Kremenek5778acf2008-10-27 18:40:21 +0000418}
419
Craig Topperc571c812013-08-22 06:02:26 +0000420void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C,
421 IdentifierInfo **Names,
422 StringLiteral **Constraints,
423 Stmt **Exprs,
424 unsigned NumOutputs,
425 unsigned NumInputs,
426 StringLiteral **Clobbers,
427 unsigned NumClobbers) {
Douglas Gregorf994f062009-04-17 20:57:14 +0000428 this->NumOutputs = NumOutputs;
429 this->NumInputs = NumInputs;
Anders Carlsson98323d22010-01-30 23:19:41 +0000430 this->NumClobbers = NumClobbers;
431
432 unsigned NumExprs = NumOutputs + NumInputs;
Chad Rosier42032fa2012-08-07 23:12:23 +0000433
Anders Carlsson98323d22010-01-30 23:19:41 +0000434 C.Deallocate(this->Names);
435 this->Names = new (C) IdentifierInfo*[NumExprs];
436 std::copy(Names, Names + NumExprs, this->Names);
Chad Rosier42032fa2012-08-07 23:12:23 +0000437
Anders Carlsson98323d22010-01-30 23:19:41 +0000438 C.Deallocate(this->Exprs);
439 this->Exprs = new (C) Stmt*[NumExprs];
440 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
Chad Rosier42032fa2012-08-07 23:12:23 +0000441
Anders Carlsson98323d22010-01-30 23:19:41 +0000442 C.Deallocate(this->Constraints);
443 this->Constraints = new (C) StringLiteral*[NumExprs];
444 std::copy(Constraints, Constraints + NumExprs, this->Constraints);
Chad Rosier42032fa2012-08-07 23:12:23 +0000445
Anders Carlsson98323d22010-01-30 23:19:41 +0000446 C.Deallocate(this->Clobbers);
447 this->Clobbers = new (C) StringLiteral*[NumClobbers];
448 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
Douglas Gregorf994f062009-04-17 20:57:14 +0000449}
450
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000451/// getNamedOperand - Given a symbolic operand reference like %[foo],
452/// translate this into a numeric value needed to reference the same operand.
453/// This returns -1 if the operand name is invalid.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000454int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const {
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000455 unsigned NumPlusOperands = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000456
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000457 // Check if this is an output operand.
458 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
459 if (getOutputName(i) == SymbolicName)
460 return i;
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000461 }
Mike Stump11289f42009-09-09 15:08:12 +0000462
Chris Lattnerd7d5fdf2009-03-10 06:33:24 +0000463 for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
464 if (getInputName(i) == SymbolicName)
465 return getNumOutputs() + NumPlusOperands + i;
466
467 // Not found.
468 return -1;
469}
470
Chris Lattner35b58362009-03-10 23:21:44 +0000471/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
472/// it into pieces. If the asm string is erroneous, emit errors and return
473/// true, otherwise return false.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000474unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
Craig Topperc571c812013-08-22 06:02:26 +0000475 const ASTContext &C, unsigned &DiagOffs) const {
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000476 StringRef Str = getAsmString()->getString();
Benjamin Kramer35b077e2010-08-17 12:54:38 +0000477 const char *StrStart = Str.begin();
478 const char *StrEnd = Str.end();
Chris Lattnera41b8472009-03-10 23:51:40 +0000479 const char *CurPtr = StrStart;
Mike Stump11289f42009-09-09 15:08:12 +0000480
Chris Lattner35b58362009-03-10 23:21:44 +0000481 // "Simple" inline asms have no constraints or operands, just convert the asm
482 // string to escape $'s.
483 if (isSimple()) {
484 std::string Result;
Chris Lattnera41b8472009-03-10 23:51:40 +0000485 for (; CurPtr != StrEnd; ++CurPtr) {
486 switch (*CurPtr) {
Chris Lattner35b58362009-03-10 23:21:44 +0000487 case '$':
488 Result += "$$";
489 break;
490 default:
Chris Lattnera41b8472009-03-10 23:51:40 +0000491 Result += *CurPtr;
Chris Lattner35b58362009-03-10 23:21:44 +0000492 break;
493 }
494 }
495 Pieces.push_back(AsmStringPiece(Result));
Chris Lattnera41b8472009-03-10 23:51:40 +0000496 return 0;
Chris Lattner35b58362009-03-10 23:21:44 +0000497 }
498
499 // CurStringPiece - The current string that we are building up as we scan the
500 // asm string.
501 std::string CurStringPiece;
Mike Stump11289f42009-09-09 15:08:12 +0000502
Douglas Gregore8bbc122011-09-02 00:18:52 +0000503 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
Chad Rosier42032fa2012-08-07 23:12:23 +0000504
Chris Lattner35b58362009-03-10 23:21:44 +0000505 while (1) {
506 // Done with the string?
Chris Lattnera41b8472009-03-10 23:51:40 +0000507 if (CurPtr == StrEnd) {
Chris Lattner35b58362009-03-10 23:21:44 +0000508 if (!CurStringPiece.empty())
509 Pieces.push_back(AsmStringPiece(CurStringPiece));
Chris Lattnera41b8472009-03-10 23:51:40 +0000510 return 0;
Chris Lattner35b58362009-03-10 23:21:44 +0000511 }
Mike Stump11289f42009-09-09 15:08:12 +0000512
Chris Lattnera41b8472009-03-10 23:51:40 +0000513 char CurChar = *CurPtr++;
Chris Lattnerda081a82010-04-05 18:44:00 +0000514 switch (CurChar) {
515 case '$': CurStringPiece += "$$"; continue;
Chris Lattner1a8f3942010-04-23 16:29:58 +0000516 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
517 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
518 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
Chris Lattnerda081a82010-04-05 18:44:00 +0000519 case '%':
520 break;
521 default:
Chris Lattner35b58362009-03-10 23:21:44 +0000522 CurStringPiece += CurChar;
523 continue;
524 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000525
Chris Lattner35b58362009-03-10 23:21:44 +0000526 // Escaped "%" character in asm string.
Chris Lattner3fa25c62009-03-11 00:06:36 +0000527 if (CurPtr == StrEnd) {
528 // % at end of string is invalid (no escape).
529 DiagOffs = CurPtr-StrStart-1;
530 return diag::err_asm_invalid_escape;
531 }
Mike Stump11289f42009-09-09 15:08:12 +0000532
Chris Lattnera41b8472009-03-10 23:51:40 +0000533 char EscapedChar = *CurPtr++;
Chris Lattner35b58362009-03-10 23:21:44 +0000534 if (EscapedChar == '%') { // %% -> %
535 // Escaped percentage sign.
536 CurStringPiece += '%';
537 continue;
538 }
Mike Stump11289f42009-09-09 15:08:12 +0000539
Chris Lattner35b58362009-03-10 23:21:44 +0000540 if (EscapedChar == '=') { // %= -> Generate an unique ID.
541 CurStringPiece += "${:uid}";
542 continue;
543 }
Mike Stump11289f42009-09-09 15:08:12 +0000544
Chris Lattner35b58362009-03-10 23:21:44 +0000545 // Otherwise, we have an operand. If we have accumulated a string so far,
546 // add it to the Pieces list.
547 if (!CurStringPiece.empty()) {
548 Pieces.push_back(AsmStringPiece(CurStringPiece));
549 CurStringPiece.clear();
550 }
Mike Stump11289f42009-09-09 15:08:12 +0000551
Akira Hatanaka987f1862014-08-22 06:05:21 +0000552 // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that
553 // don't (e.g., %x4). 'x' following the '%' is the constraint modifier.
554
555 const char *Begin = CurPtr - 1; // Points to the character following '%'.
556 const char *Percent = Begin - 1; // Points to '%'.
557
Jordan Rosea7d03842013-02-08 22:30:41 +0000558 if (isLetter(EscapedChar)) {
Benjamin Kramere87c38b2011-07-05 11:13:37 +0000559 if (CurPtr == StrEnd) { // Premature end.
560 DiagOffs = CurPtr-StrStart-1;
561 return diag::err_asm_invalid_escape;
562 }
Chris Lattnera41b8472009-03-10 23:51:40 +0000563 EscapedChar = *CurPtr++;
Chris Lattner35b58362009-03-10 23:21:44 +0000564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
Akira Hatanaka987f1862014-08-22 06:05:21 +0000566 const TargetInfo &TI = C.getTargetInfo();
567 const SourceManager &SM = C.getSourceManager();
568 const LangOptions &LO = C.getLangOpts();
569
570 // Handle operands that don't have asmSymbolicName (e.g., %x4).
Jordan Rosea7d03842013-02-08 22:30:41 +0000571 if (isDigit(EscapedChar)) {
Chris Lattner35b58362009-03-10 23:21:44 +0000572 // %n - Assembler operand n
Chris Lattner99d892b2009-03-11 22:52:17 +0000573 unsigned N = 0;
Mike Stump11289f42009-09-09 15:08:12 +0000574
Chris Lattner99d892b2009-03-11 22:52:17 +0000575 --CurPtr;
Jordan Rosea7d03842013-02-08 22:30:41 +0000576 while (CurPtr != StrEnd && isDigit(*CurPtr))
Chris Lattner84f3afa2009-03-11 23:09:16 +0000577 N = N*10 + ((*CurPtr++)-'0');
Mike Stump11289f42009-09-09 15:08:12 +0000578
Chris Lattner14311922009-03-11 00:23:13 +0000579 unsigned NumOperands =
580 getNumOutputs() + getNumPlusOperands() + getNumInputs();
581 if (N >= NumOperands) {
582 DiagOffs = CurPtr-StrStart-1;
583 return diag::err_asm_invalid_operand_number;
584 }
585
Akira Hatanaka987f1862014-08-22 06:05:21 +0000586 // Str contains "x4" (Operand without the leading %).
587 std::string Str(Begin, CurPtr - Begin);
588
589 // (BeginLoc, EndLoc) represents the range of the operand we are currently
590 // processing. Unlike Str, the range includes the leading '%'.
591 SourceLocation BeginLoc =
592 getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
593 SourceLocation EndLoc =
594 getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI);
595
Benjamin Kramer3204b152015-05-29 19:42:19 +0000596 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
Chris Lattner35b58362009-03-10 23:21:44 +0000597 continue;
598 }
Mike Stump11289f42009-09-09 15:08:12 +0000599
Akira Hatanaka987f1862014-08-22 06:05:21 +0000600 // Handle operands that have asmSymbolicName (e.g., %x[foo]).
Chris Lattner35b58362009-03-10 23:21:44 +0000601 if (EscapedChar == '[') {
Chris Lattner3fa25c62009-03-11 00:06:36 +0000602 DiagOffs = CurPtr-StrStart-1;
Mike Stump11289f42009-09-09 15:08:12 +0000603
Chris Lattner3fa25c62009-03-11 00:06:36 +0000604 // Find the ']'.
Chris Lattnera41b8472009-03-10 23:51:40 +0000605 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
Craig Topper36250ad2014-05-12 05:36:57 +0000606 if (NameEnd == nullptr)
Chris Lattner3fa25c62009-03-11 00:06:36 +0000607 return diag::err_asm_unterminated_symbolic_operand_name;
608 if (NameEnd == CurPtr)
609 return diag::err_asm_empty_symbolic_operand_name;
Mike Stump11289f42009-09-09 15:08:12 +0000610
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000611 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
Mike Stump11289f42009-09-09 15:08:12 +0000612
Chris Lattner35b58362009-03-10 23:21:44 +0000613 int N = getNamedOperand(SymbolicName);
Chris Lattner3fa25c62009-03-11 00:06:36 +0000614 if (N == -1) {
615 // Verify that an operand with that name exists.
616 DiagOffs = CurPtr-StrStart;
617 return diag::err_asm_unknown_symbolic_operand_name;
618 }
Akira Hatanaka987f1862014-08-22 06:05:21 +0000619
620 // Str contains "x[foo]" (Operand without the leading %).
621 std::string Str(Begin, NameEnd + 1 - Begin);
622
623 // (BeginLoc, EndLoc) represents the range of the operand we are currently
624 // processing. Unlike Str, the range includes the leading '%'.
625 SourceLocation BeginLoc =
626 getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI);
627 SourceLocation EndLoc =
628 getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI);
629
Benjamin Kramer3204b152015-05-29 19:42:19 +0000630 Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000631
Chris Lattner3fa25c62009-03-11 00:06:36 +0000632 CurPtr = NameEnd+1;
Chris Lattner35b58362009-03-10 23:21:44 +0000633 continue;
634 }
Mike Stump11289f42009-09-09 15:08:12 +0000635
Chris Lattner0cdaa2e2009-03-10 23:57:07 +0000636 DiagOffs = CurPtr-StrStart-1;
Chris Lattnera41b8472009-03-10 23:51:40 +0000637 return diag::err_asm_invalid_escape;
Chris Lattner35b58362009-03-10 23:21:44 +0000638 }
639}
Chad Rosier3b0c2602012-08-27 20:23:31 +0000640
641/// Assemble final IR asm string (GCC-style).
Craig Topperc571c812013-08-22 06:02:26 +0000642std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosier14836ba2012-08-24 17:05:45 +0000643 // Analyze the asm string to decompose it into its pieces. We know that Sema
644 // has already done this, so it is guaranteed to be successful.
Chad Rosierde70e0e2012-08-25 00:11:56 +0000645 SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces;
Chad Rosier14836ba2012-08-24 17:05:45 +0000646 unsigned DiagOffs;
647 AnalyzeAsmString(Pieces, C, DiagOffs);
648
649 std::string AsmString;
650 for (unsigned i = 0, e = Pieces.size(); i != e; ++i) {
651 if (Pieces[i].isString())
652 AsmString += Pieces[i].getString();
653 else if (Pieces[i].getModifier() == '\0')
654 AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo());
655 else
656 AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' +
657 Pieces[i].getModifier() + '}';
658 }
659 return AsmString;
660}
Chris Lattner35b58362009-03-10 23:21:44 +0000661
Chad Rosier3b0c2602012-08-27 20:23:31 +0000662/// Assemble final IR asm string (MS-style).
Craig Topperc571c812013-08-22 06:02:26 +0000663std::string MSAsmStmt::generateAsmString(const ASTContext &C) const {
Chad Rosier3b0c2602012-08-27 20:23:31 +0000664 // FIXME: This needs to be translated into the IR string representation.
Chad Rosier0bca4692012-08-28 20:33:49 +0000665 return AsmStr;
Chad Rosier3b0c2602012-08-27 20:23:31 +0000666}
667
Chad Rosierfe31e622012-08-24 00:07:09 +0000668Expr *MSAsmStmt::getOutputExpr(unsigned i) {
669 return cast<Expr>(Exprs[i]);
670}
671
672Expr *MSAsmStmt::getInputExpr(unsigned i) {
673 return cast<Expr>(Exprs[i + NumOutputs]);
674}
675void MSAsmStmt::setInputExpr(unsigned i, Expr *E) {
676 Exprs[i + NumOutputs] = E;
677}
678
Sam Weinigebcea982010-02-03 02:09:59 +0000679QualType CXXCatchStmt::getCaughtType() const {
680 if (ExceptionDecl)
681 return ExceptionDecl->getType();
682 return QualType();
683}
684
Chris Lattner86f5e132008-01-30 05:01:46 +0000685//===----------------------------------------------------------------------===//
686// Constructors
687//===----------------------------------------------------------------------===//
688
Craig Toppere6960e22013-08-22 05:28:54 +0000689GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc,
690 bool issimple, bool isvolatile, unsigned numoutputs,
691 unsigned numinputs, IdentifierInfo **names,
692 StringLiteral **constraints, Expr **exprs,
693 StringLiteral *asmstr, unsigned numclobbers,
694 StringLiteral **clobbers, SourceLocation rparenloc)
Chad Rosierfe3352e2012-08-27 19:38:01 +0000695 : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
696 numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) {
Nico Weberde565e32008-08-05 23:15:29 +0000697
Chad Rosier42032fa2012-08-07 23:12:23 +0000698 unsigned NumExprs = NumOutputs + NumInputs;
699
Anders Carlsson98323d22010-01-30 23:19:41 +0000700 Names = new (C) IdentifierInfo*[NumExprs];
701 std::copy(names, names + NumExprs, Names);
702
703 Exprs = new (C) Stmt*[NumExprs];
704 std::copy(exprs, exprs + NumExprs, Exprs);
705
706 Constraints = new (C) StringLiteral*[NumExprs];
707 std::copy(constraints, constraints + NumExprs, Constraints);
708
709 Clobbers = new (C) StringLiteral*[NumClobbers];
710 std::copy(clobbers, clobbers + NumClobbers, Clobbers);
Anders Carlsson94ea8aa2007-11-22 01:36:19 +0000711}
712
Craig Toppere6960e22013-08-22 05:28:54 +0000713MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000714 SourceLocation lbraceloc, bool issimple, bool isvolatile,
Chad Rosierf8037a12012-10-16 21:55:39 +0000715 ArrayRef<Token> asmtoks, unsigned numoutputs,
John McCallf413f5e2013-05-03 00:10:13 +0000716 unsigned numinputs,
Chad Rosierf8037a12012-10-16 21:55:39 +0000717 ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs,
718 StringRef asmstr, ArrayRef<StringRef> clobbers,
719 SourceLocation endloc)
720 : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs,
721 numinputs, clobbers.size()), LBraceLoc(lbraceloc),
John McCallf413f5e2013-05-03 00:10:13 +0000722 EndLoc(endloc), NumAsmToks(asmtoks.size()) {
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000723
John McCallf413f5e2013-05-03 00:10:13 +0000724 initialize(C, asmstr, asmtoks, constraints, exprs, clobbers);
725}
Chad Rosier7dbef3e2012-08-16 00:06:53 +0000726
Craig Toppere6960e22013-08-22 05:28:54 +0000727static StringRef copyIntoContext(const ASTContext &C, StringRef str) {
Benjamin Kramer2ab0d882015-08-04 12:34:23 +0000728 return str.copy(C);
John McCallf413f5e2013-05-03 00:10:13 +0000729}
730
Craig Toppere6960e22013-08-22 05:28:54 +0000731void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr,
John McCallf413f5e2013-05-03 00:10:13 +0000732 ArrayRef<Token> asmtoks,
733 ArrayRef<StringRef> constraints,
734 ArrayRef<Expr*> exprs,
735 ArrayRef<StringRef> clobbers) {
736 assert(NumAsmToks == asmtoks.size());
737 assert(NumClobbers == clobbers.size());
738
739 unsigned NumExprs = exprs.size();
740 assert(NumExprs == NumOutputs + NumInputs);
741 assert(NumExprs == constraints.size());
742
743 AsmStr = copyIntoContext(C, asmstr);
Chad Rosier99fc3812012-08-07 00:29:06 +0000744
Chad Rosierfe31e622012-08-24 00:07:09 +0000745 Exprs = new (C) Stmt*[NumExprs];
Chad Rosierf8037a12012-10-16 21:55:39 +0000746 for (unsigned i = 0, e = NumExprs; i != e; ++i)
747 Exprs[i] = exprs[i];
Chad Rosierfe31e622012-08-24 00:07:09 +0000748
Chad Rosier99fc3812012-08-07 00:29:06 +0000749 AsmToks = new (C) Token[NumAsmToks];
750 for (unsigned i = 0, e = NumAsmToks; i != e; ++i)
751 AsmToks[i] = asmtoks[i];
Chad Rosier3ed0bd92012-08-08 19:48:07 +0000752
Chad Rosier3dd7bf22012-08-28 20:28:20 +0000753 Constraints = new (C) StringRef[NumExprs];
754 for (unsigned i = 0, e = NumExprs; i != e; ++i) {
John McCallf413f5e2013-05-03 00:10:13 +0000755 Constraints[i] = copyIntoContext(C, constraints[i]);
Chad Rosier3dd7bf22012-08-28 20:28:20 +0000756 }
757
Chad Rosierbaf53f92012-08-10 21:36:25 +0000758 Clobbers = new (C) StringRef[NumClobbers];
Chad Rosierd6ef7042012-08-10 21:06:19 +0000759 for (unsigned i = 0, e = NumClobbers; i != e; ++i) {
760 // FIXME: Avoid the allocation/copy if at all possible.
John McCallf413f5e2013-05-03 00:10:13 +0000761 Clobbers[i] = copyIntoContext(C, clobbers[i]);
Chad Rosierd6ef7042012-08-10 21:06:19 +0000762 }
Chad Rosier32503022012-06-11 20:47:18 +0000763}
764
Chris Lattner86f5e132008-01-30 05:01:46 +0000765ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
766 Stmt *Body, SourceLocation FCL,
Nico Weberde565e32008-08-05 23:15:29 +0000767 SourceLocation RPL)
Chris Lattner86f5e132008-01-30 05:01:46 +0000768: Stmt(ObjCForCollectionStmtClass) {
769 SubExprs[ELEM] = Elem;
Pavel Labath515f4db2013-09-03 14:41:16 +0000770 SubExprs[COLLECTION] = Collect;
Chris Lattner86f5e132008-01-30 05:01:46 +0000771 SubExprs[BODY] = Body;
772 ForLoc = FCL;
773 RParenLoc = RPL;
774}
775
Douglas Gregor96c79492010-04-23 22:50:49 +0000776ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
777 Stmt **CatchStmts, unsigned NumCatchStmts,
778 Stmt *atFinallyStmt)
779 : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
Craig Topper36250ad2014-05-12 05:36:57 +0000780 NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) {
Douglas Gregor96c79492010-04-23 22:50:49 +0000781 Stmt **Stmts = getStmts();
782 Stmts[0] = atTryStmt;
783 for (unsigned I = 0; I != NumCatchStmts; ++I)
784 Stmts[I + 1] = CatchStmts[I];
Chad Rosier42032fa2012-08-07 23:12:23 +0000785
Douglas Gregor96c79492010-04-23 22:50:49 +0000786 if (HasFinally)
787 Stmts[NumCatchStmts + 1] = atFinallyStmt;
788}
Chris Lattner86f5e132008-01-30 05:01:46 +0000789
Craig Toppere6960e22013-08-22 05:28:54 +0000790ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context,
Chad Rosier42032fa2012-08-07 23:12:23 +0000791 SourceLocation atTryLoc,
Douglas Gregor96c79492010-04-23 22:50:49 +0000792 Stmt *atTryStmt,
Chad Rosier42032fa2012-08-07 23:12:23 +0000793 Stmt **CatchStmts,
Douglas Gregor96c79492010-04-23 22:50:49 +0000794 unsigned NumCatchStmts,
795 Stmt *atFinallyStmt) {
Chad Rosier42032fa2012-08-07 23:12:23 +0000796 unsigned Size = sizeof(ObjCAtTryStmt) +
Craig Topper36250ad2014-05-12 05:36:57 +0000797 (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *);
Chris Lattner5c0b4052010-10-30 05:14:06 +0000798 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Douglas Gregor96c79492010-04-23 22:50:49 +0000799 return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
800 atFinallyStmt);
801}
Ted Kremeneka4965842008-02-01 21:28:59 +0000802
Craig Toppere6960e22013-08-22 05:28:54 +0000803ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context,
804 unsigned NumCatchStmts,
805 bool HasFinally) {
Chad Rosier42032fa2012-08-07 23:12:23 +0000806 unsigned Size = sizeof(ObjCAtTryStmt) +
Douglas Gregor96c79492010-04-23 22:50:49 +0000807 (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
Chris Lattner5c0b4052010-10-30 05:14:06 +0000808 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Chad Rosier42032fa2012-08-07 23:12:23 +0000809 return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
Douglas Gregor96c79492010-04-23 22:50:49 +0000810}
Nico Weberde565e32008-08-05 23:15:29 +0000811
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000812SourceLocation ObjCAtTryStmt::getLocEnd() const {
Douglas Gregor96c79492010-04-23 22:50:49 +0000813 if (HasFinally)
Erik Verbruggen11a2ecc2012-12-25 14:51:39 +0000814 return getFinallyStmt()->getLocEnd();
815 if (NumCatchStmts)
816 return getCatchStmt(NumCatchStmts - 1)->getLocEnd();
817 return getTryBody()->getLocEnd();
Chris Lattner86f5e132008-01-30 05:01:46 +0000818}
819
Craig Toppere6960e22013-08-22 05:28:54 +0000820CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc,
Nico Weber9dff3782012-12-29 20:13:03 +0000821 Stmt *tryBlock, ArrayRef<Stmt*> handlers) {
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000822 std::size_t Size = sizeof(CXXTryStmt);
James Y Knight53c76162015-07-17 18:21:37 +0000823 Size += ((handlers.size() + 1) * sizeof(Stmt *));
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000824
Chris Lattner5c0b4052010-10-30 05:14:06 +0000825 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Nico Weber9dff3782012-12-29 20:13:03 +0000826 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers);
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000827}
828
Craig Toppere6960e22013-08-22 05:28:54 +0000829CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty,
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +0000830 unsigned numHandlers) {
831 std::size_t Size = sizeof(CXXTryStmt);
James Y Knight53c76162015-07-17 18:21:37 +0000832 Size += ((numHandlers + 1) * sizeof(Stmt *));
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +0000833
Chris Lattner5c0b4052010-10-30 05:14:06 +0000834 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Argyrios Kyrtzidis47cd7a92010-07-22 16:03:56 +0000835 return new (Mem) CXXTryStmt(Empty, numHandlers);
836}
837
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000838CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
Nico Weber9dff3782012-12-29 20:13:03 +0000839 ArrayRef<Stmt*> handlers)
840 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) {
Sam Weiniga16b0dd2010-02-03 03:56:39 +0000841 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
Sam Weinigebcea982010-02-03 02:09:59 +0000842 Stmts[0] = tryBlock;
Nico Weber9dff3782012-12-29 20:13:03 +0000843 std::copy(handlers.begin(), handlers.end(), Stmts + 1);
Sam Weinigebcea982010-02-03 02:09:59 +0000844}
845
Richard Smith02e85f32011-04-14 22:09:26 +0000846CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt,
847 Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
848 Stmt *Body, SourceLocation FL,
849 SourceLocation CL, SourceLocation RPL)
850 : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) {
851 SubExprs[RANGE] = Range;
852 SubExprs[BEGINEND] = BeginEndStmt;
Pavel Labath515f4db2013-09-03 14:41:16 +0000853 SubExprs[COND] = Cond;
854 SubExprs[INC] = Inc;
Richard Smith02e85f32011-04-14 22:09:26 +0000855 SubExprs[LOOPVAR] = LoopVar;
856 SubExprs[BODY] = Body;
857}
858
859Expr *CXXForRangeStmt::getRangeInit() {
860 DeclStmt *RangeStmt = getRangeStmt();
861 VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
Richard Trieu86738692014-02-27 23:59:14 +0000862 assert(RangeDecl && "for-range should have a single var decl");
Richard Smith02e85f32011-04-14 22:09:26 +0000863 return RangeDecl->getInit();
864}
865
866const Expr *CXXForRangeStmt::getRangeInit() const {
867 return const_cast<CXXForRangeStmt*>(this)->getRangeInit();
868}
869
870VarDecl *CXXForRangeStmt::getLoopVariable() {
871 Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
872 assert(LV && "No loop variable in CXXForRangeStmt");
873 return cast<VarDecl>(LV);
874}
875
876const VarDecl *CXXForRangeStmt::getLoopVariable() const {
877 return const_cast<CXXForRangeStmt*>(this)->getLoopVariable();
878}
879
Craig Toppere6960e22013-08-22 05:28:54 +0000880IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000881 Stmt *then, SourceLocation EL, Stmt *elsev)
882 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000883{
884 setConditionVariable(C, var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000885 SubExprs[COND] = cond;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000886 SubExprs[THEN] = then;
Chad Rosier42032fa2012-08-07 23:12:23 +0000887 SubExprs[ELSE] = elsev;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000888}
889
890VarDecl *IfStmt::getConditionVariable() const {
891 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000892 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000893
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000894 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
895 return cast<VarDecl>(DS->getSingleDecl());
896}
897
Craig Toppere6960e22013-08-22 05:28:54 +0000898void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000899 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000900 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000901 return;
902 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000903
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000904 SourceRange VarRange = V->getSourceRange();
905 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
906 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000907}
908
Craig Toppere6960e22013-08-22 05:28:54 +0000909ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
Chad Rosier42032fa2012-08-07 23:12:23 +0000910 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000911 SourceLocation RP)
Chad Rosier42032fa2012-08-07 23:12:23 +0000912 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000913{
914 SubExprs[INIT] = Init;
915 setConditionVariable(C, condVar);
Pavel Labath515f4db2013-09-03 14:41:16 +0000916 SubExprs[COND] = Cond;
917 SubExprs[INC] = Inc;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000918 SubExprs[BODY] = Body;
919}
920
921VarDecl *ForStmt::getConditionVariable() const {
922 if (!SubExprs[CONDVAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000923 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000924
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000925 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
926 return cast<VarDecl>(DS->getSingleDecl());
927}
928
Craig Toppere6960e22013-08-22 05:28:54 +0000929void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000930 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000931 SubExprs[CONDVAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000932 return;
933 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000934
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000935 SourceRange VarRange = V->getSourceRange();
936 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
937 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000938}
939
Craig Toppere6960e22013-08-22 05:28:54 +0000940SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond)
Benjamin Kramer475386d2015-04-02 15:29:07 +0000941 : Stmt(SwitchStmtClass), FirstCase(nullptr, false) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000942 setConditionVariable(C, Var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000943 SubExprs[COND] = cond;
Craig Topper36250ad2014-05-12 05:36:57 +0000944 SubExprs[BODY] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000945}
946
947VarDecl *SwitchStmt::getConditionVariable() const {
948 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000949 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000950
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000951 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
952 return cast<VarDecl>(DS->getSingleDecl());
953}
954
Craig Toppere6960e22013-08-22 05:28:54 +0000955void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000956 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000957 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000958 return;
959 }
Chad Rosier42032fa2012-08-07 23:12:23 +0000960
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000961 SourceRange VarRange = V->getSourceRange();
962 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
963 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000964}
965
John McCallbd066782011-02-09 08:16:59 +0000966Stmt *SwitchCase::getSubStmt() {
Chris Lattner80d51eb2011-02-28 00:18:06 +0000967 if (isa<CaseStmt>(this))
968 return cast<CaseStmt>(this)->getSubStmt();
John McCallbd066782011-02-09 08:16:59 +0000969 return cast<DefaultStmt>(this)->getSubStmt();
970}
971
Craig Toppere6960e22013-08-22 05:28:54 +0000972WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000973 SourceLocation WL)
Chris Lattner80d51eb2011-02-28 00:18:06 +0000974 : Stmt(WhileStmtClass) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000975 setConditionVariable(C, Var);
Pavel Labath515f4db2013-09-03 14:41:16 +0000976 SubExprs[COND] = cond;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000977 SubExprs[BODY] = body;
978 WhileLoc = WL;
979}
980
981VarDecl *WhileStmt::getConditionVariable() const {
982 if (!SubExprs[VAR])
Craig Topper36250ad2014-05-12 05:36:57 +0000983 return nullptr;
Chad Rosier42032fa2012-08-07 23:12:23 +0000984
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000985 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
986 return cast<VarDecl>(DS->getSingleDecl());
987}
988
Craig Toppere6960e22013-08-22 05:28:54 +0000989void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) {
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000990 if (!V) {
Craig Topper36250ad2014-05-12 05:36:57 +0000991 SubExprs[VAR] = nullptr;
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000992 return;
993 }
Daniel Dunbar62ee6412012-03-09 18:35:03 +0000994
995 SourceRange VarRange = V->getSourceRange();
996 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
997 VarRange.getEnd());
Douglas Gregor27b98ea2010-06-21 23:44:13 +0000998}
999
Ted Kremenek066dd932007-08-24 21:09:09 +00001000// IndirectGotoStmt
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001001LabelDecl *IndirectGotoStmt::getConstantTarget() {
John McCall9de91602010-10-28 08:53:48 +00001002 if (AddrLabelExpr *E =
1003 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
1004 return E->getLabel();
Craig Topper36250ad2014-05-12 05:36:57 +00001005 return nullptr;
John McCall9de91602010-10-28 08:53:48 +00001006}
Ted Kremenek066dd932007-08-24 21:09:09 +00001007
Ted Kremenek066dd932007-08-24 21:09:09 +00001008// ReturnStmt
Ted Kremenekc6501db2008-06-17 03:11:08 +00001009const Expr* ReturnStmt::getRetValue() const {
1010 return cast_or_null<Expr>(RetExpr);
1011}
1012Expr* ReturnStmt::getRetValue() {
1013 return cast_or_null<Expr>(RetExpr);
Ted Kremenek066dd932007-08-24 21:09:09 +00001014}
John Wiegley1c0675e2011-04-28 01:08:34 +00001015
Warren Huntf6be4cb2014-07-25 20:52:51 +00001016SEHTryStmt::SEHTryStmt(bool IsCXXTry,
1017 SourceLocation TryLoc,
1018 Stmt *TryBlock,
1019 Stmt *Handler)
1020 : Stmt(SEHTryStmtClass),
1021 IsCXXTry(IsCXXTry),
1022 TryLoc(TryLoc)
1023{
1024 Children[TRY] = TryBlock;
John Wiegley1c0675e2011-04-28 01:08:34 +00001025 Children[HANDLER] = Handler;
1026}
1027
Warren Huntf6be4cb2014-07-25 20:52:51 +00001028SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry,
Craig Toppere6960e22013-08-22 05:28:54 +00001029 SourceLocation TryLoc, Stmt *TryBlock,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001030 Stmt *Handler) {
1031 return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001032}
1033
1034SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
1035 return dyn_cast<SEHExceptStmt>(getHandler());
1036}
1037
1038SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const {
1039 return dyn_cast<SEHFinallyStmt>(getHandler());
1040}
1041
1042SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
1043 Expr *FilterExpr,
1044 Stmt *Block)
1045 : Stmt(SEHExceptStmtClass),
1046 Loc(Loc)
1047{
Pavel Labath515f4db2013-09-03 14:41:16 +00001048 Children[FILTER_EXPR] = FilterExpr;
John Wiegley1c0675e2011-04-28 01:08:34 +00001049 Children[BLOCK] = Block;
1050}
1051
Craig Toppere6960e22013-08-22 05:28:54 +00001052SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc,
1053 Expr *FilterExpr, Stmt *Block) {
John Wiegley1c0675e2011-04-28 01:08:34 +00001054 return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
1055}
1056
1057SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
1058 Stmt *Block)
1059 : Stmt(SEHFinallyStmtClass),
1060 Loc(Loc),
1061 Block(Block)
1062{}
1063
Craig Toppere6960e22013-08-22 05:28:54 +00001064SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc,
John Wiegley1c0675e2011-04-28 01:08:34 +00001065 Stmt *Block) {
1066 return new(C)SEHFinallyStmt(Loc,Block);
1067}
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001068
1069CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const {
1070 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1071
1072 // Offset of the first Capture object.
1073 unsigned FirstCaptureOffset =
1074 llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1075
1076 return reinterpret_cast<Capture *>(
1077 reinterpret_cast<char *>(const_cast<CapturedStmt *>(this))
1078 + FirstCaptureOffset);
1079}
1080
Wei Pan17fbf6e2013-05-04 03:59:06 +00001081CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind,
1082 ArrayRef<Capture> Captures,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001083 ArrayRef<Expr *> CaptureInits,
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001084 CapturedDecl *CD,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001085 RecordDecl *RD)
1086 : Stmt(CapturedStmtClass), NumCaptures(Captures.size()),
Wei Pan17fbf6e2013-05-04 03:59:06 +00001087 CapDeclAndKind(CD, Kind), TheRecordDecl(RD) {
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001088 assert( S && "null captured statement");
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001089 assert(CD && "null captured declaration for captured statement");
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001090 assert(RD && "null record declaration for captured statement");
1091
1092 // Copy initialization expressions.
1093 Stmt **Stored = getStoredStmts();
1094 for (unsigned I = 0, N = NumCaptures; I != N; ++I)
1095 *Stored++ = CaptureInits[I];
1096
1097 // Copy the statement being captured.
1098 *Stored = S;
1099
1100 // Copy all Capture objects.
1101 Capture *Buffer = getStoredCaptures();
1102 std::copy(Captures.begin(), Captures.end(), Buffer);
1103}
1104
1105CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures)
1106 : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures),
Craig Topper36250ad2014-05-12 05:36:57 +00001107 CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) {
1108 getStoredStmts()[NumCaptures] = nullptr;
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001109}
1110
Craig Toppere6960e22013-08-22 05:28:54 +00001111CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S,
Wei Pan17fbf6e2013-05-04 03:59:06 +00001112 CapturedRegionKind Kind,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001113 ArrayRef<Capture> Captures,
1114 ArrayRef<Expr *> CaptureInits,
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001115 CapturedDecl *CD,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001116 RecordDecl *RD) {
1117 // The layout is
1118 //
1119 // -----------------------------------------------------------
1120 // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture |
1121 // ----------------^-------------------^----------------------
1122 // getStoredStmts() getStoredCaptures()
1123 //
1124 // where S is the statement being captured.
1125 //
1126 assert(CaptureInits.size() == Captures.size() && "wrong number of arguments");
1127
1128 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1);
1129 if (!Captures.empty()) {
1130 // Realign for the following Capture array.
1131 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1132 Size += sizeof(Capture) * Captures.size();
1133 }
1134
1135 void *Mem = Context.Allocate(Size);
Wei Pan17fbf6e2013-05-04 03:59:06 +00001136 return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD);
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001137}
1138
Craig Toppere6960e22013-08-22 05:28:54 +00001139CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context,
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001140 unsigned NumCaptures) {
1141 unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1);
1142 if (NumCaptures > 0) {
1143 // Realign for the following Capture array.
1144 Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>());
1145 Size += sizeof(Capture) * NumCaptures;
1146 }
1147
1148 void *Mem = Context.Allocate(Size);
1149 return new (Mem) CapturedStmt(EmptyShell(), NumCaptures);
1150}
1151
1152Stmt::child_range CapturedStmt::children() {
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001153 // Children are captured field initilizers.
1154 return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001155}
1156
1157bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
Aaron Ballmanc656303a2014-03-14 18:08:33 +00001158 for (const auto &I : captures()) {
1159 if (!I.capturesVariable())
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001160 continue;
1161
1162 // This does not handle variable redeclarations. This should be
1163 // extended to capture variables with redeclarations, for example
1164 // a thread-private variable in OpenMP.
Aaron Ballmanc656303a2014-03-14 18:08:33 +00001165 if (I.getCapturedVar() == Var)
Tareq A. Siraj24110cc2013-04-16 18:53:08 +00001166 return true;
1167 }
1168
1169 return false;
1170}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001171
Benjamin Kramer5733e352015-07-18 17:09:36 +00001172OMPClause::child_range OMPClause::children() {
Alexey Bataev758e55e2013-09-06 18:03:48 +00001173 switch(getClauseKind()) {
1174 default : break;
1175#define OPENMP_CLAUSE(Name, Class) \
1176 case OMPC_ ## Name : return static_cast<Class *>(this)->children();
1177#include "clang/Basic/OpenMPKinds.def"
1178 }
1179 llvm_unreachable("unknown OMPClause");
1180}
1181
Alexey Bataev03b340a2014-10-21 03:16:40 +00001182void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1183 assert(VL.size() == varlist_size() &&
1184 "Number of private copies is not the same as the preallocated buffer");
1185 std::copy(VL.begin(), VL.end(), varlist_end());
1186}
1187
1188OMPPrivateClause *
1189OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
1190 SourceLocation LParenLoc, SourceLocation EndLoc,
1191 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) {
1192 // Allocate space for private variables and initializer expressions.
Alexey Bataev13193812014-02-25 11:25:38 +00001193 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
1194 llvm::alignOf<Expr *>()) +
Alexey Bataev03b340a2014-10-21 03:16:40 +00001195 2 * sizeof(Expr *) * VL.size());
1196 OMPPrivateClause *Clause =
1197 new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001198 Clause->setVarRefs(VL);
Alexey Bataev03b340a2014-10-21 03:16:40 +00001199 Clause->setPrivateCopies(PrivateVL);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001200 return Clause;
1201}
1202
Craig Toppere6960e22013-08-22 05:28:54 +00001203OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C,
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001204 unsigned N) {
Alexey Bataev13193812014-02-25 11:25:38 +00001205 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause),
1206 llvm::alignOf<Expr *>()) +
Alexey Bataev03b340a2014-10-21 03:16:40 +00001207 2 * sizeof(Expr *) * N);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001208 return new (Mem) OMPPrivateClause(N);
1209}
1210
Alexey Bataev4a5bb772014-10-08 14:01:46 +00001211void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) {
1212 assert(VL.size() == varlist_size() &&
1213 "Number of private copies is not the same as the preallocated buffer");
1214 std::copy(VL.begin(), VL.end(), varlist_end());
1215}
1216
1217void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) {
1218 assert(VL.size() == varlist_size() &&
1219 "Number of inits is not the same as the preallocated buffer");
1220 std::copy(VL.begin(), VL.end(), getPrivateCopies().end());
1221}
1222
1223OMPFirstprivateClause *
1224OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc,
1225 SourceLocation LParenLoc, SourceLocation EndLoc,
1226 ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL,
1227 ArrayRef<Expr *> InitVL) {
Alexey Bataev13193812014-02-25 11:25:38 +00001228 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
1229 llvm::alignOf<Expr *>()) +
Alexey Bataev4a5bb772014-10-08 14:01:46 +00001230 3 * sizeof(Expr *) * VL.size());
1231 OMPFirstprivateClause *Clause =
1232 new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001233 Clause->setVarRefs(VL);
Alexey Bataev4a5bb772014-10-08 14:01:46 +00001234 Clause->setPrivateCopies(PrivateVL);
1235 Clause->setInits(InitVL);
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001236 return Clause;
1237}
1238
1239OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C,
1240 unsigned N) {
Alexey Bataev13193812014-02-25 11:25:38 +00001241 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause),
1242 llvm::alignOf<Expr *>()) +
Alexey Bataev4a5bb772014-10-08 14:01:46 +00001243 3 * sizeof(Expr *) * N);
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001244 return new (Mem) OMPFirstprivateClause(N);
1245}
1246
Alexey Bataev38e89532015-04-16 04:54:05 +00001247void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) {
1248 assert(PrivateCopies.size() == varlist_size() &&
1249 "Number of private copies is not the same as the preallocated buffer");
1250 std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end());
1251}
1252
1253void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
1254 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
1255 "not the same as the "
1256 "preallocated buffer");
1257 std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end());
1258}
1259
1260void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
1261 assert(DstExprs.size() == varlist_size() && "Number of destination "
1262 "expressions is not the same as "
1263 "the preallocated buffer");
1264 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
1265}
1266
1267void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
1268 assert(AssignmentOps.size() == varlist_size() &&
1269 "Number of assignment expressions is not the same as the preallocated "
1270 "buffer");
1271 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
1272 getDestinationExprs().end());
1273}
1274
1275OMPLastprivateClause *OMPLastprivateClause::Create(
1276 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1277 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1278 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
Alexander Musman1bb328c2014-06-04 13:06:39 +00001279 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause),
1280 llvm::alignOf<Expr *>()) +
Alexey Bataev38e89532015-04-16 04:54:05 +00001281 5 * sizeof(Expr *) * VL.size());
Alexander Musman1bb328c2014-06-04 13:06:39 +00001282 OMPLastprivateClause *Clause =
1283 new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
1284 Clause->setVarRefs(VL);
Alexey Bataev38e89532015-04-16 04:54:05 +00001285 Clause->setSourceExprs(SrcExprs);
1286 Clause->setDestinationExprs(DstExprs);
1287 Clause->setAssignmentOps(AssignmentOps);
Alexander Musman1bb328c2014-06-04 13:06:39 +00001288 return Clause;
1289}
1290
1291OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C,
1292 unsigned N) {
1293 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause),
1294 llvm::alignOf<Expr *>()) +
Alexey Bataev38e89532015-04-16 04:54:05 +00001295 5 * sizeof(Expr *) * N);
Alexander Musman1bb328c2014-06-04 13:06:39 +00001296 return new (Mem) OMPLastprivateClause(N);
1297}
1298
Alexey Bataev758e55e2013-09-06 18:03:48 +00001299OMPSharedClause *OMPSharedClause::Create(const ASTContext &C,
1300 SourceLocation StartLoc,
1301 SourceLocation LParenLoc,
1302 SourceLocation EndLoc,
1303 ArrayRef<Expr *> VL) {
Alexey Bataev13193812014-02-25 11:25:38 +00001304 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
1305 llvm::alignOf<Expr *>()) +
1306 sizeof(Expr *) * VL.size());
Alexey Bataev758e55e2013-09-06 18:03:48 +00001307 OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc,
1308 EndLoc, VL.size());
1309 Clause->setVarRefs(VL);
1310 return Clause;
1311}
1312
1313OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C,
1314 unsigned N) {
Alexey Bataev13193812014-02-25 11:25:38 +00001315 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause),
1316 llvm::alignOf<Expr *>()) +
1317 sizeof(Expr *) * N);
Alexey Bataev758e55e2013-09-06 18:03:48 +00001318 return new (Mem) OMPSharedClause(N);
1319}
1320
Alexey Bataevbd9fec12015-08-18 06:47:21 +00001321void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) {
1322 assert(PL.size() == varlist_size() &&
1323 "Number of privates is not the same as the preallocated buffer");
1324 std::copy(PL.begin(), PL.end(), varlist_end());
1325}
1326
Alexander Musman3276a272015-03-21 10:12:56 +00001327void OMPLinearClause::setInits(ArrayRef<Expr *> IL) {
1328 assert(IL.size() == varlist_size() &&
1329 "Number of inits is not the same as the preallocated buffer");
Alexey Bataevbd9fec12015-08-18 06:47:21 +00001330 std::copy(IL.begin(), IL.end(), getPrivates().end());
Alexander Musman3276a272015-03-21 10:12:56 +00001331}
1332
1333void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) {
1334 assert(UL.size() == varlist_size() &&
1335 "Number of updates is not the same as the preallocated buffer");
1336 std::copy(UL.begin(), UL.end(), getInits().end());
1337}
1338
1339void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) {
1340 assert(FL.size() == varlist_size() &&
1341 "Number of final updates is not the same as the preallocated buffer");
1342 std::copy(FL.begin(), FL.end(), getUpdates().end());
1343}
1344
Alexey Bataevbd9fec12015-08-18 06:47:21 +00001345OMPLinearClause *OMPLinearClause::Create(
1346 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001347 OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc,
Alexey Bataevbd9fec12015-08-18 06:47:21 +00001348 SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL,
1349 ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep) {
Alexander Musman3276a272015-03-21 10:12:56 +00001350 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
1351 // (Step and CalcStep).
Alexander Musman8dba6642014-04-22 13:09:42 +00001352 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
1353 llvm::alignOf<Expr *>()) +
Alexey Bataevbd9fec12015-08-18 06:47:21 +00001354 (5 * VL.size() + 2) * sizeof(Expr *));
Alexey Bataev182227b2015-08-20 10:54:39 +00001355 OMPLinearClause *Clause = new (Mem) OMPLinearClause(
1356 StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size());
Alexander Musman8dba6642014-04-22 13:09:42 +00001357 Clause->setVarRefs(VL);
Alexey Bataevbd9fec12015-08-18 06:47:21 +00001358 Clause->setPrivates(PL);
Alexander Musman3276a272015-03-21 10:12:56 +00001359 Clause->setInits(IL);
1360 // Fill update and final expressions with zeroes, they are provided later,
1361 // after the directive construction.
1362 std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(),
1363 nullptr);
1364 std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(),
1365 nullptr);
Alexander Musman8dba6642014-04-22 13:09:42 +00001366 Clause->setStep(Step);
Alexander Musman3276a272015-03-21 10:12:56 +00001367 Clause->setCalcStep(CalcStep);
Alexander Musman8dba6642014-04-22 13:09:42 +00001368 return Clause;
1369}
1370
1371OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C,
1372 unsigned NumVars) {
Alexander Musman3276a272015-03-21 10:12:56 +00001373 // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions
1374 // (Step and CalcStep).
Alexander Musman8dba6642014-04-22 13:09:42 +00001375 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause),
1376 llvm::alignOf<Expr *>()) +
Alexey Bataevbd9fec12015-08-18 06:47:21 +00001377 (5 * NumVars + 2) * sizeof(Expr *));
Alexander Musman8dba6642014-04-22 13:09:42 +00001378 return new (Mem) OMPLinearClause(NumVars);
1379}
1380
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001381OMPAlignedClause *
1382OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc,
1383 SourceLocation LParenLoc, SourceLocation ColonLoc,
1384 SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) {
1385 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause),
1386 llvm::alignOf<Expr *>()) +
1387 sizeof(Expr *) * (VL.size() + 1));
1388 OMPAlignedClause *Clause = new (Mem)
1389 OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size());
1390 Clause->setVarRefs(VL);
1391 Clause->setAlignment(A);
1392 return Clause;
1393}
1394
1395OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C,
1396 unsigned NumVars) {
1397 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause),
1398 llvm::alignOf<Expr *>()) +
1399 sizeof(Expr *) * (NumVars + 1));
1400 return new (Mem) OMPAlignedClause(NumVars);
1401}
1402
Alexey Bataevf56f98c2015-04-16 05:39:01 +00001403void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
1404 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
1405 "not the same as the "
1406 "preallocated buffer");
1407 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
1408}
1409
1410void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
1411 assert(DstExprs.size() == varlist_size() && "Number of destination "
1412 "expressions is not the same as "
1413 "the preallocated buffer");
1414 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
1415}
1416
1417void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
1418 assert(AssignmentOps.size() == varlist_size() &&
1419 "Number of assignment expressions is not the same as the preallocated "
1420 "buffer");
1421 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
1422 getDestinationExprs().end());
1423}
1424
1425OMPCopyinClause *OMPCopyinClause::Create(
1426 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1427 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1428 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001429 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause),
1430 llvm::alignOf<Expr *>()) +
Alexey Bataevf56f98c2015-04-16 05:39:01 +00001431 4 * sizeof(Expr *) * VL.size());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001432 OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc,
1433 EndLoc, VL.size());
1434 Clause->setVarRefs(VL);
Alexey Bataevf56f98c2015-04-16 05:39:01 +00001435 Clause->setSourceExprs(SrcExprs);
1436 Clause->setDestinationExprs(DstExprs);
1437 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001438 return Clause;
1439}
1440
1441OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C,
1442 unsigned N) {
1443 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause),
1444 llvm::alignOf<Expr *>()) +
Alexey Bataevf56f98c2015-04-16 05:39:01 +00001445 4 * sizeof(Expr *) * N);
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001446 return new (Mem) OMPCopyinClause(N);
1447}
1448
Alexey Bataeva63048e2015-03-23 06:18:07 +00001449void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) {
1450 assert(SrcExprs.size() == varlist_size() && "Number of source expressions is "
1451 "not the same as the "
1452 "preallocated buffer");
1453 std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end());
1454}
1455
1456void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) {
1457 assert(DstExprs.size() == varlist_size() && "Number of destination "
1458 "expressions is not the same as "
1459 "the preallocated buffer");
1460 std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end());
1461}
1462
1463void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) {
1464 assert(AssignmentOps.size() == varlist_size() &&
1465 "Number of assignment expressions is not the same as the preallocated "
1466 "buffer");
1467 std::copy(AssignmentOps.begin(), AssignmentOps.end(),
1468 getDestinationExprs().end());
1469}
1470
1471OMPCopyprivateClause *OMPCopyprivateClause::Create(
1472 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1473 SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs,
1474 ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) {
Alexey Bataevbae9a792014-06-27 10:37:06 +00001475 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause),
1476 llvm::alignOf<Expr *>()) +
Alexey Bataeva63048e2015-03-23 06:18:07 +00001477 4 * sizeof(Expr *) * VL.size());
Alexey Bataevbae9a792014-06-27 10:37:06 +00001478 OMPCopyprivateClause *Clause =
1479 new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size());
1480 Clause->setVarRefs(VL);
Alexey Bataeva63048e2015-03-23 06:18:07 +00001481 Clause->setSourceExprs(SrcExprs);
1482 Clause->setDestinationExprs(DstExprs);
1483 Clause->setAssignmentOps(AssignmentOps);
Alexey Bataevbae9a792014-06-27 10:37:06 +00001484 return Clause;
1485}
1486
1487OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C,
1488 unsigned N) {
1489 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause),
1490 llvm::alignOf<Expr *>()) +
Alexey Bataeva63048e2015-03-23 06:18:07 +00001491 4 * sizeof(Expr *) * N);
Alexey Bataevbae9a792014-06-27 10:37:06 +00001492 return new (Mem) OMPCopyprivateClause(N);
1493}
1494
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001495void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) {
Alexander Musmanfd2b7592014-03-27 15:14:18 +00001496 assert(Clauses.size() == getNumClauses() &&
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001497 "Number of clauses is not the same as the preallocated buffer");
Alexander Musmanfd2b7592014-03-27 15:14:18 +00001498 std::copy(Clauses.begin(), Clauses.end(), getClauses().begin());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001499}
1500
Alexander Musmana5f070a2014-10-01 06:03:56 +00001501void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) {
1502 assert(A.size() == getCollapsedNumber() &&
1503 "Number of loop counters is not the same as the collapsed number");
1504 std::copy(A.begin(), A.end(), getCounters().begin());
1505}
1506
Alexey Bataeva8899172015-08-06 12:30:57 +00001507void OMPLoopDirective::setPrivateCounters(ArrayRef<Expr *> A) {
1508 assert(A.size() == getCollapsedNumber() && "Number of loop private counters "
1509 "is not the same as the collapsed "
1510 "number");
1511 std::copy(A.begin(), A.end(), getPrivateCounters().begin());
1512}
1513
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001514void OMPLoopDirective::setInits(ArrayRef<Expr *> A) {
1515 assert(A.size() == getCollapsedNumber() &&
1516 "Number of counter inits is not the same as the collapsed number");
1517 std::copy(A.begin(), A.end(), getInits().begin());
1518}
1519
Alexander Musmana5f070a2014-10-01 06:03:56 +00001520void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) {
1521 assert(A.size() == getCollapsedNumber() &&
1522 "Number of counter updates is not the same as the collapsed number");
1523 std::copy(A.begin(), A.end(), getUpdates().begin());
1524}
1525
1526void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) {
1527 assert(A.size() == getCollapsedNumber() &&
1528 "Number of counter finals is not the same as the collapsed number");
1529 std::copy(A.begin(), A.end(), getFinals().begin());
1530}
1531
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001532void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) {
1533 assert(
1534 LHSExprs.size() == varlist_size() &&
1535 "Number of LHS expressions is not the same as the preallocated buffer");
1536 std::copy(LHSExprs.begin(), LHSExprs.end(), varlist_end());
1537}
1538
1539void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) {
1540 assert(
1541 RHSExprs.size() == varlist_size() &&
1542 "Number of RHS expressions is not the same as the preallocated buffer");
1543 std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end());
1544}
1545
1546void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) {
1547 assert(ReductionOps.size() == varlist_size() && "Number of reduction "
1548 "expressions is not the same "
1549 "as the preallocated buffer");
1550 std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end());
1551}
1552
Alexey Bataevc5e02582014-06-16 07:08:35 +00001553OMPReductionClause *OMPReductionClause::Create(
1554 const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc,
1555 SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL,
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001556 NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo,
1557 ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs,
1558 ArrayRef<Expr *> ReductionOps) {
Alexey Bataevc5e02582014-06-16 07:08:35 +00001559 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause),
1560 llvm::alignOf<Expr *>()) +
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001561 4 * sizeof(Expr *) * VL.size());
Alexey Bataevc5e02582014-06-16 07:08:35 +00001562 OMPReductionClause *Clause = new (Mem) OMPReductionClause(
1563 StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo);
1564 Clause->setVarRefs(VL);
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001565 Clause->setLHSExprs(LHSExprs);
1566 Clause->setRHSExprs(RHSExprs);
1567 Clause->setReductionOps(ReductionOps);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001568 return Clause;
1569}
1570
1571OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C,
1572 unsigned N) {
1573 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause),
1574 llvm::alignOf<Expr *>()) +
Alexey Bataev794ba0d2015-04-10 10:43:45 +00001575 4 * sizeof(Expr *) * N);
Alexey Bataevc5e02582014-06-16 07:08:35 +00001576 return new (Mem) OMPReductionClause(N);
1577}
1578
Alexey Bataev6125da92014-07-21 11:26:11 +00001579OMPFlushClause *OMPFlushClause::Create(const ASTContext &C,
1580 SourceLocation StartLoc,
1581 SourceLocation LParenLoc,
1582 SourceLocation EndLoc,
1583 ArrayRef<Expr *> VL) {
1584 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause),
1585 llvm::alignOf<Expr *>()) +
1586 sizeof(Expr *) * VL.size());
1587 OMPFlushClause *Clause =
1588 new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size());
1589 Clause->setVarRefs(VL);
1590 return Clause;
1591}
1592
1593OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) {
1594 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause),
1595 llvm::alignOf<Expr *>()) +
1596 sizeof(Expr *) * N);
1597 return new (Mem) OMPFlushClause(N);
1598}
1599
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001600OMPDependClause *
1601OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc,
1602 SourceLocation LParenLoc, SourceLocation EndLoc,
1603 OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1604 SourceLocation ColonLoc, ArrayRef<Expr *> VL) {
1605 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause),
1606 llvm::alignOf<Expr *>()) +
1607 sizeof(Expr *) * VL.size());
1608 OMPDependClause *Clause =
1609 new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size());
1610 Clause->setVarRefs(VL);
1611 Clause->setDependencyKind(DepKind);
1612 Clause->setDependencyLoc(DepLoc);
1613 Clause->setColonLoc(ColonLoc);
1614 return Clause;
1615}
1616
1617OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) {
1618 void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause),
1619 llvm::alignOf<Expr *>()) +
1620 sizeof(Expr *) * N);
1621 return new (Mem) OMPDependClause(N);
1622}
1623
Alexey Bataevd74d0602014-10-13 06:02:40 +00001624const OMPClause *
1625OMPExecutableDirective::getSingleClause(OpenMPClauseKind K) const {
Alexey Bataevc925aa32015-04-27 08:00:32 +00001626 auto &&I = getClausesOfKind(K);
Alexey Bataevd74d0602014-10-13 06:02:40 +00001627
1628 if (I) {
1629 auto *Clause = *I;
1630 assert(!++I && "There are at least 2 clauses of the specified kind");
1631 return Clause;
1632 }
1633 return nullptr;
1634}
1635
Craig Toppercee61332013-08-21 04:01:01 +00001636OMPParallelDirective *OMPParallelDirective::Create(
Craig Toppere6960e22013-08-22 05:28:54 +00001637 const ASTContext &C,
Craig Toppercee61332013-08-21 04:01:01 +00001638 SourceLocation StartLoc,
1639 SourceLocation EndLoc,
1640 ArrayRef<OMPClause *> Clauses,
1641 Stmt *AssociatedStmt) {
Alexey Bataev13193812014-02-25 11:25:38 +00001642 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
1643 llvm::alignOf<OMPClause *>());
1644 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1645 sizeof(Stmt *));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001646 OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc,
1647 Clauses.size());
1648 Dir->setClauses(Clauses);
1649 Dir->setAssociatedStmt(AssociatedStmt);
1650 return Dir;
1651}
1652
Craig Toppere6960e22013-08-22 05:28:54 +00001653OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001654 unsigned NumClauses,
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001655 EmptyShell) {
Alexey Bataev13193812014-02-25 11:25:38 +00001656 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective),
1657 llvm::alignOf<OMPClause *>());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001658 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1659 sizeof(Stmt *));
1660 return new (Mem) OMPParallelDirective(NumClauses);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001661}
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001662
Alexey Bataevabfc0692014-06-25 06:52:00 +00001663OMPSimdDirective *
1664OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
1665 SourceLocation EndLoc, unsigned CollapsedNum,
Alexander Musmana5f070a2014-10-01 06:03:56 +00001666 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
Alexander Musmanc6388682014-12-15 07:07:06 +00001667 const HelperExprs &Exprs) {
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001668 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective),
1669 llvm::alignOf<OMPClause *>());
Alexander Musmanc6388682014-12-15 07:07:06 +00001670 void *Mem =
1671 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1672 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd));
Alexey Bataevabfc0692014-06-25 06:52:00 +00001673 OMPSimdDirective *Dir = new (Mem)
1674 OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001675 Dir->setClauses(Clauses);
1676 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmanc6388682014-12-15 07:07:06 +00001677 Dir->setIterationVariable(Exprs.IterationVarRef);
1678 Dir->setLastIteration(Exprs.LastIteration);
1679 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1680 Dir->setPreCond(Exprs.PreCond);
Alexey Bataevae05c292015-06-16 11:59:36 +00001681 Dir->setCond(Exprs.Cond);
Alexander Musmanc6388682014-12-15 07:07:06 +00001682 Dir->setInit(Exprs.Init);
1683 Dir->setInc(Exprs.Inc);
1684 Dir->setCounters(Exprs.Counters);
Alexey Bataeva8899172015-08-06 12:30:57 +00001685 Dir->setPrivateCounters(Exprs.PrivateCounters);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001686 Dir->setInits(Exprs.Inits);
Alexander Musmanc6388682014-12-15 07:07:06 +00001687 Dir->setUpdates(Exprs.Updates);
1688 Dir->setFinals(Exprs.Finals);
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001689 return Dir;
1690}
1691
1692OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C,
1693 unsigned NumClauses,
1694 unsigned CollapsedNum,
1695 EmptyShell) {
1696 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective),
1697 llvm::alignOf<OMPClause *>());
Alexander Musmanc6388682014-12-15 07:07:06 +00001698 void *Mem =
1699 C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1700 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd));
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001701 return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses);
1702}
1703
Alexey Bataevabfc0692014-06-25 06:52:00 +00001704OMPForDirective *
1705OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc,
1706 SourceLocation EndLoc, unsigned CollapsedNum,
Alexander Musmana5f070a2014-10-01 06:03:56 +00001707 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
Alexander Musmanc6388682014-12-15 07:07:06 +00001708 const HelperExprs &Exprs) {
Alexey Bataevf29276e2014-06-18 04:14:57 +00001709 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective),
1710 llvm::alignOf<OMPClause *>());
Alexander Musmanc6388682014-12-15 07:07:06 +00001711 void *Mem =
1712 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1713 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for));
Alexey Bataevf29276e2014-06-18 04:14:57 +00001714 OMPForDirective *Dir =
Alexey Bataevabfc0692014-06-25 06:52:00 +00001715 new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
Alexey Bataevf29276e2014-06-18 04:14:57 +00001716 Dir->setClauses(Clauses);
1717 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmanc6388682014-12-15 07:07:06 +00001718 Dir->setIterationVariable(Exprs.IterationVarRef);
1719 Dir->setLastIteration(Exprs.LastIteration);
1720 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1721 Dir->setPreCond(Exprs.PreCond);
Alexey Bataevae05c292015-06-16 11:59:36 +00001722 Dir->setCond(Exprs.Cond);
Alexander Musmanc6388682014-12-15 07:07:06 +00001723 Dir->setInit(Exprs.Init);
1724 Dir->setInc(Exprs.Inc);
1725 Dir->setIsLastIterVariable(Exprs.IL);
1726 Dir->setLowerBoundVariable(Exprs.LB);
1727 Dir->setUpperBoundVariable(Exprs.UB);
1728 Dir->setStrideVariable(Exprs.ST);
1729 Dir->setEnsureUpperBound(Exprs.EUB);
1730 Dir->setNextLowerBound(Exprs.NLB);
1731 Dir->setNextUpperBound(Exprs.NUB);
1732 Dir->setCounters(Exprs.Counters);
Alexey Bataeva8899172015-08-06 12:30:57 +00001733 Dir->setPrivateCounters(Exprs.PrivateCounters);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001734 Dir->setInits(Exprs.Inits);
Alexander Musmanc6388682014-12-15 07:07:06 +00001735 Dir->setUpdates(Exprs.Updates);
1736 Dir->setFinals(Exprs.Finals);
Alexey Bataevf29276e2014-06-18 04:14:57 +00001737 return Dir;
1738}
1739
1740OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C,
1741 unsigned NumClauses,
1742 unsigned CollapsedNum,
1743 EmptyShell) {
1744 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective),
1745 llvm::alignOf<OMPClause *>());
Alexander Musmanc6388682014-12-15 07:07:06 +00001746 void *Mem =
1747 C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1748 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for));
Alexey Bataevf29276e2014-06-18 04:14:57 +00001749 return new (Mem) OMPForDirective(CollapsedNum, NumClauses);
1750}
1751
Alexander Musmanc6388682014-12-15 07:07:06 +00001752OMPForSimdDirective *
1753OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc,
1754 SourceLocation EndLoc, unsigned CollapsedNum,
1755 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
1756 const HelperExprs &Exprs) {
Alexander Musmanf82886e2014-09-18 05:12:34 +00001757 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective),
1758 llvm::alignOf<OMPClause *>());
Alexander Musmanc6388682014-12-15 07:07:06 +00001759 void *Mem =
1760 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
1761 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd));
Alexander Musmanf82886e2014-09-18 05:12:34 +00001762 OMPForSimdDirective *Dir = new (Mem)
1763 OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
1764 Dir->setClauses(Clauses);
1765 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmanc6388682014-12-15 07:07:06 +00001766 Dir->setIterationVariable(Exprs.IterationVarRef);
1767 Dir->setLastIteration(Exprs.LastIteration);
1768 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1769 Dir->setPreCond(Exprs.PreCond);
Alexey Bataevae05c292015-06-16 11:59:36 +00001770 Dir->setCond(Exprs.Cond);
Alexander Musmanc6388682014-12-15 07:07:06 +00001771 Dir->setInit(Exprs.Init);
1772 Dir->setInc(Exprs.Inc);
1773 Dir->setIsLastIterVariable(Exprs.IL);
1774 Dir->setLowerBoundVariable(Exprs.LB);
1775 Dir->setUpperBoundVariable(Exprs.UB);
1776 Dir->setStrideVariable(Exprs.ST);
1777 Dir->setEnsureUpperBound(Exprs.EUB);
1778 Dir->setNextLowerBound(Exprs.NLB);
1779 Dir->setNextUpperBound(Exprs.NUB);
1780 Dir->setCounters(Exprs.Counters);
Alexey Bataeva8899172015-08-06 12:30:57 +00001781 Dir->setPrivateCounters(Exprs.PrivateCounters);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001782 Dir->setInits(Exprs.Inits);
Alexander Musmanc6388682014-12-15 07:07:06 +00001783 Dir->setUpdates(Exprs.Updates);
1784 Dir->setFinals(Exprs.Finals);
Alexander Musmanf82886e2014-09-18 05:12:34 +00001785 return Dir;
1786}
1787
1788OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C,
1789 unsigned NumClauses,
1790 unsigned CollapsedNum,
1791 EmptyShell) {
1792 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective),
1793 llvm::alignOf<OMPClause *>());
Alexander Musmanc6388682014-12-15 07:07:06 +00001794 void *Mem =
1795 C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
1796 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd));
Alexander Musmanf82886e2014-09-18 05:12:34 +00001797 return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses);
1798}
1799
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00001800OMPSectionsDirective *OMPSectionsDirective::Create(
1801 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1802 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
1803 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
1804 llvm::alignOf<OMPClause *>());
1805 void *Mem =
1806 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1807 OMPSectionsDirective *Dir =
1808 new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size());
1809 Dir->setClauses(Clauses);
1810 Dir->setAssociatedStmt(AssociatedStmt);
1811 return Dir;
1812}
1813
1814OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C,
1815 unsigned NumClauses,
1816 EmptyShell) {
1817 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective),
1818 llvm::alignOf<OMPClause *>());
1819 void *Mem =
1820 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1821 return new (Mem) OMPSectionsDirective(NumClauses);
1822}
1823
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001824OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C,
1825 SourceLocation StartLoc,
1826 SourceLocation EndLoc,
1827 Stmt *AssociatedStmt) {
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00001828 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective),
Alexey Bataev1e0498a2014-06-26 08:21:58 +00001829 llvm::alignOf<Stmt *>());
1830 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1831 OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc);
1832 Dir->setAssociatedStmt(AssociatedStmt);
1833 return Dir;
1834}
1835
1836OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C,
1837 EmptyShell) {
1838 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective),
1839 llvm::alignOf<Stmt *>());
1840 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1841 return new (Mem) OMPSectionDirective();
1842}
1843
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00001844OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C,
1845 SourceLocation StartLoc,
1846 SourceLocation EndLoc,
1847 ArrayRef<OMPClause *> Clauses,
1848 Stmt *AssociatedStmt) {
1849 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
1850 llvm::alignOf<OMPClause *>());
1851 void *Mem =
1852 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
1853 OMPSingleDirective *Dir =
1854 new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size());
1855 Dir->setClauses(Clauses);
1856 Dir->setAssociatedStmt(AssociatedStmt);
1857 return Dir;
1858}
1859
1860OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C,
1861 unsigned NumClauses,
1862 EmptyShell) {
1863 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective),
1864 llvm::alignOf<OMPClause *>());
1865 void *Mem =
1866 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
1867 return new (Mem) OMPSingleDirective(NumClauses);
1868}
1869
Alexander Musman80c22892014-07-17 08:54:58 +00001870OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C,
1871 SourceLocation StartLoc,
1872 SourceLocation EndLoc,
1873 Stmt *AssociatedStmt) {
1874 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective),
1875 llvm::alignOf<Stmt *>());
1876 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1877 OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc);
1878 Dir->setAssociatedStmt(AssociatedStmt);
1879 return Dir;
1880}
1881
1882OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C,
1883 EmptyShell) {
1884 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective),
1885 llvm::alignOf<Stmt *>());
1886 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1887 return new (Mem) OMPMasterDirective();
1888}
1889
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001890OMPCriticalDirective *OMPCriticalDirective::Create(
1891 const ASTContext &C, const DeclarationNameInfo &Name,
1892 SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) {
1893 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective),
1894 llvm::alignOf<Stmt *>());
1895 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1896 OMPCriticalDirective *Dir =
1897 new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc);
1898 Dir->setAssociatedStmt(AssociatedStmt);
1899 return Dir;
1900}
1901
1902OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C,
1903 EmptyShell) {
1904 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective),
1905 llvm::alignOf<Stmt *>());
1906 void *Mem = C.Allocate(Size + sizeof(Stmt *));
1907 return new (Mem) OMPCriticalDirective();
1908}
1909
Alexander Musmana5f070a2014-10-01 06:03:56 +00001910OMPParallelForDirective *OMPParallelForDirective::Create(
1911 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
1912 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
Alexander Musmanc6388682014-12-15 07:07:06 +00001913 const HelperExprs &Exprs) {
Alexey Bataev4acb8592014-07-07 13:01:15 +00001914 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective),
1915 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001916 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
Alexander Musmanc6388682014-12-15 07:07:06 +00001917 sizeof(Stmt *) *
1918 numLoopChildren(CollapsedNum, OMPD_parallel_for));
Alexey Bataev4acb8592014-07-07 13:01:15 +00001919 OMPParallelForDirective *Dir = new (Mem)
1920 OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size());
1921 Dir->setClauses(Clauses);
1922 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmanc6388682014-12-15 07:07:06 +00001923 Dir->setIterationVariable(Exprs.IterationVarRef);
1924 Dir->setLastIteration(Exprs.LastIteration);
1925 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1926 Dir->setPreCond(Exprs.PreCond);
Alexey Bataevae05c292015-06-16 11:59:36 +00001927 Dir->setCond(Exprs.Cond);
Alexander Musmanc6388682014-12-15 07:07:06 +00001928 Dir->setInit(Exprs.Init);
1929 Dir->setInc(Exprs.Inc);
1930 Dir->setIsLastIterVariable(Exprs.IL);
1931 Dir->setLowerBoundVariable(Exprs.LB);
1932 Dir->setUpperBoundVariable(Exprs.UB);
1933 Dir->setStrideVariable(Exprs.ST);
1934 Dir->setEnsureUpperBound(Exprs.EUB);
1935 Dir->setNextLowerBound(Exprs.NLB);
1936 Dir->setNextUpperBound(Exprs.NUB);
1937 Dir->setCounters(Exprs.Counters);
Alexey Bataeva8899172015-08-06 12:30:57 +00001938 Dir->setPrivateCounters(Exprs.PrivateCounters);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001939 Dir->setInits(Exprs.Inits);
Alexander Musmanc6388682014-12-15 07:07:06 +00001940 Dir->setUpdates(Exprs.Updates);
1941 Dir->setFinals(Exprs.Finals);
Alexey Bataev4acb8592014-07-07 13:01:15 +00001942 return Dir;
1943}
1944
1945OMPParallelForDirective *
1946OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses,
1947 unsigned CollapsedNum, EmptyShell) {
1948 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective),
1949 llvm::alignOf<OMPClause *>());
Alexander Musmana5f070a2014-10-01 06:03:56 +00001950 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses +
Alexander Musmanc6388682014-12-15 07:07:06 +00001951 sizeof(Stmt *) *
1952 numLoopChildren(CollapsedNum, OMPD_parallel_for));
Alexey Bataev4acb8592014-07-07 13:01:15 +00001953 return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses);
1954}
1955
Alexander Musmane4e893b2014-09-23 09:33:00 +00001956OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create(
1957 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
Alexander Musmana5f070a2014-10-01 06:03:56 +00001958 unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt,
Alexander Musmanc6388682014-12-15 07:07:06 +00001959 const HelperExprs &Exprs) {
Alexander Musmane4e893b2014-09-23 09:33:00 +00001960 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective),
1961 llvm::alignOf<OMPClause *>());
Alexander Musmanc6388682014-12-15 07:07:06 +00001962 void *Mem = C.Allocate(
1963 Size + sizeof(OMPClause *) * Clauses.size() +
1964 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd));
Alexander Musmane4e893b2014-09-23 09:33:00 +00001965 OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective(
1966 StartLoc, EndLoc, CollapsedNum, Clauses.size());
1967 Dir->setClauses(Clauses);
1968 Dir->setAssociatedStmt(AssociatedStmt);
Alexander Musmanc6388682014-12-15 07:07:06 +00001969 Dir->setIterationVariable(Exprs.IterationVarRef);
1970 Dir->setLastIteration(Exprs.LastIteration);
1971 Dir->setCalcLastIteration(Exprs.CalcLastIteration);
1972 Dir->setPreCond(Exprs.PreCond);
Alexey Bataevae05c292015-06-16 11:59:36 +00001973 Dir->setCond(Exprs.Cond);
Alexander Musmanc6388682014-12-15 07:07:06 +00001974 Dir->setInit(Exprs.Init);
1975 Dir->setInc(Exprs.Inc);
1976 Dir->setIsLastIterVariable(Exprs.IL);
1977 Dir->setLowerBoundVariable(Exprs.LB);
1978 Dir->setUpperBoundVariable(Exprs.UB);
1979 Dir->setStrideVariable(Exprs.ST);
1980 Dir->setEnsureUpperBound(Exprs.EUB);
1981 Dir->setNextLowerBound(Exprs.NLB);
1982 Dir->setNextUpperBound(Exprs.NUB);
1983 Dir->setCounters(Exprs.Counters);
Alexey Bataeva8899172015-08-06 12:30:57 +00001984 Dir->setPrivateCounters(Exprs.PrivateCounters);
Alexey Bataevb08f89f2015-08-14 12:25:37 +00001985 Dir->setInits(Exprs.Inits);
Alexander Musmanc6388682014-12-15 07:07:06 +00001986 Dir->setUpdates(Exprs.Updates);
1987 Dir->setFinals(Exprs.Finals);
Alexander Musmane4e893b2014-09-23 09:33:00 +00001988 return Dir;
1989}
1990
1991OMPParallelForSimdDirective *
1992OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C,
1993 unsigned NumClauses,
1994 unsigned CollapsedNum, EmptyShell) {
1995 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective),
1996 llvm::alignOf<OMPClause *>());
Alexander Musmanc6388682014-12-15 07:07:06 +00001997 void *Mem = C.Allocate(
1998 Size + sizeof(OMPClause *) * NumClauses +
1999 sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd));
Alexander Musmane4e893b2014-09-23 09:33:00 +00002000 return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses);
2001}
2002
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00002003OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create(
2004 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
2005 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
2006 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective),
2007 llvm::alignOf<OMPClause *>());
2008 void *Mem =
2009 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
2010 OMPParallelSectionsDirective *Dir =
2011 new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size());
2012 Dir->setClauses(Clauses);
2013 Dir->setAssociatedStmt(AssociatedStmt);
2014 return Dir;
2015}
2016
2017OMPParallelSectionsDirective *
2018OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C,
2019 unsigned NumClauses, EmptyShell) {
2020 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective),
2021 llvm::alignOf<OMPClause *>());
2022 void *Mem =
2023 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
2024 return new (Mem) OMPParallelSectionsDirective(NumClauses);
2025}
2026
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00002027OMPTaskDirective *OMPTaskDirective::Create(const ASTContext &C,
2028 SourceLocation StartLoc,
2029 SourceLocation EndLoc,
2030 ArrayRef<OMPClause *> Clauses,
2031 Stmt *AssociatedStmt) {
2032 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective),
2033 llvm::alignOf<OMPClause *>());
2034 void *Mem =
2035 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
2036 OMPTaskDirective *Dir =
2037 new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size());
2038 Dir->setClauses(Clauses);
2039 Dir->setAssociatedStmt(AssociatedStmt);
2040 return Dir;
2041}
2042
2043OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C,
2044 unsigned NumClauses,
2045 EmptyShell) {
2046 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective),
2047 llvm::alignOf<OMPClause *>());
2048 void *Mem =
2049 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
2050 return new (Mem) OMPTaskDirective(NumClauses);
2051}
2052
Alexey Bataev68446b72014-07-18 07:47:19 +00002053OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C,
2054 SourceLocation StartLoc,
2055 SourceLocation EndLoc) {
2056 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
2057 OMPTaskyieldDirective *Dir =
2058 new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc);
2059 return Dir;
2060}
2061
2062OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C,
2063 EmptyShell) {
2064 void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective));
2065 return new (Mem) OMPTaskyieldDirective();
2066}
2067
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00002068OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C,
2069 SourceLocation StartLoc,
2070 SourceLocation EndLoc) {
2071 void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
2072 OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc);
2073 return Dir;
2074}
2075
2076OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C,
2077 EmptyShell) {
2078 void *Mem = C.Allocate(sizeof(OMPBarrierDirective));
2079 return new (Mem) OMPBarrierDirective();
2080}
2081
Alexey Bataev2df347a2014-07-18 10:17:07 +00002082OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C,
2083 SourceLocation StartLoc,
2084 SourceLocation EndLoc) {
2085 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
2086 OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc);
2087 return Dir;
2088}
2089
2090OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C,
2091 EmptyShell) {
2092 void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective));
2093 return new (Mem) OMPTaskwaitDirective();
2094}
2095
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00002096OMPTaskgroupDirective *OMPTaskgroupDirective::Create(const ASTContext &C,
2097 SourceLocation StartLoc,
2098 SourceLocation EndLoc,
2099 Stmt *AssociatedStmt) {
2100 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskgroupDirective),
2101 llvm::alignOf<Stmt *>());
2102 void *Mem = C.Allocate(Size + sizeof(Stmt *));
2103 OMPTaskgroupDirective *Dir =
2104 new (Mem) OMPTaskgroupDirective(StartLoc, EndLoc);
2105 Dir->setAssociatedStmt(AssociatedStmt);
2106 return Dir;
2107}
2108
2109OMPTaskgroupDirective *OMPTaskgroupDirective::CreateEmpty(const ASTContext &C,
2110 EmptyShell) {
2111 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskgroupDirective),
2112 llvm::alignOf<Stmt *>());
2113 void *Mem = C.Allocate(Size + sizeof(Stmt *));
2114 return new (Mem) OMPTaskgroupDirective();
2115}
2116
Alexey Bataev6d4ed052015-07-01 06:57:41 +00002117OMPCancellationPointDirective *OMPCancellationPointDirective::Create(
2118 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
2119 OpenMPDirectiveKind CancelRegion) {
2120 unsigned Size = llvm::RoundUpToAlignment(
2121 sizeof(OMPCancellationPointDirective), llvm::alignOf<Stmt *>());
2122 void *Mem = C.Allocate(Size);
2123 OMPCancellationPointDirective *Dir =
2124 new (Mem) OMPCancellationPointDirective(StartLoc, EndLoc);
2125 Dir->setCancelRegion(CancelRegion);
2126 return Dir;
2127}
2128
2129OMPCancellationPointDirective *
2130OMPCancellationPointDirective::CreateEmpty(const ASTContext &C, EmptyShell) {
2131 unsigned Size = llvm::RoundUpToAlignment(
2132 sizeof(OMPCancellationPointDirective), llvm::alignOf<Stmt *>());
2133 void *Mem = C.Allocate(Size);
2134 return new (Mem) OMPCancellationPointDirective();
2135}
2136
Alexey Bataev80909872015-07-02 11:25:17 +00002137OMPCancelDirective *
2138OMPCancelDirective::Create(const ASTContext &C, SourceLocation StartLoc,
2139 SourceLocation EndLoc,
2140 OpenMPDirectiveKind CancelRegion) {
2141 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCancelDirective),
2142 llvm::alignOf<Stmt *>());
2143 void *Mem = C.Allocate(Size);
2144 OMPCancelDirective *Dir = new (Mem) OMPCancelDirective(StartLoc, EndLoc);
2145 Dir->setCancelRegion(CancelRegion);
2146 return Dir;
2147}
2148
2149OMPCancelDirective *OMPCancelDirective::CreateEmpty(const ASTContext &C,
2150 EmptyShell) {
2151 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCancelDirective),
2152 llvm::alignOf<Stmt *>());
2153 void *Mem = C.Allocate(Size);
2154 return new (Mem) OMPCancelDirective();
2155}
2156
Alexey Bataev6125da92014-07-21 11:26:11 +00002157OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C,
2158 SourceLocation StartLoc,
2159 SourceLocation EndLoc,
2160 ArrayRef<OMPClause *> Clauses) {
2161 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective),
2162 llvm::alignOf<OMPClause *>());
2163 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size());
2164 OMPFlushDirective *Dir =
2165 new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size());
2166 Dir->setClauses(Clauses);
2167 return Dir;
2168}
2169
2170OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C,
2171 unsigned NumClauses,
2172 EmptyShell) {
2173 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective),
2174 llvm::alignOf<OMPClause *>());
2175 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses);
2176 return new (Mem) OMPFlushDirective(NumClauses);
2177}
2178
Alexey Bataev9fb6e642014-07-22 06:45:04 +00002179OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C,
2180 SourceLocation StartLoc,
2181 SourceLocation EndLoc,
2182 Stmt *AssociatedStmt) {
2183 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective),
2184 llvm::alignOf<Stmt *>());
2185 void *Mem = C.Allocate(Size + sizeof(Stmt *));
2186 OMPOrderedDirective *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc);
2187 Dir->setAssociatedStmt(AssociatedStmt);
2188 return Dir;
2189}
2190
2191OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C,
2192 EmptyShell) {
2193 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective),
2194 llvm::alignOf<Stmt *>());
2195 void *Mem = C.Allocate(Size + sizeof(Stmt *));
2196 return new (Mem) OMPOrderedDirective();
2197}
2198
Alexey Bataevb78ca832015-04-01 03:33:17 +00002199OMPAtomicDirective *OMPAtomicDirective::Create(
2200 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
2201 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V,
2202 Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate) {
Alexey Bataev0162e452014-07-22 10:10:35 +00002203 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective),
2204 llvm::alignOf<OMPClause *>());
Alexey Bataev62cec442014-11-18 10:14:22 +00002205 void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() +
Alexey Bataev1d160b12015-03-13 12:27:31 +00002206 5 * sizeof(Stmt *));
Alexey Bataev0162e452014-07-22 10:10:35 +00002207 OMPAtomicDirective *Dir =
2208 new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size());
2209 Dir->setClauses(Clauses);
2210 Dir->setAssociatedStmt(AssociatedStmt);
Alexey Bataev62cec442014-11-18 10:14:22 +00002211 Dir->setX(X);
2212 Dir->setV(V);
2213 Dir->setExpr(E);
Alexey Bataevb4505a72015-03-30 05:20:59 +00002214 Dir->setUpdateExpr(UE);
2215 Dir->IsXLHSInRHSPart = IsXLHSInRHSPart;
Alexey Bataevb78ca832015-04-01 03:33:17 +00002216 Dir->IsPostfixUpdate = IsPostfixUpdate;
Alexey Bataev0162e452014-07-22 10:10:35 +00002217 return Dir;
2218}
2219
2220OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C,
2221 unsigned NumClauses,
2222 EmptyShell) {
2223 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective),
2224 llvm::alignOf<OMPClause *>());
2225 void *Mem =
Alexey Bataev1d160b12015-03-13 12:27:31 +00002226 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 5 * sizeof(Stmt *));
Alexey Bataev0162e452014-07-22 10:10:35 +00002227 return new (Mem) OMPAtomicDirective(NumClauses);
2228}
2229
Alexey Bataev0bd520b2014-09-19 08:19:49 +00002230OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C,
2231 SourceLocation StartLoc,
2232 SourceLocation EndLoc,
2233 ArrayRef<OMPClause *> Clauses,
2234 Stmt *AssociatedStmt) {
2235 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective),
2236 llvm::alignOf<OMPClause *>());
2237 void *Mem =
2238 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
2239 OMPTargetDirective *Dir =
2240 new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size());
2241 Dir->setClauses(Clauses);
2242 Dir->setAssociatedStmt(AssociatedStmt);
2243 return Dir;
2244}
2245
2246OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C,
2247 unsigned NumClauses,
2248 EmptyShell) {
2249 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective),
2250 llvm::alignOf<OMPClause *>());
2251 void *Mem =
2252 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
2253 return new (Mem) OMPTargetDirective(NumClauses);
2254}
2255
Michael Wong65f367f2015-07-21 13:44:28 +00002256OMPTargetDataDirective *OMPTargetDataDirective::Create(
2257 const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc,
2258 ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) {
2259 void *Mem =
2260 C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPTargetDataDirective),
2261 llvm::alignOf<OMPClause *>()) +
2262 sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
2263 OMPTargetDataDirective *Dir =
2264 new (Mem) OMPTargetDataDirective(StartLoc, EndLoc, Clauses.size());
2265 Dir->setClauses(Clauses);
2266 Dir->setAssociatedStmt(AssociatedStmt);
2267 return Dir;
2268}
2269
2270OMPTargetDataDirective *OMPTargetDataDirective::CreateEmpty(const ASTContext &C,
2271 unsigned N,
2272 EmptyShell) {
2273 void *Mem =
2274 C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPTargetDataDirective),
2275 llvm::alignOf<OMPClause *>()) +
2276 sizeof(OMPClause *) * N + sizeof(Stmt *));
2277 return new (Mem) OMPTargetDataDirective(N);
2278}
2279
Alexey Bataev13314bf2014-10-09 04:18:56 +00002280OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C,
2281 SourceLocation StartLoc,
2282 SourceLocation EndLoc,
2283 ArrayRef<OMPClause *> Clauses,
2284 Stmt *AssociatedStmt) {
2285 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective),
2286 llvm::alignOf<OMPClause *>());
2287 void *Mem =
2288 C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *));
2289 OMPTeamsDirective *Dir =
2290 new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size());
2291 Dir->setClauses(Clauses);
2292 Dir->setAssociatedStmt(AssociatedStmt);
2293 return Dir;
2294}
2295
2296OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C,
2297 unsigned NumClauses,
2298 EmptyShell) {
2299 unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective),
2300 llvm::alignOf<OMPClause *>());
2301 void *Mem =
2302 C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *));
2303 return new (Mem) OMPTeamsDirective(NumClauses);
2304}