blob: f666be7008f67c059d4a4063f75059f54d807ecb [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
Nico Weber9b982072014-07-07 00:12:30 +0000217void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
218 VisitStmt(S);
219}
220
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000221void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
222 VisitStmt(S);
223}
224
Chandler Carruth631abd92011-06-16 06:47:06 +0000225void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000226 VisitStmt(S);
227}
228
Chandler Carruth631abd92011-06-16 06:47:06 +0000229void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000230 VisitStmt(S);
231 ID.AddBoolean(S->hasEllipsis());
232 if (S->getCatchParamDecl())
233 VisitType(S->getCatchParamDecl()->getType());
234}
235
Chandler Carruth631abd92011-06-16 06:47:06 +0000236void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000237 VisitStmt(S);
238}
239
Chandler Carruth631abd92011-06-16 06:47:06 +0000240void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000241 VisitStmt(S);
242}
243
Chandler Carruth631abd92011-06-16 06:47:06 +0000244void
245StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000246 VisitStmt(S);
247}
248
Chandler Carruth631abd92011-06-16 06:47:06 +0000249void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000250 VisitStmt(S);
251}
252
Chandler Carruth631abd92011-06-16 06:47:06 +0000253void
254StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000255 VisitStmt(S);
256}
257
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000258namespace {
259class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
260 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000261 /// \brief Process clauses with list of variables.
262 template <typename T>
263 void VisitOMPClauseList(T *Node);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000264public:
265 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
266#define OPENMP_CLAUSE(Name, Class) \
267 void Visit##Class(const Class *C);
268#include "clang/Basic/OpenMPKinds.def"
269};
270
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000271void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
272 if (C->getCondition())
273 Profiler->VisitStmt(C->getCondition());
274}
275
Alexey Bataev568a8332014-03-06 06:15:19 +0000276void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
277 if (C->getNumThreads())
278 Profiler->VisitStmt(C->getNumThreads());
279}
280
Alexey Bataev62c87d22014-03-21 04:51:18 +0000281void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
282 if (C->getSafelen())
283 Profiler->VisitStmt(C->getSafelen());
284}
285
Alexander Musman8bd31e62014-05-27 15:12:19 +0000286void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
287 if (C->getNumForLoops())
288 Profiler->VisitStmt(C->getNumForLoops());
289}
290
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000291void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000292
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000293void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
294
Alexey Bataev56dafe82014-06-20 07:16:17 +0000295void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
296 if (C->getChunkSize())
297 Profiler->VisitStmt(C->getChunkSize());
298}
299
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000300void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {}
301
Alexey Bataev236070f2014-06-20 11:19:47 +0000302void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
303
Alexey Bataev756c1962013-09-24 03:17:45 +0000304template<typename T>
305void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Aaron Ballman2205d2a2014-03-14 15:55:35 +0000306 for (auto *I : Node->varlists())
307 Profiler->VisitStmt(I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000308}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000309
310void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000311 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000312}
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000313void OMPClauseProfiler::VisitOMPFirstprivateClause(
314 const OMPFirstprivateClause *C) {
315 VisitOMPClauseList(C);
316}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000317void
318OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
319 VisitOMPClauseList(C);
320}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000321void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000322 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000323}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000324void OMPClauseProfiler::VisitOMPReductionClause(
325 const OMPReductionClause *C) {
326 Profiler->VisitNestedNameSpecifier(
327 C->getQualifierLoc().getNestedNameSpecifier());
328 Profiler->VisitName(C->getNameInfo().getName());
329 VisitOMPClauseList(C);
330}
Alexander Musman8dba6642014-04-22 13:09:42 +0000331void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
332 VisitOMPClauseList(C);
333 Profiler->VisitStmt(C->getStep());
334}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000335void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
336 VisitOMPClauseList(C);
337 Profiler->VisitStmt(C->getAlignment());
338}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000339void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
340 VisitOMPClauseList(C);
341}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000342void
343OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
344 VisitOMPClauseList(C);
345}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000346}
347
348void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000349StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000350 VisitStmt(S);
351 OMPClauseProfiler P(this);
352 ArrayRef<OMPClause *> Clauses = S->clauses();
353 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
354 I != E; ++I)
355 if (*I)
356 P.Visit(*I);
357}
358
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000359void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
360 VisitOMPExecutableDirective(S);
361}
362
363void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
364 VisitOMPExecutableDirective(S);
365}
366
Alexey Bataevf29276e2014-06-18 04:14:57 +0000367void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
368 VisitOMPExecutableDirective(S);
369}
370
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000371void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
372 VisitOMPExecutableDirective(S);
373}
374
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000375void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
376 VisitOMPExecutableDirective(S);
377}
378
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000379void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
380 VisitOMPExecutableDirective(S);
381}
382
Chandler Carruth631abd92011-06-16 06:47:06 +0000383void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000384 VisitStmt(S);
385}
386
Chandler Carruth631abd92011-06-16 06:47:06 +0000387void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000388 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000389 if (!Canonical)
390 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000391 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000392 if (!Canonical)
393 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000394}
395
Chandler Carruth631abd92011-06-16 06:47:06 +0000396void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000397 VisitExpr(S);
398 ID.AddInteger(S->getIdentType());
399}
400
Chandler Carruth631abd92011-06-16 06:47:06 +0000401void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000402 VisitExpr(S);
403 S->getValue().Profile(ID);
404}
405
Chandler Carruth631abd92011-06-16 06:47:06 +0000406void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000407 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000408 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000409 ID.AddInteger(S->getValue());
410}
411
Chandler Carruth631abd92011-06-16 06:47:06 +0000412void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000413 VisitExpr(S);
414 S->getValue().Profile(ID);
415 ID.AddBoolean(S->isExact());
416}
417
Chandler Carruth631abd92011-06-16 06:47:06 +0000418void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000419 VisitExpr(S);
420}
421
Chandler Carruth631abd92011-06-16 06:47:06 +0000422void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000423 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000424 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000425 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000426}
427
Chandler Carruth631abd92011-06-16 06:47:06 +0000428void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000429 VisitExpr(S);
430}
431
Chandler Carruth631abd92011-06-16 06:47:06 +0000432void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000433 VisitExpr(S);
434}
435
Chandler Carruth631abd92011-06-16 06:47:06 +0000436void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000437 VisitExpr(S);
438 ID.AddInteger(S->getOpcode());
439}
440
Chandler Carruth631abd92011-06-16 06:47:06 +0000441void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000442 VisitType(S->getTypeSourceInfo()->getType());
443 unsigned n = S->getNumComponents();
444 for (unsigned i = 0; i < n; ++i) {
445 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
446 ID.AddInteger(ON.getKind());
447 switch (ON.getKind()) {
448 case OffsetOfExpr::OffsetOfNode::Array:
449 // Expressions handled below.
450 break;
451
452 case OffsetOfExpr::OffsetOfNode::Field:
453 VisitDecl(ON.getField());
454 break;
455
456 case OffsetOfExpr::OffsetOfNode::Identifier:
457 ID.AddPointer(ON.getFieldName());
458 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000459
Douglas Gregord1702062010-04-29 00:18:15 +0000460 case OffsetOfExpr::OffsetOfNode::Base:
461 // These nodes are implicit, and therefore don't need profiling.
462 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000463 }
464 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000465
Douglas Gregor882211c2010-04-28 22:16:22 +0000466 VisitExpr(S);
467}
468
Chandler Carruth631abd92011-06-16 06:47:06 +0000469void
470StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000471 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000472 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000473 if (S->isArgumentType())
474 VisitType(S->getArgumentType());
475}
476
Chandler Carruth631abd92011-06-16 06:47:06 +0000477void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000478 VisitExpr(S);
479}
480
Chandler Carruth631abd92011-06-16 06:47:06 +0000481void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000482 VisitExpr(S);
483}
484
Chandler Carruth631abd92011-06-16 06:47:06 +0000485void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000486 VisitExpr(S);
487 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000488 if (!Canonical)
489 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000490 ID.AddBoolean(S->isArrow());
491}
492
Chandler Carruth631abd92011-06-16 06:47:06 +0000493void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000494 VisitExpr(S);
495 ID.AddBoolean(S->isFileScope());
496}
497
Chandler Carruth631abd92011-06-16 06:47:06 +0000498void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000499 VisitExpr(S);
500}
501
Chandler Carruth631abd92011-06-16 06:47:06 +0000502void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000503 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000504 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000505}
506
Chandler Carruth631abd92011-06-16 06:47:06 +0000507void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000508 VisitCastExpr(S);
509 VisitType(S->getTypeAsWritten());
510}
511
Chandler Carruth631abd92011-06-16 06:47:06 +0000512void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000513 VisitExplicitCastExpr(S);
514}
515
Chandler Carruth631abd92011-06-16 06:47:06 +0000516void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000517 VisitExpr(S);
518 ID.AddInteger(S->getOpcode());
519}
520
Chandler Carruth631abd92011-06-16 06:47:06 +0000521void
522StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000523 VisitBinaryOperator(S);
524}
525
Chandler Carruth631abd92011-06-16 06:47:06 +0000526void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000527 VisitExpr(S);
528}
529
Chandler Carruth631abd92011-06-16 06:47:06 +0000530void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000531 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000532 VisitExpr(S);
533}
534
Chandler Carruth631abd92011-06-16 06:47:06 +0000535void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000536 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000537 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000538}
539
Chandler Carruth631abd92011-06-16 06:47:06 +0000540void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000541 VisitExpr(S);
542}
543
Chandler Carruth631abd92011-06-16 06:47:06 +0000544void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000545 VisitExpr(S);
546}
547
Hal Finkelc4d7c822013-09-18 03:29:45 +0000548void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
549 VisitExpr(S);
550}
551
Chandler Carruth631abd92011-06-16 06:47:06 +0000552void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000553 VisitExpr(S);
554}
555
Chandler Carruth631abd92011-06-16 06:47:06 +0000556void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000557 VisitExpr(S);
558}
559
Chandler Carruth631abd92011-06-16 06:47:06 +0000560void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000561 VisitExpr(S);
562}
563
Chandler Carruth631abd92011-06-16 06:47:06 +0000564void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000565 if (S->getSyntacticForm()) {
566 VisitInitListExpr(S->getSyntacticForm());
567 return;
568 }
Mike Stump11289f42009-09-09 15:08:12 +0000569
Douglas Gregor5c193b92009-07-28 00:33:38 +0000570 VisitExpr(S);
571}
572
Chandler Carruth631abd92011-06-16 06:47:06 +0000573void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000574 VisitExpr(S);
575 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000576 for (DesignatedInitExpr::const_designators_iterator D =
577 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000578 D != DEnd; ++D) {
579 if (D->isFieldDesignator()) {
580 ID.AddInteger(0);
581 VisitName(D->getFieldName());
582 continue;
583 }
Mike Stump11289f42009-09-09 15:08:12 +0000584
Douglas Gregor5c193b92009-07-28 00:33:38 +0000585 if (D->isArrayDesignator()) {
586 ID.AddInteger(1);
587 } else {
588 assert(D->isArrayRangeDesignator());
589 ID.AddInteger(2);
590 }
591 ID.AddInteger(D->getFirstExprIndex());
592 }
593}
594
Chandler Carruth631abd92011-06-16 06:47:06 +0000595void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000596 VisitExpr(S);
597}
598
Chandler Carruth631abd92011-06-16 06:47:06 +0000599void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000600 VisitExpr(S);
601 VisitName(&S->getAccessor());
602}
603
Chandler Carruth631abd92011-06-16 06:47:06 +0000604void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000605 VisitExpr(S);
606 VisitDecl(S->getBlockDecl());
607}
608
Chandler Carruth631abd92011-06-16 06:47:06 +0000609void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000610 VisitExpr(S);
611 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
612 QualType T = S->getAssocType(i);
613 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000614 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000615 else
616 VisitType(T);
617 VisitExpr(S->getAssocExpr(i));
618 }
619}
620
John McCallfe96e0b2011-11-06 09:01:30 +0000621void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
622 VisitExpr(S);
623 for (PseudoObjectExpr::const_semantics_iterator
624 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
625 // Normally, we would not profile the source expressions of OVEs.
626 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
627 Visit(OVE->getSourceExpr());
628}
629
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000630void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
631 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000632 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000633}
634
Chandler Carruth631abd92011-06-16 06:47:06 +0000635static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000636 UnaryOperatorKind &UnaryOp,
637 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000638 switch (S->getOperator()) {
639 case OO_None:
640 case OO_New:
641 case OO_Delete:
642 case OO_Array_New:
643 case OO_Array_Delete:
644 case OO_Arrow:
645 case OO_Call:
646 case OO_Conditional:
647 case NUM_OVERLOADED_OPERATORS:
648 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000649
650 case OO_Plus:
651 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000652 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000653 return Stmt::UnaryOperatorClass;
654 }
655
John McCalle3027922010-08-25 11:45:40 +0000656 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000657 return Stmt::BinaryOperatorClass;
658
659 case OO_Minus:
660 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000661 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000662 return Stmt::UnaryOperatorClass;
663 }
664
John McCalle3027922010-08-25 11:45:40 +0000665 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000666 return Stmt::BinaryOperatorClass;
667
668 case OO_Star:
669 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000670 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000671 return Stmt::UnaryOperatorClass;
672 }
673
Richard Smithf15acc52014-06-05 22:43:40 +0000674 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000675 return Stmt::BinaryOperatorClass;
676
677 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000678 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000679 return Stmt::BinaryOperatorClass;
680
681 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000682 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000683 return Stmt::BinaryOperatorClass;
684
685 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000686 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000687 return Stmt::BinaryOperatorClass;
688
689 case OO_Amp:
690 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000691 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000692 return Stmt::UnaryOperatorClass;
693 }
694
John McCalle3027922010-08-25 11:45:40 +0000695 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000696 return Stmt::BinaryOperatorClass;
697
698 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000699 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000700 return Stmt::BinaryOperatorClass;
701
702 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000703 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000704 return Stmt::UnaryOperatorClass;
705
706 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000707 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000708 return Stmt::UnaryOperatorClass;
709
710 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000711 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000712 return Stmt::BinaryOperatorClass;
713
714 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000715 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000716 return Stmt::BinaryOperatorClass;
717
718 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000719 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000720 return Stmt::BinaryOperatorClass;
721
722 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000723 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000724 return Stmt::CompoundAssignOperatorClass;
725
726 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000727 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000728 return Stmt::CompoundAssignOperatorClass;
729
730 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000731 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000732 return Stmt::CompoundAssignOperatorClass;
733
734 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000735 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000736 return Stmt::CompoundAssignOperatorClass;
737
738 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000739 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000740 return Stmt::CompoundAssignOperatorClass;
741
742 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000743 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000744 return Stmt::CompoundAssignOperatorClass;
745
746 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000747 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000748 return Stmt::CompoundAssignOperatorClass;
749
750 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000751 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000752 return Stmt::CompoundAssignOperatorClass;
753
754 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000755 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000756 return Stmt::BinaryOperatorClass;
757
758 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000759 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000760 return Stmt::BinaryOperatorClass;
761
762 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000763 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000764 return Stmt::CompoundAssignOperatorClass;
765
766 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000767 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000768 return Stmt::CompoundAssignOperatorClass;
769
770 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000771 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000772 return Stmt::BinaryOperatorClass;
773
774 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000775 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000776 return Stmt::BinaryOperatorClass;
777
778 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000779 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000780 return Stmt::BinaryOperatorClass;
781
782 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000783 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000784 return Stmt::BinaryOperatorClass;
785
786 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000787 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000788 return Stmt::BinaryOperatorClass;
789
790 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000791 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000792 return Stmt::BinaryOperatorClass;
793
794 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000795 UnaryOp = S->getNumArgs() == 1? UO_PreInc
796 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000797 return Stmt::UnaryOperatorClass;
798
799 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000800 UnaryOp = S->getNumArgs() == 1? UO_PreDec
801 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000802 return Stmt::UnaryOperatorClass;
803
804 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000805 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000806 return Stmt::BinaryOperatorClass;
807
808
809 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000810 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000811 return Stmt::BinaryOperatorClass;
812
813 case OO_Subscript:
814 return Stmt::ArraySubscriptExprClass;
815 }
816
817 llvm_unreachable("Invalid overloaded operator expression");
818}
Richard Smithf15acc52014-06-05 22:43:40 +0000819
Douglas Gregore9ceb312010-05-19 04:13:23 +0000820
Chandler Carruth631abd92011-06-16 06:47:06 +0000821void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000822 if (S->isTypeDependent()) {
823 // Type-dependent operator calls are profiled like their underlying
824 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000825 UnaryOperatorKind UnaryOp = UO_Extension;
826 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000827 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +0000828
Douglas Gregore9ceb312010-05-19 04:13:23 +0000829 ID.AddInteger(SC);
830 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
831 Visit(S->getArg(I));
832 if (SC == Stmt::UnaryOperatorClass)
833 ID.AddInteger(UnaryOp);
834 else if (SC == Stmt::BinaryOperatorClass ||
835 SC == Stmt::CompoundAssignOperatorClass)
836 ID.AddInteger(BinaryOp);
837 else
838 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +0000839
Douglas Gregore9ceb312010-05-19 04:13:23 +0000840 return;
841 }
Richard Smithf15acc52014-06-05 22:43:40 +0000842
Douglas Gregor5c193b92009-07-28 00:33:38 +0000843 VisitCallExpr(S);
844 ID.AddInteger(S->getOperator());
845}
846
Chandler Carruth631abd92011-06-16 06:47:06 +0000847void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000848 VisitCallExpr(S);
849}
850
Chandler Carruth631abd92011-06-16 06:47:06 +0000851void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000852 VisitCallExpr(S);
853}
854
Chandler Carruth631abd92011-06-16 06:47:06 +0000855void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000856 VisitExpr(S);
857}
858
Chandler Carruth631abd92011-06-16 06:47:06 +0000859void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000860 VisitExplicitCastExpr(S);
861}
862
Chandler Carruth631abd92011-06-16 06:47:06 +0000863void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000864 VisitCXXNamedCastExpr(S);
865}
866
Chandler Carruth631abd92011-06-16 06:47:06 +0000867void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000868 VisitCXXNamedCastExpr(S);
869}
870
Chandler Carruth631abd92011-06-16 06:47:06 +0000871void
872StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000873 VisitCXXNamedCastExpr(S);
874}
875
Chandler Carruth631abd92011-06-16 06:47:06 +0000876void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000877 VisitCXXNamedCastExpr(S);
878}
879
Richard Smithc67fdd42012-03-07 08:35:16 +0000880void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
881 VisitCallExpr(S);
882}
883
Chandler Carruth631abd92011-06-16 06:47:06 +0000884void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000885 VisitExpr(S);
886 ID.AddBoolean(S->getValue());
887}
888
Chandler Carruth631abd92011-06-16 06:47:06 +0000889void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000890 VisitExpr(S);
891}
892
Richard Smithcc1b96d2013-06-12 22:31:48 +0000893void StmtProfiler::VisitCXXStdInitializerListExpr(
894 const CXXStdInitializerListExpr *S) {
895 VisitExpr(S);
896}
897
Chandler Carruth631abd92011-06-16 06:47:06 +0000898void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000899 VisitExpr(S);
900 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000901 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000902}
903
Chandler Carruth631abd92011-06-16 06:47:06 +0000904void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000905 VisitExpr(S);
906 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000907 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000908}
909
John McCall5e77d762013-04-16 07:28:30 +0000910void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
911 VisitExpr(S);
912 VisitDecl(S->getPropertyDecl());
913}
914
Chandler Carruth631abd92011-06-16 06:47:06 +0000915void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000916 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000917 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000918}
919
Chandler Carruth631abd92011-06-16 06:47:06 +0000920void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000921 VisitExpr(S);
922}
923
Chandler Carruth631abd92011-06-16 06:47:06 +0000924void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000925 VisitExpr(S);
926 VisitDecl(S->getParam());
927}
928
Richard Smith852c9db2013-04-20 22:23:05 +0000929void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
930 VisitExpr(S);
931 VisitDecl(S->getField());
932}
933
Chandler Carruth631abd92011-06-16 06:47:06 +0000934void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000935 VisitExpr(S);
936 VisitDecl(
937 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
938}
939
Chandler Carruth631abd92011-06-16 06:47:06 +0000940void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000941 VisitExpr(S);
942 VisitDecl(S->getConstructor());
943 ID.AddBoolean(S->isElidable());
944}
945
Chandler Carruth631abd92011-06-16 06:47:06 +0000946void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000947 VisitExplicitCastExpr(S);
948}
949
Chandler Carruth631abd92011-06-16 06:47:06 +0000950void
951StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000952 VisitCXXConstructExpr(S);
953}
954
Chandler Carruth631abd92011-06-16 06:47:06 +0000955void
Douglas Gregore31e6062012-02-07 10:09:13 +0000956StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
957 VisitExpr(S);
958 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
959 CEnd = S->explicit_capture_end();
960 C != CEnd; ++C) {
961 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +0000962 switch (C->getCaptureKind()) {
963 case LCK_This:
964 break;
965 case LCK_ByRef:
966 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +0000967 VisitDecl(C->getCapturedVar());
968 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +0000969 break;
Douglas Gregore31e6062012-02-07 10:09:13 +0000970 }
971 }
972 // Note: If we actually needed to be able to match lambda
973 // expressions, we would have to consider parameters and return type
974 // here, among other things.
975 VisitStmt(S->getBody());
976}
977
978void
Chandler Carruth631abd92011-06-16 06:47:06 +0000979StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000980 VisitExpr(S);
981}
982
Chandler Carruth631abd92011-06-16 06:47:06 +0000983void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000984 VisitExpr(S);
985 ID.AddBoolean(S->isGlobalDelete());
986 ID.AddBoolean(S->isArrayForm());
987 VisitDecl(S->getOperatorDelete());
988}
989
990
Chandler Carruth631abd92011-06-16 06:47:06 +0000991void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000992 VisitExpr(S);
993 VisitType(S->getAllocatedType());
994 VisitDecl(S->getOperatorNew());
995 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000996 ID.AddBoolean(S->isArray());
997 ID.AddInteger(S->getNumPlacementArgs());
998 ID.AddBoolean(S->isGlobalNew());
999 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001000 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001001}
1002
Chandler Carruth631abd92011-06-16 06:47:06 +00001003void
1004StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001005 VisitExpr(S);
1006 ID.AddBoolean(S->isArrow());
1007 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001008 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001009 if (S->getScopeTypeInfo())
1010 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001011 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001012 if (S->getDestroyedTypeInfo())
1013 VisitType(S->getDestroyedType());
1014 else
1015 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001016}
1017
Chandler Carruth631abd92011-06-16 06:47:06 +00001018void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001019 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001020 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001021 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001022 ID.AddBoolean(S->hasExplicitTemplateArgs());
1023 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001024 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1025 S->getExplicitTemplateArgs().NumTemplateArgs);
1026}
1027
1028void
Chandler Carruth631abd92011-06-16 06:47:06 +00001029StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001030 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001031}
1032
Douglas Gregor29c42f22012-02-24 07:38:34 +00001033void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1034 VisitExpr(S);
1035 ID.AddInteger(S->getTrait());
1036 ID.AddInteger(S->getNumArgs());
1037 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1038 VisitType(S->getArg(I)->getType());
1039}
1040
Chandler Carruth631abd92011-06-16 06:47:06 +00001041void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001042 VisitExpr(S);
1043 ID.AddInteger(S->getTrait());
1044 VisitType(S->getQueriedType());
1045}
1046
Chandler Carruth631abd92011-06-16 06:47:06 +00001047void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001048 VisitExpr(S);
1049 ID.AddInteger(S->getTrait());
1050 VisitExpr(S->getQueriedExpression());
1051}
1052
Chandler Carruth631abd92011-06-16 06:47:06 +00001053void StmtProfiler::VisitDependentScopeDeclRefExpr(
1054 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001055 VisitExpr(S);
1056 VisitName(S->getDeclName());
1057 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001058 ID.AddBoolean(S->hasExplicitTemplateArgs());
1059 if (S->hasExplicitTemplateArgs())
1060 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001061}
1062
Chandler Carruth631abd92011-06-16 06:47:06 +00001063void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001064 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001065}
1066
Chandler Carruth631abd92011-06-16 06:47:06 +00001067void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1068 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001069 VisitExpr(S);
1070 VisitType(S->getTypeAsWritten());
1071}
1072
Chandler Carruth631abd92011-06-16 06:47:06 +00001073void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1074 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001075 ID.AddBoolean(S->isImplicitAccess());
1076 if (!S->isImplicitAccess()) {
1077 VisitExpr(S);
1078 ID.AddBoolean(S->isArrow());
1079 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001080 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001081 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001082 ID.AddBoolean(S->hasExplicitTemplateArgs());
1083 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001084 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1085}
1086
Chandler Carruth631abd92011-06-16 06:47:06 +00001087void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001088 ID.AddBoolean(S->isImplicitAccess());
1089 if (!S->isImplicitAccess()) {
1090 VisitExpr(S);
1091 ID.AddBoolean(S->isArrow());
1092 }
John McCall10eae182009-11-30 22:42:35 +00001093 VisitNestedNameSpecifier(S->getQualifier());
1094 VisitName(S->getMemberName());
1095 ID.AddBoolean(S->hasExplicitTemplateArgs());
1096 if (S->hasExplicitTemplateArgs())
1097 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001098}
1099
Chandler Carruth631abd92011-06-16 06:47:06 +00001100void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001101 VisitExpr(S);
1102}
1103
Chandler Carruth631abd92011-06-16 06:47:06 +00001104void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001105 VisitExpr(S);
1106}
1107
Chandler Carruth631abd92011-06-16 06:47:06 +00001108void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001109 VisitExpr(S);
1110 VisitDecl(S->getPack());
1111}
1112
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001113void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001114 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001115 VisitExpr(S);
1116 VisitDecl(S->getParameterPack());
1117 VisitTemplateArgument(S->getArgumentPack());
1118}
1119
John McCall7c454bb2011-07-15 05:09:51 +00001120void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1121 const SubstNonTypeTemplateParmExpr *E) {
1122 // Profile exactly as the replacement expression.
1123 Visit(E->getReplacement());
1124}
1125
Richard Smithb15fe3a2012-09-12 00:56:43 +00001126void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1127 VisitExpr(S);
1128 VisitDecl(S->getParameterPack());
1129 ID.AddInteger(S->getNumExpansions());
1130 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1131 VisitDecl(*I);
1132}
1133
Douglas Gregorfe314812011-06-21 17:03:29 +00001134void StmtProfiler::VisitMaterializeTemporaryExpr(
1135 const MaterializeTemporaryExpr *S) {
1136 VisitExpr(S);
1137}
1138
Chandler Carruth631abd92011-06-16 06:47:06 +00001139void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001140 VisitExpr(E);
1141}
1142
Chandler Carruth631abd92011-06-16 06:47:06 +00001143void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001144 VisitExpr(S);
1145}
1146
Patrick Beard0caa3942012-04-19 00:25:12 +00001147void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001148 VisitExpr(E);
1149}
1150
1151void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1152 VisitExpr(E);
1153}
1154
1155void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1156 VisitExpr(E);
1157}
1158
Chandler Carruth631abd92011-06-16 06:47:06 +00001159void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001160 VisitExpr(S);
1161 VisitType(S->getEncodedType());
1162}
1163
Chandler Carruth631abd92011-06-16 06:47:06 +00001164void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001165 VisitExpr(S);
1166 VisitName(S->getSelector());
1167}
1168
Chandler Carruth631abd92011-06-16 06:47:06 +00001169void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001170 VisitExpr(S);
1171 VisitDecl(S->getProtocol());
1172}
1173
Chandler Carruth631abd92011-06-16 06:47:06 +00001174void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001175 VisitExpr(S);
1176 VisitDecl(S->getDecl());
1177 ID.AddBoolean(S->isArrow());
1178 ID.AddBoolean(S->isFreeIvar());
1179}
1180
Chandler Carruth631abd92011-06-16 06:47:06 +00001181void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001182 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001183 if (S->isImplicitProperty()) {
1184 VisitDecl(S->getImplicitPropertyGetter());
1185 VisitDecl(S->getImplicitPropertySetter());
1186 } else {
1187 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001188 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001189 if (S->isSuperReceiver()) {
1190 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001191 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001192 }
Douglas Gregora7095092009-07-28 14:44:31 +00001193}
1194
Ted Kremeneke65b0862012-03-06 20:05:56 +00001195void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1196 VisitExpr(S);
1197 VisitDecl(S->getAtIndexMethodDecl());
1198 VisitDecl(S->setAtIndexMethodDecl());
1199}
1200
Chandler Carruth631abd92011-06-16 06:47:06 +00001201void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001202 VisitExpr(S);
1203 VisitName(S->getSelector());
1204 VisitDecl(S->getMethodDecl());
1205}
1206
Chandler Carruth631abd92011-06-16 06:47:06 +00001207void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001208 VisitExpr(S);
1209 ID.AddBoolean(S->isArrow());
1210}
1211
Ted Kremeneke65b0862012-03-06 20:05:56 +00001212void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1213 VisitExpr(S);
1214 ID.AddBoolean(S->getValue());
1215}
1216
Chandler Carruth631abd92011-06-16 06:47:06 +00001217void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1218 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001219 VisitExpr(S);
1220 ID.AddBoolean(S->shouldCopy());
1221}
1222
Chandler Carruth631abd92011-06-16 06:47:06 +00001223void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001224 VisitExplicitCastExpr(S);
1225 ID.AddBoolean(S->getBridgeKind());
1226}
1227
Chandler Carruth631abd92011-06-16 06:47:06 +00001228void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001229 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001230
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001231 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001232 if (const NonTypeTemplateParmDecl *NTTP =
1233 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001234 ID.AddInteger(NTTP->getDepth());
1235 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001236 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001237 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001238 return;
1239 }
Mike Stump11289f42009-09-09 15:08:12 +00001240
Chandler Carruth631abd92011-06-16 06:47:06 +00001241 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001242 // The Itanium C++ ABI uses the type, scope depth, and scope
1243 // index of a parameter when mangling expressions that involve
1244 // function parameters, so we will use the parameter's type for
1245 // establishing function parameter identity. That way, our
1246 // definition of "equivalent" (per C++ [temp.over.link]) is at
1247 // least as strong as the definition of "equivalent" used for
1248 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001249 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001250 ID.AddInteger(Parm->getFunctionScopeDepth());
1251 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001252 return;
1253 }
Mike Stump11289f42009-09-09 15:08:12 +00001254
Richard Smithd9a1cd82012-04-02 18:53:24 +00001255 if (const TemplateTypeParmDecl *TTP =
1256 dyn_cast<TemplateTypeParmDecl>(D)) {
1257 ID.AddInteger(TTP->getDepth());
1258 ID.AddInteger(TTP->getIndex());
1259 ID.AddBoolean(TTP->isParameterPack());
1260 return;
1261 }
1262
Chandler Carruth631abd92011-06-16 06:47:06 +00001263 if (const TemplateTemplateParmDecl *TTP =
1264 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001265 ID.AddInteger(TTP->getDepth());
1266 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001267 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001268 return;
1269 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001270 }
Mike Stump11289f42009-09-09 15:08:12 +00001271
Craig Topper36250ad2014-05-12 05:36:57 +00001272 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001273}
1274
1275void StmtProfiler::VisitType(QualType T) {
1276 if (Canonical)
1277 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001278
Douglas Gregor5c193b92009-07-28 00:33:38 +00001279 ID.AddPointer(T.getAsOpaquePtr());
1280}
1281
1282void StmtProfiler::VisitName(DeclarationName Name) {
1283 ID.AddPointer(Name.getAsOpaquePtr());
1284}
1285
1286void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1287 if (Canonical)
1288 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1289 ID.AddPointer(NNS);
1290}
1291
1292void StmtProfiler::VisitTemplateName(TemplateName Name) {
1293 if (Canonical)
1294 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001295
Douglas Gregor5c193b92009-07-28 00:33:38 +00001296 Name.Profile(ID);
1297}
1298
John McCall0ad16662009-10-29 08:12:44 +00001299void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001300 unsigned NumArgs) {
1301 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001302 for (unsigned I = 0; I != NumArgs; ++I)
1303 VisitTemplateArgument(Args[I].getArgument());
1304}
Mike Stump11289f42009-09-09 15:08:12 +00001305
John McCall0ad16662009-10-29 08:12:44 +00001306void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1307 // Mostly repetitive with TemplateArgument::Profile!
1308 ID.AddInteger(Arg.getKind());
1309 switch (Arg.getKind()) {
1310 case TemplateArgument::Null:
1311 break;
Mike Stump11289f42009-09-09 15:08:12 +00001312
John McCall0ad16662009-10-29 08:12:44 +00001313 case TemplateArgument::Type:
1314 VisitType(Arg.getAsType());
1315 break;
Mike Stump11289f42009-09-09 15:08:12 +00001316
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001317 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001318 case TemplateArgument::TemplateExpansion:
1319 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001320 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001321
John McCall0ad16662009-10-29 08:12:44 +00001322 case TemplateArgument::Declaration:
1323 VisitDecl(Arg.getAsDecl());
1324 break;
Mike Stump11289f42009-09-09 15:08:12 +00001325
Eli Friedmanb826a002012-09-26 02:36:12 +00001326 case TemplateArgument::NullPtr:
1327 VisitType(Arg.getNullPtrType());
1328 break;
1329
John McCall0ad16662009-10-29 08:12:44 +00001330 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001331 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001332 VisitType(Arg.getIntegralType());
1333 break;
Mike Stump11289f42009-09-09 15:08:12 +00001334
John McCall0ad16662009-10-29 08:12:44 +00001335 case TemplateArgument::Expression:
1336 Visit(Arg.getAsExpr());
1337 break;
Mike Stump11289f42009-09-09 15:08:12 +00001338
John McCall0ad16662009-10-29 08:12:44 +00001339 case TemplateArgument::Pack:
1340 const TemplateArgument *Pack = Arg.pack_begin();
1341 for (unsigned i = 0, e = Arg.pack_size(); i != e; ++i)
1342 VisitTemplateArgument(Pack[i]);
1343 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001344 }
1345}
1346
Jay Foad39c79802011-01-12 09:06:06 +00001347void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001348 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001349 StmtProfiler Profiler(ID, Context, Canonical);
1350 Profiler.Visit(this);
1351}