blob: 5f6e1c7d3308ecf4b183e7aeafcb9c9798fb6750 [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"
271};
272
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000273void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
274 if (C->getCondition())
275 Profiler->VisitStmt(C->getCondition());
276}
277
Alexey Bataev3778b602014-07-17 07:32:53 +0000278void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
279 if (C->getCondition())
280 Profiler->VisitStmt(C->getCondition());
281}
282
Alexey Bataev568a8332014-03-06 06:15:19 +0000283void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
284 if (C->getNumThreads())
285 Profiler->VisitStmt(C->getNumThreads());
286}
287
Alexey Bataev62c87d22014-03-21 04:51:18 +0000288void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
289 if (C->getSafelen())
290 Profiler->VisitStmt(C->getSafelen());
291}
292
Alexey Bataev66b15b52015-08-21 11:14:16 +0000293void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
294 if (C->getSimdlen())
295 Profiler->VisitStmt(C->getSimdlen());
296}
297
Alexander Musman8bd31e62014-05-27 15:12:19 +0000298void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
299 if (C->getNumForLoops())
300 Profiler->VisitStmt(C->getNumForLoops());
301}
302
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000303void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000304
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000305void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
306
Alexey Bataev56dafe82014-06-20 07:16:17 +0000307void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev040d5402015-05-12 08:35:28 +0000308 if (C->getChunkSize()) {
Alexey Bataev56dafe82014-06-20 07:16:17 +0000309 Profiler->VisitStmt(C->getChunkSize());
Alexey Bataev040d5402015-05-12 08:35:28 +0000310 if (C->getHelperChunkSize()) {
311 Profiler->VisitStmt(C->getChunkSize());
312 }
313 }
Alexey Bataev56dafe82014-06-20 07:16:17 +0000314}
315
Alexey Bataev10e775f2015-07-30 11:36:16 +0000316void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
317 if (auto *Num = C->getNumForLoops())
318 Profiler->VisitStmt(Num);
319}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000320
Alexey Bataev236070f2014-06-20 11:19:47 +0000321void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
322
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000323void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
324
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000325void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
326
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000327void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
328
Alexey Bataevdea47612014-07-23 07:46:59 +0000329void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
330
Alexey Bataev67a4f222014-07-23 10:25:33 +0000331void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
332
Alexey Bataev459dec02014-07-24 06:46:57 +0000333void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
334
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000335void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
336
Alexey Bataev346265e2015-09-25 10:37:12 +0000337void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
338
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000339void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
340
Alexey Bataevb825de12015-12-07 10:51:44 +0000341void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
342
Alexey Bataev756c1962013-09-24 03:17:45 +0000343template<typename T>
344void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000345 for (auto *E : Node->varlists()) {
346 Profiler->VisitStmt(E);
347 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000348}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000349
350void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000351 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000352 for (auto *E : C->private_copies()) {
353 Profiler->VisitStmt(E);
354 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000355}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000356void
357OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000358 VisitOMPClauseList(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000359 for (auto *E : C->private_copies()) {
360 Profiler->VisitStmt(E);
361 }
362 for (auto *E : C->inits()) {
363 Profiler->VisitStmt(E);
364 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000365}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000366void
367OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
368 VisitOMPClauseList(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000369 for (auto *E : C->source_exprs()) {
370 Profiler->VisitStmt(E);
371 }
372 for (auto *E : C->destination_exprs()) {
373 Profiler->VisitStmt(E);
374 }
375 for (auto *E : C->assignment_ops()) {
376 Profiler->VisitStmt(E);
377 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000378}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000379void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000380 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000381}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000382void OMPClauseProfiler::VisitOMPReductionClause(
383 const OMPReductionClause *C) {
384 Profiler->VisitNestedNameSpecifier(
385 C->getQualifierLoc().getNestedNameSpecifier());
386 Profiler->VisitName(C->getNameInfo().getName());
387 VisitOMPClauseList(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000388 for (auto *E : C->privates()) {
389 Profiler->VisitStmt(E);
390 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000391 for (auto *E : C->lhs_exprs()) {
392 Profiler->VisitStmt(E);
393 }
394 for (auto *E : C->rhs_exprs()) {
395 Profiler->VisitStmt(E);
396 }
397 for (auto *E : C->reduction_ops()) {
398 Profiler->VisitStmt(E);
399 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000400}
Alexander Musman8dba6642014-04-22 13:09:42 +0000401void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
402 VisitOMPClauseList(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000403 for (auto *E : C->privates()) {
404 Profiler->VisitStmt(E);
405 }
Alexander Musman3276a272015-03-21 10:12:56 +0000406 for (auto *E : C->inits()) {
407 Profiler->VisitStmt(E);
408 }
409 for (auto *E : C->updates()) {
410 Profiler->VisitStmt(E);
411 }
412 for (auto *E : C->finals()) {
413 Profiler->VisitStmt(E);
414 }
Alexander Musman8dba6642014-04-22 13:09:42 +0000415 Profiler->VisitStmt(C->getStep());
Alexander Musman3276a272015-03-21 10:12:56 +0000416 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000417}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000418void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
419 VisitOMPClauseList(C);
420 Profiler->VisitStmt(C->getAlignment());
421}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000422void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
423 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000424 for (auto *E : C->source_exprs()) {
425 Profiler->VisitStmt(E);
426 }
427 for (auto *E : C->destination_exprs()) {
428 Profiler->VisitStmt(E);
429 }
430 for (auto *E : C->assignment_ops()) {
431 Profiler->VisitStmt(E);
432 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000433}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000434void
435OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
436 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000437 for (auto *E : C->source_exprs()) {
438 Profiler->VisitStmt(E);
439 }
440 for (auto *E : C->destination_exprs()) {
441 Profiler->VisitStmt(E);
442 }
443 for (auto *E : C->assignment_ops()) {
444 Profiler->VisitStmt(E);
445 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000446}
Alexey Bataev6125da92014-07-21 11:26:11 +0000447void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
448 VisitOMPClauseList(C);
449}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000450void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
451 VisitOMPClauseList(C);
452}
Michael Wonge710d542015-08-07 16:16:36 +0000453void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
454 Profiler->VisitStmt(C->getDevice());
455}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000456void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
457 VisitOMPClauseList(C);
458}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000459void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
460 Profiler->VisitStmt(C->getNumTeams());
461}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000462void OMPClauseProfiler::VisitOMPThreadLimitClause(
463 const OMPThreadLimitClause *C) {
464 Profiler->VisitStmt(C->getThreadLimit());
465}
Alexey Bataeva0569352015-12-01 10:17:31 +0000466void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
467 Profiler->VisitStmt(C->getPriority());
468}
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000469void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
470 Profiler->VisitStmt(C->getGrainsize());
471}
Alexey Bataev382967a2015-12-08 12:06:20 +0000472void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
473 Profiler->VisitStmt(C->getNumTasks());
474}
Alexey Bataev28c75412015-12-15 08:19:24 +0000475void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
476 Profiler->VisitStmt(C->getHint());
477}
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000478}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000479
480void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000481StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000482 VisitStmt(S);
483 OMPClauseProfiler P(this);
484 ArrayRef<OMPClause *> Clauses = S->clauses();
485 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
486 I != E; ++I)
487 if (*I)
488 P.Visit(*I);
489}
490
Alexander Musman3aaab662014-08-19 11:27:13 +0000491void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
492 VisitOMPExecutableDirective(S);
493}
494
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000495void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
496 VisitOMPExecutableDirective(S);
497}
498
499void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000500 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000501}
502
Alexey Bataevf29276e2014-06-18 04:14:57 +0000503void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000504 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000505}
506
Alexander Musmanf82886e2014-09-18 05:12:34 +0000507void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
508 VisitOMPLoopDirective(S);
509}
510
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000511void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
512 VisitOMPExecutableDirective(S);
513}
514
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000515void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
516 VisitOMPExecutableDirective(S);
517}
518
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000519void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
520 VisitOMPExecutableDirective(S);
521}
522
Alexander Musman80c22892014-07-17 08:54:58 +0000523void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
524 VisitOMPExecutableDirective(S);
525}
526
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000527void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
528 VisitOMPExecutableDirective(S);
529 VisitName(S->getDirectiveName().getName());
530}
531
Alexey Bataev4acb8592014-07-07 13:01:15 +0000532void
533StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000534 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000535}
536
Alexander Musmane4e893b2014-09-23 09:33:00 +0000537void StmtProfiler::VisitOMPParallelForSimdDirective(
538 const OMPParallelForSimdDirective *S) {
539 VisitOMPLoopDirective(S);
540}
541
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000542void StmtProfiler::VisitOMPParallelSectionsDirective(
543 const OMPParallelSectionsDirective *S) {
544 VisitOMPExecutableDirective(S);
545}
546
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000547void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
548 VisitOMPExecutableDirective(S);
549}
550
Alexey Bataev68446b72014-07-18 07:47:19 +0000551void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
552 VisitOMPExecutableDirective(S);
553}
554
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000555void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
556 VisitOMPExecutableDirective(S);
557}
558
Alexey Bataev2df347a2014-07-18 10:17:07 +0000559void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
560 VisitOMPExecutableDirective(S);
561}
562
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000563void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
564 VisitOMPExecutableDirective(S);
565}
566
Alexey Bataev6125da92014-07-21 11:26:11 +0000567void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
568 VisitOMPExecutableDirective(S);
569}
570
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000571void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
572 VisitOMPExecutableDirective(S);
573}
574
Alexey Bataev0162e452014-07-22 10:10:35 +0000575void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
576 VisitOMPExecutableDirective(S);
577}
578
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000579void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
580 VisitOMPExecutableDirective(S);
581}
582
Michael Wong65f367f2015-07-21 13:44:28 +0000583void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
584 VisitOMPExecutableDirective(S);
585}
586
Alexey Bataev13314bf2014-10-09 04:18:56 +0000587void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
588 VisitOMPExecutableDirective(S);
589}
590
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000591void StmtProfiler::VisitOMPCancellationPointDirective(
592 const OMPCancellationPointDirective *S) {
593 VisitOMPExecutableDirective(S);
594}
595
Alexey Bataev80909872015-07-02 11:25:17 +0000596void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
597 VisitOMPExecutableDirective(S);
598}
599
Alexey Bataev49f6e782015-12-01 04:18:41 +0000600void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
601 VisitOMPLoopDirective(S);
602}
603
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000604void StmtProfiler::VisitOMPTaskLoopSimdDirective(
605 const OMPTaskLoopSimdDirective *S) {
606 VisitOMPLoopDirective(S);
607}
608
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000609void StmtProfiler::VisitOMPDistributeDirective(
610 const OMPDistributeDirective *S) {
611 VisitOMPLoopDirective(S);
612}
613
Chandler Carruth631abd92011-06-16 06:47:06 +0000614void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000615 VisitStmt(S);
616}
617
Chandler Carruth631abd92011-06-16 06:47:06 +0000618void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000619 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000620 if (!Canonical)
621 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000622 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000623 if (!Canonical)
624 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000625}
626
Chandler Carruth631abd92011-06-16 06:47:06 +0000627void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000628 VisitExpr(S);
629 ID.AddInteger(S->getIdentType());
630}
631
Chandler Carruth631abd92011-06-16 06:47:06 +0000632void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000633 VisitExpr(S);
634 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +0000635 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000636}
637
Chandler Carruth631abd92011-06-16 06:47:06 +0000638void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000639 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000640 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000641 ID.AddInteger(S->getValue());
642}
643
Chandler Carruth631abd92011-06-16 06:47:06 +0000644void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000645 VisitExpr(S);
646 S->getValue().Profile(ID);
647 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +0000648 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000649}
650
Chandler Carruth631abd92011-06-16 06:47:06 +0000651void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000652 VisitExpr(S);
653}
654
Chandler Carruth631abd92011-06-16 06:47:06 +0000655void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000656 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000657 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000658 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000659}
660
Chandler Carruth631abd92011-06-16 06:47:06 +0000661void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000662 VisitExpr(S);
663}
664
Chandler Carruth631abd92011-06-16 06:47:06 +0000665void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000666 VisitExpr(S);
667}
668
Chandler Carruth631abd92011-06-16 06:47:06 +0000669void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000670 VisitExpr(S);
671 ID.AddInteger(S->getOpcode());
672}
673
Chandler Carruth631abd92011-06-16 06:47:06 +0000674void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000675 VisitType(S->getTypeSourceInfo()->getType());
676 unsigned n = S->getNumComponents();
677 for (unsigned i = 0; i < n; ++i) {
678 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
679 ID.AddInteger(ON.getKind());
680 switch (ON.getKind()) {
681 case OffsetOfExpr::OffsetOfNode::Array:
682 // Expressions handled below.
683 break;
684
685 case OffsetOfExpr::OffsetOfNode::Field:
686 VisitDecl(ON.getField());
687 break;
688
689 case OffsetOfExpr::OffsetOfNode::Identifier:
690 ID.AddPointer(ON.getFieldName());
691 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000692
Douglas Gregord1702062010-04-29 00:18:15 +0000693 case OffsetOfExpr::OffsetOfNode::Base:
694 // These nodes are implicit, and therefore don't need profiling.
695 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000696 }
697 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000698
Douglas Gregor882211c2010-04-28 22:16:22 +0000699 VisitExpr(S);
700}
701
Chandler Carruth631abd92011-06-16 06:47:06 +0000702void
703StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000704 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000705 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000706 if (S->isArgumentType())
707 VisitType(S->getArgumentType());
708}
709
Chandler Carruth631abd92011-06-16 06:47:06 +0000710void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000711 VisitExpr(S);
712}
713
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000714void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
715 VisitExpr(S);
716}
717
Chandler Carruth631abd92011-06-16 06:47:06 +0000718void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000719 VisitExpr(S);
720}
721
Chandler Carruth631abd92011-06-16 06:47:06 +0000722void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000723 VisitExpr(S);
724 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000725 if (!Canonical)
726 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000727 ID.AddBoolean(S->isArrow());
728}
729
Chandler Carruth631abd92011-06-16 06:47:06 +0000730void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000731 VisitExpr(S);
732 ID.AddBoolean(S->isFileScope());
733}
734
Chandler Carruth631abd92011-06-16 06:47:06 +0000735void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000736 VisitExpr(S);
737}
738
Chandler Carruth631abd92011-06-16 06:47:06 +0000739void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000740 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000741 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000742}
743
Chandler Carruth631abd92011-06-16 06:47:06 +0000744void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000745 VisitCastExpr(S);
746 VisitType(S->getTypeAsWritten());
747}
748
Chandler Carruth631abd92011-06-16 06:47:06 +0000749void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000750 VisitExplicitCastExpr(S);
751}
752
Chandler Carruth631abd92011-06-16 06:47:06 +0000753void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000754 VisitExpr(S);
755 ID.AddInteger(S->getOpcode());
756}
757
Chandler Carruth631abd92011-06-16 06:47:06 +0000758void
759StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000760 VisitBinaryOperator(S);
761}
762
Chandler Carruth631abd92011-06-16 06:47:06 +0000763void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000764 VisitExpr(S);
765}
766
Chandler Carruth631abd92011-06-16 06:47:06 +0000767void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000768 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000769 VisitExpr(S);
770}
771
Chandler Carruth631abd92011-06-16 06:47:06 +0000772void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000773 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000774 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000775}
776
Chandler Carruth631abd92011-06-16 06:47:06 +0000777void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000778 VisitExpr(S);
779}
780
Chandler Carruth631abd92011-06-16 06:47:06 +0000781void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000782 VisitExpr(S);
783}
784
Hal Finkelc4d7c822013-09-18 03:29:45 +0000785void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
786 VisitExpr(S);
787}
788
Chandler Carruth631abd92011-06-16 06:47:06 +0000789void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000790 VisitExpr(S);
791}
792
Chandler Carruth631abd92011-06-16 06:47:06 +0000793void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000794 VisitExpr(S);
795}
796
Chandler Carruth631abd92011-06-16 06:47:06 +0000797void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000798 VisitExpr(S);
799}
800
Chandler Carruth631abd92011-06-16 06:47:06 +0000801void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000802 if (S->getSyntacticForm()) {
803 VisitInitListExpr(S->getSyntacticForm());
804 return;
805 }
Mike Stump11289f42009-09-09 15:08:12 +0000806
Douglas Gregor5c193b92009-07-28 00:33:38 +0000807 VisitExpr(S);
808}
809
Chandler Carruth631abd92011-06-16 06:47:06 +0000810void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000811 VisitExpr(S);
812 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000813 for (DesignatedInitExpr::const_designators_iterator D =
814 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000815 D != DEnd; ++D) {
816 if (D->isFieldDesignator()) {
817 ID.AddInteger(0);
818 VisitName(D->getFieldName());
819 continue;
820 }
Mike Stump11289f42009-09-09 15:08:12 +0000821
Douglas Gregor5c193b92009-07-28 00:33:38 +0000822 if (D->isArrayDesignator()) {
823 ID.AddInteger(1);
824 } else {
825 assert(D->isArrayRangeDesignator());
826 ID.AddInteger(2);
827 }
828 ID.AddInteger(D->getFirstExprIndex());
829 }
830}
831
Yunzhong Gaocb779302015-06-10 00:27:52 +0000832// Seems that if VisitInitListExpr() only works on the syntactic form of an
833// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
834void StmtProfiler::VisitDesignatedInitUpdateExpr(
835 const DesignatedInitUpdateExpr *S) {
836 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
837 "initializer");
838}
839
840void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
841 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
842}
843
Chandler Carruth631abd92011-06-16 06:47:06 +0000844void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000845 VisitExpr(S);
846}
847
Chandler Carruth631abd92011-06-16 06:47:06 +0000848void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000849 VisitExpr(S);
850 VisitName(&S->getAccessor());
851}
852
Chandler Carruth631abd92011-06-16 06:47:06 +0000853void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000854 VisitExpr(S);
855 VisitDecl(S->getBlockDecl());
856}
857
Chandler Carruth631abd92011-06-16 06:47:06 +0000858void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000859 VisitExpr(S);
860 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
861 QualType T = S->getAssocType(i);
862 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000863 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000864 else
865 VisitType(T);
866 VisitExpr(S->getAssocExpr(i));
867 }
868}
869
John McCallfe96e0b2011-11-06 09:01:30 +0000870void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
871 VisitExpr(S);
872 for (PseudoObjectExpr::const_semantics_iterator
873 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
874 // Normally, we would not profile the source expressions of OVEs.
875 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
876 Visit(OVE->getSourceExpr());
877}
878
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000879void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
880 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000881 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000882}
883
Chandler Carruth631abd92011-06-16 06:47:06 +0000884static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000885 UnaryOperatorKind &UnaryOp,
886 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000887 switch (S->getOperator()) {
888 case OO_None:
889 case OO_New:
890 case OO_Delete:
891 case OO_Array_New:
892 case OO_Array_Delete:
893 case OO_Arrow:
894 case OO_Call:
895 case OO_Conditional:
Richard Smith9be594e2015-10-22 05:12:22 +0000896 case OO_Coawait:
Douglas Gregore9ceb312010-05-19 04:13:23 +0000897 case NUM_OVERLOADED_OPERATORS:
898 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000899
900 case OO_Plus:
901 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000902 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000903 return Stmt::UnaryOperatorClass;
904 }
905
John McCalle3027922010-08-25 11:45:40 +0000906 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000907 return Stmt::BinaryOperatorClass;
908
909 case OO_Minus:
910 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000911 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000912 return Stmt::UnaryOperatorClass;
913 }
914
John McCalle3027922010-08-25 11:45:40 +0000915 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000916 return Stmt::BinaryOperatorClass;
917
918 case OO_Star:
919 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000920 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000921 return Stmt::UnaryOperatorClass;
922 }
923
Richard Smithf15acc52014-06-05 22:43:40 +0000924 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000925 return Stmt::BinaryOperatorClass;
926
927 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000928 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000929 return Stmt::BinaryOperatorClass;
930
931 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000932 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000933 return Stmt::BinaryOperatorClass;
934
935 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000936 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000937 return Stmt::BinaryOperatorClass;
938
939 case OO_Amp:
940 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000941 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000942 return Stmt::UnaryOperatorClass;
943 }
944
John McCalle3027922010-08-25 11:45:40 +0000945 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000946 return Stmt::BinaryOperatorClass;
947
948 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000949 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000950 return Stmt::BinaryOperatorClass;
951
952 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000953 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000954 return Stmt::UnaryOperatorClass;
955
956 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000957 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000958 return Stmt::UnaryOperatorClass;
959
960 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000961 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000962 return Stmt::BinaryOperatorClass;
963
964 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000965 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000966 return Stmt::BinaryOperatorClass;
967
968 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000969 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000970 return Stmt::BinaryOperatorClass;
971
972 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000973 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000974 return Stmt::CompoundAssignOperatorClass;
975
976 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000977 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000978 return Stmt::CompoundAssignOperatorClass;
979
980 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000981 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000982 return Stmt::CompoundAssignOperatorClass;
983
984 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000985 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000986 return Stmt::CompoundAssignOperatorClass;
987
988 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000989 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000990 return Stmt::CompoundAssignOperatorClass;
991
992 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000993 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000994 return Stmt::CompoundAssignOperatorClass;
995
996 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000997 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000998 return Stmt::CompoundAssignOperatorClass;
999
1000 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +00001001 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001002 return Stmt::CompoundAssignOperatorClass;
1003
1004 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +00001005 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001006 return Stmt::BinaryOperatorClass;
1007
1008 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +00001009 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001010 return Stmt::BinaryOperatorClass;
1011
1012 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +00001013 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001014 return Stmt::CompoundAssignOperatorClass;
1015
1016 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001017 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001018 return Stmt::CompoundAssignOperatorClass;
1019
1020 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +00001021 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001022 return Stmt::BinaryOperatorClass;
1023
1024 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001025 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001026 return Stmt::BinaryOperatorClass;
1027
1028 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001029 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001030 return Stmt::BinaryOperatorClass;
1031
1032 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001033 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001034 return Stmt::BinaryOperatorClass;
1035
1036 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001037 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001038 return Stmt::BinaryOperatorClass;
1039
1040 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001041 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001042 return Stmt::BinaryOperatorClass;
1043
1044 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +00001045 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1046 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001047 return Stmt::UnaryOperatorClass;
1048
1049 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001050 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1051 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001052 return Stmt::UnaryOperatorClass;
1053
1054 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001055 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001056 return Stmt::BinaryOperatorClass;
1057
Douglas Gregore9ceb312010-05-19 04:13:23 +00001058 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001059 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001060 return Stmt::BinaryOperatorClass;
1061
1062 case OO_Subscript:
1063 return Stmt::ArraySubscriptExprClass;
1064 }
1065
1066 llvm_unreachable("Invalid overloaded operator expression");
1067}
Richard Smithf15acc52014-06-05 22:43:40 +00001068
Chandler Carruth631abd92011-06-16 06:47:06 +00001069void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001070 if (S->isTypeDependent()) {
1071 // Type-dependent operator calls are profiled like their underlying
1072 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +00001073 UnaryOperatorKind UnaryOp = UO_Extension;
1074 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001075 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001076
Douglas Gregore9ceb312010-05-19 04:13:23 +00001077 ID.AddInteger(SC);
1078 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1079 Visit(S->getArg(I));
1080 if (SC == Stmt::UnaryOperatorClass)
1081 ID.AddInteger(UnaryOp);
1082 else if (SC == Stmt::BinaryOperatorClass ||
1083 SC == Stmt::CompoundAssignOperatorClass)
1084 ID.AddInteger(BinaryOp);
1085 else
1086 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001087
Douglas Gregore9ceb312010-05-19 04:13:23 +00001088 return;
1089 }
Richard Smithf15acc52014-06-05 22:43:40 +00001090
Douglas Gregor5c193b92009-07-28 00:33:38 +00001091 VisitCallExpr(S);
1092 ID.AddInteger(S->getOperator());
1093}
1094
Chandler Carruth631abd92011-06-16 06:47:06 +00001095void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001096 VisitCallExpr(S);
1097}
1098
Chandler Carruth631abd92011-06-16 06:47:06 +00001099void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001100 VisitCallExpr(S);
1101}
1102
Chandler Carruth631abd92011-06-16 06:47:06 +00001103void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001104 VisitExpr(S);
1105}
1106
Chandler Carruth631abd92011-06-16 06:47:06 +00001107void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001108 VisitExplicitCastExpr(S);
1109}
1110
Chandler Carruth631abd92011-06-16 06:47:06 +00001111void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001112 VisitCXXNamedCastExpr(S);
1113}
1114
Chandler Carruth631abd92011-06-16 06:47:06 +00001115void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001116 VisitCXXNamedCastExpr(S);
1117}
1118
Chandler Carruth631abd92011-06-16 06:47:06 +00001119void
1120StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001121 VisitCXXNamedCastExpr(S);
1122}
1123
Chandler Carruth631abd92011-06-16 06:47:06 +00001124void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001125 VisitCXXNamedCastExpr(S);
1126}
1127
Richard Smithc67fdd42012-03-07 08:35:16 +00001128void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1129 VisitCallExpr(S);
1130}
1131
Chandler Carruth631abd92011-06-16 06:47:06 +00001132void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001133 VisitExpr(S);
1134 ID.AddBoolean(S->getValue());
1135}
1136
Chandler Carruth631abd92011-06-16 06:47:06 +00001137void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001138 VisitExpr(S);
1139}
1140
Richard Smithcc1b96d2013-06-12 22:31:48 +00001141void StmtProfiler::VisitCXXStdInitializerListExpr(
1142 const CXXStdInitializerListExpr *S) {
1143 VisitExpr(S);
1144}
1145
Chandler Carruth631abd92011-06-16 06:47:06 +00001146void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001147 VisitExpr(S);
1148 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001149 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001150}
1151
Chandler Carruth631abd92011-06-16 06:47:06 +00001152void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001153 VisitExpr(S);
1154 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001155 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001156}
1157
John McCall5e77d762013-04-16 07:28:30 +00001158void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1159 VisitExpr(S);
1160 VisitDecl(S->getPropertyDecl());
1161}
1162
Alexey Bataevf7630272015-11-25 12:01:00 +00001163void StmtProfiler::VisitMSPropertySubscriptExpr(
1164 const MSPropertySubscriptExpr *S) {
1165 VisitExpr(S);
1166}
1167
Chandler Carruth631abd92011-06-16 06:47:06 +00001168void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001169 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001170 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001171}
1172
Chandler Carruth631abd92011-06-16 06:47:06 +00001173void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001174 VisitExpr(S);
1175}
1176
Chandler Carruth631abd92011-06-16 06:47:06 +00001177void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001178 VisitExpr(S);
1179 VisitDecl(S->getParam());
1180}
1181
Richard Smith852c9db2013-04-20 22:23:05 +00001182void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1183 VisitExpr(S);
1184 VisitDecl(S->getField());
1185}
1186
Chandler Carruth631abd92011-06-16 06:47:06 +00001187void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001188 VisitExpr(S);
1189 VisitDecl(
1190 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1191}
1192
Chandler Carruth631abd92011-06-16 06:47:06 +00001193void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001194 VisitExpr(S);
1195 VisitDecl(S->getConstructor());
1196 ID.AddBoolean(S->isElidable());
1197}
1198
Chandler Carruth631abd92011-06-16 06:47:06 +00001199void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001200 VisitExplicitCastExpr(S);
1201}
1202
Chandler Carruth631abd92011-06-16 06:47:06 +00001203void
1204StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001205 VisitCXXConstructExpr(S);
1206}
1207
Chandler Carruth631abd92011-06-16 06:47:06 +00001208void
Douglas Gregore31e6062012-02-07 10:09:13 +00001209StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1210 VisitExpr(S);
1211 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1212 CEnd = S->explicit_capture_end();
1213 C != CEnd; ++C) {
1214 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001215 switch (C->getCaptureKind()) {
1216 case LCK_This:
1217 break;
1218 case LCK_ByRef:
1219 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001220 VisitDecl(C->getCapturedVar());
1221 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001222 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001223 case LCK_VLAType:
1224 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001225 }
1226 }
1227 // Note: If we actually needed to be able to match lambda
1228 // expressions, we would have to consider parameters and return type
1229 // here, among other things.
1230 VisitStmt(S->getBody());
1231}
1232
1233void
Chandler Carruth631abd92011-06-16 06:47:06 +00001234StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001235 VisitExpr(S);
1236}
1237
Chandler Carruth631abd92011-06-16 06:47:06 +00001238void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001239 VisitExpr(S);
1240 ID.AddBoolean(S->isGlobalDelete());
1241 ID.AddBoolean(S->isArrayForm());
1242 VisitDecl(S->getOperatorDelete());
1243}
1244
Chandler Carruth631abd92011-06-16 06:47:06 +00001245void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001246 VisitExpr(S);
1247 VisitType(S->getAllocatedType());
1248 VisitDecl(S->getOperatorNew());
1249 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001250 ID.AddBoolean(S->isArray());
1251 ID.AddInteger(S->getNumPlacementArgs());
1252 ID.AddBoolean(S->isGlobalNew());
1253 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001254 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001255}
1256
Chandler Carruth631abd92011-06-16 06:47:06 +00001257void
1258StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001259 VisitExpr(S);
1260 ID.AddBoolean(S->isArrow());
1261 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001262 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001263 if (S->getScopeTypeInfo())
1264 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001265 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001266 if (S->getDestroyedTypeInfo())
1267 VisitType(S->getDestroyedType());
1268 else
1269 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001270}
1271
Chandler Carruth631abd92011-06-16 06:47:06 +00001272void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001273 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001274 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001275 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001276 ID.AddBoolean(S->hasExplicitTemplateArgs());
1277 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001278 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1279 S->getExplicitTemplateArgs().NumTemplateArgs);
1280}
1281
1282void
Chandler Carruth631abd92011-06-16 06:47:06 +00001283StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001284 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001285}
1286
Douglas Gregor29c42f22012-02-24 07:38:34 +00001287void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1288 VisitExpr(S);
1289 ID.AddInteger(S->getTrait());
1290 ID.AddInteger(S->getNumArgs());
1291 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1292 VisitType(S->getArg(I)->getType());
1293}
1294
Chandler Carruth631abd92011-06-16 06:47:06 +00001295void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001296 VisitExpr(S);
1297 ID.AddInteger(S->getTrait());
1298 VisitType(S->getQueriedType());
1299}
1300
Chandler Carruth631abd92011-06-16 06:47:06 +00001301void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001302 VisitExpr(S);
1303 ID.AddInteger(S->getTrait());
1304 VisitExpr(S->getQueriedExpression());
1305}
1306
Chandler Carruth631abd92011-06-16 06:47:06 +00001307void StmtProfiler::VisitDependentScopeDeclRefExpr(
1308 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001309 VisitExpr(S);
1310 VisitName(S->getDeclName());
1311 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001312 ID.AddBoolean(S->hasExplicitTemplateArgs());
1313 if (S->hasExplicitTemplateArgs())
1314 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001315}
1316
Chandler Carruth631abd92011-06-16 06:47:06 +00001317void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001318 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001319}
1320
Chandler Carruth631abd92011-06-16 06:47:06 +00001321void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1322 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001323 VisitExpr(S);
1324 VisitType(S->getTypeAsWritten());
1325}
1326
Chandler Carruth631abd92011-06-16 06:47:06 +00001327void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1328 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001329 ID.AddBoolean(S->isImplicitAccess());
1330 if (!S->isImplicitAccess()) {
1331 VisitExpr(S);
1332 ID.AddBoolean(S->isArrow());
1333 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001334 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001335 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001336 ID.AddBoolean(S->hasExplicitTemplateArgs());
1337 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001338 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1339}
1340
Chandler Carruth631abd92011-06-16 06:47:06 +00001341void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001342 ID.AddBoolean(S->isImplicitAccess());
1343 if (!S->isImplicitAccess()) {
1344 VisitExpr(S);
1345 ID.AddBoolean(S->isArrow());
1346 }
John McCall10eae182009-11-30 22:42:35 +00001347 VisitNestedNameSpecifier(S->getQualifier());
1348 VisitName(S->getMemberName());
1349 ID.AddBoolean(S->hasExplicitTemplateArgs());
1350 if (S->hasExplicitTemplateArgs())
1351 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001352}
1353
Chandler Carruth631abd92011-06-16 06:47:06 +00001354void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001355 VisitExpr(S);
1356}
1357
Chandler Carruth631abd92011-06-16 06:47:06 +00001358void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001359 VisitExpr(S);
1360}
1361
Chandler Carruth631abd92011-06-16 06:47:06 +00001362void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001363 VisitExpr(S);
1364 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00001365 if (S->isPartiallySubstituted()) {
1366 auto Args = S->getPartialArguments();
1367 ID.AddInteger(Args.size());
1368 for (const auto &TA : Args)
1369 VisitTemplateArgument(TA);
1370 } else {
1371 ID.AddInteger(0);
1372 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001373}
1374
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001375void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001376 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001377 VisitExpr(S);
1378 VisitDecl(S->getParameterPack());
1379 VisitTemplateArgument(S->getArgumentPack());
1380}
1381
John McCall7c454bb2011-07-15 05:09:51 +00001382void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1383 const SubstNonTypeTemplateParmExpr *E) {
1384 // Profile exactly as the replacement expression.
1385 Visit(E->getReplacement());
1386}
1387
Richard Smithb15fe3a2012-09-12 00:56:43 +00001388void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1389 VisitExpr(S);
1390 VisitDecl(S->getParameterPack());
1391 ID.AddInteger(S->getNumExpansions());
1392 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1393 VisitDecl(*I);
1394}
1395
Douglas Gregorfe314812011-06-21 17:03:29 +00001396void StmtProfiler::VisitMaterializeTemporaryExpr(
1397 const MaterializeTemporaryExpr *S) {
1398 VisitExpr(S);
1399}
1400
Richard Smith0f0af192014-11-08 05:07:16 +00001401void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1402 VisitExpr(S);
1403 ID.AddInteger(S->getOperator());
1404}
1405
Richard Smith9f690bd2015-10-27 06:02:45 +00001406void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1407 VisitStmt(S);
1408}
1409
1410void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1411 VisitStmt(S);
1412}
1413
1414void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1415 VisitExpr(S);
1416}
1417
1418void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1419 VisitExpr(S);
1420}
1421
Chandler Carruth631abd92011-06-16 06:47:06 +00001422void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001423 VisitExpr(E);
1424}
1425
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001426void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1427 VisitExpr(E);
1428}
1429
Chandler Carruth631abd92011-06-16 06:47:06 +00001430void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001431 VisitExpr(S);
1432}
1433
Patrick Beard0caa3942012-04-19 00:25:12 +00001434void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001435 VisitExpr(E);
1436}
1437
1438void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1439 VisitExpr(E);
1440}
1441
1442void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1443 VisitExpr(E);
1444}
1445
Chandler Carruth631abd92011-06-16 06:47:06 +00001446void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001447 VisitExpr(S);
1448 VisitType(S->getEncodedType());
1449}
1450
Chandler Carruth631abd92011-06-16 06:47:06 +00001451void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001452 VisitExpr(S);
1453 VisitName(S->getSelector());
1454}
1455
Chandler Carruth631abd92011-06-16 06:47:06 +00001456void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001457 VisitExpr(S);
1458 VisitDecl(S->getProtocol());
1459}
1460
Chandler Carruth631abd92011-06-16 06:47:06 +00001461void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001462 VisitExpr(S);
1463 VisitDecl(S->getDecl());
1464 ID.AddBoolean(S->isArrow());
1465 ID.AddBoolean(S->isFreeIvar());
1466}
1467
Chandler Carruth631abd92011-06-16 06:47:06 +00001468void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001469 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001470 if (S->isImplicitProperty()) {
1471 VisitDecl(S->getImplicitPropertyGetter());
1472 VisitDecl(S->getImplicitPropertySetter());
1473 } else {
1474 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001475 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001476 if (S->isSuperReceiver()) {
1477 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001478 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001479 }
Douglas Gregora7095092009-07-28 14:44:31 +00001480}
1481
Ted Kremeneke65b0862012-03-06 20:05:56 +00001482void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1483 VisitExpr(S);
1484 VisitDecl(S->getAtIndexMethodDecl());
1485 VisitDecl(S->setAtIndexMethodDecl());
1486}
1487
Chandler Carruth631abd92011-06-16 06:47:06 +00001488void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001489 VisitExpr(S);
1490 VisitName(S->getSelector());
1491 VisitDecl(S->getMethodDecl());
1492}
1493
Chandler Carruth631abd92011-06-16 06:47:06 +00001494void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001495 VisitExpr(S);
1496 ID.AddBoolean(S->isArrow());
1497}
1498
Ted Kremeneke65b0862012-03-06 20:05:56 +00001499void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1500 VisitExpr(S);
1501 ID.AddBoolean(S->getValue());
1502}
1503
Chandler Carruth631abd92011-06-16 06:47:06 +00001504void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1505 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001506 VisitExpr(S);
1507 ID.AddBoolean(S->shouldCopy());
1508}
1509
Chandler Carruth631abd92011-06-16 06:47:06 +00001510void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001511 VisitExplicitCastExpr(S);
1512 ID.AddBoolean(S->getBridgeKind());
1513}
1514
Chandler Carruth631abd92011-06-16 06:47:06 +00001515void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001516 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001517
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001518 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001519 if (const NonTypeTemplateParmDecl *NTTP =
1520 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001521 ID.AddInteger(NTTP->getDepth());
1522 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001523 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001524 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001525 return;
1526 }
Mike Stump11289f42009-09-09 15:08:12 +00001527
Chandler Carruth631abd92011-06-16 06:47:06 +00001528 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001529 // The Itanium C++ ABI uses the type, scope depth, and scope
1530 // index of a parameter when mangling expressions that involve
1531 // function parameters, so we will use the parameter's type for
1532 // establishing function parameter identity. That way, our
1533 // definition of "equivalent" (per C++ [temp.over.link]) is at
1534 // least as strong as the definition of "equivalent" used for
1535 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001536 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001537 ID.AddInteger(Parm->getFunctionScopeDepth());
1538 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001539 return;
1540 }
Mike Stump11289f42009-09-09 15:08:12 +00001541
Richard Smithd9a1cd82012-04-02 18:53:24 +00001542 if (const TemplateTypeParmDecl *TTP =
1543 dyn_cast<TemplateTypeParmDecl>(D)) {
1544 ID.AddInteger(TTP->getDepth());
1545 ID.AddInteger(TTP->getIndex());
1546 ID.AddBoolean(TTP->isParameterPack());
1547 return;
1548 }
1549
Chandler Carruth631abd92011-06-16 06:47:06 +00001550 if (const TemplateTemplateParmDecl *TTP =
1551 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001552 ID.AddInteger(TTP->getDepth());
1553 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001554 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001555 return;
1556 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001557 }
Mike Stump11289f42009-09-09 15:08:12 +00001558
Craig Topper36250ad2014-05-12 05:36:57 +00001559 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001560}
1561
1562void StmtProfiler::VisitType(QualType T) {
1563 if (Canonical)
1564 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001565
Douglas Gregor5c193b92009-07-28 00:33:38 +00001566 ID.AddPointer(T.getAsOpaquePtr());
1567}
1568
1569void StmtProfiler::VisitName(DeclarationName Name) {
1570 ID.AddPointer(Name.getAsOpaquePtr());
1571}
1572
1573void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1574 if (Canonical)
1575 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1576 ID.AddPointer(NNS);
1577}
1578
1579void StmtProfiler::VisitTemplateName(TemplateName Name) {
1580 if (Canonical)
1581 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001582
Douglas Gregor5c193b92009-07-28 00:33:38 +00001583 Name.Profile(ID);
1584}
1585
John McCall0ad16662009-10-29 08:12:44 +00001586void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001587 unsigned NumArgs) {
1588 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001589 for (unsigned I = 0; I != NumArgs; ++I)
1590 VisitTemplateArgument(Args[I].getArgument());
1591}
Mike Stump11289f42009-09-09 15:08:12 +00001592
John McCall0ad16662009-10-29 08:12:44 +00001593void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1594 // Mostly repetitive with TemplateArgument::Profile!
1595 ID.AddInteger(Arg.getKind());
1596 switch (Arg.getKind()) {
1597 case TemplateArgument::Null:
1598 break;
Mike Stump11289f42009-09-09 15:08:12 +00001599
John McCall0ad16662009-10-29 08:12:44 +00001600 case TemplateArgument::Type:
1601 VisitType(Arg.getAsType());
1602 break;
Mike Stump11289f42009-09-09 15:08:12 +00001603
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001604 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001605 case TemplateArgument::TemplateExpansion:
1606 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001607 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001608
John McCall0ad16662009-10-29 08:12:44 +00001609 case TemplateArgument::Declaration:
1610 VisitDecl(Arg.getAsDecl());
1611 break;
Mike Stump11289f42009-09-09 15:08:12 +00001612
Eli Friedmanb826a002012-09-26 02:36:12 +00001613 case TemplateArgument::NullPtr:
1614 VisitType(Arg.getNullPtrType());
1615 break;
1616
John McCall0ad16662009-10-29 08:12:44 +00001617 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001618 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001619 VisitType(Arg.getIntegralType());
1620 break;
Mike Stump11289f42009-09-09 15:08:12 +00001621
John McCall0ad16662009-10-29 08:12:44 +00001622 case TemplateArgument::Expression:
1623 Visit(Arg.getAsExpr());
1624 break;
Mike Stump11289f42009-09-09 15:08:12 +00001625
John McCall0ad16662009-10-29 08:12:44 +00001626 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001627 for (const auto &P : Arg.pack_elements())
1628 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001629 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001630 }
1631}
1632
Jay Foad39c79802011-01-12 09:06:06 +00001633void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001634 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001635 StmtProfiler Profiler(ID, Context, Canonical);
1636 Profiler.Visit(this);
1637}