blob: b871ffb73b4321311daa939450e46b6ed060d2b9 [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"
21#include "clang/AST/StmtVisitor.h"
22#include "llvm/ADT/FoldingSet.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Chandler Carruth631abd92011-06-16 06:47:06 +000026 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Douglas Gregor5c193b92009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
Jay Foad39c79802011-01-12 09:06:06 +000028 const ASTContext &Context;
Douglas Gregor5c193b92009-07-28 00:33:38 +000029 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000030
Douglas Gregor5c193b92009-07-28 00:33:38 +000031 public:
Jay Foad39c79802011-01-12 09:06:06 +000032 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump11289f42009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor5c193b92009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump11289f42009-09-09 15:08:12 +000035
Chandler Carruth631abd92011-06-16 06:47:06 +000036 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000037
Chandler Carruth631abd92011-06-16 06:47:06 +000038#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000040
Douglas Gregor5c193b92009-07-28 00:33:38 +000041 /// \brief Visit a declaration that is referenced within an expression
42 /// or statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000043 void VisitDecl(const Decl *D);
Mike Stump11289f42009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +000048
Douglas Gregor5c193b92009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump11289f42009-09-09 15:08:12 +000051
Douglas Gregor5c193b92009-07-28 00:33:38 +000052 /// \brief Visit a nested-name-specifier that occurs within an expression
53 /// or statement.
54 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump11289f42009-09-09 15:08:12 +000055
Douglas Gregor5c193b92009-07-28 00:33:38 +000056 /// \brief Visit a template name that occurs within an expression or
57 /// statement.
58 void VisitTemplateName(TemplateName Name);
Mike Stump11289f42009-09-09 15:08:12 +000059
Douglas Gregor5c193b92009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
63 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000064
65 /// \brief Visit a single template argument.
66 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000067 };
68}
69
Chandler Carruth631abd92011-06-16 06:47:06 +000070void StmtProfiler::VisitStmt(const Stmt *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +000071 ID.AddInteger(S->getStmtClass());
Peter Collingbournecdb9f302012-03-01 16:34:31 +000072 for (Stmt::const_child_range C = S->children(); C; ++C) {
73 if (*C)
74 Visit(*C);
75 else
76 ID.AddInteger(0);
77 }
Douglas Gregor5c193b92009-07-28 00:33:38 +000078}
79
Chandler Carruth631abd92011-06-16 06:47:06 +000080void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000081 VisitStmt(S);
Chandler Carruth631abd92011-06-16 06:47:06 +000082 for (DeclStmt::const_decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
Douglas Gregor44882592009-07-28 15:27:13 +000083 D != DEnd; ++D)
84 VisitDecl(*D);
85}
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
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000218void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
219 VisitStmt(S);
220}
221
Chandler Carruth631abd92011-06-16 06:47:06 +0000222void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000223 VisitStmt(S);
224}
225
Chandler Carruth631abd92011-06-16 06:47:06 +0000226void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000227 VisitStmt(S);
228 ID.AddBoolean(S->hasEllipsis());
229 if (S->getCatchParamDecl())
230 VisitType(S->getCatchParamDecl()->getType());
231}
232
Chandler Carruth631abd92011-06-16 06:47:06 +0000233void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000234 VisitStmt(S);
235}
236
Chandler Carruth631abd92011-06-16 06:47:06 +0000237void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000238 VisitStmt(S);
239}
240
Chandler Carruth631abd92011-06-16 06:47:06 +0000241void
242StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000243 VisitStmt(S);
244}
245
Chandler Carruth631abd92011-06-16 06:47:06 +0000246void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000247 VisitStmt(S);
248}
249
Chandler Carruth631abd92011-06-16 06:47:06 +0000250void
251StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000252 VisitStmt(S);
253}
254
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000255namespace {
256class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
257 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000258 /// \brief Process clauses with list of variables.
259 template <typename T>
260 void VisitOMPClauseList(T *Node);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000261public:
262 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
263#define OPENMP_CLAUSE(Name, Class) \
264 void Visit##Class(const Class *C);
265#include "clang/Basic/OpenMPKinds.def"
266};
267
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000268void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
269 if (C->getCondition())
270 Profiler->VisitStmt(C->getCondition());
271}
272
Alexey Bataev568a8332014-03-06 06:15:19 +0000273void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
274 if (C->getNumThreads())
275 Profiler->VisitStmt(C->getNumThreads());
276}
277
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000278void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000279
280template<typename T>
281void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
282 for (typename T::varlist_const_iterator I = Node->varlist_begin(),
283 E = Node->varlist_end();
284 I != E; ++I)
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000285 Profiler->VisitStmt(*I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000286}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000287
288void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000289 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000290}
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000291void OMPClauseProfiler::VisitOMPFirstprivateClause(
292 const OMPFirstprivateClause *C) {
293 VisitOMPClauseList(C);
294}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000295void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000296 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000297}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000298}
299
300void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000301StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000302 VisitStmt(S);
303 OMPClauseProfiler P(this);
304 ArrayRef<OMPClause *> Clauses = S->clauses();
305 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
306 I != E; ++I)
307 if (*I)
308 P.Visit(*I);
309}
310
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000311void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
312 VisitOMPExecutableDirective(S);
313}
314
315void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
316 VisitOMPExecutableDirective(S);
317}
318
Chandler Carruth631abd92011-06-16 06:47:06 +0000319void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000320 VisitStmt(S);
321}
322
Chandler Carruth631abd92011-06-16 06:47:06 +0000323void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000324 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000325 if (!Canonical)
326 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000327 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000328 if (!Canonical)
329 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000330}
331
Chandler Carruth631abd92011-06-16 06:47:06 +0000332void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000333 VisitExpr(S);
334 ID.AddInteger(S->getIdentType());
335}
336
Chandler Carruth631abd92011-06-16 06:47:06 +0000337void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000338 VisitExpr(S);
339 S->getValue().Profile(ID);
340}
341
Chandler Carruth631abd92011-06-16 06:47:06 +0000342void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000343 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000344 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000345 ID.AddInteger(S->getValue());
346}
347
Chandler Carruth631abd92011-06-16 06:47:06 +0000348void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000349 VisitExpr(S);
350 S->getValue().Profile(ID);
351 ID.AddBoolean(S->isExact());
352}
353
Chandler Carruth631abd92011-06-16 06:47:06 +0000354void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000355 VisitExpr(S);
356}
357
Chandler Carruth631abd92011-06-16 06:47:06 +0000358void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000359 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000360 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000361 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000362}
363
Chandler Carruth631abd92011-06-16 06:47:06 +0000364void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000365 VisitExpr(S);
366}
367
Chandler Carruth631abd92011-06-16 06:47:06 +0000368void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000369 VisitExpr(S);
370}
371
Chandler Carruth631abd92011-06-16 06:47:06 +0000372void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000373 VisitExpr(S);
374 ID.AddInteger(S->getOpcode());
375}
376
Chandler Carruth631abd92011-06-16 06:47:06 +0000377void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000378 VisitType(S->getTypeSourceInfo()->getType());
379 unsigned n = S->getNumComponents();
380 for (unsigned i = 0; i < n; ++i) {
381 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
382 ID.AddInteger(ON.getKind());
383 switch (ON.getKind()) {
384 case OffsetOfExpr::OffsetOfNode::Array:
385 // Expressions handled below.
386 break;
387
388 case OffsetOfExpr::OffsetOfNode::Field:
389 VisitDecl(ON.getField());
390 break;
391
392 case OffsetOfExpr::OffsetOfNode::Identifier:
393 ID.AddPointer(ON.getFieldName());
394 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000395
Douglas Gregord1702062010-04-29 00:18:15 +0000396 case OffsetOfExpr::OffsetOfNode::Base:
397 // These nodes are implicit, and therefore don't need profiling.
398 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000399 }
400 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000401
Douglas Gregor882211c2010-04-28 22:16:22 +0000402 VisitExpr(S);
403}
404
Chandler Carruth631abd92011-06-16 06:47:06 +0000405void
406StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000407 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000408 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000409 if (S->isArgumentType())
410 VisitType(S->getArgumentType());
411}
412
Chandler Carruth631abd92011-06-16 06:47:06 +0000413void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000414 VisitExpr(S);
415}
416
Chandler Carruth631abd92011-06-16 06:47:06 +0000417void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000418 VisitExpr(S);
419}
420
Chandler Carruth631abd92011-06-16 06:47:06 +0000421void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000422 VisitExpr(S);
423 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000424 if (!Canonical)
425 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000426 ID.AddBoolean(S->isArrow());
427}
428
Chandler Carruth631abd92011-06-16 06:47:06 +0000429void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000430 VisitExpr(S);
431 ID.AddBoolean(S->isFileScope());
432}
433
Chandler Carruth631abd92011-06-16 06:47:06 +0000434void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000435 VisitExpr(S);
436}
437
Chandler Carruth631abd92011-06-16 06:47:06 +0000438void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000439 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000440 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000441}
442
Chandler Carruth631abd92011-06-16 06:47:06 +0000443void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000444 VisitCastExpr(S);
445 VisitType(S->getTypeAsWritten());
446}
447
Chandler Carruth631abd92011-06-16 06:47:06 +0000448void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000449 VisitExplicitCastExpr(S);
450}
451
Chandler Carruth631abd92011-06-16 06:47:06 +0000452void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000453 VisitExpr(S);
454 ID.AddInteger(S->getOpcode());
455}
456
Chandler Carruth631abd92011-06-16 06:47:06 +0000457void
458StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000459 VisitBinaryOperator(S);
460}
461
Chandler Carruth631abd92011-06-16 06:47:06 +0000462void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000463 VisitExpr(S);
464}
465
Chandler Carruth631abd92011-06-16 06:47:06 +0000466void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000467 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000468 VisitExpr(S);
469}
470
Chandler Carruth631abd92011-06-16 06:47:06 +0000471void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000472 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000473 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000474}
475
Chandler Carruth631abd92011-06-16 06:47:06 +0000476void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000477 VisitExpr(S);
478}
479
Chandler Carruth631abd92011-06-16 06:47:06 +0000480void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000481 VisitExpr(S);
482}
483
Hal Finkelc4d7c822013-09-18 03:29:45 +0000484void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
485 VisitExpr(S);
486}
487
Chandler Carruth631abd92011-06-16 06:47:06 +0000488void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000489 VisitExpr(S);
490}
491
Chandler Carruth631abd92011-06-16 06:47:06 +0000492void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000493 VisitExpr(S);
494}
495
Chandler Carruth631abd92011-06-16 06:47:06 +0000496void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000497 VisitExpr(S);
498}
499
Chandler Carruth631abd92011-06-16 06:47:06 +0000500void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000501 if (S->getSyntacticForm()) {
502 VisitInitListExpr(S->getSyntacticForm());
503 return;
504 }
Mike Stump11289f42009-09-09 15:08:12 +0000505
Douglas Gregor5c193b92009-07-28 00:33:38 +0000506 VisitExpr(S);
507}
508
Chandler Carruth631abd92011-06-16 06:47:06 +0000509void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000510 VisitExpr(S);
511 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000512 for (DesignatedInitExpr::const_designators_iterator D =
513 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000514 D != DEnd; ++D) {
515 if (D->isFieldDesignator()) {
516 ID.AddInteger(0);
517 VisitName(D->getFieldName());
518 continue;
519 }
Mike Stump11289f42009-09-09 15:08:12 +0000520
Douglas Gregor5c193b92009-07-28 00:33:38 +0000521 if (D->isArrayDesignator()) {
522 ID.AddInteger(1);
523 } else {
524 assert(D->isArrayRangeDesignator());
525 ID.AddInteger(2);
526 }
527 ID.AddInteger(D->getFirstExprIndex());
528 }
529}
530
Chandler Carruth631abd92011-06-16 06:47:06 +0000531void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000532 VisitExpr(S);
533}
534
Chandler Carruth631abd92011-06-16 06:47:06 +0000535void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000536 VisitExpr(S);
537 VisitName(&S->getAccessor());
538}
539
Chandler Carruth631abd92011-06-16 06:47:06 +0000540void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000541 VisitExpr(S);
542 VisitDecl(S->getBlockDecl());
543}
544
Chandler Carruth631abd92011-06-16 06:47:06 +0000545void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000546 VisitExpr(S);
547 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
548 QualType T = S->getAssocType(i);
549 if (T.isNull())
550 ID.AddPointer(0);
551 else
552 VisitType(T);
553 VisitExpr(S->getAssocExpr(i));
554 }
555}
556
John McCallfe96e0b2011-11-06 09:01:30 +0000557void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
558 VisitExpr(S);
559 for (PseudoObjectExpr::const_semantics_iterator
560 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
561 // Normally, we would not profile the source expressions of OVEs.
562 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
563 Visit(OVE->getSourceExpr());
564}
565
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000566void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
567 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000568 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000569}
570
Chandler Carruth631abd92011-06-16 06:47:06 +0000571static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000572 UnaryOperatorKind &UnaryOp,
573 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000574 switch (S->getOperator()) {
575 case OO_None:
576 case OO_New:
577 case OO_Delete:
578 case OO_Array_New:
579 case OO_Array_Delete:
580 case OO_Arrow:
581 case OO_Call:
582 case OO_Conditional:
583 case NUM_OVERLOADED_OPERATORS:
584 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000585
586 case OO_Plus:
587 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000588 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000589 return Stmt::UnaryOperatorClass;
590 }
591
John McCalle3027922010-08-25 11:45:40 +0000592 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000593 return Stmt::BinaryOperatorClass;
594
595 case OO_Minus:
596 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000597 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000598 return Stmt::UnaryOperatorClass;
599 }
600
John McCalle3027922010-08-25 11:45:40 +0000601 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000602 return Stmt::BinaryOperatorClass;
603
604 case OO_Star:
605 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000606 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000607 return Stmt::UnaryOperatorClass;
608 }
609
John McCalle3027922010-08-25 11:45:40 +0000610 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000611 return Stmt::BinaryOperatorClass;
612
613 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000614 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000615 return Stmt::BinaryOperatorClass;
616
617 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000618 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000619 return Stmt::BinaryOperatorClass;
620
621 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000622 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000623 return Stmt::BinaryOperatorClass;
624
625 case OO_Amp:
626 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000627 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000628 return Stmt::UnaryOperatorClass;
629 }
630
John McCalle3027922010-08-25 11:45:40 +0000631 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000632 return Stmt::BinaryOperatorClass;
633
634 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000635 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000636 return Stmt::BinaryOperatorClass;
637
638 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000639 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000640 return Stmt::UnaryOperatorClass;
641
642 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000643 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000644 return Stmt::UnaryOperatorClass;
645
646 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000647 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000648 return Stmt::BinaryOperatorClass;
649
650 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000651 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000652 return Stmt::BinaryOperatorClass;
653
654 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000655 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000656 return Stmt::BinaryOperatorClass;
657
658 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000659 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000660 return Stmt::CompoundAssignOperatorClass;
661
662 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000663 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000664 return Stmt::CompoundAssignOperatorClass;
665
666 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000667 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000668 return Stmt::CompoundAssignOperatorClass;
669
670 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000671 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000672 return Stmt::CompoundAssignOperatorClass;
673
674 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000675 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000676 return Stmt::CompoundAssignOperatorClass;
677
678 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000679 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000680 return Stmt::CompoundAssignOperatorClass;
681
682 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000683 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000684 return Stmt::CompoundAssignOperatorClass;
685
686 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000687 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000688 return Stmt::CompoundAssignOperatorClass;
689
690 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000691 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000692 return Stmt::BinaryOperatorClass;
693
694 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000695 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000696 return Stmt::BinaryOperatorClass;
697
698 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000699 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000700 return Stmt::CompoundAssignOperatorClass;
701
702 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000703 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000704 return Stmt::CompoundAssignOperatorClass;
705
706 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000707 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000708 return Stmt::BinaryOperatorClass;
709
710 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000711 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000712 return Stmt::BinaryOperatorClass;
713
714 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000715 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000716 return Stmt::BinaryOperatorClass;
717
718 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000719 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000720 return Stmt::BinaryOperatorClass;
721
722 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000723 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000724 return Stmt::BinaryOperatorClass;
725
726 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000727 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000728 return Stmt::BinaryOperatorClass;
729
730 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000731 UnaryOp = S->getNumArgs() == 1? UO_PreInc
732 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000733 return Stmt::UnaryOperatorClass;
734
735 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000736 UnaryOp = S->getNumArgs() == 1? UO_PreDec
737 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000738 return Stmt::UnaryOperatorClass;
739
740 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000741 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000742 return Stmt::BinaryOperatorClass;
743
744
745 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000746 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000747 return Stmt::BinaryOperatorClass;
748
749 case OO_Subscript:
750 return Stmt::ArraySubscriptExprClass;
751 }
752
753 llvm_unreachable("Invalid overloaded operator expression");
754}
755
756
Chandler Carruth631abd92011-06-16 06:47:06 +0000757void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000758 if (S->isTypeDependent()) {
759 // Type-dependent operator calls are profiled like their underlying
760 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000761 UnaryOperatorKind UnaryOp = UO_Extension;
762 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000763 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
764
765 ID.AddInteger(SC);
766 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
767 Visit(S->getArg(I));
768 if (SC == Stmt::UnaryOperatorClass)
769 ID.AddInteger(UnaryOp);
770 else if (SC == Stmt::BinaryOperatorClass ||
771 SC == Stmt::CompoundAssignOperatorClass)
772 ID.AddInteger(BinaryOp);
773 else
774 assert(SC == Stmt::ArraySubscriptExprClass);
775
776 return;
777 }
778
Douglas Gregor5c193b92009-07-28 00:33:38 +0000779 VisitCallExpr(S);
780 ID.AddInteger(S->getOperator());
781}
782
Chandler Carruth631abd92011-06-16 06:47:06 +0000783void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000784 VisitCallExpr(S);
785}
786
Chandler Carruth631abd92011-06-16 06:47:06 +0000787void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000788 VisitCallExpr(S);
789}
790
Chandler Carruth631abd92011-06-16 06:47:06 +0000791void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000792 VisitExpr(S);
793}
794
Chandler Carruth631abd92011-06-16 06:47:06 +0000795void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000796 VisitExplicitCastExpr(S);
797}
798
Chandler Carruth631abd92011-06-16 06:47:06 +0000799void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000800 VisitCXXNamedCastExpr(S);
801}
802
Chandler Carruth631abd92011-06-16 06:47:06 +0000803void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000804 VisitCXXNamedCastExpr(S);
805}
806
Chandler Carruth631abd92011-06-16 06:47:06 +0000807void
808StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000809 VisitCXXNamedCastExpr(S);
810}
811
Chandler Carruth631abd92011-06-16 06:47:06 +0000812void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000813 VisitCXXNamedCastExpr(S);
814}
815
Richard Smithc67fdd42012-03-07 08:35:16 +0000816void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
817 VisitCallExpr(S);
818}
819
Chandler Carruth631abd92011-06-16 06:47:06 +0000820void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000821 VisitExpr(S);
822 ID.AddBoolean(S->getValue());
823}
824
Chandler Carruth631abd92011-06-16 06:47:06 +0000825void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000826 VisitExpr(S);
827}
828
Richard Smithcc1b96d2013-06-12 22:31:48 +0000829void StmtProfiler::VisitCXXStdInitializerListExpr(
830 const CXXStdInitializerListExpr *S) {
831 VisitExpr(S);
832}
833
Chandler Carruth631abd92011-06-16 06:47:06 +0000834void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000835 VisitExpr(S);
836 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000837 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000838}
839
Chandler Carruth631abd92011-06-16 06:47:06 +0000840void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000841 VisitExpr(S);
842 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000843 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000844}
845
John McCall5e77d762013-04-16 07:28:30 +0000846void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
847 VisitExpr(S);
848 VisitDecl(S->getPropertyDecl());
849}
850
Chandler Carruth631abd92011-06-16 06:47:06 +0000851void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000852 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000853 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000854}
855
Chandler Carruth631abd92011-06-16 06:47:06 +0000856void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000857 VisitExpr(S);
858}
859
Chandler Carruth631abd92011-06-16 06:47:06 +0000860void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000861 VisitExpr(S);
862 VisitDecl(S->getParam());
863}
864
Richard Smith852c9db2013-04-20 22:23:05 +0000865void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
866 VisitExpr(S);
867 VisitDecl(S->getField());
868}
869
Chandler Carruth631abd92011-06-16 06:47:06 +0000870void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000871 VisitExpr(S);
872 VisitDecl(
873 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
874}
875
Chandler Carruth631abd92011-06-16 06:47:06 +0000876void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000877 VisitExpr(S);
878 VisitDecl(S->getConstructor());
879 ID.AddBoolean(S->isElidable());
880}
881
Chandler Carruth631abd92011-06-16 06:47:06 +0000882void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000883 VisitExplicitCastExpr(S);
884}
885
Chandler Carruth631abd92011-06-16 06:47:06 +0000886void
887StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000888 VisitCXXConstructExpr(S);
889}
890
Chandler Carruth631abd92011-06-16 06:47:06 +0000891void
Douglas Gregore31e6062012-02-07 10:09:13 +0000892StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
893 VisitExpr(S);
894 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
895 CEnd = S->explicit_capture_end();
896 C != CEnd; ++C) {
897 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +0000898 switch (C->getCaptureKind()) {
899 case LCK_This:
900 break;
901 case LCK_ByRef:
902 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +0000903 VisitDecl(C->getCapturedVar());
904 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +0000905 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000906 }
907 }
908 // Note: If we actually needed to be able to match lambda
909 // expressions, we would have to consider parameters and return type
910 // here, among other things.
911 VisitStmt(S->getBody());
912}
913
914void
Chandler Carruth631abd92011-06-16 06:47:06 +0000915StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000916 VisitExpr(S);
917}
918
Chandler Carruth631abd92011-06-16 06:47:06 +0000919void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000920 VisitExpr(S);
921 ID.AddBoolean(S->isGlobalDelete());
922 ID.AddBoolean(S->isArrayForm());
923 VisitDecl(S->getOperatorDelete());
924}
925
926
Chandler Carruth631abd92011-06-16 06:47:06 +0000927void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000928 VisitExpr(S);
929 VisitType(S->getAllocatedType());
930 VisitDecl(S->getOperatorNew());
931 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000932 ID.AddBoolean(S->isArray());
933 ID.AddInteger(S->getNumPlacementArgs());
934 ID.AddBoolean(S->isGlobalNew());
935 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +0000936 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000937}
938
Chandler Carruth631abd92011-06-16 06:47:06 +0000939void
940StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +0000941 VisitExpr(S);
942 ID.AddBoolean(S->isArrow());
943 VisitNestedNameSpecifier(S->getQualifier());
Eli Friedman85641392013-08-09 23:37:05 +0000944 ID.AddBoolean(S->getScopeTypeInfo() != 0);
945 if (S->getScopeTypeInfo())
946 VisitType(S->getScopeTypeInfo()->getType());
947 ID.AddBoolean(S->getDestroyedTypeInfo() != 0);
948 if (S->getDestroyedTypeInfo())
949 VisitType(S->getDestroyedType());
950 else
951 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +0000952}
953
Chandler Carruth631abd92011-06-16 06:47:06 +0000954void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000955 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000956 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000957 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000958 ID.AddBoolean(S->hasExplicitTemplateArgs());
959 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000960 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
961 S->getExplicitTemplateArgs().NumTemplateArgs);
962}
963
964void
Chandler Carruth631abd92011-06-16 06:47:06 +0000965StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000966 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000967}
968
Douglas Gregor29c42f22012-02-24 07:38:34 +0000969void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
970 VisitExpr(S);
971 ID.AddInteger(S->getTrait());
972 ID.AddInteger(S->getNumArgs());
973 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
974 VisitType(S->getArg(I)->getType());
975}
976
Chandler Carruth631abd92011-06-16 06:47:06 +0000977void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +0000978 VisitExpr(S);
979 ID.AddInteger(S->getTrait());
980 VisitType(S->getQueriedType());
981}
982
Chandler Carruth631abd92011-06-16 06:47:06 +0000983void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +0000984 VisitExpr(S);
985 ID.AddInteger(S->getTrait());
986 VisitExpr(S->getQueriedExpression());
987}
988
Chandler Carruth631abd92011-06-16 06:47:06 +0000989void StmtProfiler::VisitDependentScopeDeclRefExpr(
990 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000991 VisitExpr(S);
992 VisitName(S->getDeclName());
993 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +0000994 ID.AddBoolean(S->hasExplicitTemplateArgs());
995 if (S->hasExplicitTemplateArgs())
996 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000997}
998
Chandler Carruth631abd92011-06-16 06:47:06 +0000999void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001000 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001001}
1002
Chandler Carruth631abd92011-06-16 06:47:06 +00001003void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1004 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001005 VisitExpr(S);
1006 VisitType(S->getTypeAsWritten());
1007}
1008
Chandler Carruth631abd92011-06-16 06:47:06 +00001009void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1010 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001011 ID.AddBoolean(S->isImplicitAccess());
1012 if (!S->isImplicitAccess()) {
1013 VisitExpr(S);
1014 ID.AddBoolean(S->isArrow());
1015 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001016 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001017 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001018 ID.AddBoolean(S->hasExplicitTemplateArgs());
1019 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001020 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1021}
1022
Chandler Carruth631abd92011-06-16 06:47:06 +00001023void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001024 ID.AddBoolean(S->isImplicitAccess());
1025 if (!S->isImplicitAccess()) {
1026 VisitExpr(S);
1027 ID.AddBoolean(S->isArrow());
1028 }
John McCall10eae182009-11-30 22:42:35 +00001029 VisitNestedNameSpecifier(S->getQualifier());
1030 VisitName(S->getMemberName());
1031 ID.AddBoolean(S->hasExplicitTemplateArgs());
1032 if (S->hasExplicitTemplateArgs())
1033 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001034}
1035
Chandler Carruth631abd92011-06-16 06:47:06 +00001036void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001037 VisitExpr(S);
1038}
1039
Chandler Carruth631abd92011-06-16 06:47:06 +00001040void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001041 VisitExpr(S);
1042}
1043
Chandler Carruth631abd92011-06-16 06:47:06 +00001044void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001045 VisitExpr(S);
1046 VisitDecl(S->getPack());
1047}
1048
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001049void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001050 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001051 VisitExpr(S);
1052 VisitDecl(S->getParameterPack());
1053 VisitTemplateArgument(S->getArgumentPack());
1054}
1055
John McCall7c454bb2011-07-15 05:09:51 +00001056void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1057 const SubstNonTypeTemplateParmExpr *E) {
1058 // Profile exactly as the replacement expression.
1059 Visit(E->getReplacement());
1060}
1061
Richard Smithb15fe3a2012-09-12 00:56:43 +00001062void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1063 VisitExpr(S);
1064 VisitDecl(S->getParameterPack());
1065 ID.AddInteger(S->getNumExpansions());
1066 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1067 VisitDecl(*I);
1068}
1069
Douglas Gregorfe314812011-06-21 17:03:29 +00001070void StmtProfiler::VisitMaterializeTemporaryExpr(
1071 const MaterializeTemporaryExpr *S) {
1072 VisitExpr(S);
1073}
1074
Chandler Carruth631abd92011-06-16 06:47:06 +00001075void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001076 VisitExpr(E);
1077}
1078
Chandler Carruth631abd92011-06-16 06:47:06 +00001079void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001080 VisitExpr(S);
1081}
1082
Patrick Beard0caa3942012-04-19 00:25:12 +00001083void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001084 VisitExpr(E);
1085}
1086
1087void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1088 VisitExpr(E);
1089}
1090
1091void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1092 VisitExpr(E);
1093}
1094
Chandler Carruth631abd92011-06-16 06:47:06 +00001095void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001096 VisitExpr(S);
1097 VisitType(S->getEncodedType());
1098}
1099
Chandler Carruth631abd92011-06-16 06:47:06 +00001100void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001101 VisitExpr(S);
1102 VisitName(S->getSelector());
1103}
1104
Chandler Carruth631abd92011-06-16 06:47:06 +00001105void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001106 VisitExpr(S);
1107 VisitDecl(S->getProtocol());
1108}
1109
Chandler Carruth631abd92011-06-16 06:47:06 +00001110void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001111 VisitExpr(S);
1112 VisitDecl(S->getDecl());
1113 ID.AddBoolean(S->isArrow());
1114 ID.AddBoolean(S->isFreeIvar());
1115}
1116
Chandler Carruth631abd92011-06-16 06:47:06 +00001117void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001118 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001119 if (S->isImplicitProperty()) {
1120 VisitDecl(S->getImplicitPropertyGetter());
1121 VisitDecl(S->getImplicitPropertySetter());
1122 } else {
1123 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001124 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001125 if (S->isSuperReceiver()) {
1126 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001127 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001128 }
Douglas Gregora7095092009-07-28 14:44:31 +00001129}
1130
Ted Kremeneke65b0862012-03-06 20:05:56 +00001131void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1132 VisitExpr(S);
1133 VisitDecl(S->getAtIndexMethodDecl());
1134 VisitDecl(S->setAtIndexMethodDecl());
1135}
1136
Chandler Carruth631abd92011-06-16 06:47:06 +00001137void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001138 VisitExpr(S);
1139 VisitName(S->getSelector());
1140 VisitDecl(S->getMethodDecl());
1141}
1142
Chandler Carruth631abd92011-06-16 06:47:06 +00001143void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001144 VisitExpr(S);
1145 ID.AddBoolean(S->isArrow());
1146}
1147
Ted Kremeneke65b0862012-03-06 20:05:56 +00001148void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1149 VisitExpr(S);
1150 ID.AddBoolean(S->getValue());
1151}
1152
Chandler Carruth631abd92011-06-16 06:47:06 +00001153void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1154 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001155 VisitExpr(S);
1156 ID.AddBoolean(S->shouldCopy());
1157}
1158
Chandler Carruth631abd92011-06-16 06:47:06 +00001159void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001160 VisitExplicitCastExpr(S);
1161 ID.AddBoolean(S->getBridgeKind());
1162}
1163
Chandler Carruth631abd92011-06-16 06:47:06 +00001164void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001165 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001166
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001167 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001168 if (const NonTypeTemplateParmDecl *NTTP =
1169 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001170 ID.AddInteger(NTTP->getDepth());
1171 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001172 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001173 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001174 return;
1175 }
Mike Stump11289f42009-09-09 15:08:12 +00001176
Chandler Carruth631abd92011-06-16 06:47:06 +00001177 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001178 // The Itanium C++ ABI uses the type, scope depth, and scope
1179 // index of a parameter when mangling expressions that involve
1180 // function parameters, so we will use the parameter's type for
1181 // establishing function parameter identity. That way, our
1182 // definition of "equivalent" (per C++ [temp.over.link]) is at
1183 // least as strong as the definition of "equivalent" used for
1184 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001185 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001186 ID.AddInteger(Parm->getFunctionScopeDepth());
1187 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001188 return;
1189 }
Mike Stump11289f42009-09-09 15:08:12 +00001190
Richard Smithd9a1cd82012-04-02 18:53:24 +00001191 if (const TemplateTypeParmDecl *TTP =
1192 dyn_cast<TemplateTypeParmDecl>(D)) {
1193 ID.AddInteger(TTP->getDepth());
1194 ID.AddInteger(TTP->getIndex());
1195 ID.AddBoolean(TTP->isParameterPack());
1196 return;
1197 }
1198
Chandler Carruth631abd92011-06-16 06:47:06 +00001199 if (const TemplateTemplateParmDecl *TTP =
1200 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001201 ID.AddInteger(TTP->getDepth());
1202 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001203 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001204 return;
1205 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001206 }
Mike Stump11289f42009-09-09 15:08:12 +00001207
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001208 ID.AddPointer(D? D->getCanonicalDecl() : 0);
1209}
1210
1211void StmtProfiler::VisitType(QualType T) {
1212 if (Canonical)
1213 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001214
Douglas Gregor5c193b92009-07-28 00:33:38 +00001215 ID.AddPointer(T.getAsOpaquePtr());
1216}
1217
1218void StmtProfiler::VisitName(DeclarationName Name) {
1219 ID.AddPointer(Name.getAsOpaquePtr());
1220}
1221
1222void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1223 if (Canonical)
1224 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1225 ID.AddPointer(NNS);
1226}
1227
1228void StmtProfiler::VisitTemplateName(TemplateName Name) {
1229 if (Canonical)
1230 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001231
Douglas Gregor5c193b92009-07-28 00:33:38 +00001232 Name.Profile(ID);
1233}
1234
John McCall0ad16662009-10-29 08:12:44 +00001235void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001236 unsigned NumArgs) {
1237 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001238 for (unsigned I = 0; I != NumArgs; ++I)
1239 VisitTemplateArgument(Args[I].getArgument());
1240}
Mike Stump11289f42009-09-09 15:08:12 +00001241
John McCall0ad16662009-10-29 08:12:44 +00001242void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1243 // Mostly repetitive with TemplateArgument::Profile!
1244 ID.AddInteger(Arg.getKind());
1245 switch (Arg.getKind()) {
1246 case TemplateArgument::Null:
1247 break;
Mike Stump11289f42009-09-09 15:08:12 +00001248
John McCall0ad16662009-10-29 08:12:44 +00001249 case TemplateArgument::Type:
1250 VisitType(Arg.getAsType());
1251 break;
Mike Stump11289f42009-09-09 15:08:12 +00001252
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001253 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001254 case TemplateArgument::TemplateExpansion:
1255 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001256 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001257
John McCall0ad16662009-10-29 08:12:44 +00001258 case TemplateArgument::Declaration:
1259 VisitDecl(Arg.getAsDecl());
1260 break;
Mike Stump11289f42009-09-09 15:08:12 +00001261
Eli Friedmanb826a002012-09-26 02:36:12 +00001262 case TemplateArgument::NullPtr:
1263 VisitType(Arg.getNullPtrType());
1264 break;
1265
John McCall0ad16662009-10-29 08:12:44 +00001266 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001267 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001268 VisitType(Arg.getIntegralType());
1269 break;
Mike Stump11289f42009-09-09 15:08:12 +00001270
John McCall0ad16662009-10-29 08:12:44 +00001271 case TemplateArgument::Expression:
1272 Visit(Arg.getAsExpr());
1273 break;
Mike Stump11289f42009-09-09 15:08:12 +00001274
John McCall0ad16662009-10-29 08:12:44 +00001275 case TemplateArgument::Pack:
1276 const TemplateArgument *Pack = Arg.pack_begin();
1277 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1278 VisitTemplateArgument(Pack[i]);
1279 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001280 }
1281}
1282
Jay Foad39c79802011-01-12 09:06:06 +00001283void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001284 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001285 StmtProfiler Profiler(ID, Context, Canonical);
1286 Profiler.Visit(this);
1287}