blob: 7d1d48be79160cb5e6925d2c5b88614b3ec70394 [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 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +000068}
Douglas Gregor5c193b92009-07-28 00:33:38 +000069
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) {
Alexey Bataev040d5402015-05-12 08:35:28 +0000301 if (C->getChunkSize()) {
Alexey Bataev56dafe82014-06-20 07:16:17 +0000302 Profiler->VisitStmt(C->getChunkSize());
Alexey Bataev040d5402015-05-12 08:35:28 +0000303 if (C->getHelperChunkSize()) {
304 Profiler->VisitStmt(C->getChunkSize());
305 }
306 }
Alexey Bataev56dafe82014-06-20 07:16:17 +0000307}
308
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000309void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *) {}
310
Alexey Bataev236070f2014-06-20 11:19:47 +0000311void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
312
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000313void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
314
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000315void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
316
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000317void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
318
Alexey Bataevdea47612014-07-23 07:46:59 +0000319void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
320
Alexey Bataev67a4f222014-07-23 10:25:33 +0000321void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
322
Alexey Bataev459dec02014-07-24 06:46:57 +0000323void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
324
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000325void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
326
Alexey Bataev756c1962013-09-24 03:17:45 +0000327template<typename T>
328void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000329 for (auto *E : Node->varlists()) {
330 Profiler->VisitStmt(E);
331 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000332}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000333
334void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000335 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000336 for (auto *E : C->private_copies()) {
337 Profiler->VisitStmt(E);
338 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000339}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000340void
341OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000342 VisitOMPClauseList(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000343 for (auto *E : C->private_copies()) {
344 Profiler->VisitStmt(E);
345 }
346 for (auto *E : C->inits()) {
347 Profiler->VisitStmt(E);
348 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000349}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000350void
351OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
352 VisitOMPClauseList(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000353 for (auto *E : C->source_exprs()) {
354 Profiler->VisitStmt(E);
355 }
356 for (auto *E : C->destination_exprs()) {
357 Profiler->VisitStmt(E);
358 }
359 for (auto *E : C->assignment_ops()) {
360 Profiler->VisitStmt(E);
361 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000362}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000363void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000364 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000365}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000366void OMPClauseProfiler::VisitOMPReductionClause(
367 const OMPReductionClause *C) {
368 Profiler->VisitNestedNameSpecifier(
369 C->getQualifierLoc().getNestedNameSpecifier());
370 Profiler->VisitName(C->getNameInfo().getName());
371 VisitOMPClauseList(C);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000372 for (auto *E : C->lhs_exprs()) {
373 Profiler->VisitStmt(E);
374 }
375 for (auto *E : C->rhs_exprs()) {
376 Profiler->VisitStmt(E);
377 }
378 for (auto *E : C->reduction_ops()) {
379 Profiler->VisitStmt(E);
380 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000381}
Alexander Musman8dba6642014-04-22 13:09:42 +0000382void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
383 VisitOMPClauseList(C);
Alexander Musman3276a272015-03-21 10:12:56 +0000384 for (auto *E : C->inits()) {
385 Profiler->VisitStmt(E);
386 }
387 for (auto *E : C->updates()) {
388 Profiler->VisitStmt(E);
389 }
390 for (auto *E : C->finals()) {
391 Profiler->VisitStmt(E);
392 }
Alexander Musman8dba6642014-04-22 13:09:42 +0000393 Profiler->VisitStmt(C->getStep());
Alexander Musman3276a272015-03-21 10:12:56 +0000394 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000395}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000396void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
397 VisitOMPClauseList(C);
398 Profiler->VisitStmt(C->getAlignment());
399}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000400void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
401 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000402 for (auto *E : C->source_exprs()) {
403 Profiler->VisitStmt(E);
404 }
405 for (auto *E : C->destination_exprs()) {
406 Profiler->VisitStmt(E);
407 }
408 for (auto *E : C->assignment_ops()) {
409 Profiler->VisitStmt(E);
410 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000411}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000412void
413OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
414 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000415 for (auto *E : C->source_exprs()) {
416 Profiler->VisitStmt(E);
417 }
418 for (auto *E : C->destination_exprs()) {
419 Profiler->VisitStmt(E);
420 }
421 for (auto *E : C->assignment_ops()) {
422 Profiler->VisitStmt(E);
423 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000424}
Alexey Bataev6125da92014-07-21 11:26:11 +0000425void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
426 VisitOMPClauseList(C);
427}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000428void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
429 VisitOMPClauseList(C);
430}
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000431}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000432
433void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000434StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000435 VisitStmt(S);
436 OMPClauseProfiler P(this);
437 ArrayRef<OMPClause *> Clauses = S->clauses();
438 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
439 I != E; ++I)
440 if (*I)
441 P.Visit(*I);
442}
443
Alexander Musman3aaab662014-08-19 11:27:13 +0000444void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
445 VisitOMPExecutableDirective(S);
446}
447
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000448void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
449 VisitOMPExecutableDirective(S);
450}
451
452void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000453 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000454}
455
Alexey Bataevf29276e2014-06-18 04:14:57 +0000456void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000457 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000458}
459
Alexander Musmanf82886e2014-09-18 05:12:34 +0000460void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
461 VisitOMPLoopDirective(S);
462}
463
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000464void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
465 VisitOMPExecutableDirective(S);
466}
467
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000468void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
469 VisitOMPExecutableDirective(S);
470}
471
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000472void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
473 VisitOMPExecutableDirective(S);
474}
475
Alexander Musman80c22892014-07-17 08:54:58 +0000476void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
477 VisitOMPExecutableDirective(S);
478}
479
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000480void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
481 VisitOMPExecutableDirective(S);
482 VisitName(S->getDirectiveName().getName());
483}
484
Alexey Bataev4acb8592014-07-07 13:01:15 +0000485void
486StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000487 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000488}
489
Alexander Musmane4e893b2014-09-23 09:33:00 +0000490void StmtProfiler::VisitOMPParallelForSimdDirective(
491 const OMPParallelForSimdDirective *S) {
492 VisitOMPLoopDirective(S);
493}
494
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000495void StmtProfiler::VisitOMPParallelSectionsDirective(
496 const OMPParallelSectionsDirective *S) {
497 VisitOMPExecutableDirective(S);
498}
499
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000500void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
501 VisitOMPExecutableDirective(S);
502}
503
Alexey Bataev68446b72014-07-18 07:47:19 +0000504void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
505 VisitOMPExecutableDirective(S);
506}
507
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000508void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
509 VisitOMPExecutableDirective(S);
510}
511
Alexey Bataev2df347a2014-07-18 10:17:07 +0000512void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
513 VisitOMPExecutableDirective(S);
514}
515
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000516void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
517 VisitOMPExecutableDirective(S);
518}
519
Alexey Bataev6125da92014-07-21 11:26:11 +0000520void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
521 VisitOMPExecutableDirective(S);
522}
523
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000524void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
525 VisitOMPExecutableDirective(S);
526}
527
Alexey Bataev0162e452014-07-22 10:10:35 +0000528void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
529 VisitOMPExecutableDirective(S);
530}
531
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000532void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
533 VisitOMPExecutableDirective(S);
534}
535
Alexey Bataev13314bf2014-10-09 04:18:56 +0000536void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
537 VisitOMPExecutableDirective(S);
538}
539
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000540void StmtProfiler::VisitOMPCancellationPointDirective(
541 const OMPCancellationPointDirective *S) {
542 VisitOMPExecutableDirective(S);
543}
544
Chandler Carruth631abd92011-06-16 06:47:06 +0000545void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000546 VisitStmt(S);
547}
548
Chandler Carruth631abd92011-06-16 06:47:06 +0000549void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000550 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000551 if (!Canonical)
552 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000553 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000554 if (!Canonical)
555 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000556}
557
Chandler Carruth631abd92011-06-16 06:47:06 +0000558void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000559 VisitExpr(S);
560 ID.AddInteger(S->getIdentType());
561}
562
Chandler Carruth631abd92011-06-16 06:47:06 +0000563void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000564 VisitExpr(S);
565 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +0000566 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000567}
568
Chandler Carruth631abd92011-06-16 06:47:06 +0000569void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000570 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000571 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000572 ID.AddInteger(S->getValue());
573}
574
Chandler Carruth631abd92011-06-16 06:47:06 +0000575void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000576 VisitExpr(S);
577 S->getValue().Profile(ID);
578 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +0000579 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000580}
581
Chandler Carruth631abd92011-06-16 06:47:06 +0000582void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000583 VisitExpr(S);
584}
585
Chandler Carruth631abd92011-06-16 06:47:06 +0000586void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000587 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000588 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000589 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000590}
591
Chandler Carruth631abd92011-06-16 06:47:06 +0000592void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000593 VisitExpr(S);
594}
595
Chandler Carruth631abd92011-06-16 06:47:06 +0000596void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000597 VisitExpr(S);
598}
599
Chandler Carruth631abd92011-06-16 06:47:06 +0000600void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000601 VisitExpr(S);
602 ID.AddInteger(S->getOpcode());
603}
604
Chandler Carruth631abd92011-06-16 06:47:06 +0000605void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000606 VisitType(S->getTypeSourceInfo()->getType());
607 unsigned n = S->getNumComponents();
608 for (unsigned i = 0; i < n; ++i) {
609 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
610 ID.AddInteger(ON.getKind());
611 switch (ON.getKind()) {
612 case OffsetOfExpr::OffsetOfNode::Array:
613 // Expressions handled below.
614 break;
615
616 case OffsetOfExpr::OffsetOfNode::Field:
617 VisitDecl(ON.getField());
618 break;
619
620 case OffsetOfExpr::OffsetOfNode::Identifier:
621 ID.AddPointer(ON.getFieldName());
622 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000623
Douglas Gregord1702062010-04-29 00:18:15 +0000624 case OffsetOfExpr::OffsetOfNode::Base:
625 // These nodes are implicit, and therefore don't need profiling.
626 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000627 }
628 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000629
Douglas Gregor882211c2010-04-28 22:16:22 +0000630 VisitExpr(S);
631}
632
Chandler Carruth631abd92011-06-16 06:47:06 +0000633void
634StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000635 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000636 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000637 if (S->isArgumentType())
638 VisitType(S->getArgumentType());
639}
640
Chandler Carruth631abd92011-06-16 06:47:06 +0000641void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000642 VisitExpr(S);
643}
644
Chandler Carruth631abd92011-06-16 06:47:06 +0000645void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000646 VisitExpr(S);
647}
648
Chandler Carruth631abd92011-06-16 06:47:06 +0000649void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000650 VisitExpr(S);
651 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000652 if (!Canonical)
653 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000654 ID.AddBoolean(S->isArrow());
655}
656
Chandler Carruth631abd92011-06-16 06:47:06 +0000657void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000658 VisitExpr(S);
659 ID.AddBoolean(S->isFileScope());
660}
661
Chandler Carruth631abd92011-06-16 06:47:06 +0000662void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000663 VisitExpr(S);
664}
665
Chandler Carruth631abd92011-06-16 06:47:06 +0000666void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000667 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000668 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000669}
670
Chandler Carruth631abd92011-06-16 06:47:06 +0000671void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000672 VisitCastExpr(S);
673 VisitType(S->getTypeAsWritten());
674}
675
Chandler Carruth631abd92011-06-16 06:47:06 +0000676void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000677 VisitExplicitCastExpr(S);
678}
679
Chandler Carruth631abd92011-06-16 06:47:06 +0000680void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000681 VisitExpr(S);
682 ID.AddInteger(S->getOpcode());
683}
684
Chandler Carruth631abd92011-06-16 06:47:06 +0000685void
686StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000687 VisitBinaryOperator(S);
688}
689
Chandler Carruth631abd92011-06-16 06:47:06 +0000690void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000691 VisitExpr(S);
692}
693
Chandler Carruth631abd92011-06-16 06:47:06 +0000694void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000695 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000696 VisitExpr(S);
697}
698
Chandler Carruth631abd92011-06-16 06:47:06 +0000699void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000700 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000701 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000702}
703
Chandler Carruth631abd92011-06-16 06:47:06 +0000704void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000705 VisitExpr(S);
706}
707
Chandler Carruth631abd92011-06-16 06:47:06 +0000708void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000709 VisitExpr(S);
710}
711
Hal Finkelc4d7c822013-09-18 03:29:45 +0000712void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
713 VisitExpr(S);
714}
715
Chandler Carruth631abd92011-06-16 06:47:06 +0000716void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000717 VisitExpr(S);
718}
719
Chandler Carruth631abd92011-06-16 06:47:06 +0000720void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000721 VisitExpr(S);
722}
723
Chandler Carruth631abd92011-06-16 06:47:06 +0000724void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000725 VisitExpr(S);
726}
727
Chandler Carruth631abd92011-06-16 06:47:06 +0000728void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000729 if (S->getSyntacticForm()) {
730 VisitInitListExpr(S->getSyntacticForm());
731 return;
732 }
Mike Stump11289f42009-09-09 15:08:12 +0000733
Douglas Gregor5c193b92009-07-28 00:33:38 +0000734 VisitExpr(S);
735}
736
Chandler Carruth631abd92011-06-16 06:47:06 +0000737void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000738 VisitExpr(S);
739 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000740 for (DesignatedInitExpr::const_designators_iterator D =
741 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000742 D != DEnd; ++D) {
743 if (D->isFieldDesignator()) {
744 ID.AddInteger(0);
745 VisitName(D->getFieldName());
746 continue;
747 }
Mike Stump11289f42009-09-09 15:08:12 +0000748
Douglas Gregor5c193b92009-07-28 00:33:38 +0000749 if (D->isArrayDesignator()) {
750 ID.AddInteger(1);
751 } else {
752 assert(D->isArrayRangeDesignator());
753 ID.AddInteger(2);
754 }
755 ID.AddInteger(D->getFirstExprIndex());
756 }
757}
758
Yunzhong Gaocb779302015-06-10 00:27:52 +0000759// Seems that if VisitInitListExpr() only works on the syntactic form of an
760// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
761void StmtProfiler::VisitDesignatedInitUpdateExpr(
762 const DesignatedInitUpdateExpr *S) {
763 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
764 "initializer");
765}
766
767void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
768 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
769}
770
Chandler Carruth631abd92011-06-16 06:47:06 +0000771void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000772 VisitExpr(S);
773}
774
Chandler Carruth631abd92011-06-16 06:47:06 +0000775void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000776 VisitExpr(S);
777 VisitName(&S->getAccessor());
778}
779
Chandler Carruth631abd92011-06-16 06:47:06 +0000780void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000781 VisitExpr(S);
782 VisitDecl(S->getBlockDecl());
783}
784
Chandler Carruth631abd92011-06-16 06:47:06 +0000785void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000786 VisitExpr(S);
787 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
788 QualType T = S->getAssocType(i);
789 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000790 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000791 else
792 VisitType(T);
793 VisitExpr(S->getAssocExpr(i));
794 }
795}
796
John McCallfe96e0b2011-11-06 09:01:30 +0000797void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
798 VisitExpr(S);
799 for (PseudoObjectExpr::const_semantics_iterator
800 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
801 // Normally, we would not profile the source expressions of OVEs.
802 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
803 Visit(OVE->getSourceExpr());
804}
805
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000806void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
807 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000808 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000809}
810
Chandler Carruth631abd92011-06-16 06:47:06 +0000811static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000812 UnaryOperatorKind &UnaryOp,
813 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000814 switch (S->getOperator()) {
815 case OO_None:
816 case OO_New:
817 case OO_Delete:
818 case OO_Array_New:
819 case OO_Array_Delete:
820 case OO_Arrow:
821 case OO_Call:
822 case OO_Conditional:
823 case NUM_OVERLOADED_OPERATORS:
824 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000825
826 case OO_Plus:
827 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000828 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000829 return Stmt::UnaryOperatorClass;
830 }
831
John McCalle3027922010-08-25 11:45:40 +0000832 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000833 return Stmt::BinaryOperatorClass;
834
835 case OO_Minus:
836 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000837 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000838 return Stmt::UnaryOperatorClass;
839 }
840
John McCalle3027922010-08-25 11:45:40 +0000841 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000842 return Stmt::BinaryOperatorClass;
843
844 case OO_Star:
845 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000846 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000847 return Stmt::UnaryOperatorClass;
848 }
849
Richard Smithf15acc52014-06-05 22:43:40 +0000850 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000851 return Stmt::BinaryOperatorClass;
852
853 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000854 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000855 return Stmt::BinaryOperatorClass;
856
857 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000858 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000859 return Stmt::BinaryOperatorClass;
860
861 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000862 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000863 return Stmt::BinaryOperatorClass;
864
865 case OO_Amp:
866 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000867 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000868 return Stmt::UnaryOperatorClass;
869 }
870
John McCalle3027922010-08-25 11:45:40 +0000871 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000872 return Stmt::BinaryOperatorClass;
873
874 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000875 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000876 return Stmt::BinaryOperatorClass;
877
878 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000879 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000880 return Stmt::UnaryOperatorClass;
881
882 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000883 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000884 return Stmt::UnaryOperatorClass;
885
886 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000887 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000888 return Stmt::BinaryOperatorClass;
889
890 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000891 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000892 return Stmt::BinaryOperatorClass;
893
894 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000895 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000896 return Stmt::BinaryOperatorClass;
897
898 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000899 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000900 return Stmt::CompoundAssignOperatorClass;
901
902 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000903 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000904 return Stmt::CompoundAssignOperatorClass;
905
906 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000907 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000908 return Stmt::CompoundAssignOperatorClass;
909
910 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000911 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000912 return Stmt::CompoundAssignOperatorClass;
913
914 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000915 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000916 return Stmt::CompoundAssignOperatorClass;
917
918 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000919 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000920 return Stmt::CompoundAssignOperatorClass;
921
922 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000923 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000924 return Stmt::CompoundAssignOperatorClass;
925
926 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000927 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000928 return Stmt::CompoundAssignOperatorClass;
929
930 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000931 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000932 return Stmt::BinaryOperatorClass;
933
934 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000935 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000936 return Stmt::BinaryOperatorClass;
937
938 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000939 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000940 return Stmt::CompoundAssignOperatorClass;
941
942 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000943 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000944 return Stmt::CompoundAssignOperatorClass;
945
946 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000947 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000948 return Stmt::BinaryOperatorClass;
949
950 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000951 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000952 return Stmt::BinaryOperatorClass;
953
954 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000955 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000956 return Stmt::BinaryOperatorClass;
957
958 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000959 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000960 return Stmt::BinaryOperatorClass;
961
962 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000963 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000964 return Stmt::BinaryOperatorClass;
965
966 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000967 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000968 return Stmt::BinaryOperatorClass;
969
970 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000971 UnaryOp = S->getNumArgs() == 1? UO_PreInc
972 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000973 return Stmt::UnaryOperatorClass;
974
975 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000976 UnaryOp = S->getNumArgs() == 1? UO_PreDec
977 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000978 return Stmt::UnaryOperatorClass;
979
980 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000981 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000982 return Stmt::BinaryOperatorClass;
983
984
985 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000986 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000987 return Stmt::BinaryOperatorClass;
988
989 case OO_Subscript:
990 return Stmt::ArraySubscriptExprClass;
991 }
992
993 llvm_unreachable("Invalid overloaded operator expression");
994}
Richard Smithf15acc52014-06-05 22:43:40 +0000995
Douglas Gregore9ceb312010-05-19 04:13:23 +0000996
Chandler Carruth631abd92011-06-16 06:47:06 +0000997void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000998 if (S->isTypeDependent()) {
999 // Type-dependent operator calls are profiled like their underlying
1000 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +00001001 UnaryOperatorKind UnaryOp = UO_Extension;
1002 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001003 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001004
Douglas Gregore9ceb312010-05-19 04:13:23 +00001005 ID.AddInteger(SC);
1006 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1007 Visit(S->getArg(I));
1008 if (SC == Stmt::UnaryOperatorClass)
1009 ID.AddInteger(UnaryOp);
1010 else if (SC == Stmt::BinaryOperatorClass ||
1011 SC == Stmt::CompoundAssignOperatorClass)
1012 ID.AddInteger(BinaryOp);
1013 else
1014 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001015
Douglas Gregore9ceb312010-05-19 04:13:23 +00001016 return;
1017 }
Richard Smithf15acc52014-06-05 22:43:40 +00001018
Douglas Gregor5c193b92009-07-28 00:33:38 +00001019 VisitCallExpr(S);
1020 ID.AddInteger(S->getOperator());
1021}
1022
Chandler Carruth631abd92011-06-16 06:47:06 +00001023void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001024 VisitCallExpr(S);
1025}
1026
Chandler Carruth631abd92011-06-16 06:47:06 +00001027void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001028 VisitCallExpr(S);
1029}
1030
Chandler Carruth631abd92011-06-16 06:47:06 +00001031void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001032 VisitExpr(S);
1033}
1034
Chandler Carruth631abd92011-06-16 06:47:06 +00001035void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001036 VisitExplicitCastExpr(S);
1037}
1038
Chandler Carruth631abd92011-06-16 06:47:06 +00001039void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001040 VisitCXXNamedCastExpr(S);
1041}
1042
Chandler Carruth631abd92011-06-16 06:47:06 +00001043void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001044 VisitCXXNamedCastExpr(S);
1045}
1046
Chandler Carruth631abd92011-06-16 06:47:06 +00001047void
1048StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001049 VisitCXXNamedCastExpr(S);
1050}
1051
Chandler Carruth631abd92011-06-16 06:47:06 +00001052void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001053 VisitCXXNamedCastExpr(S);
1054}
1055
Richard Smithc67fdd42012-03-07 08:35:16 +00001056void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1057 VisitCallExpr(S);
1058}
1059
Chandler Carruth631abd92011-06-16 06:47:06 +00001060void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001061 VisitExpr(S);
1062 ID.AddBoolean(S->getValue());
1063}
1064
Chandler Carruth631abd92011-06-16 06:47:06 +00001065void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001066 VisitExpr(S);
1067}
1068
Richard Smithcc1b96d2013-06-12 22:31:48 +00001069void StmtProfiler::VisitCXXStdInitializerListExpr(
1070 const CXXStdInitializerListExpr *S) {
1071 VisitExpr(S);
1072}
1073
Chandler Carruth631abd92011-06-16 06:47:06 +00001074void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001075 VisitExpr(S);
1076 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001077 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001078}
1079
Chandler Carruth631abd92011-06-16 06:47:06 +00001080void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001081 VisitExpr(S);
1082 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001083 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001084}
1085
John McCall5e77d762013-04-16 07:28:30 +00001086void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1087 VisitExpr(S);
1088 VisitDecl(S->getPropertyDecl());
1089}
1090
Chandler Carruth631abd92011-06-16 06:47:06 +00001091void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001092 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001093 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001094}
1095
Chandler Carruth631abd92011-06-16 06:47:06 +00001096void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001097 VisitExpr(S);
1098}
1099
Chandler Carruth631abd92011-06-16 06:47:06 +00001100void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001101 VisitExpr(S);
1102 VisitDecl(S->getParam());
1103}
1104
Richard Smith852c9db2013-04-20 22:23:05 +00001105void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1106 VisitExpr(S);
1107 VisitDecl(S->getField());
1108}
1109
Chandler Carruth631abd92011-06-16 06:47:06 +00001110void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001111 VisitExpr(S);
1112 VisitDecl(
1113 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1114}
1115
Chandler Carruth631abd92011-06-16 06:47:06 +00001116void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001117 VisitExpr(S);
1118 VisitDecl(S->getConstructor());
1119 ID.AddBoolean(S->isElidable());
1120}
1121
Chandler Carruth631abd92011-06-16 06:47:06 +00001122void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001123 VisitExplicitCastExpr(S);
1124}
1125
Chandler Carruth631abd92011-06-16 06:47:06 +00001126void
1127StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001128 VisitCXXConstructExpr(S);
1129}
1130
Chandler Carruth631abd92011-06-16 06:47:06 +00001131void
Douglas Gregore31e6062012-02-07 10:09:13 +00001132StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1133 VisitExpr(S);
1134 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1135 CEnd = S->explicit_capture_end();
1136 C != CEnd; ++C) {
1137 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001138 switch (C->getCaptureKind()) {
1139 case LCK_This:
1140 break;
1141 case LCK_ByRef:
1142 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001143 VisitDecl(C->getCapturedVar());
1144 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001145 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001146 case LCK_VLAType:
1147 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001148 }
1149 }
1150 // Note: If we actually needed to be able to match lambda
1151 // expressions, we would have to consider parameters and return type
1152 // here, among other things.
1153 VisitStmt(S->getBody());
1154}
1155
1156void
Chandler Carruth631abd92011-06-16 06:47:06 +00001157StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001158 VisitExpr(S);
1159}
1160
Chandler Carruth631abd92011-06-16 06:47:06 +00001161void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001162 VisitExpr(S);
1163 ID.AddBoolean(S->isGlobalDelete());
1164 ID.AddBoolean(S->isArrayForm());
1165 VisitDecl(S->getOperatorDelete());
1166}
1167
1168
Chandler Carruth631abd92011-06-16 06:47:06 +00001169void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001170 VisitExpr(S);
1171 VisitType(S->getAllocatedType());
1172 VisitDecl(S->getOperatorNew());
1173 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001174 ID.AddBoolean(S->isArray());
1175 ID.AddInteger(S->getNumPlacementArgs());
1176 ID.AddBoolean(S->isGlobalNew());
1177 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001178 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001179}
1180
Chandler Carruth631abd92011-06-16 06:47:06 +00001181void
1182StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001183 VisitExpr(S);
1184 ID.AddBoolean(S->isArrow());
1185 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001186 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001187 if (S->getScopeTypeInfo())
1188 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001189 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001190 if (S->getDestroyedTypeInfo())
1191 VisitType(S->getDestroyedType());
1192 else
1193 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001194}
1195
Chandler Carruth631abd92011-06-16 06:47:06 +00001196void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001197 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001198 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001199 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001200 ID.AddBoolean(S->hasExplicitTemplateArgs());
1201 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001202 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1203 S->getExplicitTemplateArgs().NumTemplateArgs);
1204}
1205
1206void
Chandler Carruth631abd92011-06-16 06:47:06 +00001207StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001208 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001209}
1210
Douglas Gregor29c42f22012-02-24 07:38:34 +00001211void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1212 VisitExpr(S);
1213 ID.AddInteger(S->getTrait());
1214 ID.AddInteger(S->getNumArgs());
1215 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1216 VisitType(S->getArg(I)->getType());
1217}
1218
Chandler Carruth631abd92011-06-16 06:47:06 +00001219void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001220 VisitExpr(S);
1221 ID.AddInteger(S->getTrait());
1222 VisitType(S->getQueriedType());
1223}
1224
Chandler Carruth631abd92011-06-16 06:47:06 +00001225void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001226 VisitExpr(S);
1227 ID.AddInteger(S->getTrait());
1228 VisitExpr(S->getQueriedExpression());
1229}
1230
Chandler Carruth631abd92011-06-16 06:47:06 +00001231void StmtProfiler::VisitDependentScopeDeclRefExpr(
1232 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001233 VisitExpr(S);
1234 VisitName(S->getDeclName());
1235 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001236 ID.AddBoolean(S->hasExplicitTemplateArgs());
1237 if (S->hasExplicitTemplateArgs())
1238 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001239}
1240
Chandler Carruth631abd92011-06-16 06:47:06 +00001241void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001242 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001243}
1244
Chandler Carruth631abd92011-06-16 06:47:06 +00001245void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1246 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001247 VisitExpr(S);
1248 VisitType(S->getTypeAsWritten());
1249}
1250
Chandler Carruth631abd92011-06-16 06:47:06 +00001251void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1252 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001253 ID.AddBoolean(S->isImplicitAccess());
1254 if (!S->isImplicitAccess()) {
1255 VisitExpr(S);
1256 ID.AddBoolean(S->isArrow());
1257 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001258 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001259 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001260 ID.AddBoolean(S->hasExplicitTemplateArgs());
1261 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001262 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1263}
1264
Chandler Carruth631abd92011-06-16 06:47:06 +00001265void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001266 ID.AddBoolean(S->isImplicitAccess());
1267 if (!S->isImplicitAccess()) {
1268 VisitExpr(S);
1269 ID.AddBoolean(S->isArrow());
1270 }
John McCall10eae182009-11-30 22:42:35 +00001271 VisitNestedNameSpecifier(S->getQualifier());
1272 VisitName(S->getMemberName());
1273 ID.AddBoolean(S->hasExplicitTemplateArgs());
1274 if (S->hasExplicitTemplateArgs())
1275 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001276}
1277
Chandler Carruth631abd92011-06-16 06:47:06 +00001278void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001279 VisitExpr(S);
1280}
1281
Chandler Carruth631abd92011-06-16 06:47:06 +00001282void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001283 VisitExpr(S);
1284}
1285
Chandler Carruth631abd92011-06-16 06:47:06 +00001286void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001287 VisitExpr(S);
1288 VisitDecl(S->getPack());
1289}
1290
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001291void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001292 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001293 VisitExpr(S);
1294 VisitDecl(S->getParameterPack());
1295 VisitTemplateArgument(S->getArgumentPack());
1296}
1297
John McCall7c454bb2011-07-15 05:09:51 +00001298void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1299 const SubstNonTypeTemplateParmExpr *E) {
1300 // Profile exactly as the replacement expression.
1301 Visit(E->getReplacement());
1302}
1303
Richard Smithb15fe3a2012-09-12 00:56:43 +00001304void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1305 VisitExpr(S);
1306 VisitDecl(S->getParameterPack());
1307 ID.AddInteger(S->getNumExpansions());
1308 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1309 VisitDecl(*I);
1310}
1311
Douglas Gregorfe314812011-06-21 17:03:29 +00001312void StmtProfiler::VisitMaterializeTemporaryExpr(
1313 const MaterializeTemporaryExpr *S) {
1314 VisitExpr(S);
1315}
1316
Richard Smith0f0af192014-11-08 05:07:16 +00001317void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1318 VisitExpr(S);
1319 ID.AddInteger(S->getOperator());
1320}
1321
Chandler Carruth631abd92011-06-16 06:47:06 +00001322void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001323 VisitExpr(E);
1324}
1325
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001326void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1327 VisitExpr(E);
1328}
1329
Chandler Carruth631abd92011-06-16 06:47:06 +00001330void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001331 VisitExpr(S);
1332}
1333
Patrick Beard0caa3942012-04-19 00:25:12 +00001334void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001335 VisitExpr(E);
1336}
1337
1338void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1339 VisitExpr(E);
1340}
1341
1342void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1343 VisitExpr(E);
1344}
1345
Chandler Carruth631abd92011-06-16 06:47:06 +00001346void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001347 VisitExpr(S);
1348 VisitType(S->getEncodedType());
1349}
1350
Chandler Carruth631abd92011-06-16 06:47:06 +00001351void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001352 VisitExpr(S);
1353 VisitName(S->getSelector());
1354}
1355
Chandler Carruth631abd92011-06-16 06:47:06 +00001356void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001357 VisitExpr(S);
1358 VisitDecl(S->getProtocol());
1359}
1360
Chandler Carruth631abd92011-06-16 06:47:06 +00001361void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001362 VisitExpr(S);
1363 VisitDecl(S->getDecl());
1364 ID.AddBoolean(S->isArrow());
1365 ID.AddBoolean(S->isFreeIvar());
1366}
1367
Chandler Carruth631abd92011-06-16 06:47:06 +00001368void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001369 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001370 if (S->isImplicitProperty()) {
1371 VisitDecl(S->getImplicitPropertyGetter());
1372 VisitDecl(S->getImplicitPropertySetter());
1373 } else {
1374 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001375 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001376 if (S->isSuperReceiver()) {
1377 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001378 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001379 }
Douglas Gregora7095092009-07-28 14:44:31 +00001380}
1381
Ted Kremeneke65b0862012-03-06 20:05:56 +00001382void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1383 VisitExpr(S);
1384 VisitDecl(S->getAtIndexMethodDecl());
1385 VisitDecl(S->setAtIndexMethodDecl());
1386}
1387
Chandler Carruth631abd92011-06-16 06:47:06 +00001388void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001389 VisitExpr(S);
1390 VisitName(S->getSelector());
1391 VisitDecl(S->getMethodDecl());
1392}
1393
Chandler Carruth631abd92011-06-16 06:47:06 +00001394void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001395 VisitExpr(S);
1396 ID.AddBoolean(S->isArrow());
1397}
1398
Ted Kremeneke65b0862012-03-06 20:05:56 +00001399void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1400 VisitExpr(S);
1401 ID.AddBoolean(S->getValue());
1402}
1403
Chandler Carruth631abd92011-06-16 06:47:06 +00001404void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1405 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001406 VisitExpr(S);
1407 ID.AddBoolean(S->shouldCopy());
1408}
1409
Chandler Carruth631abd92011-06-16 06:47:06 +00001410void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001411 VisitExplicitCastExpr(S);
1412 ID.AddBoolean(S->getBridgeKind());
1413}
1414
Chandler Carruth631abd92011-06-16 06:47:06 +00001415void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001416 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001417
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001418 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001419 if (const NonTypeTemplateParmDecl *NTTP =
1420 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001421 ID.AddInteger(NTTP->getDepth());
1422 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001423 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001424 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001425 return;
1426 }
Mike Stump11289f42009-09-09 15:08:12 +00001427
Chandler Carruth631abd92011-06-16 06:47:06 +00001428 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001429 // The Itanium C++ ABI uses the type, scope depth, and scope
1430 // index of a parameter when mangling expressions that involve
1431 // function parameters, so we will use the parameter's type for
1432 // establishing function parameter identity. That way, our
1433 // definition of "equivalent" (per C++ [temp.over.link]) is at
1434 // least as strong as the definition of "equivalent" used for
1435 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001436 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001437 ID.AddInteger(Parm->getFunctionScopeDepth());
1438 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001439 return;
1440 }
Mike Stump11289f42009-09-09 15:08:12 +00001441
Richard Smithd9a1cd82012-04-02 18:53:24 +00001442 if (const TemplateTypeParmDecl *TTP =
1443 dyn_cast<TemplateTypeParmDecl>(D)) {
1444 ID.AddInteger(TTP->getDepth());
1445 ID.AddInteger(TTP->getIndex());
1446 ID.AddBoolean(TTP->isParameterPack());
1447 return;
1448 }
1449
Chandler Carruth631abd92011-06-16 06:47:06 +00001450 if (const TemplateTemplateParmDecl *TTP =
1451 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001452 ID.AddInteger(TTP->getDepth());
1453 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001454 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001455 return;
1456 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001457 }
Mike Stump11289f42009-09-09 15:08:12 +00001458
Craig Topper36250ad2014-05-12 05:36:57 +00001459 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001460}
1461
1462void StmtProfiler::VisitType(QualType T) {
1463 if (Canonical)
1464 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001465
Douglas Gregor5c193b92009-07-28 00:33:38 +00001466 ID.AddPointer(T.getAsOpaquePtr());
1467}
1468
1469void StmtProfiler::VisitName(DeclarationName Name) {
1470 ID.AddPointer(Name.getAsOpaquePtr());
1471}
1472
1473void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1474 if (Canonical)
1475 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1476 ID.AddPointer(NNS);
1477}
1478
1479void StmtProfiler::VisitTemplateName(TemplateName Name) {
1480 if (Canonical)
1481 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001482
Douglas Gregor5c193b92009-07-28 00:33:38 +00001483 Name.Profile(ID);
1484}
1485
John McCall0ad16662009-10-29 08:12:44 +00001486void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001487 unsigned NumArgs) {
1488 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001489 for (unsigned I = 0; I != NumArgs; ++I)
1490 VisitTemplateArgument(Args[I].getArgument());
1491}
Mike Stump11289f42009-09-09 15:08:12 +00001492
John McCall0ad16662009-10-29 08:12:44 +00001493void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1494 // Mostly repetitive with TemplateArgument::Profile!
1495 ID.AddInteger(Arg.getKind());
1496 switch (Arg.getKind()) {
1497 case TemplateArgument::Null:
1498 break;
Mike Stump11289f42009-09-09 15:08:12 +00001499
John McCall0ad16662009-10-29 08:12:44 +00001500 case TemplateArgument::Type:
1501 VisitType(Arg.getAsType());
1502 break;
Mike Stump11289f42009-09-09 15:08:12 +00001503
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001504 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001505 case TemplateArgument::TemplateExpansion:
1506 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001507 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001508
John McCall0ad16662009-10-29 08:12:44 +00001509 case TemplateArgument::Declaration:
1510 VisitDecl(Arg.getAsDecl());
1511 break;
Mike Stump11289f42009-09-09 15:08:12 +00001512
Eli Friedmanb826a002012-09-26 02:36:12 +00001513 case TemplateArgument::NullPtr:
1514 VisitType(Arg.getNullPtrType());
1515 break;
1516
John McCall0ad16662009-10-29 08:12:44 +00001517 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001518 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001519 VisitType(Arg.getIntegralType());
1520 break;
Mike Stump11289f42009-09-09 15:08:12 +00001521
John McCall0ad16662009-10-29 08:12:44 +00001522 case TemplateArgument::Expression:
1523 Visit(Arg.getAsExpr());
1524 break;
Mike Stump11289f42009-09-09 15:08:12 +00001525
John McCall0ad16662009-10-29 08:12:44 +00001526 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001527 for (const auto &P : Arg.pack_elements())
1528 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001529 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001530 }
1531}
1532
Jay Foad39c79802011-01-12 09:06:06 +00001533void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001534 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001535 StmtProfiler Profiler(ID, Context, Canonical);
1536 Profiler.Visit(this);
1537}