blob: f6df1ca446a2d5e55eaf656953b8be7167da0f8b [file] [log] [blame]
Douglas Gregor5c193b92009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor32615a12009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor5c193b92009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregora7095092009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/ExprCXX.h"
20#include "clang/AST/ExprObjC.h"
21#include "clang/AST/StmtVisitor.h"
22#include "llvm/ADT/FoldingSet.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000023using namespace clang;
24
25namespace {
Chandler Carruth631abd92011-06-16 06:47:06 +000026 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Douglas Gregor5c193b92009-07-28 00:33:38 +000027 llvm::FoldingSetNodeID &ID;
Jay Foad39c79802011-01-12 09:06:06 +000028 const ASTContext &Context;
Douglas Gregor5c193b92009-07-28 00:33:38 +000029 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000030
Douglas Gregor5c193b92009-07-28 00:33:38 +000031 public:
Jay Foad39c79802011-01-12 09:06:06 +000032 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump11289f42009-09-09 15:08:12 +000033 bool Canonical)
Douglas Gregor5c193b92009-07-28 00:33:38 +000034 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump11289f42009-09-09 15:08:12 +000035
Chandler Carruth631abd92011-06-16 06:47:06 +000036 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000037
Chandler Carruth631abd92011-06-16 06:47:06 +000038#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000039#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000040
Douglas Gregor5c193b92009-07-28 00:33:38 +000041 /// \brief Visit a declaration that is referenced within an expression
42 /// or statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000043 void VisitDecl(const Decl *D);
Mike Stump11289f42009-09-09 15:08:12 +000044
45 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000046 /// statement.
47 void VisitType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +000048
Douglas Gregor5c193b92009-07-28 00:33:38 +000049 /// \brief Visit a name that occurs within an expression or statement.
50 void VisitName(DeclarationName Name);
Mike Stump11289f42009-09-09 15:08:12 +000051
Douglas Gregor5c193b92009-07-28 00:33:38 +000052 /// \brief Visit a nested-name-specifier that occurs within an expression
53 /// or statement.
54 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump11289f42009-09-09 15:08:12 +000055
Douglas Gregor5c193b92009-07-28 00:33:38 +000056 /// \brief Visit a template name that occurs within an expression or
57 /// statement.
58 void VisitTemplateName(TemplateName Name);
Mike Stump11289f42009-09-09 15:08:12 +000059
Douglas Gregor5c193b92009-07-28 00:33:38 +000060 /// \brief Visit template arguments that occur within an expression or
61 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000062 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
63 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000064
65 /// \brief Visit a single template argument.
66 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000067 };
68}
69
Chandler Carruth631abd92011-06-16 06:47:06 +000070void StmtProfiler::VisitStmt(const Stmt *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +000071 ID.AddInteger(S->getStmtClass());
Peter Collingbournecdb9f302012-03-01 16:34:31 +000072 for (Stmt::const_child_range C = S->children(); C; ++C) {
73 if (*C)
74 Visit(*C);
75 else
76 ID.AddInteger(0);
77 }
Douglas Gregor5c193b92009-07-28 00:33:38 +000078}
79
Chandler Carruth631abd92011-06-16 06:47:06 +000080void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000081 VisitStmt(S);
Aaron Ballman535bbcc2014-03-14 17:01:24 +000082 for (const auto *D : S->decls())
83 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +000084}
85
Chandler Carruth631abd92011-06-16 06:47:06 +000086void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000087 VisitStmt(S);
88}
89
Chandler Carruth631abd92011-06-16 06:47:06 +000090void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000091 VisitStmt(S);
92}
93
Chandler Carruth631abd92011-06-16 06:47:06 +000094void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000095 VisitStmt(S);
96}
97
Chandler Carruth631abd92011-06-16 06:47:06 +000098void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000099 VisitStmt(S);
100}
101
Chandler Carruth631abd92011-06-16 06:47:06 +0000102void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000103 VisitStmt(S);
104}
105
Chandler Carruth631abd92011-06-16 06:47:06 +0000106void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000107 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000108 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000109}
110
Richard Smithc202b282012-04-14 00:33:13 +0000111void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
112 VisitStmt(S);
113 // TODO: maybe visit attributes?
114}
115
Chandler Carruth631abd92011-06-16 06:47:06 +0000116void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000117 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000118 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000119}
120
Chandler Carruth631abd92011-06-16 06:47:06 +0000121void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000122 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000123 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000124}
125
Chandler Carruth631abd92011-06-16 06:47:06 +0000126void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000127 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000128 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000129}
130
Chandler Carruth631abd92011-06-16 06:47:06 +0000131void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000132 VisitStmt(S);
133}
134
Chandler Carruth631abd92011-06-16 06:47:06 +0000135void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000136 VisitStmt(S);
137}
138
Chandler Carruth631abd92011-06-16 06:47:06 +0000139void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000140 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000141 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000142}
143
Chandler Carruth631abd92011-06-16 06:47:06 +0000144void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000145 VisitStmt(S);
146}
147
Chandler Carruth631abd92011-06-16 06:47:06 +0000148void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000149 VisitStmt(S);
150}
151
Chandler Carruth631abd92011-06-16 06:47:06 +0000152void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000153 VisitStmt(S);
154}
155
Chandler Carruth631abd92011-06-16 06:47:06 +0000156void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000157 VisitStmt(S);
158}
159
Chad Rosierde70e0e2012-08-25 00:11:56 +0000160void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000161 VisitStmt(S);
162 ID.AddBoolean(S->isVolatile());
163 ID.AddBoolean(S->isSimple());
164 VisitStringLiteral(S->getAsmString());
165 ID.AddInteger(S->getNumOutputs());
166 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
167 ID.AddString(S->getOutputName(I));
168 VisitStringLiteral(S->getOutputConstraintLiteral(I));
169 }
170 ID.AddInteger(S->getNumInputs());
171 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
172 ID.AddString(S->getInputName(I));
173 VisitStringLiteral(S->getInputConstraintLiteral(I));
174 }
175 ID.AddInteger(S->getNumClobbers());
176 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000177 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor44882592009-07-28 15:27:13 +0000178}
179
Chad Rosier32503022012-06-11 20:47:18 +0000180void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
181 // FIXME: Implement MS style inline asm statement profiler.
182 VisitStmt(S);
183}
184
Chandler Carruth631abd92011-06-16 06:47:06 +0000185void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000186 VisitStmt(S);
187 VisitType(S->getCaughtType());
188}
189
Chandler Carruth631abd92011-06-16 06:47:06 +0000190void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000191 VisitStmt(S);
192}
193
Chandler Carruth631abd92011-06-16 06:47:06 +0000194void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000195 VisitStmt(S);
196}
197
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000198void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
199 VisitStmt(S);
200 ID.AddBoolean(S->isIfExists());
201 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
202 VisitName(S->getNameInfo().getName());
203}
204
Chandler Carruth631abd92011-06-16 06:47:06 +0000205void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000206 VisitStmt(S);
207}
208
Chandler Carruth631abd92011-06-16 06:47:06 +0000209void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000210 VisitStmt(S);
211}
212
Chandler Carruth631abd92011-06-16 06:47:06 +0000213void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000214 VisitStmt(S);
215}
216
Nico Weber9b982072014-07-07 00:12:30 +0000217void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
218 VisitStmt(S);
219}
220
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000221void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
222 VisitStmt(S);
223}
224
Chandler Carruth631abd92011-06-16 06:47:06 +0000225void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000226 VisitStmt(S);
227}
228
Chandler Carruth631abd92011-06-16 06:47:06 +0000229void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000230 VisitStmt(S);
231 ID.AddBoolean(S->hasEllipsis());
232 if (S->getCatchParamDecl())
233 VisitType(S->getCatchParamDecl()->getType());
234}
235
Chandler Carruth631abd92011-06-16 06:47:06 +0000236void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000237 VisitStmt(S);
238}
239
Chandler Carruth631abd92011-06-16 06:47:06 +0000240void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000241 VisitStmt(S);
242}
243
Chandler Carruth631abd92011-06-16 06:47:06 +0000244void
245StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000246 VisitStmt(S);
247}
248
Chandler Carruth631abd92011-06-16 06:47:06 +0000249void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000250 VisitStmt(S);
251}
252
Chandler Carruth631abd92011-06-16 06:47:06 +0000253void
254StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000255 VisitStmt(S);
256}
257
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000258namespace {
259class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
260 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000261 /// \brief Process clauses with list of variables.
262 template <typename T>
263 void VisitOMPClauseList(T *Node);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000264public:
265 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
266#define OPENMP_CLAUSE(Name, Class) \
267 void Visit##Class(const Class *C);
268#include "clang/Basic/OpenMPKinds.def"
269};
270
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000271void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
272 if (C->getCondition())
273 Profiler->VisitStmt(C->getCondition());
274}
275
Alexey Bataev3778b602014-07-17 07:32:53 +0000276void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
277 if (C->getCondition())
278 Profiler->VisitStmt(C->getCondition());
279}
280
Alexey Bataev568a8332014-03-06 06:15:19 +0000281void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
282 if (C->getNumThreads())
283 Profiler->VisitStmt(C->getNumThreads());
284}
285
Alexey Bataev62c87d22014-03-21 04:51:18 +0000286void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
287 if (C->getSafelen())
288 Profiler->VisitStmt(C->getSafelen());
289}
290
Alexander Musman8bd31e62014-05-27 15:12:19 +0000291void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
292 if (C->getNumForLoops())
293 Profiler->VisitStmt(C->getNumForLoops());
294}
295
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000296void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000297
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000298void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
299
Alexey Bataev56dafe82014-06-20 07:16:17 +0000300void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
301 if (C->getChunkSize())
302 Profiler->VisitStmt(C->getChunkSize());
303}
304
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000305void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {}
306
Alexey Bataev236070f2014-06-20 11:19:47 +0000307void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
308
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000309void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
310
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000311void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
312
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000313void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
314
Alexey Bataevdea47612014-07-23 07:46:59 +0000315void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
316
Alexey Bataev67a4f222014-07-23 10:25:33 +0000317void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
318
Alexey Bataev459dec02014-07-24 06:46:57 +0000319void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
320
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000321void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
322
Alexey Bataev756c1962013-09-24 03:17:45 +0000323template<typename T>
324void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000325 for (auto *E : Node->varlists()) {
326 Profiler->VisitStmt(E);
327 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000328}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000329
330void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000331 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000332 for (auto *E : C->private_copies()) {
333 Profiler->VisitStmt(E);
334 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000335}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000336void
337OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000338 VisitOMPClauseList(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000339 for (auto *E : C->private_copies()) {
340 Profiler->VisitStmt(E);
341 }
342 for (auto *E : C->inits()) {
343 Profiler->VisitStmt(E);
344 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000345}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000346void
347OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
348 VisitOMPClauseList(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000349 for (auto *E : C->source_exprs()) {
350 Profiler->VisitStmt(E);
351 }
352 for (auto *E : C->destination_exprs()) {
353 Profiler->VisitStmt(E);
354 }
355 for (auto *E : C->assignment_ops()) {
356 Profiler->VisitStmt(E);
357 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000358}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000359void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000360 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000361}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000362void OMPClauseProfiler::VisitOMPReductionClause(
363 const OMPReductionClause *C) {
364 Profiler->VisitNestedNameSpecifier(
365 C->getQualifierLoc().getNestedNameSpecifier());
366 Profiler->VisitName(C->getNameInfo().getName());
367 VisitOMPClauseList(C);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000368 for (auto *E : C->lhs_exprs()) {
369 Profiler->VisitStmt(E);
370 }
371 for (auto *E : C->rhs_exprs()) {
372 Profiler->VisitStmt(E);
373 }
374 for (auto *E : C->reduction_ops()) {
375 Profiler->VisitStmt(E);
376 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000377}
Alexander Musman8dba6642014-04-22 13:09:42 +0000378void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
379 VisitOMPClauseList(C);
Alexander Musman3276a272015-03-21 10:12:56 +0000380 for (auto *E : C->inits()) {
381 Profiler->VisitStmt(E);
382 }
383 for (auto *E : C->updates()) {
384 Profiler->VisitStmt(E);
385 }
386 for (auto *E : C->finals()) {
387 Profiler->VisitStmt(E);
388 }
Alexander Musman8dba6642014-04-22 13:09:42 +0000389 Profiler->VisitStmt(C->getStep());
Alexander Musman3276a272015-03-21 10:12:56 +0000390 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000391}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000392void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
393 VisitOMPClauseList(C);
394 Profiler->VisitStmt(C->getAlignment());
395}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000396void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
397 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000398 for (auto *E : C->source_exprs()) {
399 Profiler->VisitStmt(E);
400 }
401 for (auto *E : C->destination_exprs()) {
402 Profiler->VisitStmt(E);
403 }
404 for (auto *E : C->assignment_ops()) {
405 Profiler->VisitStmt(E);
406 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000407}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000408void
409OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
410 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000411 for (auto *E : C->source_exprs()) {
412 Profiler->VisitStmt(E);
413 }
414 for (auto *E : C->destination_exprs()) {
415 Profiler->VisitStmt(E);
416 }
417 for (auto *E : C->assignment_ops()) {
418 Profiler->VisitStmt(E);
419 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000420}
Alexey Bataev6125da92014-07-21 11:26:11 +0000421void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
422 VisitOMPClauseList(C);
423}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000424}
425
426void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000427StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000428 VisitStmt(S);
429 OMPClauseProfiler P(this);
430 ArrayRef<OMPClause *> Clauses = S->clauses();
431 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
432 I != E; ++I)
433 if (*I)
434 P.Visit(*I);
435}
436
Alexander Musman3aaab662014-08-19 11:27:13 +0000437void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
438 VisitOMPExecutableDirective(S);
439}
440
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000441void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
442 VisitOMPExecutableDirective(S);
443}
444
445void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000446 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000447}
448
Alexey Bataevf29276e2014-06-18 04:14:57 +0000449void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000450 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000451}
452
Alexander Musmanf82886e2014-09-18 05:12:34 +0000453void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
454 VisitOMPLoopDirective(S);
455}
456
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000457void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
458 VisitOMPExecutableDirective(S);
459}
460
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000461void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
462 VisitOMPExecutableDirective(S);
463}
464
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000465void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
466 VisitOMPExecutableDirective(S);
467}
468
Alexander Musman80c22892014-07-17 08:54:58 +0000469void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
470 VisitOMPExecutableDirective(S);
471}
472
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000473void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
474 VisitOMPExecutableDirective(S);
475 VisitName(S->getDirectiveName().getName());
476}
477
Alexey Bataev4acb8592014-07-07 13:01:15 +0000478void
479StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000480 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000481}
482
Alexander Musmane4e893b2014-09-23 09:33:00 +0000483void StmtProfiler::VisitOMPParallelForSimdDirective(
484 const OMPParallelForSimdDirective *S) {
485 VisitOMPLoopDirective(S);
486}
487
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000488void StmtProfiler::VisitOMPParallelSectionsDirective(
489 const OMPParallelSectionsDirective *S) {
490 VisitOMPExecutableDirective(S);
491}
492
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000493void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
494 VisitOMPExecutableDirective(S);
495}
496
Alexey Bataev68446b72014-07-18 07:47:19 +0000497void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
498 VisitOMPExecutableDirective(S);
499}
500
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000501void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
502 VisitOMPExecutableDirective(S);
503}
504
Alexey Bataev2df347a2014-07-18 10:17:07 +0000505void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
506 VisitOMPExecutableDirective(S);
507}
508
Alexey Bataev6125da92014-07-21 11:26:11 +0000509void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
510 VisitOMPExecutableDirective(S);
511}
512
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000513void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
514 VisitOMPExecutableDirective(S);
515}
516
Alexey Bataev0162e452014-07-22 10:10:35 +0000517void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
518 VisitOMPExecutableDirective(S);
519}
520
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000521void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
522 VisitOMPExecutableDirective(S);
523}
524
Alexey Bataev13314bf2014-10-09 04:18:56 +0000525void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
526 VisitOMPExecutableDirective(S);
527}
528
Chandler Carruth631abd92011-06-16 06:47:06 +0000529void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000530 VisitStmt(S);
531}
532
Chandler Carruth631abd92011-06-16 06:47:06 +0000533void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000534 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000535 if (!Canonical)
536 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000537 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000538 if (!Canonical)
539 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000540}
541
Chandler Carruth631abd92011-06-16 06:47:06 +0000542void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000543 VisitExpr(S);
544 ID.AddInteger(S->getIdentType());
545}
546
Chandler Carruth631abd92011-06-16 06:47:06 +0000547void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000548 VisitExpr(S);
549 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +0000550 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000551}
552
Chandler Carruth631abd92011-06-16 06:47:06 +0000553void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000554 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000555 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000556 ID.AddInteger(S->getValue());
557}
558
Chandler Carruth631abd92011-06-16 06:47:06 +0000559void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000560 VisitExpr(S);
561 S->getValue().Profile(ID);
562 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +0000563 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000564}
565
Chandler Carruth631abd92011-06-16 06:47:06 +0000566void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000567 VisitExpr(S);
568}
569
Chandler Carruth631abd92011-06-16 06:47:06 +0000570void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000571 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000572 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000573 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000574}
575
Chandler Carruth631abd92011-06-16 06:47:06 +0000576void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000577 VisitExpr(S);
578}
579
Chandler Carruth631abd92011-06-16 06:47:06 +0000580void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000581 VisitExpr(S);
582}
583
Chandler Carruth631abd92011-06-16 06:47:06 +0000584void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000585 VisitExpr(S);
586 ID.AddInteger(S->getOpcode());
587}
588
Chandler Carruth631abd92011-06-16 06:47:06 +0000589void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000590 VisitType(S->getTypeSourceInfo()->getType());
591 unsigned n = S->getNumComponents();
592 for (unsigned i = 0; i < n; ++i) {
593 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
594 ID.AddInteger(ON.getKind());
595 switch (ON.getKind()) {
596 case OffsetOfExpr::OffsetOfNode::Array:
597 // Expressions handled below.
598 break;
599
600 case OffsetOfExpr::OffsetOfNode::Field:
601 VisitDecl(ON.getField());
602 break;
603
604 case OffsetOfExpr::OffsetOfNode::Identifier:
605 ID.AddPointer(ON.getFieldName());
606 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000607
Douglas Gregord1702062010-04-29 00:18:15 +0000608 case OffsetOfExpr::OffsetOfNode::Base:
609 // These nodes are implicit, and therefore don't need profiling.
610 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000611 }
612 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000613
Douglas Gregor882211c2010-04-28 22:16:22 +0000614 VisitExpr(S);
615}
616
Chandler Carruth631abd92011-06-16 06:47:06 +0000617void
618StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000619 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000620 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000621 if (S->isArgumentType())
622 VisitType(S->getArgumentType());
623}
624
Chandler Carruth631abd92011-06-16 06:47:06 +0000625void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000626 VisitExpr(S);
627}
628
Chandler Carruth631abd92011-06-16 06:47:06 +0000629void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000630 VisitExpr(S);
631}
632
Chandler Carruth631abd92011-06-16 06:47:06 +0000633void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000634 VisitExpr(S);
635 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000636 if (!Canonical)
637 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000638 ID.AddBoolean(S->isArrow());
639}
640
Chandler Carruth631abd92011-06-16 06:47:06 +0000641void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000642 VisitExpr(S);
643 ID.AddBoolean(S->isFileScope());
644}
645
Chandler Carruth631abd92011-06-16 06:47:06 +0000646void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000647 VisitExpr(S);
648}
649
Chandler Carruth631abd92011-06-16 06:47:06 +0000650void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000651 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000652 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000653}
654
Chandler Carruth631abd92011-06-16 06:47:06 +0000655void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000656 VisitCastExpr(S);
657 VisitType(S->getTypeAsWritten());
658}
659
Chandler Carruth631abd92011-06-16 06:47:06 +0000660void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000661 VisitExplicitCastExpr(S);
662}
663
Chandler Carruth631abd92011-06-16 06:47:06 +0000664void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000665 VisitExpr(S);
666 ID.AddInteger(S->getOpcode());
667}
668
Chandler Carruth631abd92011-06-16 06:47:06 +0000669void
670StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000671 VisitBinaryOperator(S);
672}
673
Chandler Carruth631abd92011-06-16 06:47:06 +0000674void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000675 VisitExpr(S);
676}
677
Chandler Carruth631abd92011-06-16 06:47:06 +0000678void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000679 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000680 VisitExpr(S);
681}
682
Chandler Carruth631abd92011-06-16 06:47:06 +0000683void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000684 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000685 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000686}
687
Chandler Carruth631abd92011-06-16 06:47:06 +0000688void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000689 VisitExpr(S);
690}
691
Chandler Carruth631abd92011-06-16 06:47:06 +0000692void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000693 VisitExpr(S);
694}
695
Hal Finkelc4d7c822013-09-18 03:29:45 +0000696void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
697 VisitExpr(S);
698}
699
Chandler Carruth631abd92011-06-16 06:47:06 +0000700void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000701 VisitExpr(S);
702}
703
Chandler Carruth631abd92011-06-16 06:47:06 +0000704void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000705 VisitExpr(S);
706}
707
Chandler Carruth631abd92011-06-16 06:47:06 +0000708void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000709 VisitExpr(S);
710}
711
Chandler Carruth631abd92011-06-16 06:47:06 +0000712void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000713 if (S->getSyntacticForm()) {
714 VisitInitListExpr(S->getSyntacticForm());
715 return;
716 }
Mike Stump11289f42009-09-09 15:08:12 +0000717
Douglas Gregor5c193b92009-07-28 00:33:38 +0000718 VisitExpr(S);
719}
720
Chandler Carruth631abd92011-06-16 06:47:06 +0000721void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000722 VisitExpr(S);
723 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000724 for (DesignatedInitExpr::const_designators_iterator D =
725 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000726 D != DEnd; ++D) {
727 if (D->isFieldDesignator()) {
728 ID.AddInteger(0);
729 VisitName(D->getFieldName());
730 continue;
731 }
Mike Stump11289f42009-09-09 15:08:12 +0000732
Douglas Gregor5c193b92009-07-28 00:33:38 +0000733 if (D->isArrayDesignator()) {
734 ID.AddInteger(1);
735 } else {
736 assert(D->isArrayRangeDesignator());
737 ID.AddInteger(2);
738 }
739 ID.AddInteger(D->getFirstExprIndex());
740 }
741}
742
Chandler Carruth631abd92011-06-16 06:47:06 +0000743void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000744 VisitExpr(S);
745}
746
Chandler Carruth631abd92011-06-16 06:47:06 +0000747void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000748 VisitExpr(S);
749 VisitName(&S->getAccessor());
750}
751
Chandler Carruth631abd92011-06-16 06:47:06 +0000752void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000753 VisitExpr(S);
754 VisitDecl(S->getBlockDecl());
755}
756
Chandler Carruth631abd92011-06-16 06:47:06 +0000757void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000758 VisitExpr(S);
759 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
760 QualType T = S->getAssocType(i);
761 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000762 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000763 else
764 VisitType(T);
765 VisitExpr(S->getAssocExpr(i));
766 }
767}
768
John McCallfe96e0b2011-11-06 09:01:30 +0000769void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
770 VisitExpr(S);
771 for (PseudoObjectExpr::const_semantics_iterator
772 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
773 // Normally, we would not profile the source expressions of OVEs.
774 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
775 Visit(OVE->getSourceExpr());
776}
777
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000778void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
779 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000780 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000781}
782
Chandler Carruth631abd92011-06-16 06:47:06 +0000783static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000784 UnaryOperatorKind &UnaryOp,
785 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000786 switch (S->getOperator()) {
787 case OO_None:
788 case OO_New:
789 case OO_Delete:
790 case OO_Array_New:
791 case OO_Array_Delete:
792 case OO_Arrow:
793 case OO_Call:
794 case OO_Conditional:
795 case NUM_OVERLOADED_OPERATORS:
796 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000797
798 case OO_Plus:
799 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000800 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000801 return Stmt::UnaryOperatorClass;
802 }
803
John McCalle3027922010-08-25 11:45:40 +0000804 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000805 return Stmt::BinaryOperatorClass;
806
807 case OO_Minus:
808 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000809 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000810 return Stmt::UnaryOperatorClass;
811 }
812
John McCalle3027922010-08-25 11:45:40 +0000813 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000814 return Stmt::BinaryOperatorClass;
815
816 case OO_Star:
817 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000818 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000819 return Stmt::UnaryOperatorClass;
820 }
821
Richard Smithf15acc52014-06-05 22:43:40 +0000822 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000823 return Stmt::BinaryOperatorClass;
824
825 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000826 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000827 return Stmt::BinaryOperatorClass;
828
829 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000830 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000831 return Stmt::BinaryOperatorClass;
832
833 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000834 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000835 return Stmt::BinaryOperatorClass;
836
837 case OO_Amp:
838 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000839 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000840 return Stmt::UnaryOperatorClass;
841 }
842
John McCalle3027922010-08-25 11:45:40 +0000843 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000844 return Stmt::BinaryOperatorClass;
845
846 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000847 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000848 return Stmt::BinaryOperatorClass;
849
850 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000851 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000852 return Stmt::UnaryOperatorClass;
853
854 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000855 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000856 return Stmt::UnaryOperatorClass;
857
858 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000859 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000860 return Stmt::BinaryOperatorClass;
861
862 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000863 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000864 return Stmt::BinaryOperatorClass;
865
866 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000867 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000868 return Stmt::BinaryOperatorClass;
869
870 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000871 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000872 return Stmt::CompoundAssignOperatorClass;
873
874 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000875 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000876 return Stmt::CompoundAssignOperatorClass;
877
878 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000879 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000880 return Stmt::CompoundAssignOperatorClass;
881
882 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000883 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000884 return Stmt::CompoundAssignOperatorClass;
885
886 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000887 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000888 return Stmt::CompoundAssignOperatorClass;
889
890 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000891 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000892 return Stmt::CompoundAssignOperatorClass;
893
894 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000895 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000896 return Stmt::CompoundAssignOperatorClass;
897
898 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000899 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000900 return Stmt::CompoundAssignOperatorClass;
901
902 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000903 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000904 return Stmt::BinaryOperatorClass;
905
906 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000907 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000908 return Stmt::BinaryOperatorClass;
909
910 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000911 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000912 return Stmt::CompoundAssignOperatorClass;
913
914 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000915 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000916 return Stmt::CompoundAssignOperatorClass;
917
918 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000919 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000920 return Stmt::BinaryOperatorClass;
921
922 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000923 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000924 return Stmt::BinaryOperatorClass;
925
926 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000927 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000928 return Stmt::BinaryOperatorClass;
929
930 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000931 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000932 return Stmt::BinaryOperatorClass;
933
934 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000935 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000936 return Stmt::BinaryOperatorClass;
937
938 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000939 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000940 return Stmt::BinaryOperatorClass;
941
942 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000943 UnaryOp = S->getNumArgs() == 1? UO_PreInc
944 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000945 return Stmt::UnaryOperatorClass;
946
947 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000948 UnaryOp = S->getNumArgs() == 1? UO_PreDec
949 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000950 return Stmt::UnaryOperatorClass;
951
952 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000953 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000954 return Stmt::BinaryOperatorClass;
955
956
957 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000958 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000959 return Stmt::BinaryOperatorClass;
960
961 case OO_Subscript:
962 return Stmt::ArraySubscriptExprClass;
963 }
964
965 llvm_unreachable("Invalid overloaded operator expression");
966}
Richard Smithf15acc52014-06-05 22:43:40 +0000967
Douglas Gregore9ceb312010-05-19 04:13:23 +0000968
Chandler Carruth631abd92011-06-16 06:47:06 +0000969void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000970 if (S->isTypeDependent()) {
971 // Type-dependent operator calls are profiled like their underlying
972 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000973 UnaryOperatorKind UnaryOp = UO_Extension;
974 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000975 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +0000976
Douglas Gregore9ceb312010-05-19 04:13:23 +0000977 ID.AddInteger(SC);
978 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
979 Visit(S->getArg(I));
980 if (SC == Stmt::UnaryOperatorClass)
981 ID.AddInteger(UnaryOp);
982 else if (SC == Stmt::BinaryOperatorClass ||
983 SC == Stmt::CompoundAssignOperatorClass)
984 ID.AddInteger(BinaryOp);
985 else
986 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +0000987
Douglas Gregore9ceb312010-05-19 04:13:23 +0000988 return;
989 }
Richard Smithf15acc52014-06-05 22:43:40 +0000990
Douglas Gregor5c193b92009-07-28 00:33:38 +0000991 VisitCallExpr(S);
992 ID.AddInteger(S->getOperator());
993}
994
Chandler Carruth631abd92011-06-16 06:47:06 +0000995void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000996 VisitCallExpr(S);
997}
998
Chandler Carruth631abd92011-06-16 06:47:06 +0000999void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001000 VisitCallExpr(S);
1001}
1002
Chandler Carruth631abd92011-06-16 06:47:06 +00001003void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001004 VisitExpr(S);
1005}
1006
Chandler Carruth631abd92011-06-16 06:47:06 +00001007void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001008 VisitExplicitCastExpr(S);
1009}
1010
Chandler Carruth631abd92011-06-16 06:47:06 +00001011void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001012 VisitCXXNamedCastExpr(S);
1013}
1014
Chandler Carruth631abd92011-06-16 06:47:06 +00001015void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001016 VisitCXXNamedCastExpr(S);
1017}
1018
Chandler Carruth631abd92011-06-16 06:47:06 +00001019void
1020StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001021 VisitCXXNamedCastExpr(S);
1022}
1023
Chandler Carruth631abd92011-06-16 06:47:06 +00001024void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001025 VisitCXXNamedCastExpr(S);
1026}
1027
Richard Smithc67fdd42012-03-07 08:35:16 +00001028void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1029 VisitCallExpr(S);
1030}
1031
Chandler Carruth631abd92011-06-16 06:47:06 +00001032void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001033 VisitExpr(S);
1034 ID.AddBoolean(S->getValue());
1035}
1036
Chandler Carruth631abd92011-06-16 06:47:06 +00001037void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001038 VisitExpr(S);
1039}
1040
Richard Smithcc1b96d2013-06-12 22:31:48 +00001041void StmtProfiler::VisitCXXStdInitializerListExpr(
1042 const CXXStdInitializerListExpr *S) {
1043 VisitExpr(S);
1044}
1045
Chandler Carruth631abd92011-06-16 06:47:06 +00001046void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001047 VisitExpr(S);
1048 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001049 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001050}
1051
Chandler Carruth631abd92011-06-16 06:47:06 +00001052void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001053 VisitExpr(S);
1054 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001055 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001056}
1057
John McCall5e77d762013-04-16 07:28:30 +00001058void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1059 VisitExpr(S);
1060 VisitDecl(S->getPropertyDecl());
1061}
1062
Chandler Carruth631abd92011-06-16 06:47:06 +00001063void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001064 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001065 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001066}
1067
Chandler Carruth631abd92011-06-16 06:47:06 +00001068void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001069 VisitExpr(S);
1070}
1071
Chandler Carruth631abd92011-06-16 06:47:06 +00001072void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001073 VisitExpr(S);
1074 VisitDecl(S->getParam());
1075}
1076
Richard Smith852c9db2013-04-20 22:23:05 +00001077void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1078 VisitExpr(S);
1079 VisitDecl(S->getField());
1080}
1081
Chandler Carruth631abd92011-06-16 06:47:06 +00001082void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001083 VisitExpr(S);
1084 VisitDecl(
1085 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1086}
1087
Chandler Carruth631abd92011-06-16 06:47:06 +00001088void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001089 VisitExpr(S);
1090 VisitDecl(S->getConstructor());
1091 ID.AddBoolean(S->isElidable());
1092}
1093
Chandler Carruth631abd92011-06-16 06:47:06 +00001094void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001095 VisitExplicitCastExpr(S);
1096}
1097
Chandler Carruth631abd92011-06-16 06:47:06 +00001098void
1099StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001100 VisitCXXConstructExpr(S);
1101}
1102
Chandler Carruth631abd92011-06-16 06:47:06 +00001103void
Douglas Gregore31e6062012-02-07 10:09:13 +00001104StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1105 VisitExpr(S);
1106 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1107 CEnd = S->explicit_capture_end();
1108 C != CEnd; ++C) {
1109 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001110 switch (C->getCaptureKind()) {
1111 case LCK_This:
1112 break;
1113 case LCK_ByRef:
1114 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001115 VisitDecl(C->getCapturedVar());
1116 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001117 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001118 case LCK_VLAType:
1119 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001120 }
1121 }
1122 // Note: If we actually needed to be able to match lambda
1123 // expressions, we would have to consider parameters and return type
1124 // here, among other things.
1125 VisitStmt(S->getBody());
1126}
1127
1128void
Chandler Carruth631abd92011-06-16 06:47:06 +00001129StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001130 VisitExpr(S);
1131}
1132
Chandler Carruth631abd92011-06-16 06:47:06 +00001133void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001134 VisitExpr(S);
1135 ID.AddBoolean(S->isGlobalDelete());
1136 ID.AddBoolean(S->isArrayForm());
1137 VisitDecl(S->getOperatorDelete());
1138}
1139
1140
Chandler Carruth631abd92011-06-16 06:47:06 +00001141void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001142 VisitExpr(S);
1143 VisitType(S->getAllocatedType());
1144 VisitDecl(S->getOperatorNew());
1145 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001146 ID.AddBoolean(S->isArray());
1147 ID.AddInteger(S->getNumPlacementArgs());
1148 ID.AddBoolean(S->isGlobalNew());
1149 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001150 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001151}
1152
Chandler Carruth631abd92011-06-16 06:47:06 +00001153void
1154StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001155 VisitExpr(S);
1156 ID.AddBoolean(S->isArrow());
1157 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001158 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001159 if (S->getScopeTypeInfo())
1160 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001161 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001162 if (S->getDestroyedTypeInfo())
1163 VisitType(S->getDestroyedType());
1164 else
1165 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001166}
1167
Chandler Carruth631abd92011-06-16 06:47:06 +00001168void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001169 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001170 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001171 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001172 ID.AddBoolean(S->hasExplicitTemplateArgs());
1173 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001174 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1175 S->getExplicitTemplateArgs().NumTemplateArgs);
1176}
1177
1178void
Chandler Carruth631abd92011-06-16 06:47:06 +00001179StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001180 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001181}
1182
Douglas Gregor29c42f22012-02-24 07:38:34 +00001183void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1184 VisitExpr(S);
1185 ID.AddInteger(S->getTrait());
1186 ID.AddInteger(S->getNumArgs());
1187 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1188 VisitType(S->getArg(I)->getType());
1189}
1190
Chandler Carruth631abd92011-06-16 06:47:06 +00001191void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001192 VisitExpr(S);
1193 ID.AddInteger(S->getTrait());
1194 VisitType(S->getQueriedType());
1195}
1196
Chandler Carruth631abd92011-06-16 06:47:06 +00001197void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001198 VisitExpr(S);
1199 ID.AddInteger(S->getTrait());
1200 VisitExpr(S->getQueriedExpression());
1201}
1202
Chandler Carruth631abd92011-06-16 06:47:06 +00001203void StmtProfiler::VisitDependentScopeDeclRefExpr(
1204 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001205 VisitExpr(S);
1206 VisitName(S->getDeclName());
1207 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001208 ID.AddBoolean(S->hasExplicitTemplateArgs());
1209 if (S->hasExplicitTemplateArgs())
1210 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001211}
1212
Chandler Carruth631abd92011-06-16 06:47:06 +00001213void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001214 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001215}
1216
Chandler Carruth631abd92011-06-16 06:47:06 +00001217void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1218 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001219 VisitExpr(S);
1220 VisitType(S->getTypeAsWritten());
1221}
1222
Chandler Carruth631abd92011-06-16 06:47:06 +00001223void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1224 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001225 ID.AddBoolean(S->isImplicitAccess());
1226 if (!S->isImplicitAccess()) {
1227 VisitExpr(S);
1228 ID.AddBoolean(S->isArrow());
1229 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001230 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001231 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001232 ID.AddBoolean(S->hasExplicitTemplateArgs());
1233 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001234 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1235}
1236
Chandler Carruth631abd92011-06-16 06:47:06 +00001237void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001238 ID.AddBoolean(S->isImplicitAccess());
1239 if (!S->isImplicitAccess()) {
1240 VisitExpr(S);
1241 ID.AddBoolean(S->isArrow());
1242 }
John McCall10eae182009-11-30 22:42:35 +00001243 VisitNestedNameSpecifier(S->getQualifier());
1244 VisitName(S->getMemberName());
1245 ID.AddBoolean(S->hasExplicitTemplateArgs());
1246 if (S->hasExplicitTemplateArgs())
1247 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001248}
1249
Chandler Carruth631abd92011-06-16 06:47:06 +00001250void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001251 VisitExpr(S);
1252}
1253
Chandler Carruth631abd92011-06-16 06:47:06 +00001254void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001255 VisitExpr(S);
1256}
1257
Chandler Carruth631abd92011-06-16 06:47:06 +00001258void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001259 VisitExpr(S);
1260 VisitDecl(S->getPack());
1261}
1262
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001263void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001264 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001265 VisitExpr(S);
1266 VisitDecl(S->getParameterPack());
1267 VisitTemplateArgument(S->getArgumentPack());
1268}
1269
John McCall7c454bb2011-07-15 05:09:51 +00001270void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1271 const SubstNonTypeTemplateParmExpr *E) {
1272 // Profile exactly as the replacement expression.
1273 Visit(E->getReplacement());
1274}
1275
Richard Smithb15fe3a2012-09-12 00:56:43 +00001276void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1277 VisitExpr(S);
1278 VisitDecl(S->getParameterPack());
1279 ID.AddInteger(S->getNumExpansions());
1280 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1281 VisitDecl(*I);
1282}
1283
Douglas Gregorfe314812011-06-21 17:03:29 +00001284void StmtProfiler::VisitMaterializeTemporaryExpr(
1285 const MaterializeTemporaryExpr *S) {
1286 VisitExpr(S);
1287}
1288
Richard Smith0f0af192014-11-08 05:07:16 +00001289void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1290 VisitExpr(S);
1291 ID.AddInteger(S->getOperator());
1292}
1293
Chandler Carruth631abd92011-06-16 06:47:06 +00001294void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001295 VisitExpr(E);
1296}
1297
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001298void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1299 VisitExpr(E);
1300}
1301
Chandler Carruth631abd92011-06-16 06:47:06 +00001302void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001303 VisitExpr(S);
1304}
1305
Patrick Beard0caa3942012-04-19 00:25:12 +00001306void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001307 VisitExpr(E);
1308}
1309
1310void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1311 VisitExpr(E);
1312}
1313
1314void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1315 VisitExpr(E);
1316}
1317
Chandler Carruth631abd92011-06-16 06:47:06 +00001318void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001319 VisitExpr(S);
1320 VisitType(S->getEncodedType());
1321}
1322
Chandler Carruth631abd92011-06-16 06:47:06 +00001323void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001324 VisitExpr(S);
1325 VisitName(S->getSelector());
1326}
1327
Chandler Carruth631abd92011-06-16 06:47:06 +00001328void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001329 VisitExpr(S);
1330 VisitDecl(S->getProtocol());
1331}
1332
Chandler Carruth631abd92011-06-16 06:47:06 +00001333void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001334 VisitExpr(S);
1335 VisitDecl(S->getDecl());
1336 ID.AddBoolean(S->isArrow());
1337 ID.AddBoolean(S->isFreeIvar());
1338}
1339
Chandler Carruth631abd92011-06-16 06:47:06 +00001340void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001341 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001342 if (S->isImplicitProperty()) {
1343 VisitDecl(S->getImplicitPropertyGetter());
1344 VisitDecl(S->getImplicitPropertySetter());
1345 } else {
1346 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001347 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001348 if (S->isSuperReceiver()) {
1349 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001350 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001351 }
Douglas Gregora7095092009-07-28 14:44:31 +00001352}
1353
Ted Kremeneke65b0862012-03-06 20:05:56 +00001354void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1355 VisitExpr(S);
1356 VisitDecl(S->getAtIndexMethodDecl());
1357 VisitDecl(S->setAtIndexMethodDecl());
1358}
1359
Chandler Carruth631abd92011-06-16 06:47:06 +00001360void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001361 VisitExpr(S);
1362 VisitName(S->getSelector());
1363 VisitDecl(S->getMethodDecl());
1364}
1365
Chandler Carruth631abd92011-06-16 06:47:06 +00001366void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001367 VisitExpr(S);
1368 ID.AddBoolean(S->isArrow());
1369}
1370
Ted Kremeneke65b0862012-03-06 20:05:56 +00001371void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1372 VisitExpr(S);
1373 ID.AddBoolean(S->getValue());
1374}
1375
Chandler Carruth631abd92011-06-16 06:47:06 +00001376void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1377 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001378 VisitExpr(S);
1379 ID.AddBoolean(S->shouldCopy());
1380}
1381
Chandler Carruth631abd92011-06-16 06:47:06 +00001382void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001383 VisitExplicitCastExpr(S);
1384 ID.AddBoolean(S->getBridgeKind());
1385}
1386
Chandler Carruth631abd92011-06-16 06:47:06 +00001387void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001388 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001389
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001390 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001391 if (const NonTypeTemplateParmDecl *NTTP =
1392 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001393 ID.AddInteger(NTTP->getDepth());
1394 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001395 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001396 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001397 return;
1398 }
Mike Stump11289f42009-09-09 15:08:12 +00001399
Chandler Carruth631abd92011-06-16 06:47:06 +00001400 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001401 // The Itanium C++ ABI uses the type, scope depth, and scope
1402 // index of a parameter when mangling expressions that involve
1403 // function parameters, so we will use the parameter's type for
1404 // establishing function parameter identity. That way, our
1405 // definition of "equivalent" (per C++ [temp.over.link]) is at
1406 // least as strong as the definition of "equivalent" used for
1407 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001408 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001409 ID.AddInteger(Parm->getFunctionScopeDepth());
1410 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001411 return;
1412 }
Mike Stump11289f42009-09-09 15:08:12 +00001413
Richard Smithd9a1cd82012-04-02 18:53:24 +00001414 if (const TemplateTypeParmDecl *TTP =
1415 dyn_cast<TemplateTypeParmDecl>(D)) {
1416 ID.AddInteger(TTP->getDepth());
1417 ID.AddInteger(TTP->getIndex());
1418 ID.AddBoolean(TTP->isParameterPack());
1419 return;
1420 }
1421
Chandler Carruth631abd92011-06-16 06:47:06 +00001422 if (const TemplateTemplateParmDecl *TTP =
1423 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001424 ID.AddInteger(TTP->getDepth());
1425 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001426 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001427 return;
1428 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001429 }
Mike Stump11289f42009-09-09 15:08:12 +00001430
Craig Topper36250ad2014-05-12 05:36:57 +00001431 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001432}
1433
1434void StmtProfiler::VisitType(QualType T) {
1435 if (Canonical)
1436 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001437
Douglas Gregor5c193b92009-07-28 00:33:38 +00001438 ID.AddPointer(T.getAsOpaquePtr());
1439}
1440
1441void StmtProfiler::VisitName(DeclarationName Name) {
1442 ID.AddPointer(Name.getAsOpaquePtr());
1443}
1444
1445void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1446 if (Canonical)
1447 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1448 ID.AddPointer(NNS);
1449}
1450
1451void StmtProfiler::VisitTemplateName(TemplateName Name) {
1452 if (Canonical)
1453 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001454
Douglas Gregor5c193b92009-07-28 00:33:38 +00001455 Name.Profile(ID);
1456}
1457
John McCall0ad16662009-10-29 08:12:44 +00001458void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001459 unsigned NumArgs) {
1460 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001461 for (unsigned I = 0; I != NumArgs; ++I)
1462 VisitTemplateArgument(Args[I].getArgument());
1463}
Mike Stump11289f42009-09-09 15:08:12 +00001464
John McCall0ad16662009-10-29 08:12:44 +00001465void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1466 // Mostly repetitive with TemplateArgument::Profile!
1467 ID.AddInteger(Arg.getKind());
1468 switch (Arg.getKind()) {
1469 case TemplateArgument::Null:
1470 break;
Mike Stump11289f42009-09-09 15:08:12 +00001471
John McCall0ad16662009-10-29 08:12:44 +00001472 case TemplateArgument::Type:
1473 VisitType(Arg.getAsType());
1474 break;
Mike Stump11289f42009-09-09 15:08:12 +00001475
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001476 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001477 case TemplateArgument::TemplateExpansion:
1478 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001479 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001480
John McCall0ad16662009-10-29 08:12:44 +00001481 case TemplateArgument::Declaration:
1482 VisitDecl(Arg.getAsDecl());
1483 break;
Mike Stump11289f42009-09-09 15:08:12 +00001484
Eli Friedmanb826a002012-09-26 02:36:12 +00001485 case TemplateArgument::NullPtr:
1486 VisitType(Arg.getNullPtrType());
1487 break;
1488
John McCall0ad16662009-10-29 08:12:44 +00001489 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001490 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001491 VisitType(Arg.getIntegralType());
1492 break;
Mike Stump11289f42009-09-09 15:08:12 +00001493
John McCall0ad16662009-10-29 08:12:44 +00001494 case TemplateArgument::Expression:
1495 Visit(Arg.getAsExpr());
1496 break;
Mike Stump11289f42009-09-09 15:08:12 +00001497
John McCall0ad16662009-10-29 08:12:44 +00001498 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001499 for (const auto &P : Arg.pack_elements())
1500 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001501 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001502 }
1503}
1504
Jay Foad39c79802011-01-12 09:06:06 +00001505void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001506 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001507 StmtProfiler Profiler(ID, Context, Canonical);
1508 Profiler.Visit(this);
1509}