blob: 534d6bb772988e7af32709c661e44ba3e0afe105 [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
Alexander Musman8bd31e62014-05-27 15:12:19 +0000282void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
283 if (C->getNumForLoops())
284 Profiler->VisitStmt(C->getNumForLoops());
285}
286
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000287void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000288
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000289void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
290
Alexey Bataev56dafe82014-06-20 07:16:17 +0000291void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
292 if (C->getChunkSize())
293 Profiler->VisitStmt(C->getChunkSize());
294}
295
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000296void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {}
297
Alexey Bataev756c1962013-09-24 03:17:45 +0000298template<typename T>
299void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Aaron Ballman2205d2a2014-03-14 15:55:35 +0000300 for (auto *I : Node->varlists())
301 Profiler->VisitStmt(I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000302}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000303
304void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000305 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000306}
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000307void OMPClauseProfiler::VisitOMPFirstprivateClause(
308 const OMPFirstprivateClause *C) {
309 VisitOMPClauseList(C);
310}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000311void
312OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
313 VisitOMPClauseList(C);
314}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000315void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000316 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000317}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000318void OMPClauseProfiler::VisitOMPReductionClause(
319 const OMPReductionClause *C) {
320 Profiler->VisitNestedNameSpecifier(
321 C->getQualifierLoc().getNestedNameSpecifier());
322 Profiler->VisitName(C->getNameInfo().getName());
323 VisitOMPClauseList(C);
324}
Alexander Musman8dba6642014-04-22 13:09:42 +0000325void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
326 VisitOMPClauseList(C);
327 Profiler->VisitStmt(C->getStep());
328}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000329void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
330 VisitOMPClauseList(C);
331 Profiler->VisitStmt(C->getAlignment());
332}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000333void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
334 VisitOMPClauseList(C);
335}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000336}
337
338void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000339StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000340 VisitStmt(S);
341 OMPClauseProfiler P(this);
342 ArrayRef<OMPClause *> Clauses = S->clauses();
343 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
344 I != E; ++I)
345 if (*I)
346 P.Visit(*I);
347}
348
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000349void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
350 VisitOMPExecutableDirective(S);
351}
352
353void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
354 VisitOMPExecutableDirective(S);
355}
356
Alexey Bataevf29276e2014-06-18 04:14:57 +0000357void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
358 VisitOMPExecutableDirective(S);
359}
360
Chandler Carruth631abd92011-06-16 06:47:06 +0000361void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000362 VisitStmt(S);
363}
364
Chandler Carruth631abd92011-06-16 06:47:06 +0000365void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000366 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000367 if (!Canonical)
368 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000369 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000370 if (!Canonical)
371 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000372}
373
Chandler Carruth631abd92011-06-16 06:47:06 +0000374void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000375 VisitExpr(S);
376 ID.AddInteger(S->getIdentType());
377}
378
Chandler Carruth631abd92011-06-16 06:47:06 +0000379void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000380 VisitExpr(S);
381 S->getValue().Profile(ID);
382}
383
Chandler Carruth631abd92011-06-16 06:47:06 +0000384void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000385 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000386 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000387 ID.AddInteger(S->getValue());
388}
389
Chandler Carruth631abd92011-06-16 06:47:06 +0000390void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000391 VisitExpr(S);
392 S->getValue().Profile(ID);
393 ID.AddBoolean(S->isExact());
394}
395
Chandler Carruth631abd92011-06-16 06:47:06 +0000396void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000397 VisitExpr(S);
398}
399
Chandler Carruth631abd92011-06-16 06:47:06 +0000400void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000401 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000402 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000403 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000404}
405
Chandler Carruth631abd92011-06-16 06:47:06 +0000406void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000407 VisitExpr(S);
408}
409
Chandler Carruth631abd92011-06-16 06:47:06 +0000410void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000411 VisitExpr(S);
412}
413
Chandler Carruth631abd92011-06-16 06:47:06 +0000414void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000415 VisitExpr(S);
416 ID.AddInteger(S->getOpcode());
417}
418
Chandler Carruth631abd92011-06-16 06:47:06 +0000419void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000420 VisitType(S->getTypeSourceInfo()->getType());
421 unsigned n = S->getNumComponents();
422 for (unsigned i = 0; i < n; ++i) {
423 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
424 ID.AddInteger(ON.getKind());
425 switch (ON.getKind()) {
426 case OffsetOfExpr::OffsetOfNode::Array:
427 // Expressions handled below.
428 break;
429
430 case OffsetOfExpr::OffsetOfNode::Field:
431 VisitDecl(ON.getField());
432 break;
433
434 case OffsetOfExpr::OffsetOfNode::Identifier:
435 ID.AddPointer(ON.getFieldName());
436 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000437
Douglas Gregord1702062010-04-29 00:18:15 +0000438 case OffsetOfExpr::OffsetOfNode::Base:
439 // These nodes are implicit, and therefore don't need profiling.
440 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000441 }
442 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000443
Douglas Gregor882211c2010-04-28 22:16:22 +0000444 VisitExpr(S);
445}
446
Chandler Carruth631abd92011-06-16 06:47:06 +0000447void
448StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000449 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000450 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000451 if (S->isArgumentType())
452 VisitType(S->getArgumentType());
453}
454
Chandler Carruth631abd92011-06-16 06:47:06 +0000455void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000456 VisitExpr(S);
457}
458
Chandler Carruth631abd92011-06-16 06:47:06 +0000459void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000460 VisitExpr(S);
461}
462
Chandler Carruth631abd92011-06-16 06:47:06 +0000463void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000464 VisitExpr(S);
465 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000466 if (!Canonical)
467 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000468 ID.AddBoolean(S->isArrow());
469}
470
Chandler Carruth631abd92011-06-16 06:47:06 +0000471void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000472 VisitExpr(S);
473 ID.AddBoolean(S->isFileScope());
474}
475
Chandler Carruth631abd92011-06-16 06:47:06 +0000476void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000477 VisitExpr(S);
478}
479
Chandler Carruth631abd92011-06-16 06:47:06 +0000480void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000481 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000482 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000483}
484
Chandler Carruth631abd92011-06-16 06:47:06 +0000485void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000486 VisitCastExpr(S);
487 VisitType(S->getTypeAsWritten());
488}
489
Chandler Carruth631abd92011-06-16 06:47:06 +0000490void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000491 VisitExplicitCastExpr(S);
492}
493
Chandler Carruth631abd92011-06-16 06:47:06 +0000494void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000495 VisitExpr(S);
496 ID.AddInteger(S->getOpcode());
497}
498
Chandler Carruth631abd92011-06-16 06:47:06 +0000499void
500StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000501 VisitBinaryOperator(S);
502}
503
Chandler Carruth631abd92011-06-16 06:47:06 +0000504void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000505 VisitExpr(S);
506}
507
Chandler Carruth631abd92011-06-16 06:47:06 +0000508void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000509 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000510 VisitExpr(S);
511}
512
Chandler Carruth631abd92011-06-16 06:47:06 +0000513void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000514 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000515 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000516}
517
Chandler Carruth631abd92011-06-16 06:47:06 +0000518void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000519 VisitExpr(S);
520}
521
Chandler Carruth631abd92011-06-16 06:47:06 +0000522void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000523 VisitExpr(S);
524}
525
Hal Finkelc4d7c822013-09-18 03:29:45 +0000526void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
527 VisitExpr(S);
528}
529
Chandler Carruth631abd92011-06-16 06:47:06 +0000530void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000531 VisitExpr(S);
532}
533
Chandler Carruth631abd92011-06-16 06:47:06 +0000534void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000535 VisitExpr(S);
536}
537
Chandler Carruth631abd92011-06-16 06:47:06 +0000538void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000539 VisitExpr(S);
540}
541
Chandler Carruth631abd92011-06-16 06:47:06 +0000542void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000543 if (S->getSyntacticForm()) {
544 VisitInitListExpr(S->getSyntacticForm());
545 return;
546 }
Mike Stump11289f42009-09-09 15:08:12 +0000547
Douglas Gregor5c193b92009-07-28 00:33:38 +0000548 VisitExpr(S);
549}
550
Chandler Carruth631abd92011-06-16 06:47:06 +0000551void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000552 VisitExpr(S);
553 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000554 for (DesignatedInitExpr::const_designators_iterator D =
555 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000556 D != DEnd; ++D) {
557 if (D->isFieldDesignator()) {
558 ID.AddInteger(0);
559 VisitName(D->getFieldName());
560 continue;
561 }
Mike Stump11289f42009-09-09 15:08:12 +0000562
Douglas Gregor5c193b92009-07-28 00:33:38 +0000563 if (D->isArrayDesignator()) {
564 ID.AddInteger(1);
565 } else {
566 assert(D->isArrayRangeDesignator());
567 ID.AddInteger(2);
568 }
569 ID.AddInteger(D->getFirstExprIndex());
570 }
571}
572
Chandler Carruth631abd92011-06-16 06:47:06 +0000573void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000574 VisitExpr(S);
575}
576
Chandler Carruth631abd92011-06-16 06:47:06 +0000577void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000578 VisitExpr(S);
579 VisitName(&S->getAccessor());
580}
581
Chandler Carruth631abd92011-06-16 06:47:06 +0000582void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000583 VisitExpr(S);
584 VisitDecl(S->getBlockDecl());
585}
586
Chandler Carruth631abd92011-06-16 06:47:06 +0000587void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000588 VisitExpr(S);
589 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
590 QualType T = S->getAssocType(i);
591 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000592 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000593 else
594 VisitType(T);
595 VisitExpr(S->getAssocExpr(i));
596 }
597}
598
John McCallfe96e0b2011-11-06 09:01:30 +0000599void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
600 VisitExpr(S);
601 for (PseudoObjectExpr::const_semantics_iterator
602 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
603 // Normally, we would not profile the source expressions of OVEs.
604 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
605 Visit(OVE->getSourceExpr());
606}
607
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000608void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
609 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000610 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000611}
612
Chandler Carruth631abd92011-06-16 06:47:06 +0000613static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000614 UnaryOperatorKind &UnaryOp,
615 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000616 switch (S->getOperator()) {
617 case OO_None:
618 case OO_New:
619 case OO_Delete:
620 case OO_Array_New:
621 case OO_Array_Delete:
622 case OO_Arrow:
623 case OO_Call:
624 case OO_Conditional:
625 case NUM_OVERLOADED_OPERATORS:
626 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000627
628 case OO_Plus:
629 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000630 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000631 return Stmt::UnaryOperatorClass;
632 }
633
John McCalle3027922010-08-25 11:45:40 +0000634 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000635 return Stmt::BinaryOperatorClass;
636
637 case OO_Minus:
638 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000639 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000640 return Stmt::UnaryOperatorClass;
641 }
642
John McCalle3027922010-08-25 11:45:40 +0000643 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000644 return Stmt::BinaryOperatorClass;
645
646 case OO_Star:
647 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000648 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000649 return Stmt::UnaryOperatorClass;
650 }
651
Richard Smithf15acc52014-06-05 22:43:40 +0000652 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000653 return Stmt::BinaryOperatorClass;
654
655 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000656 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000657 return Stmt::BinaryOperatorClass;
658
659 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000660 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000661 return Stmt::BinaryOperatorClass;
662
663 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000664 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000665 return Stmt::BinaryOperatorClass;
666
667 case OO_Amp:
668 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000669 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000670 return Stmt::UnaryOperatorClass;
671 }
672
John McCalle3027922010-08-25 11:45:40 +0000673 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000674 return Stmt::BinaryOperatorClass;
675
676 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000677 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000678 return Stmt::BinaryOperatorClass;
679
680 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000681 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000682 return Stmt::UnaryOperatorClass;
683
684 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000685 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000686 return Stmt::UnaryOperatorClass;
687
688 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000689 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000690 return Stmt::BinaryOperatorClass;
691
692 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000693 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000694 return Stmt::BinaryOperatorClass;
695
696 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000697 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000698 return Stmt::BinaryOperatorClass;
699
700 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000701 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000702 return Stmt::CompoundAssignOperatorClass;
703
704 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000705 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000706 return Stmt::CompoundAssignOperatorClass;
707
708 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000709 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000710 return Stmt::CompoundAssignOperatorClass;
711
712 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000713 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000714 return Stmt::CompoundAssignOperatorClass;
715
716 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000717 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000718 return Stmt::CompoundAssignOperatorClass;
719
720 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000721 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000722 return Stmt::CompoundAssignOperatorClass;
723
724 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000725 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000726 return Stmt::CompoundAssignOperatorClass;
727
728 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000729 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000730 return Stmt::CompoundAssignOperatorClass;
731
732 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000733 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000734 return Stmt::BinaryOperatorClass;
735
736 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000737 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000738 return Stmt::BinaryOperatorClass;
739
740 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000741 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000742 return Stmt::CompoundAssignOperatorClass;
743
744 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000745 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000746 return Stmt::CompoundAssignOperatorClass;
747
748 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000749 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000750 return Stmt::BinaryOperatorClass;
751
752 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000753 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000754 return Stmt::BinaryOperatorClass;
755
756 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000757 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000758 return Stmt::BinaryOperatorClass;
759
760 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000761 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000762 return Stmt::BinaryOperatorClass;
763
764 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000765 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000766 return Stmt::BinaryOperatorClass;
767
768 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000769 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000770 return Stmt::BinaryOperatorClass;
771
772 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000773 UnaryOp = S->getNumArgs() == 1? UO_PreInc
774 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000775 return Stmt::UnaryOperatorClass;
776
777 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000778 UnaryOp = S->getNumArgs() == 1? UO_PreDec
779 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000780 return Stmt::UnaryOperatorClass;
781
782 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000783 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000784 return Stmt::BinaryOperatorClass;
785
786
787 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000788 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000789 return Stmt::BinaryOperatorClass;
790
791 case OO_Subscript:
792 return Stmt::ArraySubscriptExprClass;
793 }
794
795 llvm_unreachable("Invalid overloaded operator expression");
796}
Richard Smithf15acc52014-06-05 22:43:40 +0000797
Douglas Gregore9ceb312010-05-19 04:13:23 +0000798
Chandler Carruth631abd92011-06-16 06:47:06 +0000799void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000800 if (S->isTypeDependent()) {
801 // Type-dependent operator calls are profiled like their underlying
802 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000803 UnaryOperatorKind UnaryOp = UO_Extension;
804 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000805 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +0000806
Douglas Gregore9ceb312010-05-19 04:13:23 +0000807 ID.AddInteger(SC);
808 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
809 Visit(S->getArg(I));
810 if (SC == Stmt::UnaryOperatorClass)
811 ID.AddInteger(UnaryOp);
812 else if (SC == Stmt::BinaryOperatorClass ||
813 SC == Stmt::CompoundAssignOperatorClass)
814 ID.AddInteger(BinaryOp);
815 else
816 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +0000817
Douglas Gregore9ceb312010-05-19 04:13:23 +0000818 return;
819 }
Richard Smithf15acc52014-06-05 22:43:40 +0000820
Douglas Gregor5c193b92009-07-28 00:33:38 +0000821 VisitCallExpr(S);
822 ID.AddInteger(S->getOperator());
823}
824
Chandler Carruth631abd92011-06-16 06:47:06 +0000825void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000826 VisitCallExpr(S);
827}
828
Chandler Carruth631abd92011-06-16 06:47:06 +0000829void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000830 VisitCallExpr(S);
831}
832
Chandler Carruth631abd92011-06-16 06:47:06 +0000833void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000834 VisitExpr(S);
835}
836
Chandler Carruth631abd92011-06-16 06:47:06 +0000837void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000838 VisitExplicitCastExpr(S);
839}
840
Chandler Carruth631abd92011-06-16 06:47:06 +0000841void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000842 VisitCXXNamedCastExpr(S);
843}
844
Chandler Carruth631abd92011-06-16 06:47:06 +0000845void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000846 VisitCXXNamedCastExpr(S);
847}
848
Chandler Carruth631abd92011-06-16 06:47:06 +0000849void
850StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000851 VisitCXXNamedCastExpr(S);
852}
853
Chandler Carruth631abd92011-06-16 06:47:06 +0000854void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000855 VisitCXXNamedCastExpr(S);
856}
857
Richard Smithc67fdd42012-03-07 08:35:16 +0000858void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
859 VisitCallExpr(S);
860}
861
Chandler Carruth631abd92011-06-16 06:47:06 +0000862void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000863 VisitExpr(S);
864 ID.AddBoolean(S->getValue());
865}
866
Chandler Carruth631abd92011-06-16 06:47:06 +0000867void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000868 VisitExpr(S);
869}
870
Richard Smithcc1b96d2013-06-12 22:31:48 +0000871void StmtProfiler::VisitCXXStdInitializerListExpr(
872 const CXXStdInitializerListExpr *S) {
873 VisitExpr(S);
874}
875
Chandler Carruth631abd92011-06-16 06:47:06 +0000876void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000877 VisitExpr(S);
878 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000879 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000880}
881
Chandler Carruth631abd92011-06-16 06:47:06 +0000882void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000883 VisitExpr(S);
884 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000885 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000886}
887
John McCall5e77d762013-04-16 07:28:30 +0000888void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
889 VisitExpr(S);
890 VisitDecl(S->getPropertyDecl());
891}
892
Chandler Carruth631abd92011-06-16 06:47:06 +0000893void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000894 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000895 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000896}
897
Chandler Carruth631abd92011-06-16 06:47:06 +0000898void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000899 VisitExpr(S);
900}
901
Chandler Carruth631abd92011-06-16 06:47:06 +0000902void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000903 VisitExpr(S);
904 VisitDecl(S->getParam());
905}
906
Richard Smith852c9db2013-04-20 22:23:05 +0000907void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
908 VisitExpr(S);
909 VisitDecl(S->getField());
910}
911
Chandler Carruth631abd92011-06-16 06:47:06 +0000912void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000913 VisitExpr(S);
914 VisitDecl(
915 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
916}
917
Chandler Carruth631abd92011-06-16 06:47:06 +0000918void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000919 VisitExpr(S);
920 VisitDecl(S->getConstructor());
921 ID.AddBoolean(S->isElidable());
922}
923
Chandler Carruth631abd92011-06-16 06:47:06 +0000924void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000925 VisitExplicitCastExpr(S);
926}
927
Chandler Carruth631abd92011-06-16 06:47:06 +0000928void
929StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000930 VisitCXXConstructExpr(S);
931}
932
Chandler Carruth631abd92011-06-16 06:47:06 +0000933void
Douglas Gregore31e6062012-02-07 10:09:13 +0000934StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
935 VisitExpr(S);
936 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
937 CEnd = S->explicit_capture_end();
938 C != CEnd; ++C) {
939 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +0000940 switch (C->getCaptureKind()) {
941 case LCK_This:
942 break;
943 case LCK_ByRef:
944 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +0000945 VisitDecl(C->getCapturedVar());
946 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +0000947 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000948 }
949 }
950 // Note: If we actually needed to be able to match lambda
951 // expressions, we would have to consider parameters and return type
952 // here, among other things.
953 VisitStmt(S->getBody());
954}
955
956void
Chandler Carruth631abd92011-06-16 06:47:06 +0000957StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000958 VisitExpr(S);
959}
960
Chandler Carruth631abd92011-06-16 06:47:06 +0000961void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000962 VisitExpr(S);
963 ID.AddBoolean(S->isGlobalDelete());
964 ID.AddBoolean(S->isArrayForm());
965 VisitDecl(S->getOperatorDelete());
966}
967
968
Chandler Carruth631abd92011-06-16 06:47:06 +0000969void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000970 VisitExpr(S);
971 VisitType(S->getAllocatedType());
972 VisitDecl(S->getOperatorNew());
973 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000974 ID.AddBoolean(S->isArray());
975 ID.AddInteger(S->getNumPlacementArgs());
976 ID.AddBoolean(S->isGlobalNew());
977 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +0000978 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000979}
980
Chandler Carruth631abd92011-06-16 06:47:06 +0000981void
982StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +0000983 VisitExpr(S);
984 ID.AddBoolean(S->isArrow());
985 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +0000986 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +0000987 if (S->getScopeTypeInfo())
988 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +0000989 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +0000990 if (S->getDestroyedTypeInfo())
991 VisitType(S->getDestroyedType());
992 else
993 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +0000994}
995
Chandler Carruth631abd92011-06-16 06:47:06 +0000996void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +0000997 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +0000998 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000999 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001000 ID.AddBoolean(S->hasExplicitTemplateArgs());
1001 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001002 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1003 S->getExplicitTemplateArgs().NumTemplateArgs);
1004}
1005
1006void
Chandler Carruth631abd92011-06-16 06:47:06 +00001007StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001008 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001009}
1010
Douglas Gregor29c42f22012-02-24 07:38:34 +00001011void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1012 VisitExpr(S);
1013 ID.AddInteger(S->getTrait());
1014 ID.AddInteger(S->getNumArgs());
1015 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1016 VisitType(S->getArg(I)->getType());
1017}
1018
Chandler Carruth631abd92011-06-16 06:47:06 +00001019void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001020 VisitExpr(S);
1021 ID.AddInteger(S->getTrait());
1022 VisitType(S->getQueriedType());
1023}
1024
Chandler Carruth631abd92011-06-16 06:47:06 +00001025void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001026 VisitExpr(S);
1027 ID.AddInteger(S->getTrait());
1028 VisitExpr(S->getQueriedExpression());
1029}
1030
Chandler Carruth631abd92011-06-16 06:47:06 +00001031void StmtProfiler::VisitDependentScopeDeclRefExpr(
1032 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001033 VisitExpr(S);
1034 VisitName(S->getDeclName());
1035 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001036 ID.AddBoolean(S->hasExplicitTemplateArgs());
1037 if (S->hasExplicitTemplateArgs())
1038 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001039}
1040
Chandler Carruth631abd92011-06-16 06:47:06 +00001041void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001042 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001043}
1044
Chandler Carruth631abd92011-06-16 06:47:06 +00001045void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1046 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001047 VisitExpr(S);
1048 VisitType(S->getTypeAsWritten());
1049}
1050
Chandler Carruth631abd92011-06-16 06:47:06 +00001051void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1052 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001053 ID.AddBoolean(S->isImplicitAccess());
1054 if (!S->isImplicitAccess()) {
1055 VisitExpr(S);
1056 ID.AddBoolean(S->isArrow());
1057 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001058 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001059 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001060 ID.AddBoolean(S->hasExplicitTemplateArgs());
1061 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001062 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1063}
1064
Chandler Carruth631abd92011-06-16 06:47:06 +00001065void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001066 ID.AddBoolean(S->isImplicitAccess());
1067 if (!S->isImplicitAccess()) {
1068 VisitExpr(S);
1069 ID.AddBoolean(S->isArrow());
1070 }
John McCall10eae182009-11-30 22:42:35 +00001071 VisitNestedNameSpecifier(S->getQualifier());
1072 VisitName(S->getMemberName());
1073 ID.AddBoolean(S->hasExplicitTemplateArgs());
1074 if (S->hasExplicitTemplateArgs())
1075 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001076}
1077
Chandler Carruth631abd92011-06-16 06:47:06 +00001078void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001079 VisitExpr(S);
1080}
1081
Chandler Carruth631abd92011-06-16 06:47:06 +00001082void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001083 VisitExpr(S);
1084}
1085
Chandler Carruth631abd92011-06-16 06:47:06 +00001086void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001087 VisitExpr(S);
1088 VisitDecl(S->getPack());
1089}
1090
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001091void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001092 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001093 VisitExpr(S);
1094 VisitDecl(S->getParameterPack());
1095 VisitTemplateArgument(S->getArgumentPack());
1096}
1097
John McCall7c454bb2011-07-15 05:09:51 +00001098void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1099 const SubstNonTypeTemplateParmExpr *E) {
1100 // Profile exactly as the replacement expression.
1101 Visit(E->getReplacement());
1102}
1103
Richard Smithb15fe3a2012-09-12 00:56:43 +00001104void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1105 VisitExpr(S);
1106 VisitDecl(S->getParameterPack());
1107 ID.AddInteger(S->getNumExpansions());
1108 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1109 VisitDecl(*I);
1110}
1111
Douglas Gregorfe314812011-06-21 17:03:29 +00001112void StmtProfiler::VisitMaterializeTemporaryExpr(
1113 const MaterializeTemporaryExpr *S) {
1114 VisitExpr(S);
1115}
1116
Chandler Carruth631abd92011-06-16 06:47:06 +00001117void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001118 VisitExpr(E);
1119}
1120
Chandler Carruth631abd92011-06-16 06:47:06 +00001121void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001122 VisitExpr(S);
1123}
1124
Patrick Beard0caa3942012-04-19 00:25:12 +00001125void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001126 VisitExpr(E);
1127}
1128
1129void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1130 VisitExpr(E);
1131}
1132
1133void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1134 VisitExpr(E);
1135}
1136
Chandler Carruth631abd92011-06-16 06:47:06 +00001137void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001138 VisitExpr(S);
1139 VisitType(S->getEncodedType());
1140}
1141
Chandler Carruth631abd92011-06-16 06:47:06 +00001142void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001143 VisitExpr(S);
1144 VisitName(S->getSelector());
1145}
1146
Chandler Carruth631abd92011-06-16 06:47:06 +00001147void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001148 VisitExpr(S);
1149 VisitDecl(S->getProtocol());
1150}
1151
Chandler Carruth631abd92011-06-16 06:47:06 +00001152void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001153 VisitExpr(S);
1154 VisitDecl(S->getDecl());
1155 ID.AddBoolean(S->isArrow());
1156 ID.AddBoolean(S->isFreeIvar());
1157}
1158
Chandler Carruth631abd92011-06-16 06:47:06 +00001159void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001160 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001161 if (S->isImplicitProperty()) {
1162 VisitDecl(S->getImplicitPropertyGetter());
1163 VisitDecl(S->getImplicitPropertySetter());
1164 } else {
1165 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001166 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001167 if (S->isSuperReceiver()) {
1168 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001169 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001170 }
Douglas Gregora7095092009-07-28 14:44:31 +00001171}
1172
Ted Kremeneke65b0862012-03-06 20:05:56 +00001173void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1174 VisitExpr(S);
1175 VisitDecl(S->getAtIndexMethodDecl());
1176 VisitDecl(S->setAtIndexMethodDecl());
1177}
1178
Chandler Carruth631abd92011-06-16 06:47:06 +00001179void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001180 VisitExpr(S);
1181 VisitName(S->getSelector());
1182 VisitDecl(S->getMethodDecl());
1183}
1184
Chandler Carruth631abd92011-06-16 06:47:06 +00001185void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001186 VisitExpr(S);
1187 ID.AddBoolean(S->isArrow());
1188}
1189
Ted Kremeneke65b0862012-03-06 20:05:56 +00001190void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1191 VisitExpr(S);
1192 ID.AddBoolean(S->getValue());
1193}
1194
Chandler Carruth631abd92011-06-16 06:47:06 +00001195void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1196 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001197 VisitExpr(S);
1198 ID.AddBoolean(S->shouldCopy());
1199}
1200
Chandler Carruth631abd92011-06-16 06:47:06 +00001201void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001202 VisitExplicitCastExpr(S);
1203 ID.AddBoolean(S->getBridgeKind());
1204}
1205
Chandler Carruth631abd92011-06-16 06:47:06 +00001206void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001207 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001208
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001209 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001210 if (const NonTypeTemplateParmDecl *NTTP =
1211 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001212 ID.AddInteger(NTTP->getDepth());
1213 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001214 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001215 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001216 return;
1217 }
Mike Stump11289f42009-09-09 15:08:12 +00001218
Chandler Carruth631abd92011-06-16 06:47:06 +00001219 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001220 // The Itanium C++ ABI uses the type, scope depth, and scope
1221 // index of a parameter when mangling expressions that involve
1222 // function parameters, so we will use the parameter's type for
1223 // establishing function parameter identity. That way, our
1224 // definition of "equivalent" (per C++ [temp.over.link]) is at
1225 // least as strong as the definition of "equivalent" used for
1226 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001227 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001228 ID.AddInteger(Parm->getFunctionScopeDepth());
1229 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001230 return;
1231 }
Mike Stump11289f42009-09-09 15:08:12 +00001232
Richard Smithd9a1cd82012-04-02 18:53:24 +00001233 if (const TemplateTypeParmDecl *TTP =
1234 dyn_cast<TemplateTypeParmDecl>(D)) {
1235 ID.AddInteger(TTP->getDepth());
1236 ID.AddInteger(TTP->getIndex());
1237 ID.AddBoolean(TTP->isParameterPack());
1238 return;
1239 }
1240
Chandler Carruth631abd92011-06-16 06:47:06 +00001241 if (const TemplateTemplateParmDecl *TTP =
1242 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001243 ID.AddInteger(TTP->getDepth());
1244 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001245 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001246 return;
1247 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001248 }
Mike Stump11289f42009-09-09 15:08:12 +00001249
Craig Topper36250ad2014-05-12 05:36:57 +00001250 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001251}
1252
1253void StmtProfiler::VisitType(QualType T) {
1254 if (Canonical)
1255 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001256
Douglas Gregor5c193b92009-07-28 00:33:38 +00001257 ID.AddPointer(T.getAsOpaquePtr());
1258}
1259
1260void StmtProfiler::VisitName(DeclarationName Name) {
1261 ID.AddPointer(Name.getAsOpaquePtr());
1262}
1263
1264void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1265 if (Canonical)
1266 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1267 ID.AddPointer(NNS);
1268}
1269
1270void StmtProfiler::VisitTemplateName(TemplateName Name) {
1271 if (Canonical)
1272 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001273
Douglas Gregor5c193b92009-07-28 00:33:38 +00001274 Name.Profile(ID);
1275}
1276
John McCall0ad16662009-10-29 08:12:44 +00001277void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001278 unsigned NumArgs) {
1279 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001280 for (unsigned I = 0; I != NumArgs; ++I)
1281 VisitTemplateArgument(Args[I].getArgument());
1282}
Mike Stump11289f42009-09-09 15:08:12 +00001283
John McCall0ad16662009-10-29 08:12:44 +00001284void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1285 // Mostly repetitive with TemplateArgument::Profile!
1286 ID.AddInteger(Arg.getKind());
1287 switch (Arg.getKind()) {
1288 case TemplateArgument::Null:
1289 break;
Mike Stump11289f42009-09-09 15:08:12 +00001290
John McCall0ad16662009-10-29 08:12:44 +00001291 case TemplateArgument::Type:
1292 VisitType(Arg.getAsType());
1293 break;
Mike Stump11289f42009-09-09 15:08:12 +00001294
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001295 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001296 case TemplateArgument::TemplateExpansion:
1297 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001298 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001299
John McCall0ad16662009-10-29 08:12:44 +00001300 case TemplateArgument::Declaration:
1301 VisitDecl(Arg.getAsDecl());
1302 break;
Mike Stump11289f42009-09-09 15:08:12 +00001303
Eli Friedmanb826a002012-09-26 02:36:12 +00001304 case TemplateArgument::NullPtr:
1305 VisitType(Arg.getNullPtrType());
1306 break;
1307
John McCall0ad16662009-10-29 08:12:44 +00001308 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001309 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001310 VisitType(Arg.getIntegralType());
1311 break;
Mike Stump11289f42009-09-09 15:08:12 +00001312
John McCall0ad16662009-10-29 08:12:44 +00001313 case TemplateArgument::Expression:
1314 Visit(Arg.getAsExpr());
1315 break;
Mike Stump11289f42009-09-09 15:08:12 +00001316
John McCall0ad16662009-10-29 08:12:44 +00001317 case TemplateArgument::Pack:
1318 const TemplateArgument *Pack = Arg.pack_begin();
1319 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1320 VisitTemplateArgument(Pack[i]);
1321 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001322 }
1323}
1324
Jay Foad39c79802011-01-12 09:06:06 +00001325void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001326 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001327 StmtProfiler Profiler(ID, Context, Canonical);
1328 Profiler.Visit(this);
1329}