blob: 5f3a50b155bcc4c6efa9d486ae54537e7723031f [file] [log] [blame]
Douglas Gregor5c193b92009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor32615a12009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor5c193b92009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregora7095092009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/ExprCXX.h"
20#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000021#include "clang/AST/ExprOpenMP.h"
Richard Trieu639d7b62017-02-22 22:22:42 +000022#include "clang/AST/ODRHash.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000023#include "clang/AST/StmtVisitor.h"
24#include "llvm/ADT/FoldingSet.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000025using namespace clang;
26
27namespace {
Chandler Carruth631abd92011-06-16 06:47:06 +000028 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Richard Trieu639d7b62017-02-22 22:22:42 +000029 protected:
Douglas Gregor5c193b92009-07-28 00:33:38 +000030 llvm::FoldingSetNodeID &ID;
Douglas Gregor5c193b92009-07-28 00:33:38 +000031 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000032
Douglas Gregor5c193b92009-07-28 00:33:38 +000033 public:
Richard Trieu639d7b62017-02-22 22:22:42 +000034 StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical)
35 : ID(ID), Canonical(Canonical) {}
36
37 virtual ~StmtProfiler() {}
Mike Stump11289f42009-09-09 15:08:12 +000038
Chandler Carruth631abd92011-06-16 06:47:06 +000039 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000040
Chandler Carruth631abd92011-06-16 06:47:06 +000041#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000042#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000043
Douglas Gregor5c193b92009-07-28 00:33:38 +000044 /// \brief Visit a declaration that is referenced within an expression
45 /// or statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000046 virtual void VisitDecl(const Decl *D) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000047
48 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000049 /// statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000050 virtual void VisitType(QualType T) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000051
Douglas Gregor5c193b92009-07-28 00:33:38 +000052 /// \brief Visit a name that occurs within an expression or statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000053 virtual void VisitName(DeclarationName Name) = 0;
54
55 /// \brief Visit identifiers that are not in Decl's or Type's.
56 virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000057
Douglas Gregor5c193b92009-07-28 00:33:38 +000058 /// \brief Visit a nested-name-specifier that occurs within an expression
59 /// or statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000060 virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000061
Douglas Gregor5c193b92009-07-28 00:33:38 +000062 /// \brief Visit a template name that occurs within an expression or
63 /// statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000064 virtual void VisitTemplateName(TemplateName Name) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000065
Douglas Gregor5c193b92009-07-28 00:33:38 +000066 /// \brief Visit template arguments that occur within an expression or
67 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000068 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
69 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000070
71 /// \brief Visit a single template argument.
72 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000073 };
Richard Trieu639d7b62017-02-22 22:22:42 +000074
75 class StmtProfilerWithPointers : public StmtProfiler {
76 const ASTContext &Context;
77
78 public:
79 StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID,
80 const ASTContext &Context, bool Canonical)
81 : StmtProfiler(ID, Canonical), Context(Context) {}
82 private:
83 void VisitDecl(const Decl *D) override {
84 ID.AddInteger(D ? D->getKind() : 0);
85
86 if (Canonical && D) {
87 if (const NonTypeTemplateParmDecl *NTTP =
88 dyn_cast<NonTypeTemplateParmDecl>(D)) {
89 ID.AddInteger(NTTP->getDepth());
90 ID.AddInteger(NTTP->getIndex());
91 ID.AddBoolean(NTTP->isParameterPack());
92 VisitType(NTTP->getType());
93 return;
94 }
95
96 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
97 // The Itanium C++ ABI uses the type, scope depth, and scope
98 // index of a parameter when mangling expressions that involve
99 // function parameters, so we will use the parameter's type for
100 // establishing function parameter identity. That way, our
101 // definition of "equivalent" (per C++ [temp.over.link]) is at
102 // least as strong as the definition of "equivalent" used for
103 // name mangling.
104 VisitType(Parm->getType());
105 ID.AddInteger(Parm->getFunctionScopeDepth());
106 ID.AddInteger(Parm->getFunctionScopeIndex());
107 return;
108 }
109
110 if (const TemplateTypeParmDecl *TTP =
111 dyn_cast<TemplateTypeParmDecl>(D)) {
112 ID.AddInteger(TTP->getDepth());
113 ID.AddInteger(TTP->getIndex());
114 ID.AddBoolean(TTP->isParameterPack());
115 return;
116 }
117
118 if (const TemplateTemplateParmDecl *TTP =
119 dyn_cast<TemplateTemplateParmDecl>(D)) {
120 ID.AddInteger(TTP->getDepth());
121 ID.AddInteger(TTP->getIndex());
122 ID.AddBoolean(TTP->isParameterPack());
123 return;
124 }
125 }
126
127 ID.AddPointer(D ? D->getCanonicalDecl() : nullptr);
128 }
129
130 void VisitType(QualType T) override {
Richard Trieua5f4ade2017-03-04 02:42:41 +0000131 if (Canonical && !T.isNull())
Richard Trieu639d7b62017-02-22 22:22:42 +0000132 T = Context.getCanonicalType(T);
133
134 ID.AddPointer(T.getAsOpaquePtr());
135 }
136
137 void VisitName(DeclarationName Name) override {
138 ID.AddPointer(Name.getAsOpaquePtr());
139 }
140
141 void VisitIdentifierInfo(IdentifierInfo *II) override {
142 ID.AddPointer(II);
143 }
144
145 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
146 if (Canonical)
147 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
148 ID.AddPointer(NNS);
149 }
150
151 void VisitTemplateName(TemplateName Name) override {
152 if (Canonical)
153 Name = Context.getCanonicalTemplateName(Name);
154
155 Name.Profile(ID);
156 }
157 };
158
159 class StmtProfilerWithoutPointers : public StmtProfiler {
160 ODRHash &Hash;
161 public:
162 StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
163 : StmtProfiler(ID, false), Hash(Hash) {}
164
165 private:
166 void VisitType(QualType T) override {
167 Hash.AddQualType(T);
168 }
169
170 void VisitName(DeclarationName Name) override {
171 Hash.AddDeclarationName(Name);
172 }
173 void VisitIdentifierInfo(IdentifierInfo *II) override {
174 ID.AddBoolean(II);
175 if (II) {
176 Hash.AddIdentifierInfo(II);
177 }
178 }
179 void VisitDecl(const Decl *D) override {
180 ID.AddBoolean(D);
181 if (D) {
182 Hash.AddDecl(D);
183 }
184 }
185 void VisitTemplateName(TemplateName Name) override {
186 Hash.AddTemplateName(Name);
187 }
188 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
189 ID.AddBoolean(NNS);
190 if (NNS) {
191 Hash.AddNestedNameSpecifier(NNS);
192 }
193 }
194 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000195}
Douglas Gregor5c193b92009-07-28 00:33:38 +0000196
Chandler Carruth631abd92011-06-16 06:47:06 +0000197void StmtProfiler::VisitStmt(const Stmt *S) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000198 assert(S && "Requires non-null Stmt pointer");
Douglas Gregor5c193b92009-07-28 00:33:38 +0000199 ID.AddInteger(S->getStmtClass());
Benjamin Kramer642f1732015-07-02 21:03:14 +0000200 for (const Stmt *SubStmt : S->children()) {
201 if (SubStmt)
202 Visit(SubStmt);
Peter Collingbournecdb9f302012-03-01 16:34:31 +0000203 else
204 ID.AddInteger(0);
205 }
Douglas Gregor5c193b92009-07-28 00:33:38 +0000206}
207
Chandler Carruth631abd92011-06-16 06:47:06 +0000208void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000209 VisitStmt(S);
Aaron Ballman535bbcc2014-03-14 17:01:24 +0000210 for (const auto *D : S->decls())
211 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +0000212}
213
Chandler Carruth631abd92011-06-16 06:47:06 +0000214void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000215 VisitStmt(S);
216}
217
Chandler Carruth631abd92011-06-16 06:47:06 +0000218void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000219 VisitStmt(S);
220}
221
Chandler Carruth631abd92011-06-16 06:47:06 +0000222void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000223 VisitStmt(S);
224}
225
Chandler Carruth631abd92011-06-16 06:47:06 +0000226void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000227 VisitStmt(S);
228}
229
Chandler Carruth631abd92011-06-16 06:47:06 +0000230void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000231 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000232 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000233}
234
Richard Smithc202b282012-04-14 00:33:13 +0000235void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
236 VisitStmt(S);
237 // TODO: maybe visit attributes?
238}
239
Chandler Carruth631abd92011-06-16 06:47:06 +0000240void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000241 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000242 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000243}
244
Chandler Carruth631abd92011-06-16 06:47:06 +0000245void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000246 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000247 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000248}
249
Chandler Carruth631abd92011-06-16 06:47:06 +0000250void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000251 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000252 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000253}
254
Chandler Carruth631abd92011-06-16 06:47:06 +0000255void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000256 VisitStmt(S);
257}
258
Chandler Carruth631abd92011-06-16 06:47:06 +0000259void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000260 VisitStmt(S);
261}
262
Chandler Carruth631abd92011-06-16 06:47:06 +0000263void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000264 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000265 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000266}
267
Chandler Carruth631abd92011-06-16 06:47:06 +0000268void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000269 VisitStmt(S);
270}
271
Chandler Carruth631abd92011-06-16 06:47:06 +0000272void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000273 VisitStmt(S);
274}
275
Chandler Carruth631abd92011-06-16 06:47:06 +0000276void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000277 VisitStmt(S);
278}
279
Chandler Carruth631abd92011-06-16 06:47:06 +0000280void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000281 VisitStmt(S);
282}
283
Chad Rosierde70e0e2012-08-25 00:11:56 +0000284void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000285 VisitStmt(S);
286 ID.AddBoolean(S->isVolatile());
287 ID.AddBoolean(S->isSimple());
288 VisitStringLiteral(S->getAsmString());
289 ID.AddInteger(S->getNumOutputs());
290 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
291 ID.AddString(S->getOutputName(I));
292 VisitStringLiteral(S->getOutputConstraintLiteral(I));
293 }
294 ID.AddInteger(S->getNumInputs());
295 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
296 ID.AddString(S->getInputName(I));
297 VisitStringLiteral(S->getInputConstraintLiteral(I));
298 }
299 ID.AddInteger(S->getNumClobbers());
300 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000301 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor44882592009-07-28 15:27:13 +0000302}
303
Chad Rosier32503022012-06-11 20:47:18 +0000304void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
305 // FIXME: Implement MS style inline asm statement profiler.
306 VisitStmt(S);
307}
308
Chandler Carruth631abd92011-06-16 06:47:06 +0000309void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000310 VisitStmt(S);
311 VisitType(S->getCaughtType());
312}
313
Chandler Carruth631abd92011-06-16 06:47:06 +0000314void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000315 VisitStmt(S);
316}
317
Chandler Carruth631abd92011-06-16 06:47:06 +0000318void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000319 VisitStmt(S);
320}
321
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000322void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
323 VisitStmt(S);
324 ID.AddBoolean(S->isIfExists());
325 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
326 VisitName(S->getNameInfo().getName());
327}
328
Chandler Carruth631abd92011-06-16 06:47:06 +0000329void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000330 VisitStmt(S);
331}
332
Chandler Carruth631abd92011-06-16 06:47:06 +0000333void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000334 VisitStmt(S);
335}
336
Chandler Carruth631abd92011-06-16 06:47:06 +0000337void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000338 VisitStmt(S);
339}
340
Nico Weber9b982072014-07-07 00:12:30 +0000341void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
342 VisitStmt(S);
343}
344
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000345void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
346 VisitStmt(S);
347}
348
Chandler Carruth631abd92011-06-16 06:47:06 +0000349void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000350 VisitStmt(S);
351}
352
Chandler Carruth631abd92011-06-16 06:47:06 +0000353void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000354 VisitStmt(S);
355 ID.AddBoolean(S->hasEllipsis());
356 if (S->getCatchParamDecl())
357 VisitType(S->getCatchParamDecl()->getType());
358}
359
Chandler Carruth631abd92011-06-16 06:47:06 +0000360void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000361 VisitStmt(S);
362}
363
Chandler Carruth631abd92011-06-16 06:47:06 +0000364void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000365 VisitStmt(S);
366}
367
Chandler Carruth631abd92011-06-16 06:47:06 +0000368void
369StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000370 VisitStmt(S);
371}
372
Chandler Carruth631abd92011-06-16 06:47:06 +0000373void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000374 VisitStmt(S);
375}
376
Chandler Carruth631abd92011-06-16 06:47:06 +0000377void
378StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000379 VisitStmt(S);
380}
381
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000382namespace {
383class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
384 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000385 /// \brief Process clauses with list of variables.
386 template <typename T>
387 void VisitOMPClauseList(T *Node);
NAKAMURA Takumiaa13f942015-12-09 07:52:46 +0000388
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000389public:
390 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
391#define OPENMP_CLAUSE(Name, Class) \
392 void Visit##Class(const Class *C);
393#include "clang/Basic/OpenMPKinds.def"
Alexey Bataev3392d762016-02-16 11:18:12 +0000394 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000395 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000396};
397
Alexey Bataev3392d762016-02-16 11:18:12 +0000398void OMPClauseProfiler::VistOMPClauseWithPreInit(
399 const OMPClauseWithPreInit *C) {
400 if (auto *S = C->getPreInitStmt())
401 Profiler->VisitStmt(S);
402}
403
Alexey Bataev005248a2016-02-25 05:25:57 +0000404void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
405 const OMPClauseWithPostUpdate *C) {
Alexey Bataev37e594c2016-03-04 07:21:16 +0000406 VistOMPClauseWithPreInit(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000407 if (auto *E = C->getPostUpdateExpr())
408 Profiler->VisitStmt(E);
409}
410
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000411void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +0000412 VistOMPClauseWithPreInit(C);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000413 if (C->getCondition())
414 Profiler->VisitStmt(C->getCondition());
415}
416
Alexey Bataev3778b602014-07-17 07:32:53 +0000417void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
418 if (C->getCondition())
419 Profiler->VisitStmt(C->getCondition());
420}
421
Alexey Bataev568a8332014-03-06 06:15:19 +0000422void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +0000423 VistOMPClauseWithPreInit(C);
Alexey Bataev568a8332014-03-06 06:15:19 +0000424 if (C->getNumThreads())
425 Profiler->VisitStmt(C->getNumThreads());
426}
427
Alexey Bataev62c87d22014-03-21 04:51:18 +0000428void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
429 if (C->getSafelen())
430 Profiler->VisitStmt(C->getSafelen());
431}
432
Alexey Bataev66b15b52015-08-21 11:14:16 +0000433void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
434 if (C->getSimdlen())
435 Profiler->VisitStmt(C->getSimdlen());
436}
437
Alexander Musman8bd31e62014-05-27 15:12:19 +0000438void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
439 if (C->getNumForLoops())
440 Profiler->VisitStmt(C->getNumForLoops());
441}
442
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000443void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000444
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000445void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
446
Alexey Bataev56dafe82014-06-20 07:16:17 +0000447void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000448 VistOMPClauseWithPreInit(C);
449 if (auto *S = C->getChunkSize())
450 Profiler->VisitStmt(S);
Alexey Bataev56dafe82014-06-20 07:16:17 +0000451}
452
Alexey Bataev10e775f2015-07-30 11:36:16 +0000453void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
454 if (auto *Num = C->getNumForLoops())
455 Profiler->VisitStmt(Num);
456}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000457
Alexey Bataev236070f2014-06-20 11:19:47 +0000458void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
459
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000460void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
461
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000462void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
463
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000464void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
465
Alexey Bataevdea47612014-07-23 07:46:59 +0000466void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
467
Alexey Bataev67a4f222014-07-23 10:25:33 +0000468void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
469
Alexey Bataev459dec02014-07-24 06:46:57 +0000470void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
471
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000472void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
473
Alexey Bataev346265e2015-09-25 10:37:12 +0000474void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
475
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000476void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
477
Alexey Bataevb825de12015-12-07 10:51:44 +0000478void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
479
Alexey Bataev756c1962013-09-24 03:17:45 +0000480template<typename T>
481void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000482 for (auto *E : Node->varlists()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000483 if (E)
484 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000485 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000486}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000487
488void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000489 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000490 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000491 if (E)
492 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000493 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000494}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000495void
496OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000497 VisitOMPClauseList(C);
Alexey Bataev417089f2016-02-17 13:19:37 +0000498 VistOMPClauseWithPreInit(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000499 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000500 if (E)
501 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000502 }
503 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000504 if (E)
505 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000506 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000507}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000508void
509OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
510 VisitOMPClauseList(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000511 VistOMPClauseWithPostUpdate(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000512 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000513 if (E)
514 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000515 }
516 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000517 if (E)
518 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000519 }
520 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000521 if (E)
522 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000523 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000524}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000525void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000526 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000527}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000528void OMPClauseProfiler::VisitOMPReductionClause(
529 const OMPReductionClause *C) {
530 Profiler->VisitNestedNameSpecifier(
531 C->getQualifierLoc().getNestedNameSpecifier());
532 Profiler->VisitName(C->getNameInfo().getName());
533 VisitOMPClauseList(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000534 VistOMPClauseWithPostUpdate(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000535 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000536 if (E)
537 Profiler->VisitStmt(E);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000538 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000539 for (auto *E : C->lhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000540 if (E)
541 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000542 }
543 for (auto *E : C->rhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000544 if (E)
545 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000546 }
547 for (auto *E : C->reduction_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000548 if (E)
549 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000550 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000551}
Alexander Musman8dba6642014-04-22 13:09:42 +0000552void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
553 VisitOMPClauseList(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000554 VistOMPClauseWithPostUpdate(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000555 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000556 if (E)
557 Profiler->VisitStmt(E);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000558 }
Alexander Musman3276a272015-03-21 10:12:56 +0000559 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000560 if (E)
561 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000562 }
563 for (auto *E : C->updates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000564 if (E)
565 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000566 }
567 for (auto *E : C->finals()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000568 if (E)
569 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000570 }
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000571 if (C->getStep())
572 Profiler->VisitStmt(C->getStep());
573 if (C->getCalcStep())
574 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000575}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000576void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
577 VisitOMPClauseList(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000578 if (C->getAlignment())
579 Profiler->VisitStmt(C->getAlignment());
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000580}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000581void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
582 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000583 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000584 if (E)
585 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000586 }
587 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000588 if (E)
589 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000590 }
591 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000592 if (E)
593 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000594 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000595}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000596void
597OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
598 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000599 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000600 if (E)
601 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000602 }
603 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000604 if (E)
605 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000606 }
607 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000608 if (E)
609 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000610 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000611}
Alexey Bataev6125da92014-07-21 11:26:11 +0000612void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
613 VisitOMPClauseList(C);
614}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000615void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
616 VisitOMPClauseList(C);
617}
Michael Wonge710d542015-08-07 16:16:36 +0000618void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000619 if (C->getDevice())
620 Profiler->VisitStmt(C->getDevice());
Michael Wonge710d542015-08-07 16:16:36 +0000621}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000622void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
623 VisitOMPClauseList(C);
624}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000625void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +0000626 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000627 if (C->getNumTeams())
628 Profiler->VisitStmt(C->getNumTeams());
Kelvin Li099bb8c2015-11-24 20:50:12 +0000629}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000630void OMPClauseProfiler::VisitOMPThreadLimitClause(
631 const OMPThreadLimitClause *C) {
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +0000632 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000633 if (C->getThreadLimit())
634 Profiler->VisitStmt(C->getThreadLimit());
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000635}
Alexey Bataeva0569352015-12-01 10:17:31 +0000636void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000637 if (C->getPriority())
638 Profiler->VisitStmt(C->getPriority());
Alexey Bataeva0569352015-12-01 10:17:31 +0000639}
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000640void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000641 if (C->getGrainsize())
642 Profiler->VisitStmt(C->getGrainsize());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000643}
Alexey Bataev382967a2015-12-08 12:06:20 +0000644void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000645 if (C->getNumTasks())
646 Profiler->VisitStmt(C->getNumTasks());
Alexey Bataev382967a2015-12-08 12:06:20 +0000647}
Alexey Bataev28c75412015-12-15 08:19:24 +0000648void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000649 if (C->getHint())
650 Profiler->VisitStmt(C->getHint());
Alexey Bataev28c75412015-12-15 08:19:24 +0000651}
Samuel Antao661c0902016-05-26 17:39:58 +0000652void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
653 VisitOMPClauseList(C);
654}
Samuel Antaoec172c62016-05-26 17:49:04 +0000655void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
656 VisitOMPClauseList(C);
657}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000658void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
659 const OMPUseDevicePtrClause *C) {
660 VisitOMPClauseList(C);
661}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000662void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
663 const OMPIsDevicePtrClause *C) {
664 VisitOMPClauseList(C);
665}
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000666}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000667
668void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000669StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000670 VisitStmt(S);
671 OMPClauseProfiler P(this);
672 ArrayRef<OMPClause *> Clauses = S->clauses();
673 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
674 I != E; ++I)
675 if (*I)
676 P.Visit(*I);
677}
678
Alexander Musman3aaab662014-08-19 11:27:13 +0000679void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
680 VisitOMPExecutableDirective(S);
681}
682
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000683void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
684 VisitOMPExecutableDirective(S);
685}
686
687void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000688 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000689}
690
Alexey Bataevf29276e2014-06-18 04:14:57 +0000691void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000692 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000693}
694
Alexander Musmanf82886e2014-09-18 05:12:34 +0000695void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
696 VisitOMPLoopDirective(S);
697}
698
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000699void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
700 VisitOMPExecutableDirective(S);
701}
702
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000703void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
704 VisitOMPExecutableDirective(S);
705}
706
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000707void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
708 VisitOMPExecutableDirective(S);
709}
710
Alexander Musman80c22892014-07-17 08:54:58 +0000711void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
712 VisitOMPExecutableDirective(S);
713}
714
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000715void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
716 VisitOMPExecutableDirective(S);
717 VisitName(S->getDirectiveName().getName());
718}
719
Alexey Bataev4acb8592014-07-07 13:01:15 +0000720void
721StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000722 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000723}
724
Alexander Musmane4e893b2014-09-23 09:33:00 +0000725void StmtProfiler::VisitOMPParallelForSimdDirective(
726 const OMPParallelForSimdDirective *S) {
727 VisitOMPLoopDirective(S);
728}
729
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000730void StmtProfiler::VisitOMPParallelSectionsDirective(
731 const OMPParallelSectionsDirective *S) {
732 VisitOMPExecutableDirective(S);
733}
734
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000735void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
736 VisitOMPExecutableDirective(S);
737}
738
Alexey Bataev68446b72014-07-18 07:47:19 +0000739void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
740 VisitOMPExecutableDirective(S);
741}
742
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000743void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
744 VisitOMPExecutableDirective(S);
745}
746
Alexey Bataev2df347a2014-07-18 10:17:07 +0000747void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
748 VisitOMPExecutableDirective(S);
749}
750
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000751void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
752 VisitOMPExecutableDirective(S);
753}
754
Alexey Bataev6125da92014-07-21 11:26:11 +0000755void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
756 VisitOMPExecutableDirective(S);
757}
758
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000759void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
760 VisitOMPExecutableDirective(S);
761}
762
Alexey Bataev0162e452014-07-22 10:10:35 +0000763void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
764 VisitOMPExecutableDirective(S);
765}
766
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000767void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
768 VisitOMPExecutableDirective(S);
769}
770
Michael Wong65f367f2015-07-21 13:44:28 +0000771void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
772 VisitOMPExecutableDirective(S);
773}
774
Samuel Antaodf67fc42016-01-19 19:15:56 +0000775void StmtProfiler::VisitOMPTargetEnterDataDirective(
776 const OMPTargetEnterDataDirective *S) {
777 VisitOMPExecutableDirective(S);
778}
779
Samuel Antao72590762016-01-19 20:04:50 +0000780void StmtProfiler::VisitOMPTargetExitDataDirective(
781 const OMPTargetExitDataDirective *S) {
782 VisitOMPExecutableDirective(S);
783}
784
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000785void StmtProfiler::VisitOMPTargetParallelDirective(
786 const OMPTargetParallelDirective *S) {
787 VisitOMPExecutableDirective(S);
788}
789
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000790void StmtProfiler::VisitOMPTargetParallelForDirective(
791 const OMPTargetParallelForDirective *S) {
792 VisitOMPExecutableDirective(S);
793}
794
Alexey Bataev13314bf2014-10-09 04:18:56 +0000795void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
796 VisitOMPExecutableDirective(S);
797}
798
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000799void StmtProfiler::VisitOMPCancellationPointDirective(
800 const OMPCancellationPointDirective *S) {
801 VisitOMPExecutableDirective(S);
802}
803
Alexey Bataev80909872015-07-02 11:25:17 +0000804void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
805 VisitOMPExecutableDirective(S);
806}
807
Alexey Bataev49f6e782015-12-01 04:18:41 +0000808void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
809 VisitOMPLoopDirective(S);
810}
811
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000812void StmtProfiler::VisitOMPTaskLoopSimdDirective(
813 const OMPTaskLoopSimdDirective *S) {
814 VisitOMPLoopDirective(S);
815}
816
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000817void StmtProfiler::VisitOMPDistributeDirective(
818 const OMPDistributeDirective *S) {
819 VisitOMPLoopDirective(S);
820}
821
Carlo Bertollib4adf552016-01-15 18:50:31 +0000822void OMPClauseProfiler::VisitOMPDistScheduleClause(
823 const OMPDistScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000824 VistOMPClauseWithPreInit(C);
825 if (auto *S = C->getChunkSize())
826 Profiler->VisitStmt(S);
Carlo Bertollib4adf552016-01-15 18:50:31 +0000827}
828
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000829void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
830
Samuel Antao686c70c2016-05-26 17:30:50 +0000831void StmtProfiler::VisitOMPTargetUpdateDirective(
832 const OMPTargetUpdateDirective *S) {
833 VisitOMPExecutableDirective(S);
834}
835
Carlo Bertolli9925f152016-06-27 14:55:37 +0000836void StmtProfiler::VisitOMPDistributeParallelForDirective(
837 const OMPDistributeParallelForDirective *S) {
838 VisitOMPLoopDirective(S);
839}
840
Kelvin Li4a39add2016-07-05 05:00:15 +0000841void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
842 const OMPDistributeParallelForSimdDirective *S) {
843 VisitOMPLoopDirective(S);
844}
845
Kelvin Li787f3fc2016-07-06 04:45:38 +0000846void StmtProfiler::VisitOMPDistributeSimdDirective(
847 const OMPDistributeSimdDirective *S) {
848 VisitOMPLoopDirective(S);
849}
850
Kelvin Lia579b912016-07-14 02:54:56 +0000851void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
852 const OMPTargetParallelForSimdDirective *S) {
853 VisitOMPLoopDirective(S);
854}
855
Kelvin Li986330c2016-07-20 22:57:10 +0000856void StmtProfiler::VisitOMPTargetSimdDirective(
857 const OMPTargetSimdDirective *S) {
858 VisitOMPLoopDirective(S);
859}
860
Kelvin Li02532872016-08-05 14:37:37 +0000861void StmtProfiler::VisitOMPTeamsDistributeDirective(
862 const OMPTeamsDistributeDirective *S) {
863 VisitOMPLoopDirective(S);
864}
865
Kelvin Li4e325f72016-10-25 12:50:55 +0000866void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
867 const OMPTeamsDistributeSimdDirective *S) {
868 VisitOMPLoopDirective(S);
869}
870
Kelvin Li579e41c2016-11-30 23:51:03 +0000871void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
872 const OMPTeamsDistributeParallelForSimdDirective *S) {
873 VisitOMPLoopDirective(S);
874}
875
Kelvin Li7ade93f2016-12-09 03:24:30 +0000876void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
877 const OMPTeamsDistributeParallelForDirective *S) {
878 VisitOMPLoopDirective(S);
879}
880
Kelvin Libf594a52016-12-17 05:48:59 +0000881void StmtProfiler::VisitOMPTargetTeamsDirective(
882 const OMPTargetTeamsDirective *S) {
883 VisitOMPExecutableDirective(S);
884}
885
Kelvin Li83c451e2016-12-25 04:52:54 +0000886void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
887 const OMPTargetTeamsDistributeDirective *S) {
888 VisitOMPLoopDirective(S);
889}
890
Kelvin Li80e8f562016-12-29 22:16:30 +0000891void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
892 const OMPTargetTeamsDistributeParallelForDirective *S) {
893 VisitOMPLoopDirective(S);
894}
895
Kelvin Li1851df52017-01-03 05:23:48 +0000896void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
897 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
898 VisitOMPLoopDirective(S);
899}
900
Kelvin Lida681182017-01-10 18:08:18 +0000901void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
902 const OMPTargetTeamsDistributeSimdDirective *S) {
903 VisitOMPLoopDirective(S);
904}
905
Chandler Carruth631abd92011-06-16 06:47:06 +0000906void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000907 VisitStmt(S);
908}
909
Chandler Carruth631abd92011-06-16 06:47:06 +0000910void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000911 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000912 if (!Canonical)
913 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000914 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000915 if (!Canonical)
916 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000917}
918
Chandler Carruth631abd92011-06-16 06:47:06 +0000919void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000920 VisitExpr(S);
921 ID.AddInteger(S->getIdentType());
922}
923
Chandler Carruth631abd92011-06-16 06:47:06 +0000924void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000925 VisitExpr(S);
926 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +0000927 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000928}
929
Chandler Carruth631abd92011-06-16 06:47:06 +0000930void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000931 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000932 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000933 ID.AddInteger(S->getValue());
934}
935
Chandler Carruth631abd92011-06-16 06:47:06 +0000936void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000937 VisitExpr(S);
938 S->getValue().Profile(ID);
939 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +0000940 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000941}
942
Chandler Carruth631abd92011-06-16 06:47:06 +0000943void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000944 VisitExpr(S);
945}
946
Chandler Carruth631abd92011-06-16 06:47:06 +0000947void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000948 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000949 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000950 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000951}
952
Chandler Carruth631abd92011-06-16 06:47:06 +0000953void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000954 VisitExpr(S);
955}
956
Chandler Carruth631abd92011-06-16 06:47:06 +0000957void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000958 VisitExpr(S);
959}
960
Chandler Carruth631abd92011-06-16 06:47:06 +0000961void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000962 VisitExpr(S);
963 ID.AddInteger(S->getOpcode());
964}
965
Chandler Carruth631abd92011-06-16 06:47:06 +0000966void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000967 VisitType(S->getTypeSourceInfo()->getType());
968 unsigned n = S->getNumComponents();
969 for (unsigned i = 0; i < n; ++i) {
James Y Knight7281c352015-12-29 22:31:18 +0000970 const OffsetOfNode &ON = S->getComponent(i);
Douglas Gregor882211c2010-04-28 22:16:22 +0000971 ID.AddInteger(ON.getKind());
972 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000973 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000974 // Expressions handled below.
975 break;
976
James Y Knight7281c352015-12-29 22:31:18 +0000977 case OffsetOfNode::Field:
Douglas Gregor882211c2010-04-28 22:16:22 +0000978 VisitDecl(ON.getField());
979 break;
980
James Y Knight7281c352015-12-29 22:31:18 +0000981 case OffsetOfNode::Identifier:
Richard Trieu639d7b62017-02-22 22:22:42 +0000982 VisitIdentifierInfo(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +0000983 break;
James Y Knight7281c352015-12-29 22:31:18 +0000984
985 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +0000986 // These nodes are implicit, and therefore don't need profiling.
987 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000988 }
989 }
Richard Trieu639d7b62017-02-22 22:22:42 +0000990
Douglas Gregor882211c2010-04-28 22:16:22 +0000991 VisitExpr(S);
992}
993
Chandler Carruth631abd92011-06-16 06:47:06 +0000994void
995StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000996 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000997 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000998 if (S->isArgumentType())
999 VisitType(S->getArgumentType());
1000}
1001
Chandler Carruth631abd92011-06-16 06:47:06 +00001002void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001003 VisitExpr(S);
1004}
1005
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001006void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1007 VisitExpr(S);
1008}
1009
Chandler Carruth631abd92011-06-16 06:47:06 +00001010void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001011 VisitExpr(S);
1012}
1013
Chandler Carruth631abd92011-06-16 06:47:06 +00001014void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001015 VisitExpr(S);
1016 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001017 if (!Canonical)
1018 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001019 ID.AddBoolean(S->isArrow());
1020}
1021
Chandler Carruth631abd92011-06-16 06:47:06 +00001022void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001023 VisitExpr(S);
1024 ID.AddBoolean(S->isFileScope());
1025}
1026
Chandler Carruth631abd92011-06-16 06:47:06 +00001027void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001028 VisitExpr(S);
1029}
1030
Chandler Carruth631abd92011-06-16 06:47:06 +00001031void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001032 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +00001033 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001034}
1035
Chandler Carruth631abd92011-06-16 06:47:06 +00001036void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001037 VisitCastExpr(S);
1038 VisitType(S->getTypeAsWritten());
1039}
1040
Chandler Carruth631abd92011-06-16 06:47:06 +00001041void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001042 VisitExplicitCastExpr(S);
1043}
1044
Chandler Carruth631abd92011-06-16 06:47:06 +00001045void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001046 VisitExpr(S);
1047 ID.AddInteger(S->getOpcode());
1048}
1049
Chandler Carruth631abd92011-06-16 06:47:06 +00001050void
1051StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001052 VisitBinaryOperator(S);
1053}
1054
Chandler Carruth631abd92011-06-16 06:47:06 +00001055void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001056 VisitExpr(S);
1057}
1058
Chandler Carruth631abd92011-06-16 06:47:06 +00001059void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +00001060 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +00001061 VisitExpr(S);
1062}
1063
Chandler Carruth631abd92011-06-16 06:47:06 +00001064void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001065 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001066 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001067}
1068
Chandler Carruth631abd92011-06-16 06:47:06 +00001069void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001070 VisitExpr(S);
1071}
1072
Chandler Carruth631abd92011-06-16 06:47:06 +00001073void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001074 VisitExpr(S);
1075}
1076
Hal Finkelc4d7c822013-09-18 03:29:45 +00001077void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1078 VisitExpr(S);
1079}
1080
Chandler Carruth631abd92011-06-16 06:47:06 +00001081void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001082 VisitExpr(S);
1083}
1084
Chandler Carruth631abd92011-06-16 06:47:06 +00001085void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001086 VisitExpr(S);
1087}
1088
Chandler Carruth631abd92011-06-16 06:47:06 +00001089void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001090 VisitExpr(S);
1091}
1092
Chandler Carruth631abd92011-06-16 06:47:06 +00001093void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001094 if (S->getSyntacticForm()) {
1095 VisitInitListExpr(S->getSyntacticForm());
1096 return;
1097 }
Mike Stump11289f42009-09-09 15:08:12 +00001098
Douglas Gregor5c193b92009-07-28 00:33:38 +00001099 VisitExpr(S);
1100}
1101
Chandler Carruth631abd92011-06-16 06:47:06 +00001102void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001103 VisitExpr(S);
1104 ID.AddBoolean(S->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +00001105 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1106 if (D.isFieldDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001107 ID.AddInteger(0);
David Majnemerf7e36092016-06-23 00:15:04 +00001108 VisitName(D.getFieldName());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001109 continue;
1110 }
Mike Stump11289f42009-09-09 15:08:12 +00001111
David Majnemerf7e36092016-06-23 00:15:04 +00001112 if (D.isArrayDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001113 ID.AddInteger(1);
1114 } else {
David Majnemerf7e36092016-06-23 00:15:04 +00001115 assert(D.isArrayRangeDesignator());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001116 ID.AddInteger(2);
1117 }
David Majnemerf7e36092016-06-23 00:15:04 +00001118 ID.AddInteger(D.getFirstExprIndex());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001119 }
1120}
1121
Yunzhong Gaocb779302015-06-10 00:27:52 +00001122// Seems that if VisitInitListExpr() only works on the syntactic form of an
1123// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1124void StmtProfiler::VisitDesignatedInitUpdateExpr(
1125 const DesignatedInitUpdateExpr *S) {
1126 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1127 "initializer");
1128}
1129
Richard Smith410306b2016-12-12 02:53:20 +00001130void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1131 VisitExpr(S);
1132}
1133
1134void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1135 VisitExpr(S);
1136}
1137
Yunzhong Gaocb779302015-06-10 00:27:52 +00001138void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1139 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1140}
1141
Chandler Carruth631abd92011-06-16 06:47:06 +00001142void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001143 VisitExpr(S);
1144}
1145
Chandler Carruth631abd92011-06-16 06:47:06 +00001146void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001147 VisitExpr(S);
1148 VisitName(&S->getAccessor());
1149}
1150
Chandler Carruth631abd92011-06-16 06:47:06 +00001151void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001152 VisitExpr(S);
1153 VisitDecl(S->getBlockDecl());
1154}
1155
Chandler Carruth631abd92011-06-16 06:47:06 +00001156void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001157 VisitExpr(S);
1158 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
1159 QualType T = S->getAssocType(i);
1160 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +00001161 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00001162 else
1163 VisitType(T);
1164 VisitExpr(S->getAssocExpr(i));
1165 }
1166}
1167
John McCallfe96e0b2011-11-06 09:01:30 +00001168void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1169 VisitExpr(S);
1170 for (PseudoObjectExpr::const_semantics_iterator
1171 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1172 // Normally, we would not profile the source expressions of OVEs.
1173 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1174 Visit(OVE->getSourceExpr());
1175}
1176
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001177void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1178 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +00001179 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001180}
1181
Chandler Carruth631abd92011-06-16 06:47:06 +00001182static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +00001183 UnaryOperatorKind &UnaryOp,
1184 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001185 switch (S->getOperator()) {
1186 case OO_None:
1187 case OO_New:
1188 case OO_Delete:
1189 case OO_Array_New:
1190 case OO_Array_Delete:
1191 case OO_Arrow:
1192 case OO_Call:
1193 case OO_Conditional:
Richard Smith9be594e2015-10-22 05:12:22 +00001194 case OO_Coawait:
Douglas Gregore9ceb312010-05-19 04:13:23 +00001195 case NUM_OVERLOADED_OPERATORS:
1196 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +00001197
1198 case OO_Plus:
1199 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001200 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001201 return Stmt::UnaryOperatorClass;
1202 }
1203
John McCalle3027922010-08-25 11:45:40 +00001204 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001205 return Stmt::BinaryOperatorClass;
1206
1207 case OO_Minus:
1208 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001209 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001210 return Stmt::UnaryOperatorClass;
1211 }
1212
John McCalle3027922010-08-25 11:45:40 +00001213 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001214 return Stmt::BinaryOperatorClass;
1215
1216 case OO_Star:
1217 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +00001218 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001219 return Stmt::UnaryOperatorClass;
1220 }
1221
Richard Smithf15acc52014-06-05 22:43:40 +00001222 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001223 return Stmt::BinaryOperatorClass;
1224
1225 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +00001226 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001227 return Stmt::BinaryOperatorClass;
1228
1229 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +00001230 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001231 return Stmt::BinaryOperatorClass;
1232
1233 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +00001234 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001235 return Stmt::BinaryOperatorClass;
1236
1237 case OO_Amp:
1238 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001239 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001240 return Stmt::UnaryOperatorClass;
1241 }
1242
John McCalle3027922010-08-25 11:45:40 +00001243 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001244 return Stmt::BinaryOperatorClass;
1245
1246 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +00001247 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001248 return Stmt::BinaryOperatorClass;
1249
1250 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +00001251 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001252 return Stmt::UnaryOperatorClass;
1253
1254 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +00001255 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001256 return Stmt::UnaryOperatorClass;
1257
1258 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +00001259 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001260 return Stmt::BinaryOperatorClass;
1261
1262 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +00001263 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001264 return Stmt::BinaryOperatorClass;
1265
1266 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +00001267 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001268 return Stmt::BinaryOperatorClass;
1269
1270 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +00001271 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001272 return Stmt::CompoundAssignOperatorClass;
1273
1274 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +00001275 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001276 return Stmt::CompoundAssignOperatorClass;
1277
1278 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +00001279 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001280 return Stmt::CompoundAssignOperatorClass;
1281
1282 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +00001283 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001284 return Stmt::CompoundAssignOperatorClass;
1285
1286 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +00001287 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001288 return Stmt::CompoundAssignOperatorClass;
1289
1290 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +00001291 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001292 return Stmt::CompoundAssignOperatorClass;
1293
1294 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +00001295 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001296 return Stmt::CompoundAssignOperatorClass;
1297
1298 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +00001299 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001300 return Stmt::CompoundAssignOperatorClass;
1301
1302 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +00001303 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001304 return Stmt::BinaryOperatorClass;
1305
1306 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +00001307 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001308 return Stmt::BinaryOperatorClass;
1309
1310 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +00001311 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001312 return Stmt::CompoundAssignOperatorClass;
1313
1314 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001315 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001316 return Stmt::CompoundAssignOperatorClass;
1317
1318 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +00001319 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001320 return Stmt::BinaryOperatorClass;
1321
1322 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001323 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001324 return Stmt::BinaryOperatorClass;
1325
1326 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001327 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001328 return Stmt::BinaryOperatorClass;
1329
1330 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001331 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001332 return Stmt::BinaryOperatorClass;
1333
1334 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001335 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001336 return Stmt::BinaryOperatorClass;
1337
1338 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001339 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001340 return Stmt::BinaryOperatorClass;
1341
1342 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +00001343 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1344 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001345 return Stmt::UnaryOperatorClass;
1346
1347 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001348 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1349 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001350 return Stmt::UnaryOperatorClass;
1351
1352 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001353 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001354 return Stmt::BinaryOperatorClass;
1355
Douglas Gregore9ceb312010-05-19 04:13:23 +00001356 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001357 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001358 return Stmt::BinaryOperatorClass;
1359
1360 case OO_Subscript:
1361 return Stmt::ArraySubscriptExprClass;
1362 }
1363
1364 llvm_unreachable("Invalid overloaded operator expression");
1365}
Richard Smithf15acc52014-06-05 22:43:40 +00001366
Chandler Carruth631abd92011-06-16 06:47:06 +00001367void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001368 if (S->isTypeDependent()) {
1369 // Type-dependent operator calls are profiled like their underlying
1370 // syntactic operator.
Richard Smithbac0a0d2016-10-24 18:47:04 +00001371 //
1372 // An operator call to operator-> is always implicit, so just skip it. The
1373 // enclosing MemberExpr will profile the actual member access.
1374 if (S->getOperator() == OO_Arrow)
1375 return Visit(S->getArg(0));
1376
John McCalle3027922010-08-25 11:45:40 +00001377 UnaryOperatorKind UnaryOp = UO_Extension;
1378 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001379 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001380
Douglas Gregore9ceb312010-05-19 04:13:23 +00001381 ID.AddInteger(SC);
1382 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1383 Visit(S->getArg(I));
1384 if (SC == Stmt::UnaryOperatorClass)
1385 ID.AddInteger(UnaryOp);
1386 else if (SC == Stmt::BinaryOperatorClass ||
1387 SC == Stmt::CompoundAssignOperatorClass)
1388 ID.AddInteger(BinaryOp);
1389 else
1390 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001391
Douglas Gregore9ceb312010-05-19 04:13:23 +00001392 return;
1393 }
Richard Smithf15acc52014-06-05 22:43:40 +00001394
Douglas Gregor5c193b92009-07-28 00:33:38 +00001395 VisitCallExpr(S);
1396 ID.AddInteger(S->getOperator());
1397}
1398
Chandler Carruth631abd92011-06-16 06:47:06 +00001399void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001400 VisitCallExpr(S);
1401}
1402
Chandler Carruth631abd92011-06-16 06:47:06 +00001403void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001404 VisitCallExpr(S);
1405}
1406
Chandler Carruth631abd92011-06-16 06:47:06 +00001407void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001408 VisitExpr(S);
1409}
1410
Chandler Carruth631abd92011-06-16 06:47:06 +00001411void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001412 VisitExplicitCastExpr(S);
1413}
1414
Chandler Carruth631abd92011-06-16 06:47:06 +00001415void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001416 VisitCXXNamedCastExpr(S);
1417}
1418
Chandler Carruth631abd92011-06-16 06:47:06 +00001419void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001420 VisitCXXNamedCastExpr(S);
1421}
1422
Chandler Carruth631abd92011-06-16 06:47:06 +00001423void
1424StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001425 VisitCXXNamedCastExpr(S);
1426}
1427
Chandler Carruth631abd92011-06-16 06:47:06 +00001428void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001429 VisitCXXNamedCastExpr(S);
1430}
1431
Richard Smithc67fdd42012-03-07 08:35:16 +00001432void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1433 VisitCallExpr(S);
1434}
1435
Chandler Carruth631abd92011-06-16 06:47:06 +00001436void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001437 VisitExpr(S);
1438 ID.AddBoolean(S->getValue());
1439}
1440
Chandler Carruth631abd92011-06-16 06:47:06 +00001441void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001442 VisitExpr(S);
1443}
1444
Richard Smithcc1b96d2013-06-12 22:31:48 +00001445void StmtProfiler::VisitCXXStdInitializerListExpr(
1446 const CXXStdInitializerListExpr *S) {
1447 VisitExpr(S);
1448}
1449
Chandler Carruth631abd92011-06-16 06:47:06 +00001450void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001451 VisitExpr(S);
1452 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001453 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001454}
1455
Chandler Carruth631abd92011-06-16 06:47:06 +00001456void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001457 VisitExpr(S);
1458 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001459 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001460}
1461
John McCall5e77d762013-04-16 07:28:30 +00001462void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1463 VisitExpr(S);
1464 VisitDecl(S->getPropertyDecl());
1465}
1466
Alexey Bataevf7630272015-11-25 12:01:00 +00001467void StmtProfiler::VisitMSPropertySubscriptExpr(
1468 const MSPropertySubscriptExpr *S) {
1469 VisitExpr(S);
1470}
1471
Chandler Carruth631abd92011-06-16 06:47:06 +00001472void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001473 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001474 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001475}
1476
Chandler Carruth631abd92011-06-16 06:47:06 +00001477void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001478 VisitExpr(S);
1479}
1480
Chandler Carruth631abd92011-06-16 06:47:06 +00001481void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001482 VisitExpr(S);
1483 VisitDecl(S->getParam());
1484}
1485
Richard Smith852c9db2013-04-20 22:23:05 +00001486void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1487 VisitExpr(S);
1488 VisitDecl(S->getField());
1489}
1490
Chandler Carruth631abd92011-06-16 06:47:06 +00001491void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001492 VisitExpr(S);
1493 VisitDecl(
1494 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1495}
1496
Chandler Carruth631abd92011-06-16 06:47:06 +00001497void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001498 VisitExpr(S);
1499 VisitDecl(S->getConstructor());
1500 ID.AddBoolean(S->isElidable());
1501}
1502
Richard Smith5179eb72016-06-28 19:03:57 +00001503void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1504 const CXXInheritedCtorInitExpr *S) {
1505 VisitExpr(S);
1506 VisitDecl(S->getConstructor());
1507}
1508
Chandler Carruth631abd92011-06-16 06:47:06 +00001509void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001510 VisitExplicitCastExpr(S);
1511}
1512
Chandler Carruth631abd92011-06-16 06:47:06 +00001513void
1514StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001515 VisitCXXConstructExpr(S);
1516}
1517
Chandler Carruth631abd92011-06-16 06:47:06 +00001518void
Douglas Gregore31e6062012-02-07 10:09:13 +00001519StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1520 VisitExpr(S);
1521 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1522 CEnd = S->explicit_capture_end();
1523 C != CEnd; ++C) {
1524 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001525 switch (C->getCaptureKind()) {
Faisal Validc6b5962016-03-21 09:25:37 +00001526 case LCK_StarThis:
Richard Smithba71c082013-05-16 06:20:58 +00001527 case LCK_This:
1528 break;
1529 case LCK_ByRef:
1530 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001531 VisitDecl(C->getCapturedVar());
1532 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001533 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001534 case LCK_VLAType:
1535 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001536 }
1537 }
1538 // Note: If we actually needed to be able to match lambda
1539 // expressions, we would have to consider parameters and return type
1540 // here, among other things.
1541 VisitStmt(S->getBody());
1542}
1543
1544void
Chandler Carruth631abd92011-06-16 06:47:06 +00001545StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001546 VisitExpr(S);
1547}
1548
Chandler Carruth631abd92011-06-16 06:47:06 +00001549void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001550 VisitExpr(S);
1551 ID.AddBoolean(S->isGlobalDelete());
1552 ID.AddBoolean(S->isArrayForm());
1553 VisitDecl(S->getOperatorDelete());
1554}
1555
Chandler Carruth631abd92011-06-16 06:47:06 +00001556void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001557 VisitExpr(S);
1558 VisitType(S->getAllocatedType());
1559 VisitDecl(S->getOperatorNew());
1560 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001561 ID.AddBoolean(S->isArray());
1562 ID.AddInteger(S->getNumPlacementArgs());
1563 ID.AddBoolean(S->isGlobalNew());
1564 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001565 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001566}
1567
Chandler Carruth631abd92011-06-16 06:47:06 +00001568void
1569StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001570 VisitExpr(S);
1571 ID.AddBoolean(S->isArrow());
1572 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001573 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001574 if (S->getScopeTypeInfo())
1575 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001576 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001577 if (S->getDestroyedTypeInfo())
1578 VisitType(S->getDestroyedType());
1579 else
Richard Trieu639d7b62017-02-22 22:22:42 +00001580 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001581}
1582
Chandler Carruth631abd92011-06-16 06:47:06 +00001583void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001584 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001585 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001586 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001587 ID.AddBoolean(S->hasExplicitTemplateArgs());
1588 if (S->hasExplicitTemplateArgs())
James Y Knight04ec5bf2015-12-24 02:59:37 +00001589 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001590}
1591
1592void
Chandler Carruth631abd92011-06-16 06:47:06 +00001593StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001594 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001595}
1596
Douglas Gregor29c42f22012-02-24 07:38:34 +00001597void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1598 VisitExpr(S);
1599 ID.AddInteger(S->getTrait());
1600 ID.AddInteger(S->getNumArgs());
1601 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1602 VisitType(S->getArg(I)->getType());
1603}
1604
Chandler Carruth631abd92011-06-16 06:47:06 +00001605void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001606 VisitExpr(S);
1607 ID.AddInteger(S->getTrait());
1608 VisitType(S->getQueriedType());
1609}
1610
Chandler Carruth631abd92011-06-16 06:47:06 +00001611void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001612 VisitExpr(S);
1613 ID.AddInteger(S->getTrait());
1614 VisitExpr(S->getQueriedExpression());
1615}
1616
Chandler Carruth631abd92011-06-16 06:47:06 +00001617void StmtProfiler::VisitDependentScopeDeclRefExpr(
1618 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001619 VisitExpr(S);
1620 VisitName(S->getDeclName());
1621 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001622 ID.AddBoolean(S->hasExplicitTemplateArgs());
1623 if (S->hasExplicitTemplateArgs())
1624 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001625}
1626
Chandler Carruth631abd92011-06-16 06:47:06 +00001627void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001628 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001629}
1630
Chandler Carruth631abd92011-06-16 06:47:06 +00001631void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1632 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001633 VisitExpr(S);
1634 VisitType(S->getTypeAsWritten());
1635}
1636
Chandler Carruth631abd92011-06-16 06:47:06 +00001637void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1638 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001639 ID.AddBoolean(S->isImplicitAccess());
1640 if (!S->isImplicitAccess()) {
1641 VisitExpr(S);
1642 ID.AddBoolean(S->isArrow());
1643 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001644 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001645 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001646 ID.AddBoolean(S->hasExplicitTemplateArgs());
1647 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001648 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1649}
1650
Chandler Carruth631abd92011-06-16 06:47:06 +00001651void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001652 ID.AddBoolean(S->isImplicitAccess());
1653 if (!S->isImplicitAccess()) {
1654 VisitExpr(S);
1655 ID.AddBoolean(S->isArrow());
1656 }
John McCall10eae182009-11-30 22:42:35 +00001657 VisitNestedNameSpecifier(S->getQualifier());
1658 VisitName(S->getMemberName());
1659 ID.AddBoolean(S->hasExplicitTemplateArgs());
1660 if (S->hasExplicitTemplateArgs())
1661 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001662}
1663
Chandler Carruth631abd92011-06-16 06:47:06 +00001664void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001665 VisitExpr(S);
1666}
1667
Chandler Carruth631abd92011-06-16 06:47:06 +00001668void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001669 VisitExpr(S);
1670}
1671
Chandler Carruth631abd92011-06-16 06:47:06 +00001672void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001673 VisitExpr(S);
1674 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00001675 if (S->isPartiallySubstituted()) {
1676 auto Args = S->getPartialArguments();
1677 ID.AddInteger(Args.size());
1678 for (const auto &TA : Args)
1679 VisitTemplateArgument(TA);
1680 } else {
1681 ID.AddInteger(0);
1682 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001683}
1684
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001685void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001686 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001687 VisitExpr(S);
1688 VisitDecl(S->getParameterPack());
1689 VisitTemplateArgument(S->getArgumentPack());
1690}
1691
John McCall7c454bb2011-07-15 05:09:51 +00001692void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1693 const SubstNonTypeTemplateParmExpr *E) {
1694 // Profile exactly as the replacement expression.
1695 Visit(E->getReplacement());
1696}
1697
Richard Smithb15fe3a2012-09-12 00:56:43 +00001698void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1699 VisitExpr(S);
1700 VisitDecl(S->getParameterPack());
1701 ID.AddInteger(S->getNumExpansions());
1702 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1703 VisitDecl(*I);
1704}
1705
Douglas Gregorfe314812011-06-21 17:03:29 +00001706void StmtProfiler::VisitMaterializeTemporaryExpr(
1707 const MaterializeTemporaryExpr *S) {
1708 VisitExpr(S);
1709}
1710
Richard Smith0f0af192014-11-08 05:07:16 +00001711void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1712 VisitExpr(S);
1713 ID.AddInteger(S->getOperator());
1714}
1715
Richard Smith9f690bd2015-10-27 06:02:45 +00001716void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1717 VisitStmt(S);
1718}
1719
1720void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1721 VisitStmt(S);
1722}
1723
1724void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1725 VisitExpr(S);
1726}
1727
1728void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1729 VisitExpr(S);
1730}
1731
Chandler Carruth631abd92011-06-16 06:47:06 +00001732void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001733 VisitExpr(E);
1734}
1735
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001736void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1737 VisitExpr(E);
1738}
1739
Chandler Carruth631abd92011-06-16 06:47:06 +00001740void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001741 VisitExpr(S);
1742}
1743
Patrick Beard0caa3942012-04-19 00:25:12 +00001744void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001745 VisitExpr(E);
1746}
1747
1748void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1749 VisitExpr(E);
1750}
1751
1752void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1753 VisitExpr(E);
1754}
1755
Chandler Carruth631abd92011-06-16 06:47:06 +00001756void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001757 VisitExpr(S);
1758 VisitType(S->getEncodedType());
1759}
1760
Chandler Carruth631abd92011-06-16 06:47:06 +00001761void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001762 VisitExpr(S);
1763 VisitName(S->getSelector());
1764}
1765
Chandler Carruth631abd92011-06-16 06:47:06 +00001766void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001767 VisitExpr(S);
1768 VisitDecl(S->getProtocol());
1769}
1770
Chandler Carruth631abd92011-06-16 06:47:06 +00001771void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001772 VisitExpr(S);
1773 VisitDecl(S->getDecl());
1774 ID.AddBoolean(S->isArrow());
1775 ID.AddBoolean(S->isFreeIvar());
1776}
1777
Chandler Carruth631abd92011-06-16 06:47:06 +00001778void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001779 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001780 if (S->isImplicitProperty()) {
1781 VisitDecl(S->getImplicitPropertyGetter());
1782 VisitDecl(S->getImplicitPropertySetter());
1783 } else {
1784 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001785 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001786 if (S->isSuperReceiver()) {
1787 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001788 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001789 }
Douglas Gregora7095092009-07-28 14:44:31 +00001790}
1791
Ted Kremeneke65b0862012-03-06 20:05:56 +00001792void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1793 VisitExpr(S);
1794 VisitDecl(S->getAtIndexMethodDecl());
1795 VisitDecl(S->setAtIndexMethodDecl());
1796}
1797
Chandler Carruth631abd92011-06-16 06:47:06 +00001798void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001799 VisitExpr(S);
1800 VisitName(S->getSelector());
1801 VisitDecl(S->getMethodDecl());
1802}
1803
Chandler Carruth631abd92011-06-16 06:47:06 +00001804void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001805 VisitExpr(S);
1806 ID.AddBoolean(S->isArrow());
1807}
1808
Ted Kremeneke65b0862012-03-06 20:05:56 +00001809void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1810 VisitExpr(S);
1811 ID.AddBoolean(S->getValue());
1812}
1813
Chandler Carruth631abd92011-06-16 06:47:06 +00001814void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1815 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001816 VisitExpr(S);
1817 ID.AddBoolean(S->shouldCopy());
1818}
1819
Chandler Carruth631abd92011-06-16 06:47:06 +00001820void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001821 VisitExplicitCastExpr(S);
1822 ID.AddBoolean(S->getBridgeKind());
1823}
1824
Erik Pilkington29099de2016-07-16 00:35:23 +00001825void StmtProfiler::VisitObjCAvailabilityCheckExpr(
1826 const ObjCAvailabilityCheckExpr *S) {
1827 VisitExpr(S);
1828}
1829
John McCall0ad16662009-10-29 08:12:44 +00001830void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001831 unsigned NumArgs) {
1832 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001833 for (unsigned I = 0; I != NumArgs; ++I)
1834 VisitTemplateArgument(Args[I].getArgument());
1835}
Mike Stump11289f42009-09-09 15:08:12 +00001836
John McCall0ad16662009-10-29 08:12:44 +00001837void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1838 // Mostly repetitive with TemplateArgument::Profile!
1839 ID.AddInteger(Arg.getKind());
1840 switch (Arg.getKind()) {
1841 case TemplateArgument::Null:
1842 break;
Mike Stump11289f42009-09-09 15:08:12 +00001843
John McCall0ad16662009-10-29 08:12:44 +00001844 case TemplateArgument::Type:
1845 VisitType(Arg.getAsType());
1846 break;
Mike Stump11289f42009-09-09 15:08:12 +00001847
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001848 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001849 case TemplateArgument::TemplateExpansion:
1850 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001851 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001852
John McCall0ad16662009-10-29 08:12:44 +00001853 case TemplateArgument::Declaration:
1854 VisitDecl(Arg.getAsDecl());
1855 break;
Mike Stump11289f42009-09-09 15:08:12 +00001856
Eli Friedmanb826a002012-09-26 02:36:12 +00001857 case TemplateArgument::NullPtr:
1858 VisitType(Arg.getNullPtrType());
1859 break;
1860
John McCall0ad16662009-10-29 08:12:44 +00001861 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001862 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001863 VisitType(Arg.getIntegralType());
1864 break;
Mike Stump11289f42009-09-09 15:08:12 +00001865
John McCall0ad16662009-10-29 08:12:44 +00001866 case TemplateArgument::Expression:
1867 Visit(Arg.getAsExpr());
1868 break;
Mike Stump11289f42009-09-09 15:08:12 +00001869
John McCall0ad16662009-10-29 08:12:44 +00001870 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001871 for (const auto &P : Arg.pack_elements())
1872 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001873 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001874 }
1875}
1876
Jay Foad39c79802011-01-12 09:06:06 +00001877void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001878 bool Canonical) const {
Richard Trieu639d7b62017-02-22 22:22:42 +00001879 StmtProfilerWithPointers Profiler(ID, Context, Canonical);
1880 Profiler.Visit(this);
1881}
1882
1883void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
1884 class ODRHash &Hash) const {
1885 StmtProfilerWithoutPointers Profiler(ID, Hash);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001886 Profiler.Visit(this);
1887}