blob: 5dbaa0e83274d397b184d4f9441cf094e322d2f9 [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);
Aaron Ballman535bbcc2014-03-14 17:01:24 +000082 for (const auto *D : S->decls())
83 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +000084}
85
Chandler Carruth631abd92011-06-16 06:47:06 +000086void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000087 VisitStmt(S);
88}
89
Chandler Carruth631abd92011-06-16 06:47:06 +000090void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000091 VisitStmt(S);
92}
93
Chandler Carruth631abd92011-06-16 06:47:06 +000094void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000095 VisitStmt(S);
96}
97
Chandler Carruth631abd92011-06-16 06:47:06 +000098void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000099 VisitStmt(S);
100}
101
Chandler Carruth631abd92011-06-16 06:47:06 +0000102void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000103 VisitStmt(S);
104}
105
Chandler Carruth631abd92011-06-16 06:47:06 +0000106void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000107 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000108 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000109}
110
Richard Smithc202b282012-04-14 00:33:13 +0000111void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
112 VisitStmt(S);
113 // TODO: maybe visit attributes?
114}
115
Chandler Carruth631abd92011-06-16 06:47:06 +0000116void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000117 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000118 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000119}
120
Chandler Carruth631abd92011-06-16 06:47:06 +0000121void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000122 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000123 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000124}
125
Chandler Carruth631abd92011-06-16 06:47:06 +0000126void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000127 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000128 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000129}
130
Chandler Carruth631abd92011-06-16 06:47:06 +0000131void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000132 VisitStmt(S);
133}
134
Chandler Carruth631abd92011-06-16 06:47:06 +0000135void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000136 VisitStmt(S);
137}
138
Chandler Carruth631abd92011-06-16 06:47:06 +0000139void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000140 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000141 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000142}
143
Chandler Carruth631abd92011-06-16 06:47:06 +0000144void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000145 VisitStmt(S);
146}
147
Chandler Carruth631abd92011-06-16 06:47:06 +0000148void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000149 VisitStmt(S);
150}
151
Chandler Carruth631abd92011-06-16 06:47:06 +0000152void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000153 VisitStmt(S);
154}
155
Chandler Carruth631abd92011-06-16 06:47:06 +0000156void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000157 VisitStmt(S);
158}
159
Chad Rosierde70e0e2012-08-25 00:11:56 +0000160void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000161 VisitStmt(S);
162 ID.AddBoolean(S->isVolatile());
163 ID.AddBoolean(S->isSimple());
164 VisitStringLiteral(S->getAsmString());
165 ID.AddInteger(S->getNumOutputs());
166 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
167 ID.AddString(S->getOutputName(I));
168 VisitStringLiteral(S->getOutputConstraintLiteral(I));
169 }
170 ID.AddInteger(S->getNumInputs());
171 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
172 ID.AddString(S->getInputName(I));
173 VisitStringLiteral(S->getInputConstraintLiteral(I));
174 }
175 ID.AddInteger(S->getNumClobbers());
176 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000177 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor44882592009-07-28 15:27:13 +0000178}
179
Chad Rosier32503022012-06-11 20:47:18 +0000180void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
181 // FIXME: Implement MS style inline asm statement profiler.
182 VisitStmt(S);
183}
184
Chandler Carruth631abd92011-06-16 06:47:06 +0000185void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000186 VisitStmt(S);
187 VisitType(S->getCaughtType());
188}
189
Chandler Carruth631abd92011-06-16 06:47:06 +0000190void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000191 VisitStmt(S);
192}
193
Chandler Carruth631abd92011-06-16 06:47:06 +0000194void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000195 VisitStmt(S);
196}
197
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000198void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
199 VisitStmt(S);
200 ID.AddBoolean(S->isIfExists());
201 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
202 VisitName(S->getNameInfo().getName());
203}
204
Chandler Carruth631abd92011-06-16 06:47:06 +0000205void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000206 VisitStmt(S);
207}
208
Chandler Carruth631abd92011-06-16 06:47:06 +0000209void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000210 VisitStmt(S);
211}
212
Chandler Carruth631abd92011-06-16 06:47:06 +0000213void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000214 VisitStmt(S);
215}
216
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000217void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
218 VisitStmt(S);
219}
220
Chandler Carruth631abd92011-06-16 06:47:06 +0000221void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000222 VisitStmt(S);
223}
224
Chandler Carruth631abd92011-06-16 06:47:06 +0000225void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000226 VisitStmt(S);
227 ID.AddBoolean(S->hasEllipsis());
228 if (S->getCatchParamDecl())
229 VisitType(S->getCatchParamDecl()->getType());
230}
231
Chandler Carruth631abd92011-06-16 06:47:06 +0000232void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000233 VisitStmt(S);
234}
235
Chandler Carruth631abd92011-06-16 06:47:06 +0000236void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000237 VisitStmt(S);
238}
239
Chandler Carruth631abd92011-06-16 06:47:06 +0000240void
241StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000242 VisitStmt(S);
243}
244
Chandler Carruth631abd92011-06-16 06:47:06 +0000245void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000246 VisitStmt(S);
247}
248
Chandler Carruth631abd92011-06-16 06:47:06 +0000249void
250StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000251 VisitStmt(S);
252}
253
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000254namespace {
255class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
256 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000257 /// \brief Process clauses with list of variables.
258 template <typename T>
259 void VisitOMPClauseList(T *Node);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000260public:
261 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
262#define OPENMP_CLAUSE(Name, Class) \
263 void Visit##Class(const Class *C);
264#include "clang/Basic/OpenMPKinds.def"
265};
266
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000267void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
268 if (C->getCondition())
269 Profiler->VisitStmt(C->getCondition());
270}
271
Alexey Bataev568a8332014-03-06 06:15:19 +0000272void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
273 if (C->getNumThreads())
274 Profiler->VisitStmt(C->getNumThreads());
275}
276
Alexey Bataev62c87d22014-03-21 04:51:18 +0000277void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
278 if (C->getSafelen())
279 Profiler->VisitStmt(C->getSafelen());
280}
281
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000282void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000283
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000284void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
285
Alexey Bataev756c1962013-09-24 03:17:45 +0000286template<typename T>
287void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Aaron Ballman2205d2a2014-03-14 15:55:35 +0000288 for (auto *I : Node->varlists())
289 Profiler->VisitStmt(I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000290}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000291
292void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000293 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000294}
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000295void OMPClauseProfiler::VisitOMPFirstprivateClause(
296 const OMPFirstprivateClause *C) {
297 VisitOMPClauseList(C);
298}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000299void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000300 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000301}
Alexander Musman8dba6642014-04-22 13:09:42 +0000302void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
303 VisitOMPClauseList(C);
304 Profiler->VisitStmt(C->getStep());
305}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000306void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
307 VisitOMPClauseList(C);
308}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000309}
310
311void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000312StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000313 VisitStmt(S);
314 OMPClauseProfiler P(this);
315 ArrayRef<OMPClause *> Clauses = S->clauses();
316 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
317 I != E; ++I)
318 if (*I)
319 P.Visit(*I);
320}
321
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000322void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
323 VisitOMPExecutableDirective(S);
324}
325
326void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
327 VisitOMPExecutableDirective(S);
328}
329
Chandler Carruth631abd92011-06-16 06:47:06 +0000330void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000331 VisitStmt(S);
332}
333
Chandler Carruth631abd92011-06-16 06:47:06 +0000334void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000335 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000336 if (!Canonical)
337 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000338 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000339 if (!Canonical)
340 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000341}
342
Chandler Carruth631abd92011-06-16 06:47:06 +0000343void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000344 VisitExpr(S);
345 ID.AddInteger(S->getIdentType());
346}
347
Chandler Carruth631abd92011-06-16 06:47:06 +0000348void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000349 VisitExpr(S);
350 S->getValue().Profile(ID);
351}
352
Chandler Carruth631abd92011-06-16 06:47:06 +0000353void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000354 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000355 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000356 ID.AddInteger(S->getValue());
357}
358
Chandler Carruth631abd92011-06-16 06:47:06 +0000359void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000360 VisitExpr(S);
361 S->getValue().Profile(ID);
362 ID.AddBoolean(S->isExact());
363}
364
Chandler Carruth631abd92011-06-16 06:47:06 +0000365void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000366 VisitExpr(S);
367}
368
Chandler Carruth631abd92011-06-16 06:47:06 +0000369void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000370 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000371 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000372 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000373}
374
Chandler Carruth631abd92011-06-16 06:47:06 +0000375void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000376 VisitExpr(S);
377}
378
Chandler Carruth631abd92011-06-16 06:47:06 +0000379void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000380 VisitExpr(S);
381}
382
Chandler Carruth631abd92011-06-16 06:47:06 +0000383void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000384 VisitExpr(S);
385 ID.AddInteger(S->getOpcode());
386}
387
Chandler Carruth631abd92011-06-16 06:47:06 +0000388void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000389 VisitType(S->getTypeSourceInfo()->getType());
390 unsigned n = S->getNumComponents();
391 for (unsigned i = 0; i < n; ++i) {
392 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
393 ID.AddInteger(ON.getKind());
394 switch (ON.getKind()) {
395 case OffsetOfExpr::OffsetOfNode::Array:
396 // Expressions handled below.
397 break;
398
399 case OffsetOfExpr::OffsetOfNode::Field:
400 VisitDecl(ON.getField());
401 break;
402
403 case OffsetOfExpr::OffsetOfNode::Identifier:
404 ID.AddPointer(ON.getFieldName());
405 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000406
Douglas Gregord1702062010-04-29 00:18:15 +0000407 case OffsetOfExpr::OffsetOfNode::Base:
408 // These nodes are implicit, and therefore don't need profiling.
409 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000410 }
411 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000412
Douglas Gregor882211c2010-04-28 22:16:22 +0000413 VisitExpr(S);
414}
415
Chandler Carruth631abd92011-06-16 06:47:06 +0000416void
417StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000418 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000419 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000420 if (S->isArgumentType())
421 VisitType(S->getArgumentType());
422}
423
Chandler Carruth631abd92011-06-16 06:47:06 +0000424void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000425 VisitExpr(S);
426}
427
Chandler Carruth631abd92011-06-16 06:47:06 +0000428void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000429 VisitExpr(S);
430}
431
Chandler Carruth631abd92011-06-16 06:47:06 +0000432void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000433 VisitExpr(S);
434 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000435 if (!Canonical)
436 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000437 ID.AddBoolean(S->isArrow());
438}
439
Chandler Carruth631abd92011-06-16 06:47:06 +0000440void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000441 VisitExpr(S);
442 ID.AddBoolean(S->isFileScope());
443}
444
Chandler Carruth631abd92011-06-16 06:47:06 +0000445void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000446 VisitExpr(S);
447}
448
Chandler Carruth631abd92011-06-16 06:47:06 +0000449void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000450 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000451 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000452}
453
Chandler Carruth631abd92011-06-16 06:47:06 +0000454void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000455 VisitCastExpr(S);
456 VisitType(S->getTypeAsWritten());
457}
458
Chandler Carruth631abd92011-06-16 06:47:06 +0000459void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000460 VisitExplicitCastExpr(S);
461}
462
Chandler Carruth631abd92011-06-16 06:47:06 +0000463void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000464 VisitExpr(S);
465 ID.AddInteger(S->getOpcode());
466}
467
Chandler Carruth631abd92011-06-16 06:47:06 +0000468void
469StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000470 VisitBinaryOperator(S);
471}
472
Chandler Carruth631abd92011-06-16 06:47:06 +0000473void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000474 VisitExpr(S);
475}
476
Chandler Carruth631abd92011-06-16 06:47:06 +0000477void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000478 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000479 VisitExpr(S);
480}
481
Chandler Carruth631abd92011-06-16 06:47:06 +0000482void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000483 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000484 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000485}
486
Chandler Carruth631abd92011-06-16 06:47:06 +0000487void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000488 VisitExpr(S);
489}
490
Chandler Carruth631abd92011-06-16 06:47:06 +0000491void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000492 VisitExpr(S);
493}
494
Hal Finkelc4d7c822013-09-18 03:29:45 +0000495void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
496 VisitExpr(S);
497}
498
Chandler Carruth631abd92011-06-16 06:47:06 +0000499void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000500 VisitExpr(S);
501}
502
Chandler Carruth631abd92011-06-16 06:47:06 +0000503void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000504 VisitExpr(S);
505}
506
Chandler Carruth631abd92011-06-16 06:47:06 +0000507void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000508 VisitExpr(S);
509}
510
Chandler Carruth631abd92011-06-16 06:47:06 +0000511void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000512 if (S->getSyntacticForm()) {
513 VisitInitListExpr(S->getSyntacticForm());
514 return;
515 }
Mike Stump11289f42009-09-09 15:08:12 +0000516
Douglas Gregor5c193b92009-07-28 00:33:38 +0000517 VisitExpr(S);
518}
519
Chandler Carruth631abd92011-06-16 06:47:06 +0000520void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000521 VisitExpr(S);
522 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000523 for (DesignatedInitExpr::const_designators_iterator D =
524 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000525 D != DEnd; ++D) {
526 if (D->isFieldDesignator()) {
527 ID.AddInteger(0);
528 VisitName(D->getFieldName());
529 continue;
530 }
Mike Stump11289f42009-09-09 15:08:12 +0000531
Douglas Gregor5c193b92009-07-28 00:33:38 +0000532 if (D->isArrayDesignator()) {
533 ID.AddInteger(1);
534 } else {
535 assert(D->isArrayRangeDesignator());
536 ID.AddInteger(2);
537 }
538 ID.AddInteger(D->getFirstExprIndex());
539 }
540}
541
Chandler Carruth631abd92011-06-16 06:47:06 +0000542void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000543 VisitExpr(S);
544}
545
Chandler Carruth631abd92011-06-16 06:47:06 +0000546void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000547 VisitExpr(S);
548 VisitName(&S->getAccessor());
549}
550
Chandler Carruth631abd92011-06-16 06:47:06 +0000551void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000552 VisitExpr(S);
553 VisitDecl(S->getBlockDecl());
554}
555
Chandler Carruth631abd92011-06-16 06:47:06 +0000556void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000557 VisitExpr(S);
558 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
559 QualType T = S->getAssocType(i);
560 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000561 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000562 else
563 VisitType(T);
564 VisitExpr(S->getAssocExpr(i));
565 }
566}
567
John McCallfe96e0b2011-11-06 09:01:30 +0000568void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
569 VisitExpr(S);
570 for (PseudoObjectExpr::const_semantics_iterator
571 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
572 // Normally, we would not profile the source expressions of OVEs.
573 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
574 Visit(OVE->getSourceExpr());
575}
576
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000577void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
578 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000579 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000580}
581
Chandler Carruth631abd92011-06-16 06:47:06 +0000582static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000583 UnaryOperatorKind &UnaryOp,
584 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000585 switch (S->getOperator()) {
586 case OO_None:
587 case OO_New:
588 case OO_Delete:
589 case OO_Array_New:
590 case OO_Array_Delete:
591 case OO_Arrow:
592 case OO_Call:
593 case OO_Conditional:
594 case NUM_OVERLOADED_OPERATORS:
595 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000596
597 case OO_Plus:
598 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000599 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000600 return Stmt::UnaryOperatorClass;
601 }
602
John McCalle3027922010-08-25 11:45:40 +0000603 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000604 return Stmt::BinaryOperatorClass;
605
606 case OO_Minus:
607 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000608 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000609 return Stmt::UnaryOperatorClass;
610 }
611
John McCalle3027922010-08-25 11:45:40 +0000612 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000613 return Stmt::BinaryOperatorClass;
614
615 case OO_Star:
616 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000617 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000618 return Stmt::UnaryOperatorClass;
619 }
620
John McCalle3027922010-08-25 11:45:40 +0000621 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000622 return Stmt::BinaryOperatorClass;
623
624 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000625 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000626 return Stmt::BinaryOperatorClass;
627
628 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000629 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000630 return Stmt::BinaryOperatorClass;
631
632 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000633 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000634 return Stmt::BinaryOperatorClass;
635
636 case OO_Amp:
637 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000638 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000639 return Stmt::UnaryOperatorClass;
640 }
641
John McCalle3027922010-08-25 11:45:40 +0000642 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000643 return Stmt::BinaryOperatorClass;
644
645 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000646 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000647 return Stmt::BinaryOperatorClass;
648
649 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000650 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000651 return Stmt::UnaryOperatorClass;
652
653 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000654 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000655 return Stmt::UnaryOperatorClass;
656
657 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000658 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000659 return Stmt::BinaryOperatorClass;
660
661 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000662 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000663 return Stmt::BinaryOperatorClass;
664
665 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000666 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000667 return Stmt::BinaryOperatorClass;
668
669 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000670 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000671 return Stmt::CompoundAssignOperatorClass;
672
673 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000674 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000675 return Stmt::CompoundAssignOperatorClass;
676
677 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000678 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000679 return Stmt::CompoundAssignOperatorClass;
680
681 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000682 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000683 return Stmt::CompoundAssignOperatorClass;
684
685 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000686 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000687 return Stmt::CompoundAssignOperatorClass;
688
689 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000690 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000691 return Stmt::CompoundAssignOperatorClass;
692
693 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000694 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000695 return Stmt::CompoundAssignOperatorClass;
696
697 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000698 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000699 return Stmt::CompoundAssignOperatorClass;
700
701 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000702 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000703 return Stmt::BinaryOperatorClass;
704
705 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000706 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000707 return Stmt::BinaryOperatorClass;
708
709 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000710 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000711 return Stmt::CompoundAssignOperatorClass;
712
713 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000714 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000715 return Stmt::CompoundAssignOperatorClass;
716
717 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000718 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000719 return Stmt::BinaryOperatorClass;
720
721 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000722 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000723 return Stmt::BinaryOperatorClass;
724
725 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000726 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000727 return Stmt::BinaryOperatorClass;
728
729 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000730 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000731 return Stmt::BinaryOperatorClass;
732
733 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000734 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000735 return Stmt::BinaryOperatorClass;
736
737 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000738 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000739 return Stmt::BinaryOperatorClass;
740
741 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000742 UnaryOp = S->getNumArgs() == 1? UO_PreInc
743 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000744 return Stmt::UnaryOperatorClass;
745
746 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000747 UnaryOp = S->getNumArgs() == 1? UO_PreDec
748 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000749 return Stmt::UnaryOperatorClass;
750
751 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000752 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000753 return Stmt::BinaryOperatorClass;
754
755
756 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000757 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000758 return Stmt::BinaryOperatorClass;
759
760 case OO_Subscript:
761 return Stmt::ArraySubscriptExprClass;
762 }
763
764 llvm_unreachable("Invalid overloaded operator expression");
765}
766
767
Chandler Carruth631abd92011-06-16 06:47:06 +0000768void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000769 if (S->isTypeDependent()) {
770 // Type-dependent operator calls are profiled like their underlying
771 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000772 UnaryOperatorKind UnaryOp = UO_Extension;
773 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000774 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
775
776 ID.AddInteger(SC);
777 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
778 Visit(S->getArg(I));
779 if (SC == Stmt::UnaryOperatorClass)
780 ID.AddInteger(UnaryOp);
781 else if (SC == Stmt::BinaryOperatorClass ||
782 SC == Stmt::CompoundAssignOperatorClass)
783 ID.AddInteger(BinaryOp);
784 else
785 assert(SC == Stmt::ArraySubscriptExprClass);
786
787 return;
788 }
789
Douglas Gregor5c193b92009-07-28 00:33:38 +0000790 VisitCallExpr(S);
791 ID.AddInteger(S->getOperator());
792}
793
Chandler Carruth631abd92011-06-16 06:47:06 +0000794void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000795 VisitCallExpr(S);
796}
797
Chandler Carruth631abd92011-06-16 06:47:06 +0000798void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000799 VisitCallExpr(S);
800}
801
Chandler Carruth631abd92011-06-16 06:47:06 +0000802void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000803 VisitExpr(S);
804}
805
Chandler Carruth631abd92011-06-16 06:47:06 +0000806void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000807 VisitExplicitCastExpr(S);
808}
809
Chandler Carruth631abd92011-06-16 06:47:06 +0000810void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000811 VisitCXXNamedCastExpr(S);
812}
813
Chandler Carruth631abd92011-06-16 06:47:06 +0000814void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000815 VisitCXXNamedCastExpr(S);
816}
817
Chandler Carruth631abd92011-06-16 06:47:06 +0000818void
819StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000820 VisitCXXNamedCastExpr(S);
821}
822
Chandler Carruth631abd92011-06-16 06:47:06 +0000823void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000824 VisitCXXNamedCastExpr(S);
825}
826
Richard Smithc67fdd42012-03-07 08:35:16 +0000827void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
828 VisitCallExpr(S);
829}
830
Chandler Carruth631abd92011-06-16 06:47:06 +0000831void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000832 VisitExpr(S);
833 ID.AddBoolean(S->getValue());
834}
835
Chandler Carruth631abd92011-06-16 06:47:06 +0000836void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000837 VisitExpr(S);
838}
839
Richard Smithcc1b96d2013-06-12 22:31:48 +0000840void StmtProfiler::VisitCXXStdInitializerListExpr(
841 const CXXStdInitializerListExpr *S) {
842 VisitExpr(S);
843}
844
Chandler Carruth631abd92011-06-16 06:47:06 +0000845void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000846 VisitExpr(S);
847 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000848 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000849}
850
Chandler Carruth631abd92011-06-16 06:47:06 +0000851void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000852 VisitExpr(S);
853 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000854 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000855}
856
John McCall5e77d762013-04-16 07:28:30 +0000857void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
858 VisitExpr(S);
859 VisitDecl(S->getPropertyDecl());
860}
861
Chandler Carruth631abd92011-06-16 06:47:06 +0000862void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000863 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000864 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000865}
866
Chandler Carruth631abd92011-06-16 06:47:06 +0000867void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000868 VisitExpr(S);
869}
870
Chandler Carruth631abd92011-06-16 06:47:06 +0000871void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000872 VisitExpr(S);
873 VisitDecl(S->getParam());
874}
875
Richard Smith852c9db2013-04-20 22:23:05 +0000876void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
877 VisitExpr(S);
878 VisitDecl(S->getField());
879}
880
Chandler Carruth631abd92011-06-16 06:47:06 +0000881void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000882 VisitExpr(S);
883 VisitDecl(
884 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
885}
886
Chandler Carruth631abd92011-06-16 06:47:06 +0000887void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000888 VisitExpr(S);
889 VisitDecl(S->getConstructor());
890 ID.AddBoolean(S->isElidable());
891}
892
Chandler Carruth631abd92011-06-16 06:47:06 +0000893void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000894 VisitExplicitCastExpr(S);
895}
896
Chandler Carruth631abd92011-06-16 06:47:06 +0000897void
898StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000899 VisitCXXConstructExpr(S);
900}
901
Chandler Carruth631abd92011-06-16 06:47:06 +0000902void
Douglas Gregore31e6062012-02-07 10:09:13 +0000903StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
904 VisitExpr(S);
905 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
906 CEnd = S->explicit_capture_end();
907 C != CEnd; ++C) {
908 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +0000909 switch (C->getCaptureKind()) {
910 case LCK_This:
911 break;
912 case LCK_ByRef:
913 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +0000914 VisitDecl(C->getCapturedVar());
915 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +0000916 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000917 }
918 }
919 // Note: If we actually needed to be able to match lambda
920 // expressions, we would have to consider parameters and return type
921 // here, among other things.
922 VisitStmt(S->getBody());
923}
924
925void
Chandler Carruth631abd92011-06-16 06:47:06 +0000926StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000927 VisitExpr(S);
928}
929
Chandler Carruth631abd92011-06-16 06:47:06 +0000930void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000931 VisitExpr(S);
932 ID.AddBoolean(S->isGlobalDelete());
933 ID.AddBoolean(S->isArrayForm());
934 VisitDecl(S->getOperatorDelete());
935}
936
937
Chandler Carruth631abd92011-06-16 06:47:06 +0000938void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000939 VisitExpr(S);
940 VisitType(S->getAllocatedType());
941 VisitDecl(S->getOperatorNew());
942 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000943 ID.AddBoolean(S->isArray());
944 ID.AddInteger(S->getNumPlacementArgs());
945 ID.AddBoolean(S->isGlobalNew());
946 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +0000947 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000948}
949
Chandler Carruth631abd92011-06-16 06:47:06 +0000950void
951StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +0000952 VisitExpr(S);
953 ID.AddBoolean(S->isArrow());
954 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +0000955 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +0000956 if (S->getScopeTypeInfo())
957 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +0000958 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +0000959 if (S->getDestroyedTypeInfo())
960 VisitType(S->getDestroyedType());
961 else
962 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +0000963}
964
Chandler Carruth631abd92011-06-16 06:47:06 +0000965void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000966 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000967 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000968 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +0000969 ID.AddBoolean(S->hasExplicitTemplateArgs());
970 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000971 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
972 S->getExplicitTemplateArgs().NumTemplateArgs);
973}
974
975void
Chandler Carruth631abd92011-06-16 06:47:06 +0000976StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +0000977 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +0000978}
979
Douglas Gregor29c42f22012-02-24 07:38:34 +0000980void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
981 VisitExpr(S);
982 ID.AddInteger(S->getTrait());
983 ID.AddInteger(S->getNumArgs());
984 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
985 VisitType(S->getArg(I)->getType());
986}
987
Chandler Carruth631abd92011-06-16 06:47:06 +0000988void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +0000989 VisitExpr(S);
990 ID.AddInteger(S->getTrait());
991 VisitType(S->getQueriedType());
992}
993
Chandler Carruth631abd92011-06-16 06:47:06 +0000994void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +0000995 VisitExpr(S);
996 ID.AddInteger(S->getTrait());
997 VisitExpr(S->getQueriedExpression());
998}
999
Chandler Carruth631abd92011-06-16 06:47:06 +00001000void StmtProfiler::VisitDependentScopeDeclRefExpr(
1001 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001002 VisitExpr(S);
1003 VisitName(S->getDeclName());
1004 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001005 ID.AddBoolean(S->hasExplicitTemplateArgs());
1006 if (S->hasExplicitTemplateArgs())
1007 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001008}
1009
Chandler Carruth631abd92011-06-16 06:47:06 +00001010void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001011 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001012}
1013
Chandler Carruth631abd92011-06-16 06:47:06 +00001014void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1015 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001016 VisitExpr(S);
1017 VisitType(S->getTypeAsWritten());
1018}
1019
Chandler Carruth631abd92011-06-16 06:47:06 +00001020void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1021 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001022 ID.AddBoolean(S->isImplicitAccess());
1023 if (!S->isImplicitAccess()) {
1024 VisitExpr(S);
1025 ID.AddBoolean(S->isArrow());
1026 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001027 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001028 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001029 ID.AddBoolean(S->hasExplicitTemplateArgs());
1030 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001031 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1032}
1033
Chandler Carruth631abd92011-06-16 06:47:06 +00001034void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001035 ID.AddBoolean(S->isImplicitAccess());
1036 if (!S->isImplicitAccess()) {
1037 VisitExpr(S);
1038 ID.AddBoolean(S->isArrow());
1039 }
John McCall10eae182009-11-30 22:42:35 +00001040 VisitNestedNameSpecifier(S->getQualifier());
1041 VisitName(S->getMemberName());
1042 ID.AddBoolean(S->hasExplicitTemplateArgs());
1043 if (S->hasExplicitTemplateArgs())
1044 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001045}
1046
Chandler Carruth631abd92011-06-16 06:47:06 +00001047void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001048 VisitExpr(S);
1049}
1050
Chandler Carruth631abd92011-06-16 06:47:06 +00001051void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001052 VisitExpr(S);
1053}
1054
Chandler Carruth631abd92011-06-16 06:47:06 +00001055void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001056 VisitExpr(S);
1057 VisitDecl(S->getPack());
1058}
1059
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001060void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001061 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001062 VisitExpr(S);
1063 VisitDecl(S->getParameterPack());
1064 VisitTemplateArgument(S->getArgumentPack());
1065}
1066
John McCall7c454bb2011-07-15 05:09:51 +00001067void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1068 const SubstNonTypeTemplateParmExpr *E) {
1069 // Profile exactly as the replacement expression.
1070 Visit(E->getReplacement());
1071}
1072
Richard Smithb15fe3a2012-09-12 00:56:43 +00001073void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1074 VisitExpr(S);
1075 VisitDecl(S->getParameterPack());
1076 ID.AddInteger(S->getNumExpansions());
1077 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1078 VisitDecl(*I);
1079}
1080
Douglas Gregorfe314812011-06-21 17:03:29 +00001081void StmtProfiler::VisitMaterializeTemporaryExpr(
1082 const MaterializeTemporaryExpr *S) {
1083 VisitExpr(S);
1084}
1085
Chandler Carruth631abd92011-06-16 06:47:06 +00001086void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001087 VisitExpr(E);
1088}
1089
Chandler Carruth631abd92011-06-16 06:47:06 +00001090void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001091 VisitExpr(S);
1092}
1093
Patrick Beard0caa3942012-04-19 00:25:12 +00001094void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001095 VisitExpr(E);
1096}
1097
1098void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1099 VisitExpr(E);
1100}
1101
1102void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1103 VisitExpr(E);
1104}
1105
Chandler Carruth631abd92011-06-16 06:47:06 +00001106void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001107 VisitExpr(S);
1108 VisitType(S->getEncodedType());
1109}
1110
Chandler Carruth631abd92011-06-16 06:47:06 +00001111void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001112 VisitExpr(S);
1113 VisitName(S->getSelector());
1114}
1115
Chandler Carruth631abd92011-06-16 06:47:06 +00001116void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001117 VisitExpr(S);
1118 VisitDecl(S->getProtocol());
1119}
1120
Chandler Carruth631abd92011-06-16 06:47:06 +00001121void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001122 VisitExpr(S);
1123 VisitDecl(S->getDecl());
1124 ID.AddBoolean(S->isArrow());
1125 ID.AddBoolean(S->isFreeIvar());
1126}
1127
Chandler Carruth631abd92011-06-16 06:47:06 +00001128void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001129 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001130 if (S->isImplicitProperty()) {
1131 VisitDecl(S->getImplicitPropertyGetter());
1132 VisitDecl(S->getImplicitPropertySetter());
1133 } else {
1134 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001135 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001136 if (S->isSuperReceiver()) {
1137 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001138 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001139 }
Douglas Gregora7095092009-07-28 14:44:31 +00001140}
1141
Ted Kremeneke65b0862012-03-06 20:05:56 +00001142void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1143 VisitExpr(S);
1144 VisitDecl(S->getAtIndexMethodDecl());
1145 VisitDecl(S->setAtIndexMethodDecl());
1146}
1147
Chandler Carruth631abd92011-06-16 06:47:06 +00001148void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001149 VisitExpr(S);
1150 VisitName(S->getSelector());
1151 VisitDecl(S->getMethodDecl());
1152}
1153
Chandler Carruth631abd92011-06-16 06:47:06 +00001154void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001155 VisitExpr(S);
1156 ID.AddBoolean(S->isArrow());
1157}
1158
Ted Kremeneke65b0862012-03-06 20:05:56 +00001159void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1160 VisitExpr(S);
1161 ID.AddBoolean(S->getValue());
1162}
1163
Chandler Carruth631abd92011-06-16 06:47:06 +00001164void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1165 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001166 VisitExpr(S);
1167 ID.AddBoolean(S->shouldCopy());
1168}
1169
Chandler Carruth631abd92011-06-16 06:47:06 +00001170void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001171 VisitExplicitCastExpr(S);
1172 ID.AddBoolean(S->getBridgeKind());
1173}
1174
Chandler Carruth631abd92011-06-16 06:47:06 +00001175void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001176 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001177
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001178 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001179 if (const NonTypeTemplateParmDecl *NTTP =
1180 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001181 ID.AddInteger(NTTP->getDepth());
1182 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001183 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001184 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001185 return;
1186 }
Mike Stump11289f42009-09-09 15:08:12 +00001187
Chandler Carruth631abd92011-06-16 06:47:06 +00001188 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001189 // The Itanium C++ ABI uses the type, scope depth, and scope
1190 // index of a parameter when mangling expressions that involve
1191 // function parameters, so we will use the parameter's type for
1192 // establishing function parameter identity. That way, our
1193 // definition of "equivalent" (per C++ [temp.over.link]) is at
1194 // least as strong as the definition of "equivalent" used for
1195 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001196 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001197 ID.AddInteger(Parm->getFunctionScopeDepth());
1198 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001199 return;
1200 }
Mike Stump11289f42009-09-09 15:08:12 +00001201
Richard Smithd9a1cd82012-04-02 18:53:24 +00001202 if (const TemplateTypeParmDecl *TTP =
1203 dyn_cast<TemplateTypeParmDecl>(D)) {
1204 ID.AddInteger(TTP->getDepth());
1205 ID.AddInteger(TTP->getIndex());
1206 ID.AddBoolean(TTP->isParameterPack());
1207 return;
1208 }
1209
Chandler Carruth631abd92011-06-16 06:47:06 +00001210 if (const TemplateTemplateParmDecl *TTP =
1211 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001212 ID.AddInteger(TTP->getDepth());
1213 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001214 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001215 return;
1216 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001217 }
Mike Stump11289f42009-09-09 15:08:12 +00001218
Craig Topper36250ad2014-05-12 05:36:57 +00001219 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001220}
1221
1222void StmtProfiler::VisitType(QualType T) {
1223 if (Canonical)
1224 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001225
Douglas Gregor5c193b92009-07-28 00:33:38 +00001226 ID.AddPointer(T.getAsOpaquePtr());
1227}
1228
1229void StmtProfiler::VisitName(DeclarationName Name) {
1230 ID.AddPointer(Name.getAsOpaquePtr());
1231}
1232
1233void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1234 if (Canonical)
1235 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1236 ID.AddPointer(NNS);
1237}
1238
1239void StmtProfiler::VisitTemplateName(TemplateName Name) {
1240 if (Canonical)
1241 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregor5c193b92009-07-28 00:33:38 +00001243 Name.Profile(ID);
1244}
1245
John McCall0ad16662009-10-29 08:12:44 +00001246void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001247 unsigned NumArgs) {
1248 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001249 for (unsigned I = 0; I != NumArgs; ++I)
1250 VisitTemplateArgument(Args[I].getArgument());
1251}
Mike Stump11289f42009-09-09 15:08:12 +00001252
John McCall0ad16662009-10-29 08:12:44 +00001253void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1254 // Mostly repetitive with TemplateArgument::Profile!
1255 ID.AddInteger(Arg.getKind());
1256 switch (Arg.getKind()) {
1257 case TemplateArgument::Null:
1258 break;
Mike Stump11289f42009-09-09 15:08:12 +00001259
John McCall0ad16662009-10-29 08:12:44 +00001260 case TemplateArgument::Type:
1261 VisitType(Arg.getAsType());
1262 break;
Mike Stump11289f42009-09-09 15:08:12 +00001263
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001264 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001265 case TemplateArgument::TemplateExpansion:
1266 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001267 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001268
John McCall0ad16662009-10-29 08:12:44 +00001269 case TemplateArgument::Declaration:
1270 VisitDecl(Arg.getAsDecl());
1271 break;
Mike Stump11289f42009-09-09 15:08:12 +00001272
Eli Friedmanb826a002012-09-26 02:36:12 +00001273 case TemplateArgument::NullPtr:
1274 VisitType(Arg.getNullPtrType());
1275 break;
1276
John McCall0ad16662009-10-29 08:12:44 +00001277 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001278 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001279 VisitType(Arg.getIntegralType());
1280 break;
Mike Stump11289f42009-09-09 15:08:12 +00001281
John McCall0ad16662009-10-29 08:12:44 +00001282 case TemplateArgument::Expression:
1283 Visit(Arg.getAsExpr());
1284 break;
Mike Stump11289f42009-09-09 15:08:12 +00001285
John McCall0ad16662009-10-29 08:12:44 +00001286 case TemplateArgument::Pack:
1287 const TemplateArgument *Pack = Arg.pack_begin();
1288 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1289 VisitTemplateArgument(Pack[i]);
1290 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001291 }
1292}
1293
Jay Foad39c79802011-01-12 09:06:06 +00001294void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001295 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001296 StmtProfiler Profiler(ID, Context, Canonical);
1297 Profiler.Visit(this);
1298}