blob: d106969efe647c51a3410a032ae24991d746175a [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"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000021#include "clang/AST/ExprOpenMP.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000022#include "clang/AST/StmtVisitor.h"
23#include "llvm/ADT/FoldingSet.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000024using namespace clang;
25
26namespace {
Chandler Carruth631abd92011-06-16 06:47:06 +000027 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Douglas Gregor5c193b92009-07-28 00:33:38 +000028 llvm::FoldingSetNodeID &ID;
Jay Foad39c79802011-01-12 09:06:06 +000029 const ASTContext &Context;
Douglas Gregor5c193b92009-07-28 00:33:38 +000030 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000031
Douglas Gregor5c193b92009-07-28 00:33:38 +000032 public:
Jay Foad39c79802011-01-12 09:06:06 +000033 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump11289f42009-09-09 15:08:12 +000034 bool Canonical)
Douglas Gregor5c193b92009-07-28 00:33:38 +000035 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump11289f42009-09-09 15:08:12 +000036
Chandler Carruth631abd92011-06-16 06:47:06 +000037 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000038
Chandler Carruth631abd92011-06-16 06:47:06 +000039#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000040#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregor5c193b92009-07-28 00:33:38 +000042 /// \brief Visit a declaration that is referenced within an expression
43 /// or statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000044 void VisitDecl(const Decl *D);
Mike Stump11289f42009-09-09 15:08:12 +000045
46 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000047 /// statement.
48 void VisitType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +000049
Douglas Gregor5c193b92009-07-28 00:33:38 +000050 /// \brief Visit a name that occurs within an expression or statement.
51 void VisitName(DeclarationName Name);
Mike Stump11289f42009-09-09 15:08:12 +000052
Douglas Gregor5c193b92009-07-28 00:33:38 +000053 /// \brief Visit a nested-name-specifier that occurs within an expression
54 /// or statement.
55 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump11289f42009-09-09 15:08:12 +000056
Douglas Gregor5c193b92009-07-28 00:33:38 +000057 /// \brief Visit a template name that occurs within an expression or
58 /// statement.
59 void VisitTemplateName(TemplateName Name);
Mike Stump11289f42009-09-09 15:08:12 +000060
Douglas Gregor5c193b92009-07-28 00:33:38 +000061 /// \brief Visit template arguments that occur within an expression or
62 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000063 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
64 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000065
66 /// \brief Visit a single template argument.
67 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000068 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +000069}
Douglas Gregor5c193b92009-07-28 00:33:38 +000070
Chandler Carruth631abd92011-06-16 06:47:06 +000071void StmtProfiler::VisitStmt(const Stmt *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +000072 ID.AddInteger(S->getStmtClass());
Benjamin Kramer642f1732015-07-02 21:03:14 +000073 for (const Stmt *SubStmt : S->children()) {
74 if (SubStmt)
75 Visit(SubStmt);
Peter Collingbournecdb9f302012-03-01 16:34:31 +000076 else
77 ID.AddInteger(0);
78 }
Douglas Gregor5c193b92009-07-28 00:33:38 +000079}
80
Chandler Carruth631abd92011-06-16 06:47:06 +000081void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000082 VisitStmt(S);
Aaron Ballman535bbcc2014-03-14 17:01:24 +000083 for (const auto *D : S->decls())
84 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +000085}
86
Chandler Carruth631abd92011-06-16 06:47:06 +000087void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000088 VisitStmt(S);
89}
90
Chandler Carruth631abd92011-06-16 06:47:06 +000091void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000092 VisitStmt(S);
93}
94
Chandler Carruth631abd92011-06-16 06:47:06 +000095void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000096 VisitStmt(S);
97}
98
Chandler Carruth631abd92011-06-16 06:47:06 +000099void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000100 VisitStmt(S);
101}
102
Chandler Carruth631abd92011-06-16 06:47:06 +0000103void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000104 VisitStmt(S);
105}
106
Chandler Carruth631abd92011-06-16 06:47:06 +0000107void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000108 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000109 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000110}
111
Richard Smithc202b282012-04-14 00:33:13 +0000112void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
113 VisitStmt(S);
114 // TODO: maybe visit attributes?
115}
116
Chandler Carruth631abd92011-06-16 06:47:06 +0000117void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000118 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000119 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000120}
121
Chandler Carruth631abd92011-06-16 06:47:06 +0000122void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000123 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000124 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000125}
126
Chandler Carruth631abd92011-06-16 06:47:06 +0000127void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000128 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000129 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000130}
131
Chandler Carruth631abd92011-06-16 06:47:06 +0000132void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000133 VisitStmt(S);
134}
135
Chandler Carruth631abd92011-06-16 06:47:06 +0000136void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000137 VisitStmt(S);
138}
139
Chandler Carruth631abd92011-06-16 06:47:06 +0000140void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000141 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000142 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000143}
144
Chandler Carruth631abd92011-06-16 06:47:06 +0000145void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000146 VisitStmt(S);
147}
148
Chandler Carruth631abd92011-06-16 06:47:06 +0000149void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000150 VisitStmt(S);
151}
152
Chandler Carruth631abd92011-06-16 06:47:06 +0000153void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000154 VisitStmt(S);
155}
156
Chandler Carruth631abd92011-06-16 06:47:06 +0000157void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000158 VisitStmt(S);
159}
160
Chad Rosierde70e0e2012-08-25 00:11:56 +0000161void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000162 VisitStmt(S);
163 ID.AddBoolean(S->isVolatile());
164 ID.AddBoolean(S->isSimple());
165 VisitStringLiteral(S->getAsmString());
166 ID.AddInteger(S->getNumOutputs());
167 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
168 ID.AddString(S->getOutputName(I));
169 VisitStringLiteral(S->getOutputConstraintLiteral(I));
170 }
171 ID.AddInteger(S->getNumInputs());
172 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
173 ID.AddString(S->getInputName(I));
174 VisitStringLiteral(S->getInputConstraintLiteral(I));
175 }
176 ID.AddInteger(S->getNumClobbers());
177 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000178 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor44882592009-07-28 15:27:13 +0000179}
180
Chad Rosier32503022012-06-11 20:47:18 +0000181void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
182 // FIXME: Implement MS style inline asm statement profiler.
183 VisitStmt(S);
184}
185
Chandler Carruth631abd92011-06-16 06:47:06 +0000186void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000187 VisitStmt(S);
188 VisitType(S->getCaughtType());
189}
190
Chandler Carruth631abd92011-06-16 06:47:06 +0000191void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000192 VisitStmt(S);
193}
194
Chandler Carruth631abd92011-06-16 06:47:06 +0000195void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000196 VisitStmt(S);
197}
198
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000199void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
200 VisitStmt(S);
201 ID.AddBoolean(S->isIfExists());
202 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
203 VisitName(S->getNameInfo().getName());
204}
205
Chandler Carruth631abd92011-06-16 06:47:06 +0000206void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000207 VisitStmt(S);
208}
209
Chandler Carruth631abd92011-06-16 06:47:06 +0000210void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000211 VisitStmt(S);
212}
213
Chandler Carruth631abd92011-06-16 06:47:06 +0000214void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000215 VisitStmt(S);
216}
217
Nico Weber9b982072014-07-07 00:12:30 +0000218void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
219 VisitStmt(S);
220}
221
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000222void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
223 VisitStmt(S);
224}
225
Chandler Carruth631abd92011-06-16 06:47:06 +0000226void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000227 VisitStmt(S);
228}
229
Chandler Carruth631abd92011-06-16 06:47:06 +0000230void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000231 VisitStmt(S);
232 ID.AddBoolean(S->hasEllipsis());
233 if (S->getCatchParamDecl())
234 VisitType(S->getCatchParamDecl()->getType());
235}
236
Chandler Carruth631abd92011-06-16 06:47:06 +0000237void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000238 VisitStmt(S);
239}
240
Chandler Carruth631abd92011-06-16 06:47:06 +0000241void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000242 VisitStmt(S);
243}
244
Chandler Carruth631abd92011-06-16 06:47:06 +0000245void
246StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000247 VisitStmt(S);
248}
249
Chandler Carruth631abd92011-06-16 06:47:06 +0000250void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000251 VisitStmt(S);
252}
253
Chandler Carruth631abd92011-06-16 06:47:06 +0000254void
255StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000256 VisitStmt(S);
257}
258
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000259namespace {
260class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
261 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000262 /// \brief Process clauses with list of variables.
263 template <typename T>
264 void VisitOMPClauseList(T *Node);
NAKAMURA Takumiaa13f942015-12-09 07:52:46 +0000265
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000266public:
267 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
268#define OPENMP_CLAUSE(Name, Class) \
269 void Visit##Class(const Class *C);
270#include "clang/Basic/OpenMPKinds.def"
Alexey Bataev3392d762016-02-16 11:18:12 +0000271 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000272};
273
Alexey Bataev3392d762016-02-16 11:18:12 +0000274void OMPClauseProfiler::VistOMPClauseWithPreInit(
275 const OMPClauseWithPreInit *C) {
276 if (auto *S = C->getPreInitStmt())
277 Profiler->VisitStmt(S);
278}
279
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000280void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
281 if (C->getCondition())
282 Profiler->VisitStmt(C->getCondition());
283}
284
Alexey Bataev3778b602014-07-17 07:32:53 +0000285void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
286 if (C->getCondition())
287 Profiler->VisitStmt(C->getCondition());
288}
289
Alexey Bataev568a8332014-03-06 06:15:19 +0000290void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
291 if (C->getNumThreads())
292 Profiler->VisitStmt(C->getNumThreads());
293}
294
Alexey Bataev62c87d22014-03-21 04:51:18 +0000295void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
296 if (C->getSafelen())
297 Profiler->VisitStmt(C->getSafelen());
298}
299
Alexey Bataev66b15b52015-08-21 11:14:16 +0000300void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
301 if (C->getSimdlen())
302 Profiler->VisitStmt(C->getSimdlen());
303}
304
Alexander Musman8bd31e62014-05-27 15:12:19 +0000305void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
306 if (C->getNumForLoops())
307 Profiler->VisitStmt(C->getNumForLoops());
308}
309
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000310void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000311
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000312void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
313
Alexey Bataev56dafe82014-06-20 07:16:17 +0000314void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000315 VistOMPClauseWithPreInit(C);
316 if (auto *S = C->getChunkSize())
317 Profiler->VisitStmt(S);
Alexey Bataev56dafe82014-06-20 07:16:17 +0000318}
319
Alexey Bataev10e775f2015-07-30 11:36:16 +0000320void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
321 if (auto *Num = C->getNumForLoops())
322 Profiler->VisitStmt(Num);
323}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000324
Alexey Bataev236070f2014-06-20 11:19:47 +0000325void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
326
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000327void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
328
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000329void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
330
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000331void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
332
Alexey Bataevdea47612014-07-23 07:46:59 +0000333void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
334
Alexey Bataev67a4f222014-07-23 10:25:33 +0000335void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
336
Alexey Bataev459dec02014-07-24 06:46:57 +0000337void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
338
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000339void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
340
Alexey Bataev346265e2015-09-25 10:37:12 +0000341void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
342
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000343void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
344
Alexey Bataevb825de12015-12-07 10:51:44 +0000345void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
346
Alexey Bataev756c1962013-09-24 03:17:45 +0000347template<typename T>
348void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000349 for (auto *E : Node->varlists()) {
350 Profiler->VisitStmt(E);
351 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000352}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000353
354void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000355 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000356 for (auto *E : C->private_copies()) {
357 Profiler->VisitStmt(E);
358 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000359}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000360void
361OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000362 VisitOMPClauseList(C);
Alexey Bataev417089f2016-02-17 13:19:37 +0000363 VistOMPClauseWithPreInit(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000364 for (auto *E : C->private_copies()) {
365 Profiler->VisitStmt(E);
366 }
367 for (auto *E : C->inits()) {
368 Profiler->VisitStmt(E);
369 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000370}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000371void
372OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
373 VisitOMPClauseList(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000374 for (auto *E : C->source_exprs()) {
375 Profiler->VisitStmt(E);
376 }
377 for (auto *E : C->destination_exprs()) {
378 Profiler->VisitStmt(E);
379 }
380 for (auto *E : C->assignment_ops()) {
381 Profiler->VisitStmt(E);
382 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000383}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000384void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000385 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000386}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000387void OMPClauseProfiler::VisitOMPReductionClause(
388 const OMPReductionClause *C) {
389 Profiler->VisitNestedNameSpecifier(
390 C->getQualifierLoc().getNestedNameSpecifier());
391 Profiler->VisitName(C->getNameInfo().getName());
392 VisitOMPClauseList(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000393 for (auto *E : C->privates()) {
394 Profiler->VisitStmt(E);
395 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000396 for (auto *E : C->lhs_exprs()) {
397 Profiler->VisitStmt(E);
398 }
399 for (auto *E : C->rhs_exprs()) {
400 Profiler->VisitStmt(E);
401 }
402 for (auto *E : C->reduction_ops()) {
403 Profiler->VisitStmt(E);
404 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000405}
Alexander Musman8dba6642014-04-22 13:09:42 +0000406void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
407 VisitOMPClauseList(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000408 for (auto *E : C->privates()) {
409 Profiler->VisitStmt(E);
410 }
Alexander Musman3276a272015-03-21 10:12:56 +0000411 for (auto *E : C->inits()) {
412 Profiler->VisitStmt(E);
413 }
414 for (auto *E : C->updates()) {
415 Profiler->VisitStmt(E);
416 }
417 for (auto *E : C->finals()) {
418 Profiler->VisitStmt(E);
419 }
Alexander Musman8dba6642014-04-22 13:09:42 +0000420 Profiler->VisitStmt(C->getStep());
Alexander Musman3276a272015-03-21 10:12:56 +0000421 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000422}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000423void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
424 VisitOMPClauseList(C);
425 Profiler->VisitStmt(C->getAlignment());
426}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000427void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
428 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000429 for (auto *E : C->source_exprs()) {
430 Profiler->VisitStmt(E);
431 }
432 for (auto *E : C->destination_exprs()) {
433 Profiler->VisitStmt(E);
434 }
435 for (auto *E : C->assignment_ops()) {
436 Profiler->VisitStmt(E);
437 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000438}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000439void
440OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
441 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000442 for (auto *E : C->source_exprs()) {
443 Profiler->VisitStmt(E);
444 }
445 for (auto *E : C->destination_exprs()) {
446 Profiler->VisitStmt(E);
447 }
448 for (auto *E : C->assignment_ops()) {
449 Profiler->VisitStmt(E);
450 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000451}
Alexey Bataev6125da92014-07-21 11:26:11 +0000452void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
453 VisitOMPClauseList(C);
454}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000455void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
456 VisitOMPClauseList(C);
457}
Michael Wonge710d542015-08-07 16:16:36 +0000458void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
459 Profiler->VisitStmt(C->getDevice());
460}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000461void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
462 VisitOMPClauseList(C);
463}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000464void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
465 Profiler->VisitStmt(C->getNumTeams());
466}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000467void OMPClauseProfiler::VisitOMPThreadLimitClause(
468 const OMPThreadLimitClause *C) {
469 Profiler->VisitStmt(C->getThreadLimit());
470}
Alexey Bataeva0569352015-12-01 10:17:31 +0000471void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
472 Profiler->VisitStmt(C->getPriority());
473}
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000474void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
475 Profiler->VisitStmt(C->getGrainsize());
476}
Alexey Bataev382967a2015-12-08 12:06:20 +0000477void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
478 Profiler->VisitStmt(C->getNumTasks());
479}
Alexey Bataev28c75412015-12-15 08:19:24 +0000480void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
481 Profiler->VisitStmt(C->getHint());
482}
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000483}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000484
485void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000486StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000487 VisitStmt(S);
488 OMPClauseProfiler P(this);
489 ArrayRef<OMPClause *> Clauses = S->clauses();
490 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
491 I != E; ++I)
492 if (*I)
493 P.Visit(*I);
494}
495
Alexander Musman3aaab662014-08-19 11:27:13 +0000496void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
497 VisitOMPExecutableDirective(S);
498}
499
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000500void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
501 VisitOMPExecutableDirective(S);
502}
503
504void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000505 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000506}
507
Alexey Bataevf29276e2014-06-18 04:14:57 +0000508void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000509 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000510}
511
Alexander Musmanf82886e2014-09-18 05:12:34 +0000512void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
513 VisitOMPLoopDirective(S);
514}
515
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000516void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
517 VisitOMPExecutableDirective(S);
518}
519
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000520void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
521 VisitOMPExecutableDirective(S);
522}
523
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000524void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
525 VisitOMPExecutableDirective(S);
526}
527
Alexander Musman80c22892014-07-17 08:54:58 +0000528void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
529 VisitOMPExecutableDirective(S);
530}
531
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000532void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
533 VisitOMPExecutableDirective(S);
534 VisitName(S->getDirectiveName().getName());
535}
536
Alexey Bataev4acb8592014-07-07 13:01:15 +0000537void
538StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000539 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000540}
541
Alexander Musmane4e893b2014-09-23 09:33:00 +0000542void StmtProfiler::VisitOMPParallelForSimdDirective(
543 const OMPParallelForSimdDirective *S) {
544 VisitOMPLoopDirective(S);
545}
546
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000547void StmtProfiler::VisitOMPParallelSectionsDirective(
548 const OMPParallelSectionsDirective *S) {
549 VisitOMPExecutableDirective(S);
550}
551
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000552void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
553 VisitOMPExecutableDirective(S);
554}
555
Alexey Bataev68446b72014-07-18 07:47:19 +0000556void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
557 VisitOMPExecutableDirective(S);
558}
559
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000560void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
561 VisitOMPExecutableDirective(S);
562}
563
Alexey Bataev2df347a2014-07-18 10:17:07 +0000564void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
565 VisitOMPExecutableDirective(S);
566}
567
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000568void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
569 VisitOMPExecutableDirective(S);
570}
571
Alexey Bataev6125da92014-07-21 11:26:11 +0000572void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
573 VisitOMPExecutableDirective(S);
574}
575
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000576void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
577 VisitOMPExecutableDirective(S);
578}
579
Alexey Bataev0162e452014-07-22 10:10:35 +0000580void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
581 VisitOMPExecutableDirective(S);
582}
583
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000584void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
585 VisitOMPExecutableDirective(S);
586}
587
Michael Wong65f367f2015-07-21 13:44:28 +0000588void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
589 VisitOMPExecutableDirective(S);
590}
591
Samuel Antaodf67fc42016-01-19 19:15:56 +0000592void StmtProfiler::VisitOMPTargetEnterDataDirective(
593 const OMPTargetEnterDataDirective *S) {
594 VisitOMPExecutableDirective(S);
595}
596
Samuel Antao72590762016-01-19 20:04:50 +0000597void StmtProfiler::VisitOMPTargetExitDataDirective(
598 const OMPTargetExitDataDirective *S) {
599 VisitOMPExecutableDirective(S);
600}
601
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000602void StmtProfiler::VisitOMPTargetParallelDirective(
603 const OMPTargetParallelDirective *S) {
604 VisitOMPExecutableDirective(S);
605}
606
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000607void StmtProfiler::VisitOMPTargetParallelForDirective(
608 const OMPTargetParallelForDirective *S) {
609 VisitOMPExecutableDirective(S);
610}
611
Alexey Bataev13314bf2014-10-09 04:18:56 +0000612void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
613 VisitOMPExecutableDirective(S);
614}
615
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000616void StmtProfiler::VisitOMPCancellationPointDirective(
617 const OMPCancellationPointDirective *S) {
618 VisitOMPExecutableDirective(S);
619}
620
Alexey Bataev80909872015-07-02 11:25:17 +0000621void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
622 VisitOMPExecutableDirective(S);
623}
624
Alexey Bataev49f6e782015-12-01 04:18:41 +0000625void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
626 VisitOMPLoopDirective(S);
627}
628
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000629void StmtProfiler::VisitOMPTaskLoopSimdDirective(
630 const OMPTaskLoopSimdDirective *S) {
631 VisitOMPLoopDirective(S);
632}
633
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000634void StmtProfiler::VisitOMPDistributeDirective(
635 const OMPDistributeDirective *S) {
636 VisitOMPLoopDirective(S);
637}
638
Carlo Bertollib4adf552016-01-15 18:50:31 +0000639void OMPClauseProfiler::VisitOMPDistScheduleClause(
640 const OMPDistScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000641 VistOMPClauseWithPreInit(C);
642 if (auto *S = C->getChunkSize())
643 Profiler->VisitStmt(S);
Carlo Bertollib4adf552016-01-15 18:50:31 +0000644}
645
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000646void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
647
Chandler Carruth631abd92011-06-16 06:47:06 +0000648void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000649 VisitStmt(S);
650}
651
Chandler Carruth631abd92011-06-16 06:47:06 +0000652void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000653 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000654 if (!Canonical)
655 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000656 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000657 if (!Canonical)
658 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000659}
660
Chandler Carruth631abd92011-06-16 06:47:06 +0000661void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000662 VisitExpr(S);
663 ID.AddInteger(S->getIdentType());
664}
665
Chandler Carruth631abd92011-06-16 06:47:06 +0000666void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000667 VisitExpr(S);
668 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +0000669 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000670}
671
Chandler Carruth631abd92011-06-16 06:47:06 +0000672void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000673 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000674 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000675 ID.AddInteger(S->getValue());
676}
677
Chandler Carruth631abd92011-06-16 06:47:06 +0000678void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000679 VisitExpr(S);
680 S->getValue().Profile(ID);
681 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +0000682 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000683}
684
Chandler Carruth631abd92011-06-16 06:47:06 +0000685void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000686 VisitExpr(S);
687}
688
Chandler Carruth631abd92011-06-16 06:47:06 +0000689void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000690 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000691 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000692 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000693}
694
Chandler Carruth631abd92011-06-16 06:47:06 +0000695void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000696 VisitExpr(S);
697}
698
Chandler Carruth631abd92011-06-16 06:47:06 +0000699void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000700 VisitExpr(S);
701}
702
Chandler Carruth631abd92011-06-16 06:47:06 +0000703void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000704 VisitExpr(S);
705 ID.AddInteger(S->getOpcode());
706}
707
Chandler Carruth631abd92011-06-16 06:47:06 +0000708void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000709 VisitType(S->getTypeSourceInfo()->getType());
710 unsigned n = S->getNumComponents();
711 for (unsigned i = 0; i < n; ++i) {
James Y Knight7281c352015-12-29 22:31:18 +0000712 const OffsetOfNode &ON = S->getComponent(i);
Douglas Gregor882211c2010-04-28 22:16:22 +0000713 ID.AddInteger(ON.getKind());
714 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000715 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000716 // Expressions handled below.
717 break;
718
James Y Knight7281c352015-12-29 22:31:18 +0000719 case OffsetOfNode::Field:
Douglas Gregor882211c2010-04-28 22:16:22 +0000720 VisitDecl(ON.getField());
721 break;
722
James Y Knight7281c352015-12-29 22:31:18 +0000723 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +0000724 ID.AddPointer(ON.getFieldName());
725 break;
James Y Knight7281c352015-12-29 22:31:18 +0000726
727 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +0000728 // These nodes are implicit, and therefore don't need profiling.
729 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000730 }
731 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000732
Douglas Gregor882211c2010-04-28 22:16:22 +0000733 VisitExpr(S);
734}
735
Chandler Carruth631abd92011-06-16 06:47:06 +0000736void
737StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000738 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000739 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000740 if (S->isArgumentType())
741 VisitType(S->getArgumentType());
742}
743
Chandler Carruth631abd92011-06-16 06:47:06 +0000744void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000745 VisitExpr(S);
746}
747
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000748void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
749 VisitExpr(S);
750}
751
Chandler Carruth631abd92011-06-16 06:47:06 +0000752void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000753 VisitExpr(S);
754}
755
Chandler Carruth631abd92011-06-16 06:47:06 +0000756void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000757 VisitExpr(S);
758 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000759 if (!Canonical)
760 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000761 ID.AddBoolean(S->isArrow());
762}
763
Chandler Carruth631abd92011-06-16 06:47:06 +0000764void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000765 VisitExpr(S);
766 ID.AddBoolean(S->isFileScope());
767}
768
Chandler Carruth631abd92011-06-16 06:47:06 +0000769void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000770 VisitExpr(S);
771}
772
Chandler Carruth631abd92011-06-16 06:47:06 +0000773void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000774 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000775 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000776}
777
Chandler Carruth631abd92011-06-16 06:47:06 +0000778void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000779 VisitCastExpr(S);
780 VisitType(S->getTypeAsWritten());
781}
782
Chandler Carruth631abd92011-06-16 06:47:06 +0000783void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000784 VisitExplicitCastExpr(S);
785}
786
Chandler Carruth631abd92011-06-16 06:47:06 +0000787void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000788 VisitExpr(S);
789 ID.AddInteger(S->getOpcode());
790}
791
Chandler Carruth631abd92011-06-16 06:47:06 +0000792void
793StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000794 VisitBinaryOperator(S);
795}
796
Chandler Carruth631abd92011-06-16 06:47:06 +0000797void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000798 VisitExpr(S);
799}
800
Chandler Carruth631abd92011-06-16 06:47:06 +0000801void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000802 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000803 VisitExpr(S);
804}
805
Chandler Carruth631abd92011-06-16 06:47:06 +0000806void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000807 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000808 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000809}
810
Chandler Carruth631abd92011-06-16 06:47:06 +0000811void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000812 VisitExpr(S);
813}
814
Chandler Carruth631abd92011-06-16 06:47:06 +0000815void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000816 VisitExpr(S);
817}
818
Hal Finkelc4d7c822013-09-18 03:29:45 +0000819void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
820 VisitExpr(S);
821}
822
Chandler Carruth631abd92011-06-16 06:47:06 +0000823void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000824 VisitExpr(S);
825}
826
Chandler Carruth631abd92011-06-16 06:47:06 +0000827void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000828 VisitExpr(S);
829}
830
Chandler Carruth631abd92011-06-16 06:47:06 +0000831void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000832 VisitExpr(S);
833}
834
Chandler Carruth631abd92011-06-16 06:47:06 +0000835void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000836 if (S->getSyntacticForm()) {
837 VisitInitListExpr(S->getSyntacticForm());
838 return;
839 }
Mike Stump11289f42009-09-09 15:08:12 +0000840
Douglas Gregor5c193b92009-07-28 00:33:38 +0000841 VisitExpr(S);
842}
843
Chandler Carruth631abd92011-06-16 06:47:06 +0000844void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000845 VisitExpr(S);
846 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000847 for (DesignatedInitExpr::const_designators_iterator D =
848 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000849 D != DEnd; ++D) {
850 if (D->isFieldDesignator()) {
851 ID.AddInteger(0);
852 VisitName(D->getFieldName());
853 continue;
854 }
Mike Stump11289f42009-09-09 15:08:12 +0000855
Douglas Gregor5c193b92009-07-28 00:33:38 +0000856 if (D->isArrayDesignator()) {
857 ID.AddInteger(1);
858 } else {
859 assert(D->isArrayRangeDesignator());
860 ID.AddInteger(2);
861 }
862 ID.AddInteger(D->getFirstExprIndex());
863 }
864}
865
Yunzhong Gaocb779302015-06-10 00:27:52 +0000866// Seems that if VisitInitListExpr() only works on the syntactic form of an
867// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
868void StmtProfiler::VisitDesignatedInitUpdateExpr(
869 const DesignatedInitUpdateExpr *S) {
870 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
871 "initializer");
872}
873
874void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
875 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
876}
877
Chandler Carruth631abd92011-06-16 06:47:06 +0000878void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000879 VisitExpr(S);
880}
881
Chandler Carruth631abd92011-06-16 06:47:06 +0000882void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000883 VisitExpr(S);
884 VisitName(&S->getAccessor());
885}
886
Chandler Carruth631abd92011-06-16 06:47:06 +0000887void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000888 VisitExpr(S);
889 VisitDecl(S->getBlockDecl());
890}
891
Chandler Carruth631abd92011-06-16 06:47:06 +0000892void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000893 VisitExpr(S);
894 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
895 QualType T = S->getAssocType(i);
896 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000897 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000898 else
899 VisitType(T);
900 VisitExpr(S->getAssocExpr(i));
901 }
902}
903
John McCallfe96e0b2011-11-06 09:01:30 +0000904void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
905 VisitExpr(S);
906 for (PseudoObjectExpr::const_semantics_iterator
907 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
908 // Normally, we would not profile the source expressions of OVEs.
909 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
910 Visit(OVE->getSourceExpr());
911}
912
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000913void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
914 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000915 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000916}
917
Chandler Carruth631abd92011-06-16 06:47:06 +0000918static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000919 UnaryOperatorKind &UnaryOp,
920 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000921 switch (S->getOperator()) {
922 case OO_None:
923 case OO_New:
924 case OO_Delete:
925 case OO_Array_New:
926 case OO_Array_Delete:
927 case OO_Arrow:
928 case OO_Call:
929 case OO_Conditional:
Richard Smith9be594e2015-10-22 05:12:22 +0000930 case OO_Coawait:
Douglas Gregore9ceb312010-05-19 04:13:23 +0000931 case NUM_OVERLOADED_OPERATORS:
932 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000933
934 case OO_Plus:
935 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000936 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000937 return Stmt::UnaryOperatorClass;
938 }
939
John McCalle3027922010-08-25 11:45:40 +0000940 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000941 return Stmt::BinaryOperatorClass;
942
943 case OO_Minus:
944 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000945 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000946 return Stmt::UnaryOperatorClass;
947 }
948
John McCalle3027922010-08-25 11:45:40 +0000949 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000950 return Stmt::BinaryOperatorClass;
951
952 case OO_Star:
953 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000954 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000955 return Stmt::UnaryOperatorClass;
956 }
957
Richard Smithf15acc52014-06-05 22:43:40 +0000958 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000959 return Stmt::BinaryOperatorClass;
960
961 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000962 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000963 return Stmt::BinaryOperatorClass;
964
965 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000966 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000967 return Stmt::BinaryOperatorClass;
968
969 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000970 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000971 return Stmt::BinaryOperatorClass;
972
973 case OO_Amp:
974 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000975 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000976 return Stmt::UnaryOperatorClass;
977 }
978
John McCalle3027922010-08-25 11:45:40 +0000979 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000980 return Stmt::BinaryOperatorClass;
981
982 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000983 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000984 return Stmt::BinaryOperatorClass;
985
986 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000987 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000988 return Stmt::UnaryOperatorClass;
989
990 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000991 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000992 return Stmt::UnaryOperatorClass;
993
994 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000995 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000996 return Stmt::BinaryOperatorClass;
997
998 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000999 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001000 return Stmt::BinaryOperatorClass;
1001
1002 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +00001003 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001004 return Stmt::BinaryOperatorClass;
1005
1006 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +00001007 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001008 return Stmt::CompoundAssignOperatorClass;
1009
1010 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +00001011 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001012 return Stmt::CompoundAssignOperatorClass;
1013
1014 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +00001015 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001016 return Stmt::CompoundAssignOperatorClass;
1017
1018 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +00001019 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001020 return Stmt::CompoundAssignOperatorClass;
1021
1022 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +00001023 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001024 return Stmt::CompoundAssignOperatorClass;
1025
1026 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +00001027 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001028 return Stmt::CompoundAssignOperatorClass;
1029
1030 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +00001031 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001032 return Stmt::CompoundAssignOperatorClass;
1033
1034 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +00001035 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001036 return Stmt::CompoundAssignOperatorClass;
1037
1038 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +00001039 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001040 return Stmt::BinaryOperatorClass;
1041
1042 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +00001043 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001044 return Stmt::BinaryOperatorClass;
1045
1046 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +00001047 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001048 return Stmt::CompoundAssignOperatorClass;
1049
1050 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001051 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001052 return Stmt::CompoundAssignOperatorClass;
1053
1054 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +00001055 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001056 return Stmt::BinaryOperatorClass;
1057
1058 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001059 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001060 return Stmt::BinaryOperatorClass;
1061
1062 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001063 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001064 return Stmt::BinaryOperatorClass;
1065
1066 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001067 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001068 return Stmt::BinaryOperatorClass;
1069
1070 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001071 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001072 return Stmt::BinaryOperatorClass;
1073
1074 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001075 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001076 return Stmt::BinaryOperatorClass;
1077
1078 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +00001079 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1080 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001081 return Stmt::UnaryOperatorClass;
1082
1083 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001084 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1085 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001086 return Stmt::UnaryOperatorClass;
1087
1088 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001089 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001090 return Stmt::BinaryOperatorClass;
1091
Douglas Gregore9ceb312010-05-19 04:13:23 +00001092 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001093 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001094 return Stmt::BinaryOperatorClass;
1095
1096 case OO_Subscript:
1097 return Stmt::ArraySubscriptExprClass;
1098 }
1099
1100 llvm_unreachable("Invalid overloaded operator expression");
1101}
Richard Smithf15acc52014-06-05 22:43:40 +00001102
Chandler Carruth631abd92011-06-16 06:47:06 +00001103void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001104 if (S->isTypeDependent()) {
1105 // Type-dependent operator calls are profiled like their underlying
1106 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +00001107 UnaryOperatorKind UnaryOp = UO_Extension;
1108 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001109 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001110
Douglas Gregore9ceb312010-05-19 04:13:23 +00001111 ID.AddInteger(SC);
1112 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1113 Visit(S->getArg(I));
1114 if (SC == Stmt::UnaryOperatorClass)
1115 ID.AddInteger(UnaryOp);
1116 else if (SC == Stmt::BinaryOperatorClass ||
1117 SC == Stmt::CompoundAssignOperatorClass)
1118 ID.AddInteger(BinaryOp);
1119 else
1120 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001121
Douglas Gregore9ceb312010-05-19 04:13:23 +00001122 return;
1123 }
Richard Smithf15acc52014-06-05 22:43:40 +00001124
Douglas Gregor5c193b92009-07-28 00:33:38 +00001125 VisitCallExpr(S);
1126 ID.AddInteger(S->getOperator());
1127}
1128
Chandler Carruth631abd92011-06-16 06:47:06 +00001129void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001130 VisitCallExpr(S);
1131}
1132
Chandler Carruth631abd92011-06-16 06:47:06 +00001133void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001134 VisitCallExpr(S);
1135}
1136
Chandler Carruth631abd92011-06-16 06:47:06 +00001137void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001138 VisitExpr(S);
1139}
1140
Chandler Carruth631abd92011-06-16 06:47:06 +00001141void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001142 VisitExplicitCastExpr(S);
1143}
1144
Chandler Carruth631abd92011-06-16 06:47:06 +00001145void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001146 VisitCXXNamedCastExpr(S);
1147}
1148
Chandler Carruth631abd92011-06-16 06:47:06 +00001149void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001150 VisitCXXNamedCastExpr(S);
1151}
1152
Chandler Carruth631abd92011-06-16 06:47:06 +00001153void
1154StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001155 VisitCXXNamedCastExpr(S);
1156}
1157
Chandler Carruth631abd92011-06-16 06:47:06 +00001158void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001159 VisitCXXNamedCastExpr(S);
1160}
1161
Richard Smithc67fdd42012-03-07 08:35:16 +00001162void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1163 VisitCallExpr(S);
1164}
1165
Chandler Carruth631abd92011-06-16 06:47:06 +00001166void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001167 VisitExpr(S);
1168 ID.AddBoolean(S->getValue());
1169}
1170
Chandler Carruth631abd92011-06-16 06:47:06 +00001171void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001172 VisitExpr(S);
1173}
1174
Richard Smithcc1b96d2013-06-12 22:31:48 +00001175void StmtProfiler::VisitCXXStdInitializerListExpr(
1176 const CXXStdInitializerListExpr *S) {
1177 VisitExpr(S);
1178}
1179
Chandler Carruth631abd92011-06-16 06:47:06 +00001180void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001181 VisitExpr(S);
1182 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001183 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001184}
1185
Chandler Carruth631abd92011-06-16 06:47:06 +00001186void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001187 VisitExpr(S);
1188 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001189 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001190}
1191
John McCall5e77d762013-04-16 07:28:30 +00001192void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1193 VisitExpr(S);
1194 VisitDecl(S->getPropertyDecl());
1195}
1196
Alexey Bataevf7630272015-11-25 12:01:00 +00001197void StmtProfiler::VisitMSPropertySubscriptExpr(
1198 const MSPropertySubscriptExpr *S) {
1199 VisitExpr(S);
1200}
1201
Chandler Carruth631abd92011-06-16 06:47:06 +00001202void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001203 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001204 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001205}
1206
Chandler Carruth631abd92011-06-16 06:47:06 +00001207void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001208 VisitExpr(S);
1209}
1210
Chandler Carruth631abd92011-06-16 06:47:06 +00001211void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001212 VisitExpr(S);
1213 VisitDecl(S->getParam());
1214}
1215
Richard Smith852c9db2013-04-20 22:23:05 +00001216void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1217 VisitExpr(S);
1218 VisitDecl(S->getField());
1219}
1220
Chandler Carruth631abd92011-06-16 06:47:06 +00001221void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001222 VisitExpr(S);
1223 VisitDecl(
1224 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1225}
1226
Chandler Carruth631abd92011-06-16 06:47:06 +00001227void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001228 VisitExpr(S);
1229 VisitDecl(S->getConstructor());
1230 ID.AddBoolean(S->isElidable());
1231}
1232
Chandler Carruth631abd92011-06-16 06:47:06 +00001233void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001234 VisitExplicitCastExpr(S);
1235}
1236
Chandler Carruth631abd92011-06-16 06:47:06 +00001237void
1238StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001239 VisitCXXConstructExpr(S);
1240}
1241
Chandler Carruth631abd92011-06-16 06:47:06 +00001242void
Douglas Gregore31e6062012-02-07 10:09:13 +00001243StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1244 VisitExpr(S);
1245 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1246 CEnd = S->explicit_capture_end();
1247 C != CEnd; ++C) {
1248 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001249 switch (C->getCaptureKind()) {
1250 case LCK_This:
1251 break;
1252 case LCK_ByRef:
1253 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001254 VisitDecl(C->getCapturedVar());
1255 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001256 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001257 case LCK_VLAType:
1258 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001259 }
1260 }
1261 // Note: If we actually needed to be able to match lambda
1262 // expressions, we would have to consider parameters and return type
1263 // here, among other things.
1264 VisitStmt(S->getBody());
1265}
1266
1267void
Chandler Carruth631abd92011-06-16 06:47:06 +00001268StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001269 VisitExpr(S);
1270}
1271
Chandler Carruth631abd92011-06-16 06:47:06 +00001272void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001273 VisitExpr(S);
1274 ID.AddBoolean(S->isGlobalDelete());
1275 ID.AddBoolean(S->isArrayForm());
1276 VisitDecl(S->getOperatorDelete());
1277}
1278
Chandler Carruth631abd92011-06-16 06:47:06 +00001279void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001280 VisitExpr(S);
1281 VisitType(S->getAllocatedType());
1282 VisitDecl(S->getOperatorNew());
1283 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001284 ID.AddBoolean(S->isArray());
1285 ID.AddInteger(S->getNumPlacementArgs());
1286 ID.AddBoolean(S->isGlobalNew());
1287 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001288 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001289}
1290
Chandler Carruth631abd92011-06-16 06:47:06 +00001291void
1292StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001293 VisitExpr(S);
1294 ID.AddBoolean(S->isArrow());
1295 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001296 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001297 if (S->getScopeTypeInfo())
1298 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001299 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001300 if (S->getDestroyedTypeInfo())
1301 VisitType(S->getDestroyedType());
1302 else
1303 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001304}
1305
Chandler Carruth631abd92011-06-16 06:47:06 +00001306void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001307 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001308 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001309 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001310 ID.AddBoolean(S->hasExplicitTemplateArgs());
1311 if (S->hasExplicitTemplateArgs())
James Y Knight04ec5bf2015-12-24 02:59:37 +00001312 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001313}
1314
1315void
Chandler Carruth631abd92011-06-16 06:47:06 +00001316StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001317 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001318}
1319
Douglas Gregor29c42f22012-02-24 07:38:34 +00001320void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1321 VisitExpr(S);
1322 ID.AddInteger(S->getTrait());
1323 ID.AddInteger(S->getNumArgs());
1324 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1325 VisitType(S->getArg(I)->getType());
1326}
1327
Chandler Carruth631abd92011-06-16 06:47:06 +00001328void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001329 VisitExpr(S);
1330 ID.AddInteger(S->getTrait());
1331 VisitType(S->getQueriedType());
1332}
1333
Chandler Carruth631abd92011-06-16 06:47:06 +00001334void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001335 VisitExpr(S);
1336 ID.AddInteger(S->getTrait());
1337 VisitExpr(S->getQueriedExpression());
1338}
1339
Chandler Carruth631abd92011-06-16 06:47:06 +00001340void StmtProfiler::VisitDependentScopeDeclRefExpr(
1341 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001342 VisitExpr(S);
1343 VisitName(S->getDeclName());
1344 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001345 ID.AddBoolean(S->hasExplicitTemplateArgs());
1346 if (S->hasExplicitTemplateArgs())
1347 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001348}
1349
Chandler Carruth631abd92011-06-16 06:47:06 +00001350void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001351 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001352}
1353
Chandler Carruth631abd92011-06-16 06:47:06 +00001354void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1355 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001356 VisitExpr(S);
1357 VisitType(S->getTypeAsWritten());
1358}
1359
Chandler Carruth631abd92011-06-16 06:47:06 +00001360void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1361 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001362 ID.AddBoolean(S->isImplicitAccess());
1363 if (!S->isImplicitAccess()) {
1364 VisitExpr(S);
1365 ID.AddBoolean(S->isArrow());
1366 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001367 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001368 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001369 ID.AddBoolean(S->hasExplicitTemplateArgs());
1370 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001371 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1372}
1373
Chandler Carruth631abd92011-06-16 06:47:06 +00001374void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001375 ID.AddBoolean(S->isImplicitAccess());
1376 if (!S->isImplicitAccess()) {
1377 VisitExpr(S);
1378 ID.AddBoolean(S->isArrow());
1379 }
John McCall10eae182009-11-30 22:42:35 +00001380 VisitNestedNameSpecifier(S->getQualifier());
1381 VisitName(S->getMemberName());
1382 ID.AddBoolean(S->hasExplicitTemplateArgs());
1383 if (S->hasExplicitTemplateArgs())
1384 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001385}
1386
Chandler Carruth631abd92011-06-16 06:47:06 +00001387void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001388 VisitExpr(S);
1389}
1390
Chandler Carruth631abd92011-06-16 06:47:06 +00001391void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001392 VisitExpr(S);
1393}
1394
Chandler Carruth631abd92011-06-16 06:47:06 +00001395void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001396 VisitExpr(S);
1397 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00001398 if (S->isPartiallySubstituted()) {
1399 auto Args = S->getPartialArguments();
1400 ID.AddInteger(Args.size());
1401 for (const auto &TA : Args)
1402 VisitTemplateArgument(TA);
1403 } else {
1404 ID.AddInteger(0);
1405 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001406}
1407
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001408void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001409 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001410 VisitExpr(S);
1411 VisitDecl(S->getParameterPack());
1412 VisitTemplateArgument(S->getArgumentPack());
1413}
1414
John McCall7c454bb2011-07-15 05:09:51 +00001415void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1416 const SubstNonTypeTemplateParmExpr *E) {
1417 // Profile exactly as the replacement expression.
1418 Visit(E->getReplacement());
1419}
1420
Richard Smithb15fe3a2012-09-12 00:56:43 +00001421void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1422 VisitExpr(S);
1423 VisitDecl(S->getParameterPack());
1424 ID.AddInteger(S->getNumExpansions());
1425 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1426 VisitDecl(*I);
1427}
1428
Douglas Gregorfe314812011-06-21 17:03:29 +00001429void StmtProfiler::VisitMaterializeTemporaryExpr(
1430 const MaterializeTemporaryExpr *S) {
1431 VisitExpr(S);
1432}
1433
Richard Smith0f0af192014-11-08 05:07:16 +00001434void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1435 VisitExpr(S);
1436 ID.AddInteger(S->getOperator());
1437}
1438
Richard Smith9f690bd2015-10-27 06:02:45 +00001439void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1440 VisitStmt(S);
1441}
1442
1443void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1444 VisitStmt(S);
1445}
1446
1447void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1448 VisitExpr(S);
1449}
1450
1451void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1452 VisitExpr(S);
1453}
1454
Chandler Carruth631abd92011-06-16 06:47:06 +00001455void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001456 VisitExpr(E);
1457}
1458
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001459void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1460 VisitExpr(E);
1461}
1462
Chandler Carruth631abd92011-06-16 06:47:06 +00001463void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001464 VisitExpr(S);
1465}
1466
Patrick Beard0caa3942012-04-19 00:25:12 +00001467void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001468 VisitExpr(E);
1469}
1470
1471void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1472 VisitExpr(E);
1473}
1474
1475void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1476 VisitExpr(E);
1477}
1478
Chandler Carruth631abd92011-06-16 06:47:06 +00001479void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001480 VisitExpr(S);
1481 VisitType(S->getEncodedType());
1482}
1483
Chandler Carruth631abd92011-06-16 06:47:06 +00001484void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001485 VisitExpr(S);
1486 VisitName(S->getSelector());
1487}
1488
Chandler Carruth631abd92011-06-16 06:47:06 +00001489void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001490 VisitExpr(S);
1491 VisitDecl(S->getProtocol());
1492}
1493
Chandler Carruth631abd92011-06-16 06:47:06 +00001494void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001495 VisitExpr(S);
1496 VisitDecl(S->getDecl());
1497 ID.AddBoolean(S->isArrow());
1498 ID.AddBoolean(S->isFreeIvar());
1499}
1500
Chandler Carruth631abd92011-06-16 06:47:06 +00001501void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001502 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001503 if (S->isImplicitProperty()) {
1504 VisitDecl(S->getImplicitPropertyGetter());
1505 VisitDecl(S->getImplicitPropertySetter());
1506 } else {
1507 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001508 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001509 if (S->isSuperReceiver()) {
1510 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001511 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001512 }
Douglas Gregora7095092009-07-28 14:44:31 +00001513}
1514
Ted Kremeneke65b0862012-03-06 20:05:56 +00001515void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1516 VisitExpr(S);
1517 VisitDecl(S->getAtIndexMethodDecl());
1518 VisitDecl(S->setAtIndexMethodDecl());
1519}
1520
Chandler Carruth631abd92011-06-16 06:47:06 +00001521void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001522 VisitExpr(S);
1523 VisitName(S->getSelector());
1524 VisitDecl(S->getMethodDecl());
1525}
1526
Chandler Carruth631abd92011-06-16 06:47:06 +00001527void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001528 VisitExpr(S);
1529 ID.AddBoolean(S->isArrow());
1530}
1531
Ted Kremeneke65b0862012-03-06 20:05:56 +00001532void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1533 VisitExpr(S);
1534 ID.AddBoolean(S->getValue());
1535}
1536
Chandler Carruth631abd92011-06-16 06:47:06 +00001537void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1538 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001539 VisitExpr(S);
1540 ID.AddBoolean(S->shouldCopy());
1541}
1542
Chandler Carruth631abd92011-06-16 06:47:06 +00001543void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001544 VisitExplicitCastExpr(S);
1545 ID.AddBoolean(S->getBridgeKind());
1546}
1547
Chandler Carruth631abd92011-06-16 06:47:06 +00001548void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001549 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001550
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001551 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001552 if (const NonTypeTemplateParmDecl *NTTP =
1553 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001554 ID.AddInteger(NTTP->getDepth());
1555 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001556 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001557 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001558 return;
1559 }
Mike Stump11289f42009-09-09 15:08:12 +00001560
Chandler Carruth631abd92011-06-16 06:47:06 +00001561 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001562 // The Itanium C++ ABI uses the type, scope depth, and scope
1563 // index of a parameter when mangling expressions that involve
1564 // function parameters, so we will use the parameter's type for
1565 // establishing function parameter identity. That way, our
1566 // definition of "equivalent" (per C++ [temp.over.link]) is at
1567 // least as strong as the definition of "equivalent" used for
1568 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001569 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001570 ID.AddInteger(Parm->getFunctionScopeDepth());
1571 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001572 return;
1573 }
Mike Stump11289f42009-09-09 15:08:12 +00001574
Richard Smithd9a1cd82012-04-02 18:53:24 +00001575 if (const TemplateTypeParmDecl *TTP =
1576 dyn_cast<TemplateTypeParmDecl>(D)) {
1577 ID.AddInteger(TTP->getDepth());
1578 ID.AddInteger(TTP->getIndex());
1579 ID.AddBoolean(TTP->isParameterPack());
1580 return;
1581 }
1582
Chandler Carruth631abd92011-06-16 06:47:06 +00001583 if (const TemplateTemplateParmDecl *TTP =
1584 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001585 ID.AddInteger(TTP->getDepth());
1586 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001587 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001588 return;
1589 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001590 }
Mike Stump11289f42009-09-09 15:08:12 +00001591
Craig Topper36250ad2014-05-12 05:36:57 +00001592 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001593}
1594
1595void StmtProfiler::VisitType(QualType T) {
1596 if (Canonical)
1597 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001598
Douglas Gregor5c193b92009-07-28 00:33:38 +00001599 ID.AddPointer(T.getAsOpaquePtr());
1600}
1601
1602void StmtProfiler::VisitName(DeclarationName Name) {
1603 ID.AddPointer(Name.getAsOpaquePtr());
1604}
1605
1606void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1607 if (Canonical)
1608 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1609 ID.AddPointer(NNS);
1610}
1611
1612void StmtProfiler::VisitTemplateName(TemplateName Name) {
1613 if (Canonical)
1614 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001615
Douglas Gregor5c193b92009-07-28 00:33:38 +00001616 Name.Profile(ID);
1617}
1618
John McCall0ad16662009-10-29 08:12:44 +00001619void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001620 unsigned NumArgs) {
1621 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001622 for (unsigned I = 0; I != NumArgs; ++I)
1623 VisitTemplateArgument(Args[I].getArgument());
1624}
Mike Stump11289f42009-09-09 15:08:12 +00001625
John McCall0ad16662009-10-29 08:12:44 +00001626void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1627 // Mostly repetitive with TemplateArgument::Profile!
1628 ID.AddInteger(Arg.getKind());
1629 switch (Arg.getKind()) {
1630 case TemplateArgument::Null:
1631 break;
Mike Stump11289f42009-09-09 15:08:12 +00001632
John McCall0ad16662009-10-29 08:12:44 +00001633 case TemplateArgument::Type:
1634 VisitType(Arg.getAsType());
1635 break;
Mike Stump11289f42009-09-09 15:08:12 +00001636
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001637 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001638 case TemplateArgument::TemplateExpansion:
1639 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001640 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001641
John McCall0ad16662009-10-29 08:12:44 +00001642 case TemplateArgument::Declaration:
1643 VisitDecl(Arg.getAsDecl());
1644 break;
Mike Stump11289f42009-09-09 15:08:12 +00001645
Eli Friedmanb826a002012-09-26 02:36:12 +00001646 case TemplateArgument::NullPtr:
1647 VisitType(Arg.getNullPtrType());
1648 break;
1649
John McCall0ad16662009-10-29 08:12:44 +00001650 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001651 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001652 VisitType(Arg.getIntegralType());
1653 break;
Mike Stump11289f42009-09-09 15:08:12 +00001654
John McCall0ad16662009-10-29 08:12:44 +00001655 case TemplateArgument::Expression:
1656 Visit(Arg.getAsExpr());
1657 break;
Mike Stump11289f42009-09-09 15:08:12 +00001658
John McCall0ad16662009-10-29 08:12:44 +00001659 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001660 for (const auto &P : Arg.pack_elements())
1661 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001662 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001663 }
1664}
1665
Jay Foad39c79802011-01-12 09:06:06 +00001666void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001667 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001668 StmtProfiler Profiler(ID, Context, Canonical);
1669 Profiler.Visit(this);
1670}