blob: 3b195aae6c928822561a10b0abb5ec1f2b131458 [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"
Douglas Gregor5c193b92009-07-28 00:33:38 +000022#include "clang/AST/StmtVisitor.h"
23#include "llvm/ADT/FoldingSet.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000024using namespace clang;
25
26namespace {
Chandler Carruth631abd92011-06-16 06:47:06 +000027 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Douglas Gregor5c193b92009-07-28 00:33:38 +000028 llvm::FoldingSetNodeID &ID;
Jay Foad39c79802011-01-12 09:06:06 +000029 const ASTContext &Context;
Douglas Gregor5c193b92009-07-28 00:33:38 +000030 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000031
Douglas Gregor5c193b92009-07-28 00:33:38 +000032 public:
Jay Foad39c79802011-01-12 09:06:06 +000033 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump11289f42009-09-09 15:08:12 +000034 bool Canonical)
Douglas Gregor5c193b92009-07-28 00:33:38 +000035 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump11289f42009-09-09 15:08:12 +000036
Chandler Carruth631abd92011-06-16 06:47:06 +000037 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000038
Chandler Carruth631abd92011-06-16 06:47:06 +000039#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000040#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregor5c193b92009-07-28 00:33:38 +000042 /// \brief Visit a declaration that is referenced within an expression
43 /// or statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000044 void VisitDecl(const Decl *D);
Mike Stump11289f42009-09-09 15:08:12 +000045
46 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000047 /// statement.
48 void VisitType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +000049
Douglas Gregor5c193b92009-07-28 00:33:38 +000050 /// \brief Visit a name that occurs within an expression or statement.
51 void VisitName(DeclarationName Name);
Mike Stump11289f42009-09-09 15:08:12 +000052
Douglas Gregor5c193b92009-07-28 00:33:38 +000053 /// \brief Visit a nested-name-specifier that occurs within an expression
54 /// or statement.
55 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump11289f42009-09-09 15:08:12 +000056
Douglas Gregor5c193b92009-07-28 00:33:38 +000057 /// \brief Visit a template name that occurs within an expression or
58 /// statement.
59 void VisitTemplateName(TemplateName Name);
Mike Stump11289f42009-09-09 15:08:12 +000060
Douglas Gregor5c193b92009-07-28 00:33:38 +000061 /// \brief Visit template arguments that occur within an expression or
62 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000063 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
64 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000065
66 /// \brief Visit a single template argument.
67 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000068 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +000069}
Douglas Gregor5c193b92009-07-28 00:33:38 +000070
Chandler Carruth631abd92011-06-16 06:47:06 +000071void StmtProfiler::VisitStmt(const Stmt *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +000072 ID.AddInteger(S->getStmtClass());
Benjamin Kramer642f1732015-07-02 21:03:14 +000073 for (const Stmt *SubStmt : S->children()) {
74 if (SubStmt)
75 Visit(SubStmt);
Peter Collingbournecdb9f302012-03-01 16:34:31 +000076 else
77 ID.AddInteger(0);
78 }
Douglas Gregor5c193b92009-07-28 00:33:38 +000079}
80
Chandler Carruth631abd92011-06-16 06:47:06 +000081void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000082 VisitStmt(S);
Aaron Ballman535bbcc2014-03-14 17:01:24 +000083 for (const auto *D : S->decls())
84 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +000085}
86
Chandler Carruth631abd92011-06-16 06:47:06 +000087void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000088 VisitStmt(S);
89}
90
Chandler Carruth631abd92011-06-16 06:47:06 +000091void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000092 VisitStmt(S);
93}
94
Chandler Carruth631abd92011-06-16 06:47:06 +000095void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000096 VisitStmt(S);
97}
98
Chandler Carruth631abd92011-06-16 06:47:06 +000099void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000100 VisitStmt(S);
101}
102
Chandler Carruth631abd92011-06-16 06:47:06 +0000103void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000104 VisitStmt(S);
105}
106
Chandler Carruth631abd92011-06-16 06:47:06 +0000107void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000108 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000109 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000110}
111
Richard Smithc202b282012-04-14 00:33:13 +0000112void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
113 VisitStmt(S);
114 // TODO: maybe visit attributes?
115}
116
Chandler Carruth631abd92011-06-16 06:47:06 +0000117void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000118 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000120}
121
Chandler Carruth631abd92011-06-16 06:47:06 +0000122void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000123 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000124 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000125}
126
Chandler Carruth631abd92011-06-16 06:47:06 +0000127void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000128 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000129 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000130}
131
Chandler Carruth631abd92011-06-16 06:47:06 +0000132void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000133 VisitStmt(S);
134}
135
Chandler Carruth631abd92011-06-16 06:47:06 +0000136void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000137 VisitStmt(S);
138}
139
Chandler Carruth631abd92011-06-16 06:47:06 +0000140void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000141 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000142 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000143}
144
Chandler Carruth631abd92011-06-16 06:47:06 +0000145void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000146 VisitStmt(S);
147}
148
Chandler Carruth631abd92011-06-16 06:47:06 +0000149void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000150 VisitStmt(S);
151}
152
Chandler Carruth631abd92011-06-16 06:47:06 +0000153void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000154 VisitStmt(S);
155}
156
Chandler Carruth631abd92011-06-16 06:47:06 +0000157void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000158 VisitStmt(S);
159}
160
Chad Rosierde70e0e2012-08-25 00:11:56 +0000161void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000162 VisitStmt(S);
163 ID.AddBoolean(S->isVolatile());
164 ID.AddBoolean(S->isSimple());
165 VisitStringLiteral(S->getAsmString());
166 ID.AddInteger(S->getNumOutputs());
167 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
168 ID.AddString(S->getOutputName(I));
169 VisitStringLiteral(S->getOutputConstraintLiteral(I));
170 }
171 ID.AddInteger(S->getNumInputs());
172 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
173 ID.AddString(S->getInputName(I));
174 VisitStringLiteral(S->getInputConstraintLiteral(I));
175 }
176 ID.AddInteger(S->getNumClobbers());
177 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000178 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor44882592009-07-28 15:27:13 +0000179}
180
Chad Rosier32503022012-06-11 20:47:18 +0000181void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
182 // FIXME: Implement MS style inline asm statement profiler.
183 VisitStmt(S);
184}
185
Chandler Carruth631abd92011-06-16 06:47:06 +0000186void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000187 VisitStmt(S);
188 VisitType(S->getCaughtType());
189}
190
Chandler Carruth631abd92011-06-16 06:47:06 +0000191void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000192 VisitStmt(S);
193}
194
Chandler Carruth631abd92011-06-16 06:47:06 +0000195void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000196 VisitStmt(S);
197}
198
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000199void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
200 VisitStmt(S);
201 ID.AddBoolean(S->isIfExists());
202 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
203 VisitName(S->getNameInfo().getName());
204}
205
Chandler Carruth631abd92011-06-16 06:47:06 +0000206void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000207 VisitStmt(S);
208}
209
Chandler Carruth631abd92011-06-16 06:47:06 +0000210void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000211 VisitStmt(S);
212}
213
Chandler Carruth631abd92011-06-16 06:47:06 +0000214void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000215 VisitStmt(S);
216}
217
Nico Weber9b982072014-07-07 00:12:30 +0000218void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
219 VisitStmt(S);
220}
221
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000222void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
223 VisitStmt(S);
224}
225
Chandler Carruth631abd92011-06-16 06:47:06 +0000226void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000227 VisitStmt(S);
228}
229
Chandler Carruth631abd92011-06-16 06:47:06 +0000230void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000231 VisitStmt(S);
232 ID.AddBoolean(S->hasEllipsis());
233 if (S->getCatchParamDecl())
234 VisitType(S->getCatchParamDecl()->getType());
235}
236
Chandler Carruth631abd92011-06-16 06:47:06 +0000237void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000238 VisitStmt(S);
239}
240
Chandler Carruth631abd92011-06-16 06:47:06 +0000241void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000242 VisitStmt(S);
243}
244
Chandler Carruth631abd92011-06-16 06:47:06 +0000245void
246StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000247 VisitStmt(S);
248}
249
Chandler Carruth631abd92011-06-16 06:47:06 +0000250void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000251 VisitStmt(S);
252}
253
Chandler Carruth631abd92011-06-16 06:47:06 +0000254void
255StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000256 VisitStmt(S);
257}
258
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000259namespace {
260class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
261 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000262 /// \brief Process clauses with list of variables.
263 template <typename T>
264 void VisitOMPClauseList(T *Node);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000265public:
266 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
267#define OPENMP_CLAUSE(Name, Class) \
268 void Visit##Class(const Class *C);
269#include "clang/Basic/OpenMPKinds.def"
270};
271
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000272void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
273 if (C->getCondition())
274 Profiler->VisitStmt(C->getCondition());
275}
276
Alexey Bataev3778b602014-07-17 07:32:53 +0000277void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
278 if (C->getCondition())
279 Profiler->VisitStmt(C->getCondition());
280}
281
Alexey Bataev568a8332014-03-06 06:15:19 +0000282void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
283 if (C->getNumThreads())
284 Profiler->VisitStmt(C->getNumThreads());
285}
286
Alexey Bataev62c87d22014-03-21 04:51:18 +0000287void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
288 if (C->getSafelen())
289 Profiler->VisitStmt(C->getSafelen());
290}
291
Alexey Bataev66b15b52015-08-21 11:14:16 +0000292void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
293 if (C->getSimdlen())
294 Profiler->VisitStmt(C->getSimdlen());
295}
296
Alexander Musman8bd31e62014-05-27 15:12:19 +0000297void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
298 if (C->getNumForLoops())
299 Profiler->VisitStmt(C->getNumForLoops());
300}
301
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000302void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000303
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000304void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
305
Alexey Bataev56dafe82014-06-20 07:16:17 +0000306void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev040d5402015-05-12 08:35:28 +0000307 if (C->getChunkSize()) {
Alexey Bataev56dafe82014-06-20 07:16:17 +0000308 Profiler->VisitStmt(C->getChunkSize());
Alexey Bataev040d5402015-05-12 08:35:28 +0000309 if (C->getHelperChunkSize()) {
310 Profiler->VisitStmt(C->getChunkSize());
311 }
312 }
Alexey Bataev56dafe82014-06-20 07:16:17 +0000313}
314
Alexey Bataev10e775f2015-07-30 11:36:16 +0000315void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
316 if (auto *Num = C->getNumForLoops())
317 Profiler->VisitStmt(Num);
318}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000319
Alexey Bataev236070f2014-06-20 11:19:47 +0000320void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
321
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000322void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
323
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000324void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
325
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000326void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
327
Alexey Bataevdea47612014-07-23 07:46:59 +0000328void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
329
Alexey Bataev67a4f222014-07-23 10:25:33 +0000330void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
331
Alexey Bataev459dec02014-07-24 06:46:57 +0000332void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
333
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000334void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
335
Alexey Bataev346265e2015-09-25 10:37:12 +0000336void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
337
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000338void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
339
Alexey Bataev756c1962013-09-24 03:17:45 +0000340template<typename T>
341void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000342 for (auto *E : Node->varlists()) {
343 Profiler->VisitStmt(E);
344 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000345}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000346
347void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000348 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000349 for (auto *E : C->private_copies()) {
350 Profiler->VisitStmt(E);
351 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000352}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000353void
354OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000355 VisitOMPClauseList(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000356 for (auto *E : C->private_copies()) {
357 Profiler->VisitStmt(E);
358 }
359 for (auto *E : C->inits()) {
360 Profiler->VisitStmt(E);
361 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000362}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000363void
364OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
365 VisitOMPClauseList(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000366 for (auto *E : C->source_exprs()) {
367 Profiler->VisitStmt(E);
368 }
369 for (auto *E : C->destination_exprs()) {
370 Profiler->VisitStmt(E);
371 }
372 for (auto *E : C->assignment_ops()) {
373 Profiler->VisitStmt(E);
374 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000375}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000376void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000377 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000378}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000379void OMPClauseProfiler::VisitOMPReductionClause(
380 const OMPReductionClause *C) {
381 Profiler->VisitNestedNameSpecifier(
382 C->getQualifierLoc().getNestedNameSpecifier());
383 Profiler->VisitName(C->getNameInfo().getName());
384 VisitOMPClauseList(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000385 for (auto *E : C->privates()) {
386 Profiler->VisitStmt(E);
387 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000388 for (auto *E : C->lhs_exprs()) {
389 Profiler->VisitStmt(E);
390 }
391 for (auto *E : C->rhs_exprs()) {
392 Profiler->VisitStmt(E);
393 }
394 for (auto *E : C->reduction_ops()) {
395 Profiler->VisitStmt(E);
396 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000397}
Alexander Musman8dba6642014-04-22 13:09:42 +0000398void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
399 VisitOMPClauseList(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000400 for (auto *E : C->privates()) {
401 Profiler->VisitStmt(E);
402 }
Alexander Musman3276a272015-03-21 10:12:56 +0000403 for (auto *E : C->inits()) {
404 Profiler->VisitStmt(E);
405 }
406 for (auto *E : C->updates()) {
407 Profiler->VisitStmt(E);
408 }
409 for (auto *E : C->finals()) {
410 Profiler->VisitStmt(E);
411 }
Alexander Musman8dba6642014-04-22 13:09:42 +0000412 Profiler->VisitStmt(C->getStep());
Alexander Musman3276a272015-03-21 10:12:56 +0000413 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000414}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000415void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
416 VisitOMPClauseList(C);
417 Profiler->VisitStmt(C->getAlignment());
418}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000419void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
420 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000421 for (auto *E : C->source_exprs()) {
422 Profiler->VisitStmt(E);
423 }
424 for (auto *E : C->destination_exprs()) {
425 Profiler->VisitStmt(E);
426 }
427 for (auto *E : C->assignment_ops()) {
428 Profiler->VisitStmt(E);
429 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000430}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000431void
432OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
433 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000434 for (auto *E : C->source_exprs()) {
435 Profiler->VisitStmt(E);
436 }
437 for (auto *E : C->destination_exprs()) {
438 Profiler->VisitStmt(E);
439 }
440 for (auto *E : C->assignment_ops()) {
441 Profiler->VisitStmt(E);
442 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000443}
Alexey Bataev6125da92014-07-21 11:26:11 +0000444void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
445 VisitOMPClauseList(C);
446}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000447void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
448 VisitOMPClauseList(C);
449}
Michael Wonge710d542015-08-07 16:16:36 +0000450void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
451 Profiler->VisitStmt(C->getDevice());
452}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000453void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
454 VisitOMPClauseList(C);
455}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000456void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
457 Profiler->VisitStmt(C->getNumTeams());
458}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000459void OMPClauseProfiler::VisitOMPThreadLimitClause(
460 const OMPThreadLimitClause *C) {
461 Profiler->VisitStmt(C->getThreadLimit());
462}
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000463}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000464
465void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000466StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000467 VisitStmt(S);
468 OMPClauseProfiler P(this);
469 ArrayRef<OMPClause *> Clauses = S->clauses();
470 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
471 I != E; ++I)
472 if (*I)
473 P.Visit(*I);
474}
475
Alexander Musman3aaab662014-08-19 11:27:13 +0000476void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
477 VisitOMPExecutableDirective(S);
478}
479
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000480void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
481 VisitOMPExecutableDirective(S);
482}
483
484void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000485 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000486}
487
Alexey Bataevf29276e2014-06-18 04:14:57 +0000488void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000489 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000490}
491
Alexander Musmanf82886e2014-09-18 05:12:34 +0000492void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
493 VisitOMPLoopDirective(S);
494}
495
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000496void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
497 VisitOMPExecutableDirective(S);
498}
499
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000500void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
501 VisitOMPExecutableDirective(S);
502}
503
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000504void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
505 VisitOMPExecutableDirective(S);
506}
507
Alexander Musman80c22892014-07-17 08:54:58 +0000508void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
509 VisitOMPExecutableDirective(S);
510}
511
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000512void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
513 VisitOMPExecutableDirective(S);
514 VisitName(S->getDirectiveName().getName());
515}
516
Alexey Bataev4acb8592014-07-07 13:01:15 +0000517void
518StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000519 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000520}
521
Alexander Musmane4e893b2014-09-23 09:33:00 +0000522void StmtProfiler::VisitOMPParallelForSimdDirective(
523 const OMPParallelForSimdDirective *S) {
524 VisitOMPLoopDirective(S);
525}
526
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000527void StmtProfiler::VisitOMPParallelSectionsDirective(
528 const OMPParallelSectionsDirective *S) {
529 VisitOMPExecutableDirective(S);
530}
531
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000532void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
533 VisitOMPExecutableDirective(S);
534}
535
Alexey Bataev68446b72014-07-18 07:47:19 +0000536void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
537 VisitOMPExecutableDirective(S);
538}
539
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000540void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
541 VisitOMPExecutableDirective(S);
542}
543
Alexey Bataev2df347a2014-07-18 10:17:07 +0000544void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
545 VisitOMPExecutableDirective(S);
546}
547
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000548void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
549 VisitOMPExecutableDirective(S);
550}
551
Alexey Bataev6125da92014-07-21 11:26:11 +0000552void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
553 VisitOMPExecutableDirective(S);
554}
555
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000556void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
557 VisitOMPExecutableDirective(S);
558}
559
Alexey Bataev0162e452014-07-22 10:10:35 +0000560void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
561 VisitOMPExecutableDirective(S);
562}
563
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000564void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
565 VisitOMPExecutableDirective(S);
566}
567
Michael Wong65f367f2015-07-21 13:44:28 +0000568void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
569 VisitOMPExecutableDirective(S);
570}
571
Alexey Bataev13314bf2014-10-09 04:18:56 +0000572void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
573 VisitOMPExecutableDirective(S);
574}
575
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000576void StmtProfiler::VisitOMPCancellationPointDirective(
577 const OMPCancellationPointDirective *S) {
578 VisitOMPExecutableDirective(S);
579}
580
Alexey Bataev80909872015-07-02 11:25:17 +0000581void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
582 VisitOMPExecutableDirective(S);
583}
584
Alexey Bataev49f6e782015-12-01 04:18:41 +0000585void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
586 VisitOMPLoopDirective(S);
587}
588
Chandler Carruth631abd92011-06-16 06:47:06 +0000589void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000590 VisitStmt(S);
591}
592
Chandler Carruth631abd92011-06-16 06:47:06 +0000593void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000594 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000595 if (!Canonical)
596 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000597 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000598 if (!Canonical)
599 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000600}
601
Chandler Carruth631abd92011-06-16 06:47:06 +0000602void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000603 VisitExpr(S);
604 ID.AddInteger(S->getIdentType());
605}
606
Chandler Carruth631abd92011-06-16 06:47:06 +0000607void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000608 VisitExpr(S);
609 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +0000610 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000611}
612
Chandler Carruth631abd92011-06-16 06:47:06 +0000613void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000614 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000615 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000616 ID.AddInteger(S->getValue());
617}
618
Chandler Carruth631abd92011-06-16 06:47:06 +0000619void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000620 VisitExpr(S);
621 S->getValue().Profile(ID);
622 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +0000623 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000624}
625
Chandler Carruth631abd92011-06-16 06:47:06 +0000626void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000627 VisitExpr(S);
628}
629
Chandler Carruth631abd92011-06-16 06:47:06 +0000630void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000631 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000632 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000633 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000634}
635
Chandler Carruth631abd92011-06-16 06:47:06 +0000636void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000637 VisitExpr(S);
638}
639
Chandler Carruth631abd92011-06-16 06:47:06 +0000640void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000641 VisitExpr(S);
642}
643
Chandler Carruth631abd92011-06-16 06:47:06 +0000644void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000645 VisitExpr(S);
646 ID.AddInteger(S->getOpcode());
647}
648
Chandler Carruth631abd92011-06-16 06:47:06 +0000649void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000650 VisitType(S->getTypeSourceInfo()->getType());
651 unsigned n = S->getNumComponents();
652 for (unsigned i = 0; i < n; ++i) {
653 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
654 ID.AddInteger(ON.getKind());
655 switch (ON.getKind()) {
656 case OffsetOfExpr::OffsetOfNode::Array:
657 // Expressions handled below.
658 break;
659
660 case OffsetOfExpr::OffsetOfNode::Field:
661 VisitDecl(ON.getField());
662 break;
663
664 case OffsetOfExpr::OffsetOfNode::Identifier:
665 ID.AddPointer(ON.getFieldName());
666 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000667
Douglas Gregord1702062010-04-29 00:18:15 +0000668 case OffsetOfExpr::OffsetOfNode::Base:
669 // These nodes are implicit, and therefore don't need profiling.
670 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000671 }
672 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000673
Douglas Gregor882211c2010-04-28 22:16:22 +0000674 VisitExpr(S);
675}
676
Chandler Carruth631abd92011-06-16 06:47:06 +0000677void
678StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000679 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000680 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000681 if (S->isArgumentType())
682 VisitType(S->getArgumentType());
683}
684
Chandler Carruth631abd92011-06-16 06:47:06 +0000685void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000686 VisitExpr(S);
687}
688
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000689void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
690 VisitExpr(S);
691}
692
Chandler Carruth631abd92011-06-16 06:47:06 +0000693void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000694 VisitExpr(S);
695}
696
Chandler Carruth631abd92011-06-16 06:47:06 +0000697void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000698 VisitExpr(S);
699 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000700 if (!Canonical)
701 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000702 ID.AddBoolean(S->isArrow());
703}
704
Chandler Carruth631abd92011-06-16 06:47:06 +0000705void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000706 VisitExpr(S);
707 ID.AddBoolean(S->isFileScope());
708}
709
Chandler Carruth631abd92011-06-16 06:47:06 +0000710void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000711 VisitExpr(S);
712}
713
Chandler Carruth631abd92011-06-16 06:47:06 +0000714void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000715 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000716 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000717}
718
Chandler Carruth631abd92011-06-16 06:47:06 +0000719void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000720 VisitCastExpr(S);
721 VisitType(S->getTypeAsWritten());
722}
723
Chandler Carruth631abd92011-06-16 06:47:06 +0000724void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000725 VisitExplicitCastExpr(S);
726}
727
Chandler Carruth631abd92011-06-16 06:47:06 +0000728void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000729 VisitExpr(S);
730 ID.AddInteger(S->getOpcode());
731}
732
Chandler Carruth631abd92011-06-16 06:47:06 +0000733void
734StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000735 VisitBinaryOperator(S);
736}
737
Chandler Carruth631abd92011-06-16 06:47:06 +0000738void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000739 VisitExpr(S);
740}
741
Chandler Carruth631abd92011-06-16 06:47:06 +0000742void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000743 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000744 VisitExpr(S);
745}
746
Chandler Carruth631abd92011-06-16 06:47:06 +0000747void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000748 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000749 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000750}
751
Chandler Carruth631abd92011-06-16 06:47:06 +0000752void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000753 VisitExpr(S);
754}
755
Chandler Carruth631abd92011-06-16 06:47:06 +0000756void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000757 VisitExpr(S);
758}
759
Hal Finkelc4d7c822013-09-18 03:29:45 +0000760void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
761 VisitExpr(S);
762}
763
Chandler Carruth631abd92011-06-16 06:47:06 +0000764void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000765 VisitExpr(S);
766}
767
Chandler Carruth631abd92011-06-16 06:47:06 +0000768void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000769 VisitExpr(S);
770}
771
Chandler Carruth631abd92011-06-16 06:47:06 +0000772void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000773 VisitExpr(S);
774}
775
Chandler Carruth631abd92011-06-16 06:47:06 +0000776void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000777 if (S->getSyntacticForm()) {
778 VisitInitListExpr(S->getSyntacticForm());
779 return;
780 }
Mike Stump11289f42009-09-09 15:08:12 +0000781
Douglas Gregor5c193b92009-07-28 00:33:38 +0000782 VisitExpr(S);
783}
784
Chandler Carruth631abd92011-06-16 06:47:06 +0000785void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000786 VisitExpr(S);
787 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000788 for (DesignatedInitExpr::const_designators_iterator D =
789 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000790 D != DEnd; ++D) {
791 if (D->isFieldDesignator()) {
792 ID.AddInteger(0);
793 VisitName(D->getFieldName());
794 continue;
795 }
Mike Stump11289f42009-09-09 15:08:12 +0000796
Douglas Gregor5c193b92009-07-28 00:33:38 +0000797 if (D->isArrayDesignator()) {
798 ID.AddInteger(1);
799 } else {
800 assert(D->isArrayRangeDesignator());
801 ID.AddInteger(2);
802 }
803 ID.AddInteger(D->getFirstExprIndex());
804 }
805}
806
Yunzhong Gaocb779302015-06-10 00:27:52 +0000807// Seems that if VisitInitListExpr() only works on the syntactic form of an
808// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
809void StmtProfiler::VisitDesignatedInitUpdateExpr(
810 const DesignatedInitUpdateExpr *S) {
811 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
812 "initializer");
813}
814
815void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
816 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
817}
818
Chandler Carruth631abd92011-06-16 06:47:06 +0000819void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000820 VisitExpr(S);
821}
822
Chandler Carruth631abd92011-06-16 06:47:06 +0000823void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000824 VisitExpr(S);
825 VisitName(&S->getAccessor());
826}
827
Chandler Carruth631abd92011-06-16 06:47:06 +0000828void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000829 VisitExpr(S);
830 VisitDecl(S->getBlockDecl());
831}
832
Chandler Carruth631abd92011-06-16 06:47:06 +0000833void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000834 VisitExpr(S);
835 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
836 QualType T = S->getAssocType(i);
837 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000838 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000839 else
840 VisitType(T);
841 VisitExpr(S->getAssocExpr(i));
842 }
843}
844
John McCallfe96e0b2011-11-06 09:01:30 +0000845void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
846 VisitExpr(S);
847 for (PseudoObjectExpr::const_semantics_iterator
848 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
849 // Normally, we would not profile the source expressions of OVEs.
850 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
851 Visit(OVE->getSourceExpr());
852}
853
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000854void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
855 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000856 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000857}
858
Chandler Carruth631abd92011-06-16 06:47:06 +0000859static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000860 UnaryOperatorKind &UnaryOp,
861 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000862 switch (S->getOperator()) {
863 case OO_None:
864 case OO_New:
865 case OO_Delete:
866 case OO_Array_New:
867 case OO_Array_Delete:
868 case OO_Arrow:
869 case OO_Call:
870 case OO_Conditional:
Richard Smith9be594e2015-10-22 05:12:22 +0000871 case OO_Coawait:
Douglas Gregore9ceb312010-05-19 04:13:23 +0000872 case NUM_OVERLOADED_OPERATORS:
873 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000874
875 case OO_Plus:
876 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000877 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000878 return Stmt::UnaryOperatorClass;
879 }
880
John McCalle3027922010-08-25 11:45:40 +0000881 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000882 return Stmt::BinaryOperatorClass;
883
884 case OO_Minus:
885 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000886 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000887 return Stmt::UnaryOperatorClass;
888 }
889
John McCalle3027922010-08-25 11:45:40 +0000890 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000891 return Stmt::BinaryOperatorClass;
892
893 case OO_Star:
894 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000895 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000896 return Stmt::UnaryOperatorClass;
897 }
898
Richard Smithf15acc52014-06-05 22:43:40 +0000899 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000900 return Stmt::BinaryOperatorClass;
901
902 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000903 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000904 return Stmt::BinaryOperatorClass;
905
906 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000907 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000908 return Stmt::BinaryOperatorClass;
909
910 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000911 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000912 return Stmt::BinaryOperatorClass;
913
914 case OO_Amp:
915 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000916 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000917 return Stmt::UnaryOperatorClass;
918 }
919
John McCalle3027922010-08-25 11:45:40 +0000920 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000921 return Stmt::BinaryOperatorClass;
922
923 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000924 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000925 return Stmt::BinaryOperatorClass;
926
927 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000928 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000929 return Stmt::UnaryOperatorClass;
930
931 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000932 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000933 return Stmt::UnaryOperatorClass;
934
935 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000936 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000937 return Stmt::BinaryOperatorClass;
938
939 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000940 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000941 return Stmt::BinaryOperatorClass;
942
943 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000944 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000945 return Stmt::BinaryOperatorClass;
946
947 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000948 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000949 return Stmt::CompoundAssignOperatorClass;
950
951 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000952 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000953 return Stmt::CompoundAssignOperatorClass;
954
955 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000956 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000957 return Stmt::CompoundAssignOperatorClass;
958
959 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000960 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000961 return Stmt::CompoundAssignOperatorClass;
962
963 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000964 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000965 return Stmt::CompoundAssignOperatorClass;
966
967 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000968 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000969 return Stmt::CompoundAssignOperatorClass;
970
971 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000972 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000973 return Stmt::CompoundAssignOperatorClass;
974
975 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000976 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000977 return Stmt::CompoundAssignOperatorClass;
978
979 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000980 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000981 return Stmt::BinaryOperatorClass;
982
983 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000984 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000985 return Stmt::BinaryOperatorClass;
986
987 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000988 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000989 return Stmt::CompoundAssignOperatorClass;
990
991 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000992 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000993 return Stmt::CompoundAssignOperatorClass;
994
995 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000996 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000997 return Stmt::BinaryOperatorClass;
998
999 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001000 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001001 return Stmt::BinaryOperatorClass;
1002
1003 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001004 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001005 return Stmt::BinaryOperatorClass;
1006
1007 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001008 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001009 return Stmt::BinaryOperatorClass;
1010
1011 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001012 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001013 return Stmt::BinaryOperatorClass;
1014
1015 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001016 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001017 return Stmt::BinaryOperatorClass;
1018
1019 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +00001020 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1021 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001022 return Stmt::UnaryOperatorClass;
1023
1024 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001025 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1026 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001027 return Stmt::UnaryOperatorClass;
1028
1029 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001030 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001031 return Stmt::BinaryOperatorClass;
1032
1033
1034 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001035 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001036 return Stmt::BinaryOperatorClass;
1037
1038 case OO_Subscript:
1039 return Stmt::ArraySubscriptExprClass;
1040 }
1041
1042 llvm_unreachable("Invalid overloaded operator expression");
1043}
Richard Smithf15acc52014-06-05 22:43:40 +00001044
Douglas Gregore9ceb312010-05-19 04:13:23 +00001045
Chandler Carruth631abd92011-06-16 06:47:06 +00001046void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001047 if (S->isTypeDependent()) {
1048 // Type-dependent operator calls are profiled like their underlying
1049 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +00001050 UnaryOperatorKind UnaryOp = UO_Extension;
1051 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001052 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001053
Douglas Gregore9ceb312010-05-19 04:13:23 +00001054 ID.AddInteger(SC);
1055 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1056 Visit(S->getArg(I));
1057 if (SC == Stmt::UnaryOperatorClass)
1058 ID.AddInteger(UnaryOp);
1059 else if (SC == Stmt::BinaryOperatorClass ||
1060 SC == Stmt::CompoundAssignOperatorClass)
1061 ID.AddInteger(BinaryOp);
1062 else
1063 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001064
Douglas Gregore9ceb312010-05-19 04:13:23 +00001065 return;
1066 }
Richard Smithf15acc52014-06-05 22:43:40 +00001067
Douglas Gregor5c193b92009-07-28 00:33:38 +00001068 VisitCallExpr(S);
1069 ID.AddInteger(S->getOperator());
1070}
1071
Chandler Carruth631abd92011-06-16 06:47:06 +00001072void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001073 VisitCallExpr(S);
1074}
1075
Chandler Carruth631abd92011-06-16 06:47:06 +00001076void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001077 VisitCallExpr(S);
1078}
1079
Chandler Carruth631abd92011-06-16 06:47:06 +00001080void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001081 VisitExpr(S);
1082}
1083
Chandler Carruth631abd92011-06-16 06:47:06 +00001084void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001085 VisitExplicitCastExpr(S);
1086}
1087
Chandler Carruth631abd92011-06-16 06:47:06 +00001088void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001089 VisitCXXNamedCastExpr(S);
1090}
1091
Chandler Carruth631abd92011-06-16 06:47:06 +00001092void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001093 VisitCXXNamedCastExpr(S);
1094}
1095
Chandler Carruth631abd92011-06-16 06:47:06 +00001096void
1097StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001098 VisitCXXNamedCastExpr(S);
1099}
1100
Chandler Carruth631abd92011-06-16 06:47:06 +00001101void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001102 VisitCXXNamedCastExpr(S);
1103}
1104
Richard Smithc67fdd42012-03-07 08:35:16 +00001105void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1106 VisitCallExpr(S);
1107}
1108
Chandler Carruth631abd92011-06-16 06:47:06 +00001109void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001110 VisitExpr(S);
1111 ID.AddBoolean(S->getValue());
1112}
1113
Chandler Carruth631abd92011-06-16 06:47:06 +00001114void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001115 VisitExpr(S);
1116}
1117
Richard Smithcc1b96d2013-06-12 22:31:48 +00001118void StmtProfiler::VisitCXXStdInitializerListExpr(
1119 const CXXStdInitializerListExpr *S) {
1120 VisitExpr(S);
1121}
1122
Chandler Carruth631abd92011-06-16 06:47:06 +00001123void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001124 VisitExpr(S);
1125 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001126 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001127}
1128
Chandler Carruth631abd92011-06-16 06:47:06 +00001129void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001130 VisitExpr(S);
1131 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001132 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001133}
1134
John McCall5e77d762013-04-16 07:28:30 +00001135void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1136 VisitExpr(S);
1137 VisitDecl(S->getPropertyDecl());
1138}
1139
Alexey Bataevf7630272015-11-25 12:01:00 +00001140void StmtProfiler::VisitMSPropertySubscriptExpr(
1141 const MSPropertySubscriptExpr *S) {
1142 VisitExpr(S);
1143}
1144
Chandler Carruth631abd92011-06-16 06:47:06 +00001145void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001146 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001147 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001148}
1149
Chandler Carruth631abd92011-06-16 06:47:06 +00001150void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001151 VisitExpr(S);
1152}
1153
Chandler Carruth631abd92011-06-16 06:47:06 +00001154void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001155 VisitExpr(S);
1156 VisitDecl(S->getParam());
1157}
1158
Richard Smith852c9db2013-04-20 22:23:05 +00001159void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1160 VisitExpr(S);
1161 VisitDecl(S->getField());
1162}
1163
Chandler Carruth631abd92011-06-16 06:47:06 +00001164void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001165 VisitExpr(S);
1166 VisitDecl(
1167 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1168}
1169
Chandler Carruth631abd92011-06-16 06:47:06 +00001170void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001171 VisitExpr(S);
1172 VisitDecl(S->getConstructor());
1173 ID.AddBoolean(S->isElidable());
1174}
1175
Chandler Carruth631abd92011-06-16 06:47:06 +00001176void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001177 VisitExplicitCastExpr(S);
1178}
1179
Chandler Carruth631abd92011-06-16 06:47:06 +00001180void
1181StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001182 VisitCXXConstructExpr(S);
1183}
1184
Chandler Carruth631abd92011-06-16 06:47:06 +00001185void
Douglas Gregore31e6062012-02-07 10:09:13 +00001186StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1187 VisitExpr(S);
1188 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1189 CEnd = S->explicit_capture_end();
1190 C != CEnd; ++C) {
1191 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001192 switch (C->getCaptureKind()) {
1193 case LCK_This:
1194 break;
1195 case LCK_ByRef:
1196 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001197 VisitDecl(C->getCapturedVar());
1198 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001199 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001200 case LCK_VLAType:
1201 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001202 }
1203 }
1204 // Note: If we actually needed to be able to match lambda
1205 // expressions, we would have to consider parameters and return type
1206 // here, among other things.
1207 VisitStmt(S->getBody());
1208}
1209
1210void
Chandler Carruth631abd92011-06-16 06:47:06 +00001211StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001212 VisitExpr(S);
1213}
1214
Chandler Carruth631abd92011-06-16 06:47:06 +00001215void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001216 VisitExpr(S);
1217 ID.AddBoolean(S->isGlobalDelete());
1218 ID.AddBoolean(S->isArrayForm());
1219 VisitDecl(S->getOperatorDelete());
1220}
1221
1222
Chandler Carruth631abd92011-06-16 06:47:06 +00001223void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001224 VisitExpr(S);
1225 VisitType(S->getAllocatedType());
1226 VisitDecl(S->getOperatorNew());
1227 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001228 ID.AddBoolean(S->isArray());
1229 ID.AddInteger(S->getNumPlacementArgs());
1230 ID.AddBoolean(S->isGlobalNew());
1231 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001232 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001233}
1234
Chandler Carruth631abd92011-06-16 06:47:06 +00001235void
1236StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001237 VisitExpr(S);
1238 ID.AddBoolean(S->isArrow());
1239 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001240 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001241 if (S->getScopeTypeInfo())
1242 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001243 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001244 if (S->getDestroyedTypeInfo())
1245 VisitType(S->getDestroyedType());
1246 else
1247 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001248}
1249
Chandler Carruth631abd92011-06-16 06:47:06 +00001250void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001251 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001252 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001253 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001254 ID.AddBoolean(S->hasExplicitTemplateArgs());
1255 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001256 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1257 S->getExplicitTemplateArgs().NumTemplateArgs);
1258}
1259
1260void
Chandler Carruth631abd92011-06-16 06:47:06 +00001261StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001262 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001263}
1264
Douglas Gregor29c42f22012-02-24 07:38:34 +00001265void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1266 VisitExpr(S);
1267 ID.AddInteger(S->getTrait());
1268 ID.AddInteger(S->getNumArgs());
1269 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1270 VisitType(S->getArg(I)->getType());
1271}
1272
Chandler Carruth631abd92011-06-16 06:47:06 +00001273void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001274 VisitExpr(S);
1275 ID.AddInteger(S->getTrait());
1276 VisitType(S->getQueriedType());
1277}
1278
Chandler Carruth631abd92011-06-16 06:47:06 +00001279void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001280 VisitExpr(S);
1281 ID.AddInteger(S->getTrait());
1282 VisitExpr(S->getQueriedExpression());
1283}
1284
Chandler Carruth631abd92011-06-16 06:47:06 +00001285void StmtProfiler::VisitDependentScopeDeclRefExpr(
1286 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001287 VisitExpr(S);
1288 VisitName(S->getDeclName());
1289 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001290 ID.AddBoolean(S->hasExplicitTemplateArgs());
1291 if (S->hasExplicitTemplateArgs())
1292 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001293}
1294
Chandler Carruth631abd92011-06-16 06:47:06 +00001295void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001296 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001297}
1298
Chandler Carruth631abd92011-06-16 06:47:06 +00001299void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1300 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001301 VisitExpr(S);
1302 VisitType(S->getTypeAsWritten());
1303}
1304
Chandler Carruth631abd92011-06-16 06:47:06 +00001305void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1306 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001307 ID.AddBoolean(S->isImplicitAccess());
1308 if (!S->isImplicitAccess()) {
1309 VisitExpr(S);
1310 ID.AddBoolean(S->isArrow());
1311 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001312 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001313 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001314 ID.AddBoolean(S->hasExplicitTemplateArgs());
1315 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001316 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1317}
1318
Chandler Carruth631abd92011-06-16 06:47:06 +00001319void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001320 ID.AddBoolean(S->isImplicitAccess());
1321 if (!S->isImplicitAccess()) {
1322 VisitExpr(S);
1323 ID.AddBoolean(S->isArrow());
1324 }
John McCall10eae182009-11-30 22:42:35 +00001325 VisitNestedNameSpecifier(S->getQualifier());
1326 VisitName(S->getMemberName());
1327 ID.AddBoolean(S->hasExplicitTemplateArgs());
1328 if (S->hasExplicitTemplateArgs())
1329 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001330}
1331
Chandler Carruth631abd92011-06-16 06:47:06 +00001332void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001333 VisitExpr(S);
1334}
1335
Chandler Carruth631abd92011-06-16 06:47:06 +00001336void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001337 VisitExpr(S);
1338}
1339
Chandler Carruth631abd92011-06-16 06:47:06 +00001340void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001341 VisitExpr(S);
1342 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00001343 if (S->isPartiallySubstituted()) {
1344 auto Args = S->getPartialArguments();
1345 ID.AddInteger(Args.size());
1346 for (const auto &TA : Args)
1347 VisitTemplateArgument(TA);
1348 } else {
1349 ID.AddInteger(0);
1350 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001351}
1352
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001353void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001354 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001355 VisitExpr(S);
1356 VisitDecl(S->getParameterPack());
1357 VisitTemplateArgument(S->getArgumentPack());
1358}
1359
John McCall7c454bb2011-07-15 05:09:51 +00001360void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1361 const SubstNonTypeTemplateParmExpr *E) {
1362 // Profile exactly as the replacement expression.
1363 Visit(E->getReplacement());
1364}
1365
Richard Smithb15fe3a2012-09-12 00:56:43 +00001366void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1367 VisitExpr(S);
1368 VisitDecl(S->getParameterPack());
1369 ID.AddInteger(S->getNumExpansions());
1370 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1371 VisitDecl(*I);
1372}
1373
Douglas Gregorfe314812011-06-21 17:03:29 +00001374void StmtProfiler::VisitMaterializeTemporaryExpr(
1375 const MaterializeTemporaryExpr *S) {
1376 VisitExpr(S);
1377}
1378
Richard Smith0f0af192014-11-08 05:07:16 +00001379void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1380 VisitExpr(S);
1381 ID.AddInteger(S->getOperator());
1382}
1383
Richard Smith9f690bd2015-10-27 06:02:45 +00001384void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1385 VisitStmt(S);
1386}
1387
1388void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1389 VisitStmt(S);
1390}
1391
1392void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1393 VisitExpr(S);
1394}
1395
1396void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1397 VisitExpr(S);
1398}
1399
Chandler Carruth631abd92011-06-16 06:47:06 +00001400void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001401 VisitExpr(E);
1402}
1403
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001404void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1405 VisitExpr(E);
1406}
1407
Chandler Carruth631abd92011-06-16 06:47:06 +00001408void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001409 VisitExpr(S);
1410}
1411
Patrick Beard0caa3942012-04-19 00:25:12 +00001412void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001413 VisitExpr(E);
1414}
1415
1416void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1417 VisitExpr(E);
1418}
1419
1420void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1421 VisitExpr(E);
1422}
1423
Chandler Carruth631abd92011-06-16 06:47:06 +00001424void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001425 VisitExpr(S);
1426 VisitType(S->getEncodedType());
1427}
1428
Chandler Carruth631abd92011-06-16 06:47:06 +00001429void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001430 VisitExpr(S);
1431 VisitName(S->getSelector());
1432}
1433
Chandler Carruth631abd92011-06-16 06:47:06 +00001434void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001435 VisitExpr(S);
1436 VisitDecl(S->getProtocol());
1437}
1438
Chandler Carruth631abd92011-06-16 06:47:06 +00001439void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001440 VisitExpr(S);
1441 VisitDecl(S->getDecl());
1442 ID.AddBoolean(S->isArrow());
1443 ID.AddBoolean(S->isFreeIvar());
1444}
1445
Chandler Carruth631abd92011-06-16 06:47:06 +00001446void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001447 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001448 if (S->isImplicitProperty()) {
1449 VisitDecl(S->getImplicitPropertyGetter());
1450 VisitDecl(S->getImplicitPropertySetter());
1451 } else {
1452 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001453 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001454 if (S->isSuperReceiver()) {
1455 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001456 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001457 }
Douglas Gregora7095092009-07-28 14:44:31 +00001458}
1459
Ted Kremeneke65b0862012-03-06 20:05:56 +00001460void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1461 VisitExpr(S);
1462 VisitDecl(S->getAtIndexMethodDecl());
1463 VisitDecl(S->setAtIndexMethodDecl());
1464}
1465
Chandler Carruth631abd92011-06-16 06:47:06 +00001466void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001467 VisitExpr(S);
1468 VisitName(S->getSelector());
1469 VisitDecl(S->getMethodDecl());
1470}
1471
Chandler Carruth631abd92011-06-16 06:47:06 +00001472void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001473 VisitExpr(S);
1474 ID.AddBoolean(S->isArrow());
1475}
1476
Ted Kremeneke65b0862012-03-06 20:05:56 +00001477void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1478 VisitExpr(S);
1479 ID.AddBoolean(S->getValue());
1480}
1481
Chandler Carruth631abd92011-06-16 06:47:06 +00001482void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1483 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001484 VisitExpr(S);
1485 ID.AddBoolean(S->shouldCopy());
1486}
1487
Chandler Carruth631abd92011-06-16 06:47:06 +00001488void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001489 VisitExplicitCastExpr(S);
1490 ID.AddBoolean(S->getBridgeKind());
1491}
1492
Chandler Carruth631abd92011-06-16 06:47:06 +00001493void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001494 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001495
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001496 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001497 if (const NonTypeTemplateParmDecl *NTTP =
1498 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001499 ID.AddInteger(NTTP->getDepth());
1500 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001501 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001502 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001503 return;
1504 }
Mike Stump11289f42009-09-09 15:08:12 +00001505
Chandler Carruth631abd92011-06-16 06:47:06 +00001506 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001507 // The Itanium C++ ABI uses the type, scope depth, and scope
1508 // index of a parameter when mangling expressions that involve
1509 // function parameters, so we will use the parameter's type for
1510 // establishing function parameter identity. That way, our
1511 // definition of "equivalent" (per C++ [temp.over.link]) is at
1512 // least as strong as the definition of "equivalent" used for
1513 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001514 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001515 ID.AddInteger(Parm->getFunctionScopeDepth());
1516 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001517 return;
1518 }
Mike Stump11289f42009-09-09 15:08:12 +00001519
Richard Smithd9a1cd82012-04-02 18:53:24 +00001520 if (const TemplateTypeParmDecl *TTP =
1521 dyn_cast<TemplateTypeParmDecl>(D)) {
1522 ID.AddInteger(TTP->getDepth());
1523 ID.AddInteger(TTP->getIndex());
1524 ID.AddBoolean(TTP->isParameterPack());
1525 return;
1526 }
1527
Chandler Carruth631abd92011-06-16 06:47:06 +00001528 if (const TemplateTemplateParmDecl *TTP =
1529 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001530 ID.AddInteger(TTP->getDepth());
1531 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001532 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001533 return;
1534 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001535 }
Mike Stump11289f42009-09-09 15:08:12 +00001536
Craig Topper36250ad2014-05-12 05:36:57 +00001537 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001538}
1539
1540void StmtProfiler::VisitType(QualType T) {
1541 if (Canonical)
1542 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001543
Douglas Gregor5c193b92009-07-28 00:33:38 +00001544 ID.AddPointer(T.getAsOpaquePtr());
1545}
1546
1547void StmtProfiler::VisitName(DeclarationName Name) {
1548 ID.AddPointer(Name.getAsOpaquePtr());
1549}
1550
1551void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1552 if (Canonical)
1553 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1554 ID.AddPointer(NNS);
1555}
1556
1557void StmtProfiler::VisitTemplateName(TemplateName Name) {
1558 if (Canonical)
1559 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001560
Douglas Gregor5c193b92009-07-28 00:33:38 +00001561 Name.Profile(ID);
1562}
1563
John McCall0ad16662009-10-29 08:12:44 +00001564void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001565 unsigned NumArgs) {
1566 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001567 for (unsigned I = 0; I != NumArgs; ++I)
1568 VisitTemplateArgument(Args[I].getArgument());
1569}
Mike Stump11289f42009-09-09 15:08:12 +00001570
John McCall0ad16662009-10-29 08:12:44 +00001571void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1572 // Mostly repetitive with TemplateArgument::Profile!
1573 ID.AddInteger(Arg.getKind());
1574 switch (Arg.getKind()) {
1575 case TemplateArgument::Null:
1576 break;
Mike Stump11289f42009-09-09 15:08:12 +00001577
John McCall0ad16662009-10-29 08:12:44 +00001578 case TemplateArgument::Type:
1579 VisitType(Arg.getAsType());
1580 break;
Mike Stump11289f42009-09-09 15:08:12 +00001581
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001582 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001583 case TemplateArgument::TemplateExpansion:
1584 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001585 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001586
John McCall0ad16662009-10-29 08:12:44 +00001587 case TemplateArgument::Declaration:
1588 VisitDecl(Arg.getAsDecl());
1589 break;
Mike Stump11289f42009-09-09 15:08:12 +00001590
Eli Friedmanb826a002012-09-26 02:36:12 +00001591 case TemplateArgument::NullPtr:
1592 VisitType(Arg.getNullPtrType());
1593 break;
1594
John McCall0ad16662009-10-29 08:12:44 +00001595 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001596 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001597 VisitType(Arg.getIntegralType());
1598 break;
Mike Stump11289f42009-09-09 15:08:12 +00001599
John McCall0ad16662009-10-29 08:12:44 +00001600 case TemplateArgument::Expression:
1601 Visit(Arg.getAsExpr());
1602 break;
Mike Stump11289f42009-09-09 15:08:12 +00001603
John McCall0ad16662009-10-29 08:12:44 +00001604 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001605 for (const auto &P : Arg.pack_elements())
1606 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001607 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001608 }
1609}
1610
Jay Foad39c79802011-01-12 09:06:06 +00001611void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001612 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001613 StmtProfiler Profiler(ID, Context, Canonical);
1614 Profiler.Visit(this);
1615}