blob: 0e308861fca46f02a590f9fd05efc35d6f21ad2f [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 Bataev3778b602014-07-17 07:32:53 +0000276void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
277 if (C->getCondition())
278 Profiler->VisitStmt(C->getCondition());
279}
280
Alexey Bataev568a8332014-03-06 06:15:19 +0000281void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
282 if (C->getNumThreads())
283 Profiler->VisitStmt(C->getNumThreads());
284}
285
Alexey Bataev62c87d22014-03-21 04:51:18 +0000286void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
287 if (C->getSafelen())
288 Profiler->VisitStmt(C->getSafelen());
289}
290
Alexander Musman8bd31e62014-05-27 15:12:19 +0000291void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
292 if (C->getNumForLoops())
293 Profiler->VisitStmt(C->getNumForLoops());
294}
295
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000296void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000297
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000298void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
299
Alexey Bataev56dafe82014-06-20 07:16:17 +0000300void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
301 if (C->getChunkSize())
302 Profiler->VisitStmt(C->getChunkSize());
303}
304
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000305void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {}
306
Alexey Bataev236070f2014-06-20 11:19:47 +0000307void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
308
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000309void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
310
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000311void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
312
Alexey Bataev756c1962013-09-24 03:17:45 +0000313template<typename T>
314void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Aaron Ballman2205d2a2014-03-14 15:55:35 +0000315 for (auto *I : Node->varlists())
316 Profiler->VisitStmt(I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000317}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000318
319void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000320 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321}
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000322void OMPClauseProfiler::VisitOMPFirstprivateClause(
323 const OMPFirstprivateClause *C) {
324 VisitOMPClauseList(C);
325}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000326void
327OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
328 VisitOMPClauseList(C);
329}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000330void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000331 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000332}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000333void OMPClauseProfiler::VisitOMPReductionClause(
334 const OMPReductionClause *C) {
335 Profiler->VisitNestedNameSpecifier(
336 C->getQualifierLoc().getNestedNameSpecifier());
337 Profiler->VisitName(C->getNameInfo().getName());
338 VisitOMPClauseList(C);
339}
Alexander Musman8dba6642014-04-22 13:09:42 +0000340void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
341 VisitOMPClauseList(C);
342 Profiler->VisitStmt(C->getStep());
343}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000344void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
345 VisitOMPClauseList(C);
346 Profiler->VisitStmt(C->getAlignment());
347}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000348void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
349 VisitOMPClauseList(C);
350}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000351void
352OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
353 VisitOMPClauseList(C);
354}
Alexey Bataev6125da92014-07-21 11:26:11 +0000355void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
356 VisitOMPClauseList(C);
357}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000358}
359
360void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000361StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000362 VisitStmt(S);
363 OMPClauseProfiler P(this);
364 ArrayRef<OMPClause *> Clauses = S->clauses();
365 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
366 I != E; ++I)
367 if (*I)
368 P.Visit(*I);
369}
370
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000371void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
372 VisitOMPExecutableDirective(S);
373}
374
375void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
376 VisitOMPExecutableDirective(S);
377}
378
Alexey Bataevf29276e2014-06-18 04:14:57 +0000379void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
380 VisitOMPExecutableDirective(S);
381}
382
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000383void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
384 VisitOMPExecutableDirective(S);
385}
386
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000387void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
388 VisitOMPExecutableDirective(S);
389}
390
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000391void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
392 VisitOMPExecutableDirective(S);
393}
394
Alexander Musman80c22892014-07-17 08:54:58 +0000395void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
396 VisitOMPExecutableDirective(S);
397}
398
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000399void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
400 VisitOMPExecutableDirective(S);
401 VisitName(S->getDirectiveName().getName());
402}
403
Alexey Bataev4acb8592014-07-07 13:01:15 +0000404void
405StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
406 VisitOMPExecutableDirective(S);
407}
408
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000409void StmtProfiler::VisitOMPParallelSectionsDirective(
410 const OMPParallelSectionsDirective *S) {
411 VisitOMPExecutableDirective(S);
412}
413
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000414void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
415 VisitOMPExecutableDirective(S);
416}
417
Alexey Bataev68446b72014-07-18 07:47:19 +0000418void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
419 VisitOMPExecutableDirective(S);
420}
421
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000422void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
423 VisitOMPExecutableDirective(S);
424}
425
Alexey Bataev2df347a2014-07-18 10:17:07 +0000426void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
427 VisitOMPExecutableDirective(S);
428}
429
Alexey Bataev6125da92014-07-21 11:26:11 +0000430void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
431 VisitOMPExecutableDirective(S);
432}
433
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000434void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
435 VisitOMPExecutableDirective(S);
436}
437
Chandler Carruth631abd92011-06-16 06:47:06 +0000438void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000439 VisitStmt(S);
440}
441
Chandler Carruth631abd92011-06-16 06:47:06 +0000442void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000443 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000444 if (!Canonical)
445 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000446 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000447 if (!Canonical)
448 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000449}
450
Chandler Carruth631abd92011-06-16 06:47:06 +0000451void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000452 VisitExpr(S);
453 ID.AddInteger(S->getIdentType());
454}
455
Chandler Carruth631abd92011-06-16 06:47:06 +0000456void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000457 VisitExpr(S);
458 S->getValue().Profile(ID);
459}
460
Chandler Carruth631abd92011-06-16 06:47:06 +0000461void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000462 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000463 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000464 ID.AddInteger(S->getValue());
465}
466
Chandler Carruth631abd92011-06-16 06:47:06 +0000467void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000468 VisitExpr(S);
469 S->getValue().Profile(ID);
470 ID.AddBoolean(S->isExact());
471}
472
Chandler Carruth631abd92011-06-16 06:47:06 +0000473void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000474 VisitExpr(S);
475}
476
Chandler Carruth631abd92011-06-16 06:47:06 +0000477void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000478 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000479 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000480 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000481}
482
Chandler Carruth631abd92011-06-16 06:47:06 +0000483void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000484 VisitExpr(S);
485}
486
Chandler Carruth631abd92011-06-16 06:47:06 +0000487void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000488 VisitExpr(S);
489}
490
Chandler Carruth631abd92011-06-16 06:47:06 +0000491void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000492 VisitExpr(S);
493 ID.AddInteger(S->getOpcode());
494}
495
Chandler Carruth631abd92011-06-16 06:47:06 +0000496void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000497 VisitType(S->getTypeSourceInfo()->getType());
498 unsigned n = S->getNumComponents();
499 for (unsigned i = 0; i < n; ++i) {
500 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
501 ID.AddInteger(ON.getKind());
502 switch (ON.getKind()) {
503 case OffsetOfExpr::OffsetOfNode::Array:
504 // Expressions handled below.
505 break;
506
507 case OffsetOfExpr::OffsetOfNode::Field:
508 VisitDecl(ON.getField());
509 break;
510
511 case OffsetOfExpr::OffsetOfNode::Identifier:
512 ID.AddPointer(ON.getFieldName());
513 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000514
Douglas Gregord1702062010-04-29 00:18:15 +0000515 case OffsetOfExpr::OffsetOfNode::Base:
516 // These nodes are implicit, and therefore don't need profiling.
517 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000518 }
519 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000520
Douglas Gregor882211c2010-04-28 22:16:22 +0000521 VisitExpr(S);
522}
523
Chandler Carruth631abd92011-06-16 06:47:06 +0000524void
525StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000526 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000527 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000528 if (S->isArgumentType())
529 VisitType(S->getArgumentType());
530}
531
Chandler Carruth631abd92011-06-16 06:47:06 +0000532void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000533 VisitExpr(S);
534}
535
Chandler Carruth631abd92011-06-16 06:47:06 +0000536void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000537 VisitExpr(S);
538}
539
Chandler Carruth631abd92011-06-16 06:47:06 +0000540void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000541 VisitExpr(S);
542 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000543 if (!Canonical)
544 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000545 ID.AddBoolean(S->isArrow());
546}
547
Chandler Carruth631abd92011-06-16 06:47:06 +0000548void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000549 VisitExpr(S);
550 ID.AddBoolean(S->isFileScope());
551}
552
Chandler Carruth631abd92011-06-16 06:47:06 +0000553void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000554 VisitExpr(S);
555}
556
Chandler Carruth631abd92011-06-16 06:47:06 +0000557void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000558 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000559 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000560}
561
Chandler Carruth631abd92011-06-16 06:47:06 +0000562void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000563 VisitCastExpr(S);
564 VisitType(S->getTypeAsWritten());
565}
566
Chandler Carruth631abd92011-06-16 06:47:06 +0000567void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000568 VisitExplicitCastExpr(S);
569}
570
Chandler Carruth631abd92011-06-16 06:47:06 +0000571void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000572 VisitExpr(S);
573 ID.AddInteger(S->getOpcode());
574}
575
Chandler Carruth631abd92011-06-16 06:47:06 +0000576void
577StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000578 VisitBinaryOperator(S);
579}
580
Chandler Carruth631abd92011-06-16 06:47:06 +0000581void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000582 VisitExpr(S);
583}
584
Chandler Carruth631abd92011-06-16 06:47:06 +0000585void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000586 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000587 VisitExpr(S);
588}
589
Chandler Carruth631abd92011-06-16 06:47:06 +0000590void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000591 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000592 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000593}
594
Chandler Carruth631abd92011-06-16 06:47:06 +0000595void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000596 VisitExpr(S);
597}
598
Chandler Carruth631abd92011-06-16 06:47:06 +0000599void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000600 VisitExpr(S);
601}
602
Hal Finkelc4d7c822013-09-18 03:29:45 +0000603void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
604 VisitExpr(S);
605}
606
Chandler Carruth631abd92011-06-16 06:47:06 +0000607void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000608 VisitExpr(S);
609}
610
Chandler Carruth631abd92011-06-16 06:47:06 +0000611void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000612 VisitExpr(S);
613}
614
Chandler Carruth631abd92011-06-16 06:47:06 +0000615void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000616 VisitExpr(S);
617}
618
Chandler Carruth631abd92011-06-16 06:47:06 +0000619void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000620 if (S->getSyntacticForm()) {
621 VisitInitListExpr(S->getSyntacticForm());
622 return;
623 }
Mike Stump11289f42009-09-09 15:08:12 +0000624
Douglas Gregor5c193b92009-07-28 00:33:38 +0000625 VisitExpr(S);
626}
627
Chandler Carruth631abd92011-06-16 06:47:06 +0000628void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000629 VisitExpr(S);
630 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000631 for (DesignatedInitExpr::const_designators_iterator D =
632 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000633 D != DEnd; ++D) {
634 if (D->isFieldDesignator()) {
635 ID.AddInteger(0);
636 VisitName(D->getFieldName());
637 continue;
638 }
Mike Stump11289f42009-09-09 15:08:12 +0000639
Douglas Gregor5c193b92009-07-28 00:33:38 +0000640 if (D->isArrayDesignator()) {
641 ID.AddInteger(1);
642 } else {
643 assert(D->isArrayRangeDesignator());
644 ID.AddInteger(2);
645 }
646 ID.AddInteger(D->getFirstExprIndex());
647 }
648}
649
Chandler Carruth631abd92011-06-16 06:47:06 +0000650void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000651 VisitExpr(S);
652}
653
Chandler Carruth631abd92011-06-16 06:47:06 +0000654void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000655 VisitExpr(S);
656 VisitName(&S->getAccessor());
657}
658
Chandler Carruth631abd92011-06-16 06:47:06 +0000659void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000660 VisitExpr(S);
661 VisitDecl(S->getBlockDecl());
662}
663
Chandler Carruth631abd92011-06-16 06:47:06 +0000664void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000665 VisitExpr(S);
666 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
667 QualType T = S->getAssocType(i);
668 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000669 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000670 else
671 VisitType(T);
672 VisitExpr(S->getAssocExpr(i));
673 }
674}
675
John McCallfe96e0b2011-11-06 09:01:30 +0000676void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
677 VisitExpr(S);
678 for (PseudoObjectExpr::const_semantics_iterator
679 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
680 // Normally, we would not profile the source expressions of OVEs.
681 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
682 Visit(OVE->getSourceExpr());
683}
684
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000685void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
686 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000687 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000688}
689
Chandler Carruth631abd92011-06-16 06:47:06 +0000690static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000691 UnaryOperatorKind &UnaryOp,
692 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000693 switch (S->getOperator()) {
694 case OO_None:
695 case OO_New:
696 case OO_Delete:
697 case OO_Array_New:
698 case OO_Array_Delete:
699 case OO_Arrow:
700 case OO_Call:
701 case OO_Conditional:
702 case NUM_OVERLOADED_OPERATORS:
703 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000704
705 case OO_Plus:
706 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000707 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000708 return Stmt::UnaryOperatorClass;
709 }
710
John McCalle3027922010-08-25 11:45:40 +0000711 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000712 return Stmt::BinaryOperatorClass;
713
714 case OO_Minus:
715 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000716 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000717 return Stmt::UnaryOperatorClass;
718 }
719
John McCalle3027922010-08-25 11:45:40 +0000720 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000721 return Stmt::BinaryOperatorClass;
722
723 case OO_Star:
724 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000725 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000726 return Stmt::UnaryOperatorClass;
727 }
728
Richard Smithf15acc52014-06-05 22:43:40 +0000729 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000730 return Stmt::BinaryOperatorClass;
731
732 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000733 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000734 return Stmt::BinaryOperatorClass;
735
736 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000737 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000738 return Stmt::BinaryOperatorClass;
739
740 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000741 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000742 return Stmt::BinaryOperatorClass;
743
744 case OO_Amp:
745 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000746 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000747 return Stmt::UnaryOperatorClass;
748 }
749
John McCalle3027922010-08-25 11:45:40 +0000750 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000751 return Stmt::BinaryOperatorClass;
752
753 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000754 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000755 return Stmt::BinaryOperatorClass;
756
757 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000758 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000759 return Stmt::UnaryOperatorClass;
760
761 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000762 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000763 return Stmt::UnaryOperatorClass;
764
765 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000766 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000767 return Stmt::BinaryOperatorClass;
768
769 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000770 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000771 return Stmt::BinaryOperatorClass;
772
773 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000774 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000775 return Stmt::BinaryOperatorClass;
776
777 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000778 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000779 return Stmt::CompoundAssignOperatorClass;
780
781 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000782 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000783 return Stmt::CompoundAssignOperatorClass;
784
785 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000786 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000787 return Stmt::CompoundAssignOperatorClass;
788
789 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000790 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000791 return Stmt::CompoundAssignOperatorClass;
792
793 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000794 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000795 return Stmt::CompoundAssignOperatorClass;
796
797 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000798 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000799 return Stmt::CompoundAssignOperatorClass;
800
801 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000802 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000803 return Stmt::CompoundAssignOperatorClass;
804
805 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000806 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000807 return Stmt::CompoundAssignOperatorClass;
808
809 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000810 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000811 return Stmt::BinaryOperatorClass;
812
813 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000814 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000815 return Stmt::BinaryOperatorClass;
816
817 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000818 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000819 return Stmt::CompoundAssignOperatorClass;
820
821 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000822 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000823 return Stmt::CompoundAssignOperatorClass;
824
825 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000826 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000827 return Stmt::BinaryOperatorClass;
828
829 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000830 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000831 return Stmt::BinaryOperatorClass;
832
833 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000834 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000835 return Stmt::BinaryOperatorClass;
836
837 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000838 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000839 return Stmt::BinaryOperatorClass;
840
841 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000842 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000843 return Stmt::BinaryOperatorClass;
844
845 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000846 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000847 return Stmt::BinaryOperatorClass;
848
849 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000850 UnaryOp = S->getNumArgs() == 1? UO_PreInc
851 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000852 return Stmt::UnaryOperatorClass;
853
854 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000855 UnaryOp = S->getNumArgs() == 1? UO_PreDec
856 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000857 return Stmt::UnaryOperatorClass;
858
859 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000860 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000861 return Stmt::BinaryOperatorClass;
862
863
864 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000865 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000866 return Stmt::BinaryOperatorClass;
867
868 case OO_Subscript:
869 return Stmt::ArraySubscriptExprClass;
870 }
871
872 llvm_unreachable("Invalid overloaded operator expression");
873}
Richard Smithf15acc52014-06-05 22:43:40 +0000874
Douglas Gregore9ceb312010-05-19 04:13:23 +0000875
Chandler Carruth631abd92011-06-16 06:47:06 +0000876void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000877 if (S->isTypeDependent()) {
878 // Type-dependent operator calls are profiled like their underlying
879 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000880 UnaryOperatorKind UnaryOp = UO_Extension;
881 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000882 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +0000883
Douglas Gregore9ceb312010-05-19 04:13:23 +0000884 ID.AddInteger(SC);
885 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
886 Visit(S->getArg(I));
887 if (SC == Stmt::UnaryOperatorClass)
888 ID.AddInteger(UnaryOp);
889 else if (SC == Stmt::BinaryOperatorClass ||
890 SC == Stmt::CompoundAssignOperatorClass)
891 ID.AddInteger(BinaryOp);
892 else
893 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +0000894
Douglas Gregore9ceb312010-05-19 04:13:23 +0000895 return;
896 }
Richard Smithf15acc52014-06-05 22:43:40 +0000897
Douglas Gregor5c193b92009-07-28 00:33:38 +0000898 VisitCallExpr(S);
899 ID.AddInteger(S->getOperator());
900}
901
Chandler Carruth631abd92011-06-16 06:47:06 +0000902void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000903 VisitCallExpr(S);
904}
905
Chandler Carruth631abd92011-06-16 06:47:06 +0000906void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000907 VisitCallExpr(S);
908}
909
Chandler Carruth631abd92011-06-16 06:47:06 +0000910void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000911 VisitExpr(S);
912}
913
Chandler Carruth631abd92011-06-16 06:47:06 +0000914void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000915 VisitExplicitCastExpr(S);
916}
917
Chandler Carruth631abd92011-06-16 06:47:06 +0000918void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000919 VisitCXXNamedCastExpr(S);
920}
921
Chandler Carruth631abd92011-06-16 06:47:06 +0000922void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000923 VisitCXXNamedCastExpr(S);
924}
925
Chandler Carruth631abd92011-06-16 06:47:06 +0000926void
927StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000928 VisitCXXNamedCastExpr(S);
929}
930
Chandler Carruth631abd92011-06-16 06:47:06 +0000931void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000932 VisitCXXNamedCastExpr(S);
933}
934
Richard Smithc67fdd42012-03-07 08:35:16 +0000935void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
936 VisitCallExpr(S);
937}
938
Chandler Carruth631abd92011-06-16 06:47:06 +0000939void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000940 VisitExpr(S);
941 ID.AddBoolean(S->getValue());
942}
943
Chandler Carruth631abd92011-06-16 06:47:06 +0000944void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000945 VisitExpr(S);
946}
947
Richard Smithcc1b96d2013-06-12 22:31:48 +0000948void StmtProfiler::VisitCXXStdInitializerListExpr(
949 const CXXStdInitializerListExpr *S) {
950 VisitExpr(S);
951}
952
Chandler Carruth631abd92011-06-16 06:47:06 +0000953void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000954 VisitExpr(S);
955 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000956 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000957}
958
Chandler Carruth631abd92011-06-16 06:47:06 +0000959void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000960 VisitExpr(S);
961 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000962 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000963}
964
John McCall5e77d762013-04-16 07:28:30 +0000965void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
966 VisitExpr(S);
967 VisitDecl(S->getPropertyDecl());
968}
969
Chandler Carruth631abd92011-06-16 06:47:06 +0000970void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000971 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000972 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000973}
974
Chandler Carruth631abd92011-06-16 06:47:06 +0000975void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000976 VisitExpr(S);
977}
978
Chandler Carruth631abd92011-06-16 06:47:06 +0000979void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000980 VisitExpr(S);
981 VisitDecl(S->getParam());
982}
983
Richard Smith852c9db2013-04-20 22:23:05 +0000984void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
985 VisitExpr(S);
986 VisitDecl(S->getField());
987}
988
Chandler Carruth631abd92011-06-16 06:47:06 +0000989void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000990 VisitExpr(S);
991 VisitDecl(
992 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
993}
994
Chandler Carruth631abd92011-06-16 06:47:06 +0000995void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000996 VisitExpr(S);
997 VisitDecl(S->getConstructor());
998 ID.AddBoolean(S->isElidable());
999}
1000
Chandler Carruth631abd92011-06-16 06:47:06 +00001001void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001002 VisitExplicitCastExpr(S);
1003}
1004
Chandler Carruth631abd92011-06-16 06:47:06 +00001005void
1006StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001007 VisitCXXConstructExpr(S);
1008}
1009
Chandler Carruth631abd92011-06-16 06:47:06 +00001010void
Douglas Gregore31e6062012-02-07 10:09:13 +00001011StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1012 VisitExpr(S);
1013 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1014 CEnd = S->explicit_capture_end();
1015 C != CEnd; ++C) {
1016 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001017 switch (C->getCaptureKind()) {
1018 case LCK_This:
1019 break;
1020 case LCK_ByRef:
1021 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001022 VisitDecl(C->getCapturedVar());
1023 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001024 break;
Douglas Gregore31e6062012-02-07 10:09:13 +00001025 }
1026 }
1027 // Note: If we actually needed to be able to match lambda
1028 // expressions, we would have to consider parameters and return type
1029 // here, among other things.
1030 VisitStmt(S->getBody());
1031}
1032
1033void
Chandler Carruth631abd92011-06-16 06:47:06 +00001034StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001035 VisitExpr(S);
1036}
1037
Chandler Carruth631abd92011-06-16 06:47:06 +00001038void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001039 VisitExpr(S);
1040 ID.AddBoolean(S->isGlobalDelete());
1041 ID.AddBoolean(S->isArrayForm());
1042 VisitDecl(S->getOperatorDelete());
1043}
1044
1045
Chandler Carruth631abd92011-06-16 06:47:06 +00001046void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001047 VisitExpr(S);
1048 VisitType(S->getAllocatedType());
1049 VisitDecl(S->getOperatorNew());
1050 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001051 ID.AddBoolean(S->isArray());
1052 ID.AddInteger(S->getNumPlacementArgs());
1053 ID.AddBoolean(S->isGlobalNew());
1054 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001055 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001056}
1057
Chandler Carruth631abd92011-06-16 06:47:06 +00001058void
1059StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001060 VisitExpr(S);
1061 ID.AddBoolean(S->isArrow());
1062 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001063 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001064 if (S->getScopeTypeInfo())
1065 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001066 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001067 if (S->getDestroyedTypeInfo())
1068 VisitType(S->getDestroyedType());
1069 else
1070 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001071}
1072
Chandler Carruth631abd92011-06-16 06:47:06 +00001073void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001074 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001075 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001076 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001077 ID.AddBoolean(S->hasExplicitTemplateArgs());
1078 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001079 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1080 S->getExplicitTemplateArgs().NumTemplateArgs);
1081}
1082
1083void
Chandler Carruth631abd92011-06-16 06:47:06 +00001084StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001085 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001086}
1087
Douglas Gregor29c42f22012-02-24 07:38:34 +00001088void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1089 VisitExpr(S);
1090 ID.AddInteger(S->getTrait());
1091 ID.AddInteger(S->getNumArgs());
1092 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1093 VisitType(S->getArg(I)->getType());
1094}
1095
Chandler Carruth631abd92011-06-16 06:47:06 +00001096void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001097 VisitExpr(S);
1098 ID.AddInteger(S->getTrait());
1099 VisitType(S->getQueriedType());
1100}
1101
Chandler Carruth631abd92011-06-16 06:47:06 +00001102void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001103 VisitExpr(S);
1104 ID.AddInteger(S->getTrait());
1105 VisitExpr(S->getQueriedExpression());
1106}
1107
Chandler Carruth631abd92011-06-16 06:47:06 +00001108void StmtProfiler::VisitDependentScopeDeclRefExpr(
1109 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001110 VisitExpr(S);
1111 VisitName(S->getDeclName());
1112 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001113 ID.AddBoolean(S->hasExplicitTemplateArgs());
1114 if (S->hasExplicitTemplateArgs())
1115 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001116}
1117
Chandler Carruth631abd92011-06-16 06:47:06 +00001118void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001119 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001120}
1121
Chandler Carruth631abd92011-06-16 06:47:06 +00001122void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1123 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001124 VisitExpr(S);
1125 VisitType(S->getTypeAsWritten());
1126}
1127
Chandler Carruth631abd92011-06-16 06:47:06 +00001128void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1129 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001130 ID.AddBoolean(S->isImplicitAccess());
1131 if (!S->isImplicitAccess()) {
1132 VisitExpr(S);
1133 ID.AddBoolean(S->isArrow());
1134 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001135 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001136 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001137 ID.AddBoolean(S->hasExplicitTemplateArgs());
1138 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001139 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1140}
1141
Chandler Carruth631abd92011-06-16 06:47:06 +00001142void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001143 ID.AddBoolean(S->isImplicitAccess());
1144 if (!S->isImplicitAccess()) {
1145 VisitExpr(S);
1146 ID.AddBoolean(S->isArrow());
1147 }
John McCall10eae182009-11-30 22:42:35 +00001148 VisitNestedNameSpecifier(S->getQualifier());
1149 VisitName(S->getMemberName());
1150 ID.AddBoolean(S->hasExplicitTemplateArgs());
1151 if (S->hasExplicitTemplateArgs())
1152 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001153}
1154
Chandler Carruth631abd92011-06-16 06:47:06 +00001155void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001156 VisitExpr(S);
1157}
1158
Chandler Carruth631abd92011-06-16 06:47:06 +00001159void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001160 VisitExpr(S);
1161}
1162
Chandler Carruth631abd92011-06-16 06:47:06 +00001163void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001164 VisitExpr(S);
1165 VisitDecl(S->getPack());
1166}
1167
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001168void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001169 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001170 VisitExpr(S);
1171 VisitDecl(S->getParameterPack());
1172 VisitTemplateArgument(S->getArgumentPack());
1173}
1174
John McCall7c454bb2011-07-15 05:09:51 +00001175void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1176 const SubstNonTypeTemplateParmExpr *E) {
1177 // Profile exactly as the replacement expression.
1178 Visit(E->getReplacement());
1179}
1180
Richard Smithb15fe3a2012-09-12 00:56:43 +00001181void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1182 VisitExpr(S);
1183 VisitDecl(S->getParameterPack());
1184 ID.AddInteger(S->getNumExpansions());
1185 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1186 VisitDecl(*I);
1187}
1188
Douglas Gregorfe314812011-06-21 17:03:29 +00001189void StmtProfiler::VisitMaterializeTemporaryExpr(
1190 const MaterializeTemporaryExpr *S) {
1191 VisitExpr(S);
1192}
1193
Chandler Carruth631abd92011-06-16 06:47:06 +00001194void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001195 VisitExpr(E);
1196}
1197
Chandler Carruth631abd92011-06-16 06:47:06 +00001198void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001199 VisitExpr(S);
1200}
1201
Patrick Beard0caa3942012-04-19 00:25:12 +00001202void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001203 VisitExpr(E);
1204}
1205
1206void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1207 VisitExpr(E);
1208}
1209
1210void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1211 VisitExpr(E);
1212}
1213
Chandler Carruth631abd92011-06-16 06:47:06 +00001214void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001215 VisitExpr(S);
1216 VisitType(S->getEncodedType());
1217}
1218
Chandler Carruth631abd92011-06-16 06:47:06 +00001219void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001220 VisitExpr(S);
1221 VisitName(S->getSelector());
1222}
1223
Chandler Carruth631abd92011-06-16 06:47:06 +00001224void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001225 VisitExpr(S);
1226 VisitDecl(S->getProtocol());
1227}
1228
Chandler Carruth631abd92011-06-16 06:47:06 +00001229void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001230 VisitExpr(S);
1231 VisitDecl(S->getDecl());
1232 ID.AddBoolean(S->isArrow());
1233 ID.AddBoolean(S->isFreeIvar());
1234}
1235
Chandler Carruth631abd92011-06-16 06:47:06 +00001236void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001237 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001238 if (S->isImplicitProperty()) {
1239 VisitDecl(S->getImplicitPropertyGetter());
1240 VisitDecl(S->getImplicitPropertySetter());
1241 } else {
1242 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001243 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001244 if (S->isSuperReceiver()) {
1245 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001246 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001247 }
Douglas Gregora7095092009-07-28 14:44:31 +00001248}
1249
Ted Kremeneke65b0862012-03-06 20:05:56 +00001250void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1251 VisitExpr(S);
1252 VisitDecl(S->getAtIndexMethodDecl());
1253 VisitDecl(S->setAtIndexMethodDecl());
1254}
1255
Chandler Carruth631abd92011-06-16 06:47:06 +00001256void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001257 VisitExpr(S);
1258 VisitName(S->getSelector());
1259 VisitDecl(S->getMethodDecl());
1260}
1261
Chandler Carruth631abd92011-06-16 06:47:06 +00001262void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001263 VisitExpr(S);
1264 ID.AddBoolean(S->isArrow());
1265}
1266
Ted Kremeneke65b0862012-03-06 20:05:56 +00001267void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1268 VisitExpr(S);
1269 ID.AddBoolean(S->getValue());
1270}
1271
Chandler Carruth631abd92011-06-16 06:47:06 +00001272void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1273 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001274 VisitExpr(S);
1275 ID.AddBoolean(S->shouldCopy());
1276}
1277
Chandler Carruth631abd92011-06-16 06:47:06 +00001278void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001279 VisitExplicitCastExpr(S);
1280 ID.AddBoolean(S->getBridgeKind());
1281}
1282
Chandler Carruth631abd92011-06-16 06:47:06 +00001283void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001284 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001285
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001286 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001287 if (const NonTypeTemplateParmDecl *NTTP =
1288 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001289 ID.AddInteger(NTTP->getDepth());
1290 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001291 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001292 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001293 return;
1294 }
Mike Stump11289f42009-09-09 15:08:12 +00001295
Chandler Carruth631abd92011-06-16 06:47:06 +00001296 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001297 // The Itanium C++ ABI uses the type, scope depth, and scope
1298 // index of a parameter when mangling expressions that involve
1299 // function parameters, so we will use the parameter's type for
1300 // establishing function parameter identity. That way, our
1301 // definition of "equivalent" (per C++ [temp.over.link]) is at
1302 // least as strong as the definition of "equivalent" used for
1303 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001304 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001305 ID.AddInteger(Parm->getFunctionScopeDepth());
1306 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001307 return;
1308 }
Mike Stump11289f42009-09-09 15:08:12 +00001309
Richard Smithd9a1cd82012-04-02 18:53:24 +00001310 if (const TemplateTypeParmDecl *TTP =
1311 dyn_cast<TemplateTypeParmDecl>(D)) {
1312 ID.AddInteger(TTP->getDepth());
1313 ID.AddInteger(TTP->getIndex());
1314 ID.AddBoolean(TTP->isParameterPack());
1315 return;
1316 }
1317
Chandler Carruth631abd92011-06-16 06:47:06 +00001318 if (const TemplateTemplateParmDecl *TTP =
1319 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001320 ID.AddInteger(TTP->getDepth());
1321 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001322 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001323 return;
1324 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001325 }
Mike Stump11289f42009-09-09 15:08:12 +00001326
Craig Topper36250ad2014-05-12 05:36:57 +00001327 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001328}
1329
1330void StmtProfiler::VisitType(QualType T) {
1331 if (Canonical)
1332 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001333
Douglas Gregor5c193b92009-07-28 00:33:38 +00001334 ID.AddPointer(T.getAsOpaquePtr());
1335}
1336
1337void StmtProfiler::VisitName(DeclarationName Name) {
1338 ID.AddPointer(Name.getAsOpaquePtr());
1339}
1340
1341void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1342 if (Canonical)
1343 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1344 ID.AddPointer(NNS);
1345}
1346
1347void StmtProfiler::VisitTemplateName(TemplateName Name) {
1348 if (Canonical)
1349 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001350
Douglas Gregor5c193b92009-07-28 00:33:38 +00001351 Name.Profile(ID);
1352}
1353
John McCall0ad16662009-10-29 08:12:44 +00001354void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001355 unsigned NumArgs) {
1356 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001357 for (unsigned I = 0; I != NumArgs; ++I)
1358 VisitTemplateArgument(Args[I].getArgument());
1359}
Mike Stump11289f42009-09-09 15:08:12 +00001360
John McCall0ad16662009-10-29 08:12:44 +00001361void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1362 // Mostly repetitive with TemplateArgument::Profile!
1363 ID.AddInteger(Arg.getKind());
1364 switch (Arg.getKind()) {
1365 case TemplateArgument::Null:
1366 break;
Mike Stump11289f42009-09-09 15:08:12 +00001367
John McCall0ad16662009-10-29 08:12:44 +00001368 case TemplateArgument::Type:
1369 VisitType(Arg.getAsType());
1370 break;
Mike Stump11289f42009-09-09 15:08:12 +00001371
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001372 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001373 case TemplateArgument::TemplateExpansion:
1374 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001375 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001376
John McCall0ad16662009-10-29 08:12:44 +00001377 case TemplateArgument::Declaration:
1378 VisitDecl(Arg.getAsDecl());
1379 break;
Mike Stump11289f42009-09-09 15:08:12 +00001380
Eli Friedmanb826a002012-09-26 02:36:12 +00001381 case TemplateArgument::NullPtr:
1382 VisitType(Arg.getNullPtrType());
1383 break;
1384
John McCall0ad16662009-10-29 08:12:44 +00001385 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001386 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001387 VisitType(Arg.getIntegralType());
1388 break;
Mike Stump11289f42009-09-09 15:08:12 +00001389
John McCall0ad16662009-10-29 08:12:44 +00001390 case TemplateArgument::Expression:
1391 Visit(Arg.getAsExpr());
1392 break;
Mike Stump11289f42009-09-09 15:08:12 +00001393
John McCall0ad16662009-10-29 08:12:44 +00001394 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001395 for (const auto &P : Arg.pack_elements())
1396 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001397 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001398 }
1399}
1400
Jay Foad39c79802011-01-12 09:06:06 +00001401void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001402 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001403 StmtProfiler Profiler(ID, Context, Canonical);
1404 Profiler.Visit(this);
1405}