blob: 002a17fc2120906d01d8701bc69f07d77ba01950 [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);
349}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000350void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000351 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000352}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000353void OMPClauseProfiler::VisitOMPReductionClause(
354 const OMPReductionClause *C) {
355 Profiler->VisitNestedNameSpecifier(
356 C->getQualifierLoc().getNestedNameSpecifier());
357 Profiler->VisitName(C->getNameInfo().getName());
358 VisitOMPClauseList(C);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000359 for (auto *E : C->lhs_exprs()) {
360 Profiler->VisitStmt(E);
361 }
362 for (auto *E : C->rhs_exprs()) {
363 Profiler->VisitStmt(E);
364 }
365 for (auto *E : C->reduction_ops()) {
366 Profiler->VisitStmt(E);
367 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000368}
Alexander Musman8dba6642014-04-22 13:09:42 +0000369void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
370 VisitOMPClauseList(C);
Alexander Musman3276a272015-03-21 10:12:56 +0000371 for (auto *E : C->inits()) {
372 Profiler->VisitStmt(E);
373 }
374 for (auto *E : C->updates()) {
375 Profiler->VisitStmt(E);
376 }
377 for (auto *E : C->finals()) {
378 Profiler->VisitStmt(E);
379 }
Alexander Musman8dba6642014-04-22 13:09:42 +0000380 Profiler->VisitStmt(C->getStep());
Alexander Musman3276a272015-03-21 10:12:56 +0000381 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000382}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000383void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
384 VisitOMPClauseList(C);
385 Profiler->VisitStmt(C->getAlignment());
386}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000387void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
388 VisitOMPClauseList(C);
389}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000390void
391OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
392 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000393 for (auto *E : C->source_exprs()) {
394 Profiler->VisitStmt(E);
395 }
396 for (auto *E : C->destination_exprs()) {
397 Profiler->VisitStmt(E);
398 }
399 for (auto *E : C->assignment_ops()) {
400 Profiler->VisitStmt(E);
401 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000402}
Alexey Bataev6125da92014-07-21 11:26:11 +0000403void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
404 VisitOMPClauseList(C);
405}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000406}
407
408void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000409StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000410 VisitStmt(S);
411 OMPClauseProfiler P(this);
412 ArrayRef<OMPClause *> Clauses = S->clauses();
413 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
414 I != E; ++I)
415 if (*I)
416 P.Visit(*I);
417}
418
Alexander Musman3aaab662014-08-19 11:27:13 +0000419void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
420 VisitOMPExecutableDirective(S);
421}
422
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000423void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
424 VisitOMPExecutableDirective(S);
425}
426
427void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000428 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000429}
430
Alexey Bataevf29276e2014-06-18 04:14:57 +0000431void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000432 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000433}
434
Alexander Musmanf82886e2014-09-18 05:12:34 +0000435void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
436 VisitOMPLoopDirective(S);
437}
438
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000439void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
440 VisitOMPExecutableDirective(S);
441}
442
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000443void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
444 VisitOMPExecutableDirective(S);
445}
446
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000447void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
448 VisitOMPExecutableDirective(S);
449}
450
Alexander Musman80c22892014-07-17 08:54:58 +0000451void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
452 VisitOMPExecutableDirective(S);
453}
454
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000455void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
456 VisitOMPExecutableDirective(S);
457 VisitName(S->getDirectiveName().getName());
458}
459
Alexey Bataev4acb8592014-07-07 13:01:15 +0000460void
461StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000462 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000463}
464
Alexander Musmane4e893b2014-09-23 09:33:00 +0000465void StmtProfiler::VisitOMPParallelForSimdDirective(
466 const OMPParallelForSimdDirective *S) {
467 VisitOMPLoopDirective(S);
468}
469
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000470void StmtProfiler::VisitOMPParallelSectionsDirective(
471 const OMPParallelSectionsDirective *S) {
472 VisitOMPExecutableDirective(S);
473}
474
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000475void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
476 VisitOMPExecutableDirective(S);
477}
478
Alexey Bataev68446b72014-07-18 07:47:19 +0000479void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
480 VisitOMPExecutableDirective(S);
481}
482
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000483void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
484 VisitOMPExecutableDirective(S);
485}
486
Alexey Bataev2df347a2014-07-18 10:17:07 +0000487void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
488 VisitOMPExecutableDirective(S);
489}
490
Alexey Bataev6125da92014-07-21 11:26:11 +0000491void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
492 VisitOMPExecutableDirective(S);
493}
494
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000495void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
496 VisitOMPExecutableDirective(S);
497}
498
Alexey Bataev0162e452014-07-22 10:10:35 +0000499void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
500 VisitOMPExecutableDirective(S);
501}
502
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000503void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
504 VisitOMPExecutableDirective(S);
505}
506
Alexey Bataev13314bf2014-10-09 04:18:56 +0000507void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
508 VisitOMPExecutableDirective(S);
509}
510
Chandler Carruth631abd92011-06-16 06:47:06 +0000511void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000512 VisitStmt(S);
513}
514
Chandler Carruth631abd92011-06-16 06:47:06 +0000515void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000516 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000517 if (!Canonical)
518 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000519 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000520 if (!Canonical)
521 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000522}
523
Chandler Carruth631abd92011-06-16 06:47:06 +0000524void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000525 VisitExpr(S);
526 ID.AddInteger(S->getIdentType());
527}
528
Chandler Carruth631abd92011-06-16 06:47:06 +0000529void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000530 VisitExpr(S);
531 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +0000532 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000533}
534
Chandler Carruth631abd92011-06-16 06:47:06 +0000535void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000536 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000537 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000538 ID.AddInteger(S->getValue());
539}
540
Chandler Carruth631abd92011-06-16 06:47:06 +0000541void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000542 VisitExpr(S);
543 S->getValue().Profile(ID);
544 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +0000545 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000546}
547
Chandler Carruth631abd92011-06-16 06:47:06 +0000548void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000549 VisitExpr(S);
550}
551
Chandler Carruth631abd92011-06-16 06:47:06 +0000552void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000553 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000554 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000555 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000556}
557
Chandler Carruth631abd92011-06-16 06:47:06 +0000558void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000559 VisitExpr(S);
560}
561
Chandler Carruth631abd92011-06-16 06:47:06 +0000562void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000563 VisitExpr(S);
564}
565
Chandler Carruth631abd92011-06-16 06:47:06 +0000566void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000567 VisitExpr(S);
568 ID.AddInteger(S->getOpcode());
569}
570
Chandler Carruth631abd92011-06-16 06:47:06 +0000571void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000572 VisitType(S->getTypeSourceInfo()->getType());
573 unsigned n = S->getNumComponents();
574 for (unsigned i = 0; i < n; ++i) {
575 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
576 ID.AddInteger(ON.getKind());
577 switch (ON.getKind()) {
578 case OffsetOfExpr::OffsetOfNode::Array:
579 // Expressions handled below.
580 break;
581
582 case OffsetOfExpr::OffsetOfNode::Field:
583 VisitDecl(ON.getField());
584 break;
585
586 case OffsetOfExpr::OffsetOfNode::Identifier:
587 ID.AddPointer(ON.getFieldName());
588 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000589
Douglas Gregord1702062010-04-29 00:18:15 +0000590 case OffsetOfExpr::OffsetOfNode::Base:
591 // These nodes are implicit, and therefore don't need profiling.
592 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000593 }
594 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000595
Douglas Gregor882211c2010-04-28 22:16:22 +0000596 VisitExpr(S);
597}
598
Chandler Carruth631abd92011-06-16 06:47:06 +0000599void
600StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000601 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000602 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000603 if (S->isArgumentType())
604 VisitType(S->getArgumentType());
605}
606
Chandler Carruth631abd92011-06-16 06:47:06 +0000607void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000608 VisitExpr(S);
609}
610
Chandler Carruth631abd92011-06-16 06:47:06 +0000611void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000612 VisitExpr(S);
613}
614
Chandler Carruth631abd92011-06-16 06:47:06 +0000615void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000616 VisitExpr(S);
617 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000618 if (!Canonical)
619 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000620 ID.AddBoolean(S->isArrow());
621}
622
Chandler Carruth631abd92011-06-16 06:47:06 +0000623void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000624 VisitExpr(S);
625 ID.AddBoolean(S->isFileScope());
626}
627
Chandler Carruth631abd92011-06-16 06:47:06 +0000628void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000629 VisitExpr(S);
630}
631
Chandler Carruth631abd92011-06-16 06:47:06 +0000632void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000633 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000634 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000635}
636
Chandler Carruth631abd92011-06-16 06:47:06 +0000637void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000638 VisitCastExpr(S);
639 VisitType(S->getTypeAsWritten());
640}
641
Chandler Carruth631abd92011-06-16 06:47:06 +0000642void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000643 VisitExplicitCastExpr(S);
644}
645
Chandler Carruth631abd92011-06-16 06:47:06 +0000646void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000647 VisitExpr(S);
648 ID.AddInteger(S->getOpcode());
649}
650
Chandler Carruth631abd92011-06-16 06:47:06 +0000651void
652StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000653 VisitBinaryOperator(S);
654}
655
Chandler Carruth631abd92011-06-16 06:47:06 +0000656void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000657 VisitExpr(S);
658}
659
Chandler Carruth631abd92011-06-16 06:47:06 +0000660void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000661 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000662 VisitExpr(S);
663}
664
Chandler Carruth631abd92011-06-16 06:47:06 +0000665void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000666 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000667 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000668}
669
Chandler Carruth631abd92011-06-16 06:47:06 +0000670void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000671 VisitExpr(S);
672}
673
Chandler Carruth631abd92011-06-16 06:47:06 +0000674void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000675 VisitExpr(S);
676}
677
Hal Finkelc4d7c822013-09-18 03:29:45 +0000678void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
679 VisitExpr(S);
680}
681
Chandler Carruth631abd92011-06-16 06:47:06 +0000682void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000683 VisitExpr(S);
684}
685
Chandler Carruth631abd92011-06-16 06:47:06 +0000686void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000687 VisitExpr(S);
688}
689
Chandler Carruth631abd92011-06-16 06:47:06 +0000690void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000691 VisitExpr(S);
692}
693
Chandler Carruth631abd92011-06-16 06:47:06 +0000694void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000695 if (S->getSyntacticForm()) {
696 VisitInitListExpr(S->getSyntacticForm());
697 return;
698 }
Mike Stump11289f42009-09-09 15:08:12 +0000699
Douglas Gregor5c193b92009-07-28 00:33:38 +0000700 VisitExpr(S);
701}
702
Chandler Carruth631abd92011-06-16 06:47:06 +0000703void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000704 VisitExpr(S);
705 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000706 for (DesignatedInitExpr::const_designators_iterator D =
707 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000708 D != DEnd; ++D) {
709 if (D->isFieldDesignator()) {
710 ID.AddInteger(0);
711 VisitName(D->getFieldName());
712 continue;
713 }
Mike Stump11289f42009-09-09 15:08:12 +0000714
Douglas Gregor5c193b92009-07-28 00:33:38 +0000715 if (D->isArrayDesignator()) {
716 ID.AddInteger(1);
717 } else {
718 assert(D->isArrayRangeDesignator());
719 ID.AddInteger(2);
720 }
721 ID.AddInteger(D->getFirstExprIndex());
722 }
723}
724
Chandler Carruth631abd92011-06-16 06:47:06 +0000725void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000726 VisitExpr(S);
727}
728
Chandler Carruth631abd92011-06-16 06:47:06 +0000729void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000730 VisitExpr(S);
731 VisitName(&S->getAccessor());
732}
733
Chandler Carruth631abd92011-06-16 06:47:06 +0000734void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000735 VisitExpr(S);
736 VisitDecl(S->getBlockDecl());
737}
738
Chandler Carruth631abd92011-06-16 06:47:06 +0000739void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000740 VisitExpr(S);
741 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
742 QualType T = S->getAssocType(i);
743 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000744 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000745 else
746 VisitType(T);
747 VisitExpr(S->getAssocExpr(i));
748 }
749}
750
John McCallfe96e0b2011-11-06 09:01:30 +0000751void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
752 VisitExpr(S);
753 for (PseudoObjectExpr::const_semantics_iterator
754 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
755 // Normally, we would not profile the source expressions of OVEs.
756 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
757 Visit(OVE->getSourceExpr());
758}
759
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000760void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
761 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000762 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000763}
764
Chandler Carruth631abd92011-06-16 06:47:06 +0000765static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000766 UnaryOperatorKind &UnaryOp,
767 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000768 switch (S->getOperator()) {
769 case OO_None:
770 case OO_New:
771 case OO_Delete:
772 case OO_Array_New:
773 case OO_Array_Delete:
774 case OO_Arrow:
775 case OO_Call:
776 case OO_Conditional:
777 case NUM_OVERLOADED_OPERATORS:
778 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000779
780 case OO_Plus:
781 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000782 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000783 return Stmt::UnaryOperatorClass;
784 }
785
John McCalle3027922010-08-25 11:45:40 +0000786 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000787 return Stmt::BinaryOperatorClass;
788
789 case OO_Minus:
790 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000791 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000792 return Stmt::UnaryOperatorClass;
793 }
794
John McCalle3027922010-08-25 11:45:40 +0000795 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000796 return Stmt::BinaryOperatorClass;
797
798 case OO_Star:
799 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000800 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000801 return Stmt::UnaryOperatorClass;
802 }
803
Richard Smithf15acc52014-06-05 22:43:40 +0000804 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000805 return Stmt::BinaryOperatorClass;
806
807 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000808 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000809 return Stmt::BinaryOperatorClass;
810
811 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000812 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000813 return Stmt::BinaryOperatorClass;
814
815 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000816 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000817 return Stmt::BinaryOperatorClass;
818
819 case OO_Amp:
820 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000821 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000822 return Stmt::UnaryOperatorClass;
823 }
824
John McCalle3027922010-08-25 11:45:40 +0000825 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000826 return Stmt::BinaryOperatorClass;
827
828 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000829 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000830 return Stmt::BinaryOperatorClass;
831
832 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000833 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000834 return Stmt::UnaryOperatorClass;
835
836 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000837 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000838 return Stmt::UnaryOperatorClass;
839
840 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000841 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000842 return Stmt::BinaryOperatorClass;
843
844 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000845 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000846 return Stmt::BinaryOperatorClass;
847
848 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000849 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000850 return Stmt::BinaryOperatorClass;
851
852 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000853 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000854 return Stmt::CompoundAssignOperatorClass;
855
856 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000857 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000858 return Stmt::CompoundAssignOperatorClass;
859
860 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000861 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000862 return Stmt::CompoundAssignOperatorClass;
863
864 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000865 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000866 return Stmt::CompoundAssignOperatorClass;
867
868 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000869 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000870 return Stmt::CompoundAssignOperatorClass;
871
872 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000873 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000874 return Stmt::CompoundAssignOperatorClass;
875
876 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000877 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000878 return Stmt::CompoundAssignOperatorClass;
879
880 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000881 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000882 return Stmt::CompoundAssignOperatorClass;
883
884 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000885 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000886 return Stmt::BinaryOperatorClass;
887
888 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000889 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000890 return Stmt::BinaryOperatorClass;
891
892 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000893 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000894 return Stmt::CompoundAssignOperatorClass;
895
896 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000897 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000898 return Stmt::CompoundAssignOperatorClass;
899
900 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000901 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000902 return Stmt::BinaryOperatorClass;
903
904 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000905 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000906 return Stmt::BinaryOperatorClass;
907
908 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000909 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000910 return Stmt::BinaryOperatorClass;
911
912 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000913 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000914 return Stmt::BinaryOperatorClass;
915
916 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000917 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000918 return Stmt::BinaryOperatorClass;
919
920 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000921 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000922 return Stmt::BinaryOperatorClass;
923
924 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000925 UnaryOp = S->getNumArgs() == 1? UO_PreInc
926 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000927 return Stmt::UnaryOperatorClass;
928
929 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000930 UnaryOp = S->getNumArgs() == 1? UO_PreDec
931 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000932 return Stmt::UnaryOperatorClass;
933
934 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000935 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000936 return Stmt::BinaryOperatorClass;
937
938
939 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000940 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000941 return Stmt::BinaryOperatorClass;
942
943 case OO_Subscript:
944 return Stmt::ArraySubscriptExprClass;
945 }
946
947 llvm_unreachable("Invalid overloaded operator expression");
948}
Richard Smithf15acc52014-06-05 22:43:40 +0000949
Douglas Gregore9ceb312010-05-19 04:13:23 +0000950
Chandler Carruth631abd92011-06-16 06:47:06 +0000951void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000952 if (S->isTypeDependent()) {
953 // Type-dependent operator calls are profiled like their underlying
954 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000955 UnaryOperatorKind UnaryOp = UO_Extension;
956 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000957 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +0000958
Douglas Gregore9ceb312010-05-19 04:13:23 +0000959 ID.AddInteger(SC);
960 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
961 Visit(S->getArg(I));
962 if (SC == Stmt::UnaryOperatorClass)
963 ID.AddInteger(UnaryOp);
964 else if (SC == Stmt::BinaryOperatorClass ||
965 SC == Stmt::CompoundAssignOperatorClass)
966 ID.AddInteger(BinaryOp);
967 else
968 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +0000969
Douglas Gregore9ceb312010-05-19 04:13:23 +0000970 return;
971 }
Richard Smithf15acc52014-06-05 22:43:40 +0000972
Douglas Gregor5c193b92009-07-28 00:33:38 +0000973 VisitCallExpr(S);
974 ID.AddInteger(S->getOperator());
975}
976
Chandler Carruth631abd92011-06-16 06:47:06 +0000977void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000978 VisitCallExpr(S);
979}
980
Chandler Carruth631abd92011-06-16 06:47:06 +0000981void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000982 VisitCallExpr(S);
983}
984
Chandler Carruth631abd92011-06-16 06:47:06 +0000985void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000986 VisitExpr(S);
987}
988
Chandler Carruth631abd92011-06-16 06:47:06 +0000989void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000990 VisitExplicitCastExpr(S);
991}
992
Chandler Carruth631abd92011-06-16 06:47:06 +0000993void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000994 VisitCXXNamedCastExpr(S);
995}
996
Chandler Carruth631abd92011-06-16 06:47:06 +0000997void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000998 VisitCXXNamedCastExpr(S);
999}
1000
Chandler Carruth631abd92011-06-16 06:47:06 +00001001void
1002StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001003 VisitCXXNamedCastExpr(S);
1004}
1005
Chandler Carruth631abd92011-06-16 06:47:06 +00001006void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001007 VisitCXXNamedCastExpr(S);
1008}
1009
Richard Smithc67fdd42012-03-07 08:35:16 +00001010void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1011 VisitCallExpr(S);
1012}
1013
Chandler Carruth631abd92011-06-16 06:47:06 +00001014void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001015 VisitExpr(S);
1016 ID.AddBoolean(S->getValue());
1017}
1018
Chandler Carruth631abd92011-06-16 06:47:06 +00001019void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001020 VisitExpr(S);
1021}
1022
Richard Smithcc1b96d2013-06-12 22:31:48 +00001023void StmtProfiler::VisitCXXStdInitializerListExpr(
1024 const CXXStdInitializerListExpr *S) {
1025 VisitExpr(S);
1026}
1027
Chandler Carruth631abd92011-06-16 06:47:06 +00001028void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001029 VisitExpr(S);
1030 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001031 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001032}
1033
Chandler Carruth631abd92011-06-16 06:47:06 +00001034void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001035 VisitExpr(S);
1036 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001037 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001038}
1039
John McCall5e77d762013-04-16 07:28:30 +00001040void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1041 VisitExpr(S);
1042 VisitDecl(S->getPropertyDecl());
1043}
1044
Chandler Carruth631abd92011-06-16 06:47:06 +00001045void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001046 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001047 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001048}
1049
Chandler Carruth631abd92011-06-16 06:47:06 +00001050void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001051 VisitExpr(S);
1052}
1053
Chandler Carruth631abd92011-06-16 06:47:06 +00001054void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001055 VisitExpr(S);
1056 VisitDecl(S->getParam());
1057}
1058
Richard Smith852c9db2013-04-20 22:23:05 +00001059void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1060 VisitExpr(S);
1061 VisitDecl(S->getField());
1062}
1063
Chandler Carruth631abd92011-06-16 06:47:06 +00001064void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001065 VisitExpr(S);
1066 VisitDecl(
1067 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1068}
1069
Chandler Carruth631abd92011-06-16 06:47:06 +00001070void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001071 VisitExpr(S);
1072 VisitDecl(S->getConstructor());
1073 ID.AddBoolean(S->isElidable());
1074}
1075
Chandler Carruth631abd92011-06-16 06:47:06 +00001076void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001077 VisitExplicitCastExpr(S);
1078}
1079
Chandler Carruth631abd92011-06-16 06:47:06 +00001080void
1081StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001082 VisitCXXConstructExpr(S);
1083}
1084
Chandler Carruth631abd92011-06-16 06:47:06 +00001085void
Douglas Gregore31e6062012-02-07 10:09:13 +00001086StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1087 VisitExpr(S);
1088 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1089 CEnd = S->explicit_capture_end();
1090 C != CEnd; ++C) {
1091 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001092 switch (C->getCaptureKind()) {
1093 case LCK_This:
1094 break;
1095 case LCK_ByRef:
1096 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001097 VisitDecl(C->getCapturedVar());
1098 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001099 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001100 case LCK_VLAType:
1101 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001102 }
1103 }
1104 // Note: If we actually needed to be able to match lambda
1105 // expressions, we would have to consider parameters and return type
1106 // here, among other things.
1107 VisitStmt(S->getBody());
1108}
1109
1110void
Chandler Carruth631abd92011-06-16 06:47:06 +00001111StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001112 VisitExpr(S);
1113}
1114
Chandler Carruth631abd92011-06-16 06:47:06 +00001115void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001116 VisitExpr(S);
1117 ID.AddBoolean(S->isGlobalDelete());
1118 ID.AddBoolean(S->isArrayForm());
1119 VisitDecl(S->getOperatorDelete());
1120}
1121
1122
Chandler Carruth631abd92011-06-16 06:47:06 +00001123void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001124 VisitExpr(S);
1125 VisitType(S->getAllocatedType());
1126 VisitDecl(S->getOperatorNew());
1127 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001128 ID.AddBoolean(S->isArray());
1129 ID.AddInteger(S->getNumPlacementArgs());
1130 ID.AddBoolean(S->isGlobalNew());
1131 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001132 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001133}
1134
Chandler Carruth631abd92011-06-16 06:47:06 +00001135void
1136StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001137 VisitExpr(S);
1138 ID.AddBoolean(S->isArrow());
1139 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001140 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001141 if (S->getScopeTypeInfo())
1142 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001143 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001144 if (S->getDestroyedTypeInfo())
1145 VisitType(S->getDestroyedType());
1146 else
1147 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001148}
1149
Chandler Carruth631abd92011-06-16 06:47:06 +00001150void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001151 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001152 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001153 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001154 ID.AddBoolean(S->hasExplicitTemplateArgs());
1155 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001156 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1157 S->getExplicitTemplateArgs().NumTemplateArgs);
1158}
1159
1160void
Chandler Carruth631abd92011-06-16 06:47:06 +00001161StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001162 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001163}
1164
Douglas Gregor29c42f22012-02-24 07:38:34 +00001165void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1166 VisitExpr(S);
1167 ID.AddInteger(S->getTrait());
1168 ID.AddInteger(S->getNumArgs());
1169 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1170 VisitType(S->getArg(I)->getType());
1171}
1172
Chandler Carruth631abd92011-06-16 06:47:06 +00001173void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001174 VisitExpr(S);
1175 ID.AddInteger(S->getTrait());
1176 VisitType(S->getQueriedType());
1177}
1178
Chandler Carruth631abd92011-06-16 06:47:06 +00001179void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001180 VisitExpr(S);
1181 ID.AddInteger(S->getTrait());
1182 VisitExpr(S->getQueriedExpression());
1183}
1184
Chandler Carruth631abd92011-06-16 06:47:06 +00001185void StmtProfiler::VisitDependentScopeDeclRefExpr(
1186 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001187 VisitExpr(S);
1188 VisitName(S->getDeclName());
1189 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001190 ID.AddBoolean(S->hasExplicitTemplateArgs());
1191 if (S->hasExplicitTemplateArgs())
1192 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001193}
1194
Chandler Carruth631abd92011-06-16 06:47:06 +00001195void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001196 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001197}
1198
Chandler Carruth631abd92011-06-16 06:47:06 +00001199void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1200 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001201 VisitExpr(S);
1202 VisitType(S->getTypeAsWritten());
1203}
1204
Chandler Carruth631abd92011-06-16 06:47:06 +00001205void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1206 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001207 ID.AddBoolean(S->isImplicitAccess());
1208 if (!S->isImplicitAccess()) {
1209 VisitExpr(S);
1210 ID.AddBoolean(S->isArrow());
1211 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001212 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001213 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001214 ID.AddBoolean(S->hasExplicitTemplateArgs());
1215 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001216 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1217}
1218
Chandler Carruth631abd92011-06-16 06:47:06 +00001219void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001220 ID.AddBoolean(S->isImplicitAccess());
1221 if (!S->isImplicitAccess()) {
1222 VisitExpr(S);
1223 ID.AddBoolean(S->isArrow());
1224 }
John McCall10eae182009-11-30 22:42:35 +00001225 VisitNestedNameSpecifier(S->getQualifier());
1226 VisitName(S->getMemberName());
1227 ID.AddBoolean(S->hasExplicitTemplateArgs());
1228 if (S->hasExplicitTemplateArgs())
1229 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001230}
1231
Chandler Carruth631abd92011-06-16 06:47:06 +00001232void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001233 VisitExpr(S);
1234}
1235
Chandler Carruth631abd92011-06-16 06:47:06 +00001236void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001237 VisitExpr(S);
1238}
1239
Chandler Carruth631abd92011-06-16 06:47:06 +00001240void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001241 VisitExpr(S);
1242 VisitDecl(S->getPack());
1243}
1244
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001245void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001246 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001247 VisitExpr(S);
1248 VisitDecl(S->getParameterPack());
1249 VisitTemplateArgument(S->getArgumentPack());
1250}
1251
John McCall7c454bb2011-07-15 05:09:51 +00001252void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1253 const SubstNonTypeTemplateParmExpr *E) {
1254 // Profile exactly as the replacement expression.
1255 Visit(E->getReplacement());
1256}
1257
Richard Smithb15fe3a2012-09-12 00:56:43 +00001258void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1259 VisitExpr(S);
1260 VisitDecl(S->getParameterPack());
1261 ID.AddInteger(S->getNumExpansions());
1262 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1263 VisitDecl(*I);
1264}
1265
Douglas Gregorfe314812011-06-21 17:03:29 +00001266void StmtProfiler::VisitMaterializeTemporaryExpr(
1267 const MaterializeTemporaryExpr *S) {
1268 VisitExpr(S);
1269}
1270
Richard Smith0f0af192014-11-08 05:07:16 +00001271void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1272 VisitExpr(S);
1273 ID.AddInteger(S->getOperator());
1274}
1275
Chandler Carruth631abd92011-06-16 06:47:06 +00001276void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001277 VisitExpr(E);
1278}
1279
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001280void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1281 VisitExpr(E);
1282}
1283
Chandler Carruth631abd92011-06-16 06:47:06 +00001284void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001285 VisitExpr(S);
1286}
1287
Patrick Beard0caa3942012-04-19 00:25:12 +00001288void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001289 VisitExpr(E);
1290}
1291
1292void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1293 VisitExpr(E);
1294}
1295
1296void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1297 VisitExpr(E);
1298}
1299
Chandler Carruth631abd92011-06-16 06:47:06 +00001300void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001301 VisitExpr(S);
1302 VisitType(S->getEncodedType());
1303}
1304
Chandler Carruth631abd92011-06-16 06:47:06 +00001305void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001306 VisitExpr(S);
1307 VisitName(S->getSelector());
1308}
1309
Chandler Carruth631abd92011-06-16 06:47:06 +00001310void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001311 VisitExpr(S);
1312 VisitDecl(S->getProtocol());
1313}
1314
Chandler Carruth631abd92011-06-16 06:47:06 +00001315void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001316 VisitExpr(S);
1317 VisitDecl(S->getDecl());
1318 ID.AddBoolean(S->isArrow());
1319 ID.AddBoolean(S->isFreeIvar());
1320}
1321
Chandler Carruth631abd92011-06-16 06:47:06 +00001322void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001323 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001324 if (S->isImplicitProperty()) {
1325 VisitDecl(S->getImplicitPropertyGetter());
1326 VisitDecl(S->getImplicitPropertySetter());
1327 } else {
1328 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001329 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001330 if (S->isSuperReceiver()) {
1331 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001332 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001333 }
Douglas Gregora7095092009-07-28 14:44:31 +00001334}
1335
Ted Kremeneke65b0862012-03-06 20:05:56 +00001336void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1337 VisitExpr(S);
1338 VisitDecl(S->getAtIndexMethodDecl());
1339 VisitDecl(S->setAtIndexMethodDecl());
1340}
1341
Chandler Carruth631abd92011-06-16 06:47:06 +00001342void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001343 VisitExpr(S);
1344 VisitName(S->getSelector());
1345 VisitDecl(S->getMethodDecl());
1346}
1347
Chandler Carruth631abd92011-06-16 06:47:06 +00001348void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001349 VisitExpr(S);
1350 ID.AddBoolean(S->isArrow());
1351}
1352
Ted Kremeneke65b0862012-03-06 20:05:56 +00001353void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1354 VisitExpr(S);
1355 ID.AddBoolean(S->getValue());
1356}
1357
Chandler Carruth631abd92011-06-16 06:47:06 +00001358void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1359 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001360 VisitExpr(S);
1361 ID.AddBoolean(S->shouldCopy());
1362}
1363
Chandler Carruth631abd92011-06-16 06:47:06 +00001364void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001365 VisitExplicitCastExpr(S);
1366 ID.AddBoolean(S->getBridgeKind());
1367}
1368
Chandler Carruth631abd92011-06-16 06:47:06 +00001369void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001370 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001371
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001372 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001373 if (const NonTypeTemplateParmDecl *NTTP =
1374 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001375 ID.AddInteger(NTTP->getDepth());
1376 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001377 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001378 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001379 return;
1380 }
Mike Stump11289f42009-09-09 15:08:12 +00001381
Chandler Carruth631abd92011-06-16 06:47:06 +00001382 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001383 // The Itanium C++ ABI uses the type, scope depth, and scope
1384 // index of a parameter when mangling expressions that involve
1385 // function parameters, so we will use the parameter's type for
1386 // establishing function parameter identity. That way, our
1387 // definition of "equivalent" (per C++ [temp.over.link]) is at
1388 // least as strong as the definition of "equivalent" used for
1389 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001390 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001391 ID.AddInteger(Parm->getFunctionScopeDepth());
1392 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001393 return;
1394 }
Mike Stump11289f42009-09-09 15:08:12 +00001395
Richard Smithd9a1cd82012-04-02 18:53:24 +00001396 if (const TemplateTypeParmDecl *TTP =
1397 dyn_cast<TemplateTypeParmDecl>(D)) {
1398 ID.AddInteger(TTP->getDepth());
1399 ID.AddInteger(TTP->getIndex());
1400 ID.AddBoolean(TTP->isParameterPack());
1401 return;
1402 }
1403
Chandler Carruth631abd92011-06-16 06:47:06 +00001404 if (const TemplateTemplateParmDecl *TTP =
1405 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001406 ID.AddInteger(TTP->getDepth());
1407 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001408 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001409 return;
1410 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001411 }
Mike Stump11289f42009-09-09 15:08:12 +00001412
Craig Topper36250ad2014-05-12 05:36:57 +00001413 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001414}
1415
1416void StmtProfiler::VisitType(QualType T) {
1417 if (Canonical)
1418 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001419
Douglas Gregor5c193b92009-07-28 00:33:38 +00001420 ID.AddPointer(T.getAsOpaquePtr());
1421}
1422
1423void StmtProfiler::VisitName(DeclarationName Name) {
1424 ID.AddPointer(Name.getAsOpaquePtr());
1425}
1426
1427void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1428 if (Canonical)
1429 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1430 ID.AddPointer(NNS);
1431}
1432
1433void StmtProfiler::VisitTemplateName(TemplateName Name) {
1434 if (Canonical)
1435 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001436
Douglas Gregor5c193b92009-07-28 00:33:38 +00001437 Name.Profile(ID);
1438}
1439
John McCall0ad16662009-10-29 08:12:44 +00001440void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001441 unsigned NumArgs) {
1442 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001443 for (unsigned I = 0; I != NumArgs; ++I)
1444 VisitTemplateArgument(Args[I].getArgument());
1445}
Mike Stump11289f42009-09-09 15:08:12 +00001446
John McCall0ad16662009-10-29 08:12:44 +00001447void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1448 // Mostly repetitive with TemplateArgument::Profile!
1449 ID.AddInteger(Arg.getKind());
1450 switch (Arg.getKind()) {
1451 case TemplateArgument::Null:
1452 break;
Mike Stump11289f42009-09-09 15:08:12 +00001453
John McCall0ad16662009-10-29 08:12:44 +00001454 case TemplateArgument::Type:
1455 VisitType(Arg.getAsType());
1456 break;
Mike Stump11289f42009-09-09 15:08:12 +00001457
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001458 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001459 case TemplateArgument::TemplateExpansion:
1460 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001461 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001462
John McCall0ad16662009-10-29 08:12:44 +00001463 case TemplateArgument::Declaration:
1464 VisitDecl(Arg.getAsDecl());
1465 break;
Mike Stump11289f42009-09-09 15:08:12 +00001466
Eli Friedmanb826a002012-09-26 02:36:12 +00001467 case TemplateArgument::NullPtr:
1468 VisitType(Arg.getNullPtrType());
1469 break;
1470
John McCall0ad16662009-10-29 08:12:44 +00001471 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001472 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001473 VisitType(Arg.getIntegralType());
1474 break;
Mike Stump11289f42009-09-09 15:08:12 +00001475
John McCall0ad16662009-10-29 08:12:44 +00001476 case TemplateArgument::Expression:
1477 Visit(Arg.getAsExpr());
1478 break;
Mike Stump11289f42009-09-09 15:08:12 +00001479
John McCall0ad16662009-10-29 08:12:44 +00001480 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001481 for (const auto &P : Arg.pack_elements())
1482 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001483 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001484 }
1485}
1486
Jay Foad39c79802011-01-12 09:06:06 +00001487void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001488 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001489 StmtProfiler Profiler(ID, Context, Canonical);
1490 Profiler.Visit(this);
1491}