blob: cc61fae276f654e3c6689507dac97f8ea24d201a [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) {
Aaron Ballman2205d2a2014-03-14 15:55:35 +0000325 for (auto *I : Node->varlists())
326 Profiler->VisitStmt(I);
Alexey Bataev756c1962013-09-24 03:17:45 +0000327}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000328
329void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000330 VisitOMPClauseList(C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000331}
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000332void OMPClauseProfiler::VisitOMPFirstprivateClause(
333 const OMPFirstprivateClause *C) {
334 VisitOMPClauseList(C);
335}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000336void
337OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
338 VisitOMPClauseList(C);
339}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000340void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000341 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000342}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000343void OMPClauseProfiler::VisitOMPReductionClause(
344 const OMPReductionClause *C) {
345 Profiler->VisitNestedNameSpecifier(
346 C->getQualifierLoc().getNestedNameSpecifier());
347 Profiler->VisitName(C->getNameInfo().getName());
348 VisitOMPClauseList(C);
349}
Alexander Musman8dba6642014-04-22 13:09:42 +0000350void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
351 VisitOMPClauseList(C);
352 Profiler->VisitStmt(C->getStep());
353}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000354void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
355 VisitOMPClauseList(C);
356 Profiler->VisitStmt(C->getAlignment());
357}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000358void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
359 VisitOMPClauseList(C);
360}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000361void
362OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
363 VisitOMPClauseList(C);
364}
Alexey Bataev6125da92014-07-21 11:26:11 +0000365void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
366 VisitOMPClauseList(C);
367}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000368}
369
370void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000371StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000372 VisitStmt(S);
373 OMPClauseProfiler P(this);
374 ArrayRef<OMPClause *> Clauses = S->clauses();
375 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
376 I != E; ++I)
377 if (*I)
378 P.Visit(*I);
379}
380
Alexander Musman3aaab662014-08-19 11:27:13 +0000381void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
382 VisitOMPExecutableDirective(S);
383}
384
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000385void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
386 VisitOMPExecutableDirective(S);
387}
388
389void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000390 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000391}
392
Alexey Bataevf29276e2014-06-18 04:14:57 +0000393void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000394 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000395}
396
Alexander Musmanf82886e2014-09-18 05:12:34 +0000397void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
398 VisitOMPLoopDirective(S);
399}
400
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000401void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
402 VisitOMPExecutableDirective(S);
403}
404
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000405void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
406 VisitOMPExecutableDirective(S);
407}
408
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000409void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
410 VisitOMPExecutableDirective(S);
411}
412
Alexander Musman80c22892014-07-17 08:54:58 +0000413void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
414 VisitOMPExecutableDirective(S);
415}
416
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000417void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
418 VisitOMPExecutableDirective(S);
419 VisitName(S->getDirectiveName().getName());
420}
421
Alexey Bataev4acb8592014-07-07 13:01:15 +0000422void
423StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000424 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000425}
426
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000427void StmtProfiler::VisitOMPParallelSectionsDirective(
428 const OMPParallelSectionsDirective *S) {
429 VisitOMPExecutableDirective(S);
430}
431
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000432void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
433 VisitOMPExecutableDirective(S);
434}
435
Alexey Bataev68446b72014-07-18 07:47:19 +0000436void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
437 VisitOMPExecutableDirective(S);
438}
439
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000440void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
441 VisitOMPExecutableDirective(S);
442}
443
Alexey Bataev2df347a2014-07-18 10:17:07 +0000444void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
445 VisitOMPExecutableDirective(S);
446}
447
Alexey Bataev6125da92014-07-21 11:26:11 +0000448void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
449 VisitOMPExecutableDirective(S);
450}
451
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000452void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
453 VisitOMPExecutableDirective(S);
454}
455
Alexey Bataev0162e452014-07-22 10:10:35 +0000456void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
457 VisitOMPExecutableDirective(S);
458}
459
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000460void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
461 VisitOMPExecutableDirective(S);
462}
463
Chandler Carruth631abd92011-06-16 06:47:06 +0000464void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000465 VisitStmt(S);
466}
467
Chandler Carruth631abd92011-06-16 06:47:06 +0000468void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000469 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000470 if (!Canonical)
471 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000472 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000473 if (!Canonical)
474 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000475}
476
Chandler Carruth631abd92011-06-16 06:47:06 +0000477void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000478 VisitExpr(S);
479 ID.AddInteger(S->getIdentType());
480}
481
Chandler Carruth631abd92011-06-16 06:47:06 +0000482void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000483 VisitExpr(S);
484 S->getValue().Profile(ID);
485}
486
Chandler Carruth631abd92011-06-16 06:47:06 +0000487void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000488 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000489 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000490 ID.AddInteger(S->getValue());
491}
492
Chandler Carruth631abd92011-06-16 06:47:06 +0000493void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000494 VisitExpr(S);
495 S->getValue().Profile(ID);
496 ID.AddBoolean(S->isExact());
497}
498
Chandler Carruth631abd92011-06-16 06:47:06 +0000499void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000500 VisitExpr(S);
501}
502
Chandler Carruth631abd92011-06-16 06:47:06 +0000503void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000504 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000505 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000506 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000507}
508
Chandler Carruth631abd92011-06-16 06:47:06 +0000509void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000510 VisitExpr(S);
511}
512
Chandler Carruth631abd92011-06-16 06:47:06 +0000513void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000514 VisitExpr(S);
515}
516
Chandler Carruth631abd92011-06-16 06:47:06 +0000517void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000518 VisitExpr(S);
519 ID.AddInteger(S->getOpcode());
520}
521
Chandler Carruth631abd92011-06-16 06:47:06 +0000522void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000523 VisitType(S->getTypeSourceInfo()->getType());
524 unsigned n = S->getNumComponents();
525 for (unsigned i = 0; i < n; ++i) {
526 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i);
527 ID.AddInteger(ON.getKind());
528 switch (ON.getKind()) {
529 case OffsetOfExpr::OffsetOfNode::Array:
530 // Expressions handled below.
531 break;
532
533 case OffsetOfExpr::OffsetOfNode::Field:
534 VisitDecl(ON.getField());
535 break;
536
537 case OffsetOfExpr::OffsetOfNode::Identifier:
538 ID.AddPointer(ON.getFieldName());
539 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000540
Douglas Gregord1702062010-04-29 00:18:15 +0000541 case OffsetOfExpr::OffsetOfNode::Base:
542 // These nodes are implicit, and therefore don't need profiling.
543 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000544 }
545 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000546
Douglas Gregor882211c2010-04-28 22:16:22 +0000547 VisitExpr(S);
548}
549
Chandler Carruth631abd92011-06-16 06:47:06 +0000550void
551StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000552 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000553 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000554 if (S->isArgumentType())
555 VisitType(S->getArgumentType());
556}
557
Chandler Carruth631abd92011-06-16 06:47:06 +0000558void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000559 VisitExpr(S);
560}
561
Chandler Carruth631abd92011-06-16 06:47:06 +0000562void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000563 VisitExpr(S);
564}
565
Chandler Carruth631abd92011-06-16 06:47:06 +0000566void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000567 VisitExpr(S);
568 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000569 if (!Canonical)
570 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000571 ID.AddBoolean(S->isArrow());
572}
573
Chandler Carruth631abd92011-06-16 06:47:06 +0000574void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000575 VisitExpr(S);
576 ID.AddBoolean(S->isFileScope());
577}
578
Chandler Carruth631abd92011-06-16 06:47:06 +0000579void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000580 VisitExpr(S);
581}
582
Chandler Carruth631abd92011-06-16 06:47:06 +0000583void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000584 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000585 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000586}
587
Chandler Carruth631abd92011-06-16 06:47:06 +0000588void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000589 VisitCastExpr(S);
590 VisitType(S->getTypeAsWritten());
591}
592
Chandler Carruth631abd92011-06-16 06:47:06 +0000593void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000594 VisitExplicitCastExpr(S);
595}
596
Chandler Carruth631abd92011-06-16 06:47:06 +0000597void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000598 VisitExpr(S);
599 ID.AddInteger(S->getOpcode());
600}
601
Chandler Carruth631abd92011-06-16 06:47:06 +0000602void
603StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000604 VisitBinaryOperator(S);
605}
606
Chandler Carruth631abd92011-06-16 06:47:06 +0000607void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000608 VisitExpr(S);
609}
610
Chandler Carruth631abd92011-06-16 06:47:06 +0000611void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000612 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000613 VisitExpr(S);
614}
615
Chandler Carruth631abd92011-06-16 06:47:06 +0000616void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000617 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000618 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000619}
620
Chandler Carruth631abd92011-06-16 06:47:06 +0000621void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000622 VisitExpr(S);
623}
624
Chandler Carruth631abd92011-06-16 06:47:06 +0000625void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000626 VisitExpr(S);
627}
628
Hal Finkelc4d7c822013-09-18 03:29:45 +0000629void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
630 VisitExpr(S);
631}
632
Chandler Carruth631abd92011-06-16 06:47:06 +0000633void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000634 VisitExpr(S);
635}
636
Chandler Carruth631abd92011-06-16 06:47:06 +0000637void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000638 VisitExpr(S);
639}
640
Chandler Carruth631abd92011-06-16 06:47:06 +0000641void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000642 VisitExpr(S);
643}
644
Chandler Carruth631abd92011-06-16 06:47:06 +0000645void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000646 if (S->getSyntacticForm()) {
647 VisitInitListExpr(S->getSyntacticForm());
648 return;
649 }
Mike Stump11289f42009-09-09 15:08:12 +0000650
Douglas Gregor5c193b92009-07-28 00:33:38 +0000651 VisitExpr(S);
652}
653
Chandler Carruth631abd92011-06-16 06:47:06 +0000654void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000655 VisitExpr(S);
656 ID.AddBoolean(S->usesGNUSyntax());
Chandler Carruth631abd92011-06-16 06:47:06 +0000657 for (DesignatedInitExpr::const_designators_iterator D =
658 S->designators_begin(), DEnd = S->designators_end();
Douglas Gregor5c193b92009-07-28 00:33:38 +0000659 D != DEnd; ++D) {
660 if (D->isFieldDesignator()) {
661 ID.AddInteger(0);
662 VisitName(D->getFieldName());
663 continue;
664 }
Mike Stump11289f42009-09-09 15:08:12 +0000665
Douglas Gregor5c193b92009-07-28 00:33:38 +0000666 if (D->isArrayDesignator()) {
667 ID.AddInteger(1);
668 } else {
669 assert(D->isArrayRangeDesignator());
670 ID.AddInteger(2);
671 }
672 ID.AddInteger(D->getFirstExprIndex());
673 }
674}
675
Chandler Carruth631abd92011-06-16 06:47:06 +0000676void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000677 VisitExpr(S);
678}
679
Chandler Carruth631abd92011-06-16 06:47:06 +0000680void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000681 VisitExpr(S);
682 VisitName(&S->getAccessor());
683}
684
Chandler Carruth631abd92011-06-16 06:47:06 +0000685void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000686 VisitExpr(S);
687 VisitDecl(S->getBlockDecl());
688}
689
Chandler Carruth631abd92011-06-16 06:47:06 +0000690void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000691 VisitExpr(S);
692 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
693 QualType T = S->getAssocType(i);
694 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000695 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000696 else
697 VisitType(T);
698 VisitExpr(S->getAssocExpr(i));
699 }
700}
701
John McCallfe96e0b2011-11-06 09:01:30 +0000702void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
703 VisitExpr(S);
704 for (PseudoObjectExpr::const_semantics_iterator
705 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
706 // Normally, we would not profile the source expressions of OVEs.
707 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
708 Visit(OVE->getSourceExpr());
709}
710
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000711void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
712 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000713 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000714}
715
Chandler Carruth631abd92011-06-16 06:47:06 +0000716static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000717 UnaryOperatorKind &UnaryOp,
718 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000719 switch (S->getOperator()) {
720 case OO_None:
721 case OO_New:
722 case OO_Delete:
723 case OO_Array_New:
724 case OO_Array_Delete:
725 case OO_Arrow:
726 case OO_Call:
727 case OO_Conditional:
728 case NUM_OVERLOADED_OPERATORS:
729 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000730
731 case OO_Plus:
732 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000733 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000734 return Stmt::UnaryOperatorClass;
735 }
736
John McCalle3027922010-08-25 11:45:40 +0000737 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000738 return Stmt::BinaryOperatorClass;
739
740 case OO_Minus:
741 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000742 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000743 return Stmt::UnaryOperatorClass;
744 }
745
John McCalle3027922010-08-25 11:45:40 +0000746 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000747 return Stmt::BinaryOperatorClass;
748
749 case OO_Star:
750 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +0000751 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000752 return Stmt::UnaryOperatorClass;
753 }
754
Richard Smithf15acc52014-06-05 22:43:40 +0000755 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000756 return Stmt::BinaryOperatorClass;
757
758 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +0000759 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000760 return Stmt::BinaryOperatorClass;
761
762 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +0000763 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000764 return Stmt::BinaryOperatorClass;
765
766 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +0000767 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000768 return Stmt::BinaryOperatorClass;
769
770 case OO_Amp:
771 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000772 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000773 return Stmt::UnaryOperatorClass;
774 }
775
John McCalle3027922010-08-25 11:45:40 +0000776 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000777 return Stmt::BinaryOperatorClass;
778
779 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +0000780 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000781 return Stmt::BinaryOperatorClass;
782
783 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +0000784 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000785 return Stmt::UnaryOperatorClass;
786
787 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +0000788 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000789 return Stmt::UnaryOperatorClass;
790
791 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +0000792 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000793 return Stmt::BinaryOperatorClass;
794
795 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +0000796 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000797 return Stmt::BinaryOperatorClass;
798
799 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +0000800 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000801 return Stmt::BinaryOperatorClass;
802
803 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +0000804 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000805 return Stmt::CompoundAssignOperatorClass;
806
807 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +0000808 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000809 return Stmt::CompoundAssignOperatorClass;
810
811 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +0000812 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000813 return Stmt::CompoundAssignOperatorClass;
814
815 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +0000816 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000817 return Stmt::CompoundAssignOperatorClass;
818
819 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +0000820 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000821 return Stmt::CompoundAssignOperatorClass;
822
823 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +0000824 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000825 return Stmt::CompoundAssignOperatorClass;
826
827 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +0000828 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000829 return Stmt::CompoundAssignOperatorClass;
830
831 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +0000832 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000833 return Stmt::CompoundAssignOperatorClass;
834
835 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +0000836 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000837 return Stmt::BinaryOperatorClass;
838
839 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +0000840 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000841 return Stmt::BinaryOperatorClass;
842
843 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +0000844 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000845 return Stmt::CompoundAssignOperatorClass;
846
847 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000848 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000849 return Stmt::CompoundAssignOperatorClass;
850
851 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +0000852 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000853 return Stmt::BinaryOperatorClass;
854
855 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +0000856 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000857 return Stmt::BinaryOperatorClass;
858
859 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +0000860 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000861 return Stmt::BinaryOperatorClass;
862
863 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +0000864 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000865 return Stmt::BinaryOperatorClass;
866
867 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +0000868 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000869 return Stmt::BinaryOperatorClass;
870
871 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +0000872 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000873 return Stmt::BinaryOperatorClass;
874
875 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +0000876 UnaryOp = S->getNumArgs() == 1? UO_PreInc
877 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000878 return Stmt::UnaryOperatorClass;
879
880 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +0000881 UnaryOp = S->getNumArgs() == 1? UO_PreDec
882 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000883 return Stmt::UnaryOperatorClass;
884
885 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +0000886 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000887 return Stmt::BinaryOperatorClass;
888
889
890 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +0000891 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000892 return Stmt::BinaryOperatorClass;
893
894 case OO_Subscript:
895 return Stmt::ArraySubscriptExprClass;
896 }
897
898 llvm_unreachable("Invalid overloaded operator expression");
899}
Richard Smithf15acc52014-06-05 22:43:40 +0000900
Douglas Gregore9ceb312010-05-19 04:13:23 +0000901
Chandler Carruth631abd92011-06-16 06:47:06 +0000902void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000903 if (S->isTypeDependent()) {
904 // Type-dependent operator calls are profiled like their underlying
905 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +0000906 UnaryOperatorKind UnaryOp = UO_Extension;
907 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000908 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +0000909
Douglas Gregore9ceb312010-05-19 04:13:23 +0000910 ID.AddInteger(SC);
911 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
912 Visit(S->getArg(I));
913 if (SC == Stmt::UnaryOperatorClass)
914 ID.AddInteger(UnaryOp);
915 else if (SC == Stmt::BinaryOperatorClass ||
916 SC == Stmt::CompoundAssignOperatorClass)
917 ID.AddInteger(BinaryOp);
918 else
919 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +0000920
Douglas Gregore9ceb312010-05-19 04:13:23 +0000921 return;
922 }
Richard Smithf15acc52014-06-05 22:43:40 +0000923
Douglas Gregor5c193b92009-07-28 00:33:38 +0000924 VisitCallExpr(S);
925 ID.AddInteger(S->getOperator());
926}
927
Chandler Carruth631abd92011-06-16 06:47:06 +0000928void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000929 VisitCallExpr(S);
930}
931
Chandler Carruth631abd92011-06-16 06:47:06 +0000932void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +0000933 VisitCallExpr(S);
934}
935
Chandler Carruth631abd92011-06-16 06:47:06 +0000936void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +0000937 VisitExpr(S);
938}
939
Chandler Carruth631abd92011-06-16 06:47:06 +0000940void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000941 VisitExplicitCastExpr(S);
942}
943
Chandler Carruth631abd92011-06-16 06:47:06 +0000944void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000945 VisitCXXNamedCastExpr(S);
946}
947
Chandler Carruth631abd92011-06-16 06:47:06 +0000948void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000949 VisitCXXNamedCastExpr(S);
950}
951
Chandler Carruth631abd92011-06-16 06:47:06 +0000952void
953StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000954 VisitCXXNamedCastExpr(S);
955}
956
Chandler Carruth631abd92011-06-16 06:47:06 +0000957void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000958 VisitCXXNamedCastExpr(S);
959}
960
Richard Smithc67fdd42012-03-07 08:35:16 +0000961void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
962 VisitCallExpr(S);
963}
964
Chandler Carruth631abd92011-06-16 06:47:06 +0000965void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000966 VisitExpr(S);
967 ID.AddBoolean(S->getValue());
968}
969
Chandler Carruth631abd92011-06-16 06:47:06 +0000970void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000971 VisitExpr(S);
972}
973
Richard Smithcc1b96d2013-06-12 22:31:48 +0000974void StmtProfiler::VisitCXXStdInitializerListExpr(
975 const CXXStdInitializerListExpr *S) {
976 VisitExpr(S);
977}
978
Chandler Carruth631abd92011-06-16 06:47:06 +0000979void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000980 VisitExpr(S);
981 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000982 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000983}
984
Chandler Carruth631abd92011-06-16 06:47:06 +0000985void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +0000986 VisitExpr(S);
987 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +0000988 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +0000989}
990
John McCall5e77d762013-04-16 07:28:30 +0000991void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
992 VisitExpr(S);
993 VisitDecl(S->getPropertyDecl());
994}
995
Chandler Carruth631abd92011-06-16 06:47:06 +0000996void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000997 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +0000998 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000999}
1000
Chandler Carruth631abd92011-06-16 06:47:06 +00001001void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001002 VisitExpr(S);
1003}
1004
Chandler Carruth631abd92011-06-16 06:47:06 +00001005void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001006 VisitExpr(S);
1007 VisitDecl(S->getParam());
1008}
1009
Richard Smith852c9db2013-04-20 22:23:05 +00001010void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1011 VisitExpr(S);
1012 VisitDecl(S->getField());
1013}
1014
Chandler Carruth631abd92011-06-16 06:47:06 +00001015void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001016 VisitExpr(S);
1017 VisitDecl(
1018 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1019}
1020
Chandler Carruth631abd92011-06-16 06:47:06 +00001021void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001022 VisitExpr(S);
1023 VisitDecl(S->getConstructor());
1024 ID.AddBoolean(S->isElidable());
1025}
1026
Chandler Carruth631abd92011-06-16 06:47:06 +00001027void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001028 VisitExplicitCastExpr(S);
1029}
1030
Chandler Carruth631abd92011-06-16 06:47:06 +00001031void
1032StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001033 VisitCXXConstructExpr(S);
1034}
1035
Chandler Carruth631abd92011-06-16 06:47:06 +00001036void
Douglas Gregore31e6062012-02-07 10:09:13 +00001037StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1038 VisitExpr(S);
1039 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1040 CEnd = S->explicit_capture_end();
1041 C != CEnd; ++C) {
1042 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001043 switch (C->getCaptureKind()) {
1044 case LCK_This:
1045 break;
1046 case LCK_ByRef:
1047 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001048 VisitDecl(C->getCapturedVar());
1049 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001050 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001051 case LCK_VLAType:
1052 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001053 }
1054 }
1055 // Note: If we actually needed to be able to match lambda
1056 // expressions, we would have to consider parameters and return type
1057 // here, among other things.
1058 VisitStmt(S->getBody());
1059}
1060
1061void
Chandler Carruth631abd92011-06-16 06:47:06 +00001062StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001063 VisitExpr(S);
1064}
1065
Chandler Carruth631abd92011-06-16 06:47:06 +00001066void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001067 VisitExpr(S);
1068 ID.AddBoolean(S->isGlobalDelete());
1069 ID.AddBoolean(S->isArrayForm());
1070 VisitDecl(S->getOperatorDelete());
1071}
1072
1073
Chandler Carruth631abd92011-06-16 06:47:06 +00001074void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001075 VisitExpr(S);
1076 VisitType(S->getAllocatedType());
1077 VisitDecl(S->getOperatorNew());
1078 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001079 ID.AddBoolean(S->isArray());
1080 ID.AddInteger(S->getNumPlacementArgs());
1081 ID.AddBoolean(S->isGlobalNew());
1082 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001083 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001084}
1085
Chandler Carruth631abd92011-06-16 06:47:06 +00001086void
1087StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001088 VisitExpr(S);
1089 ID.AddBoolean(S->isArrow());
1090 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001091 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001092 if (S->getScopeTypeInfo())
1093 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001094 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001095 if (S->getDestroyedTypeInfo())
1096 VisitType(S->getDestroyedType());
1097 else
1098 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001099}
1100
Chandler Carruth631abd92011-06-16 06:47:06 +00001101void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001102 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001103 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001104 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001105 ID.AddBoolean(S->hasExplicitTemplateArgs());
1106 if (S->hasExplicitTemplateArgs())
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001107 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(),
1108 S->getExplicitTemplateArgs().NumTemplateArgs);
1109}
1110
1111void
Chandler Carruth631abd92011-06-16 06:47:06 +00001112StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001113 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001114}
1115
Douglas Gregor29c42f22012-02-24 07:38:34 +00001116void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1117 VisitExpr(S);
1118 ID.AddInteger(S->getTrait());
1119 ID.AddInteger(S->getNumArgs());
1120 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1121 VisitType(S->getArg(I)->getType());
1122}
1123
Chandler Carruth631abd92011-06-16 06:47:06 +00001124void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001125 VisitExpr(S);
1126 ID.AddInteger(S->getTrait());
1127 VisitType(S->getQueriedType());
1128}
1129
Chandler Carruth631abd92011-06-16 06:47:06 +00001130void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001131 VisitExpr(S);
1132 ID.AddInteger(S->getTrait());
1133 VisitExpr(S->getQueriedExpression());
1134}
1135
Chandler Carruth631abd92011-06-16 06:47:06 +00001136void StmtProfiler::VisitDependentScopeDeclRefExpr(
1137 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001138 VisitExpr(S);
1139 VisitName(S->getDeclName());
1140 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001141 ID.AddBoolean(S->hasExplicitTemplateArgs());
1142 if (S->hasExplicitTemplateArgs())
1143 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001144}
1145
Chandler Carruth631abd92011-06-16 06:47:06 +00001146void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001147 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001148}
1149
Chandler Carruth631abd92011-06-16 06:47:06 +00001150void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1151 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001152 VisitExpr(S);
1153 VisitType(S->getTypeAsWritten());
1154}
1155
Chandler Carruth631abd92011-06-16 06:47:06 +00001156void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1157 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001158 ID.AddBoolean(S->isImplicitAccess());
1159 if (!S->isImplicitAccess()) {
1160 VisitExpr(S);
1161 ID.AddBoolean(S->isArrow());
1162 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001163 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001164 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001165 ID.AddBoolean(S->hasExplicitTemplateArgs());
1166 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001167 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1168}
1169
Chandler Carruth631abd92011-06-16 06:47:06 +00001170void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001171 ID.AddBoolean(S->isImplicitAccess());
1172 if (!S->isImplicitAccess()) {
1173 VisitExpr(S);
1174 ID.AddBoolean(S->isArrow());
1175 }
John McCall10eae182009-11-30 22:42:35 +00001176 VisitNestedNameSpecifier(S->getQualifier());
1177 VisitName(S->getMemberName());
1178 ID.AddBoolean(S->hasExplicitTemplateArgs());
1179 if (S->hasExplicitTemplateArgs())
1180 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001181}
1182
Chandler Carruth631abd92011-06-16 06:47:06 +00001183void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001184 VisitExpr(S);
1185}
1186
Chandler Carruth631abd92011-06-16 06:47:06 +00001187void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001188 VisitExpr(S);
1189}
1190
Chandler Carruth631abd92011-06-16 06:47:06 +00001191void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001192 VisitExpr(S);
1193 VisitDecl(S->getPack());
1194}
1195
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001196void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001197 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001198 VisitExpr(S);
1199 VisitDecl(S->getParameterPack());
1200 VisitTemplateArgument(S->getArgumentPack());
1201}
1202
John McCall7c454bb2011-07-15 05:09:51 +00001203void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1204 const SubstNonTypeTemplateParmExpr *E) {
1205 // Profile exactly as the replacement expression.
1206 Visit(E->getReplacement());
1207}
1208
Richard Smithb15fe3a2012-09-12 00:56:43 +00001209void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1210 VisitExpr(S);
1211 VisitDecl(S->getParameterPack());
1212 ID.AddInteger(S->getNumExpansions());
1213 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1214 VisitDecl(*I);
1215}
1216
Douglas Gregorfe314812011-06-21 17:03:29 +00001217void StmtProfiler::VisitMaterializeTemporaryExpr(
1218 const MaterializeTemporaryExpr *S) {
1219 VisitExpr(S);
1220}
1221
Chandler Carruth631abd92011-06-16 06:47:06 +00001222void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001223 VisitExpr(E);
1224}
1225
Chandler Carruth631abd92011-06-16 06:47:06 +00001226void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001227 VisitExpr(S);
1228}
1229
Patrick Beard0caa3942012-04-19 00:25:12 +00001230void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001231 VisitExpr(E);
1232}
1233
1234void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1235 VisitExpr(E);
1236}
1237
1238void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1239 VisitExpr(E);
1240}
1241
Chandler Carruth631abd92011-06-16 06:47:06 +00001242void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001243 VisitExpr(S);
1244 VisitType(S->getEncodedType());
1245}
1246
Chandler Carruth631abd92011-06-16 06:47:06 +00001247void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001248 VisitExpr(S);
1249 VisitName(S->getSelector());
1250}
1251
Chandler Carruth631abd92011-06-16 06:47:06 +00001252void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001253 VisitExpr(S);
1254 VisitDecl(S->getProtocol());
1255}
1256
Chandler Carruth631abd92011-06-16 06:47:06 +00001257void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001258 VisitExpr(S);
1259 VisitDecl(S->getDecl());
1260 ID.AddBoolean(S->isArrow());
1261 ID.AddBoolean(S->isFreeIvar());
1262}
1263
Chandler Carruth631abd92011-06-16 06:47:06 +00001264void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001265 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001266 if (S->isImplicitProperty()) {
1267 VisitDecl(S->getImplicitPropertyGetter());
1268 VisitDecl(S->getImplicitPropertySetter());
1269 } else {
1270 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001271 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001272 if (S->isSuperReceiver()) {
1273 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001274 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001275 }
Douglas Gregora7095092009-07-28 14:44:31 +00001276}
1277
Ted Kremeneke65b0862012-03-06 20:05:56 +00001278void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1279 VisitExpr(S);
1280 VisitDecl(S->getAtIndexMethodDecl());
1281 VisitDecl(S->setAtIndexMethodDecl());
1282}
1283
Chandler Carruth631abd92011-06-16 06:47:06 +00001284void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001285 VisitExpr(S);
1286 VisitName(S->getSelector());
1287 VisitDecl(S->getMethodDecl());
1288}
1289
Chandler Carruth631abd92011-06-16 06:47:06 +00001290void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001291 VisitExpr(S);
1292 ID.AddBoolean(S->isArrow());
1293}
1294
Ted Kremeneke65b0862012-03-06 20:05:56 +00001295void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1296 VisitExpr(S);
1297 ID.AddBoolean(S->getValue());
1298}
1299
Chandler Carruth631abd92011-06-16 06:47:06 +00001300void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1301 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001302 VisitExpr(S);
1303 ID.AddBoolean(S->shouldCopy());
1304}
1305
Chandler Carruth631abd92011-06-16 06:47:06 +00001306void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001307 VisitExplicitCastExpr(S);
1308 ID.AddBoolean(S->getBridgeKind());
1309}
1310
Chandler Carruth631abd92011-06-16 06:47:06 +00001311void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001312 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001313
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001314 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001315 if (const NonTypeTemplateParmDecl *NTTP =
1316 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001317 ID.AddInteger(NTTP->getDepth());
1318 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001319 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001320 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001321 return;
1322 }
Mike Stump11289f42009-09-09 15:08:12 +00001323
Chandler Carruth631abd92011-06-16 06:47:06 +00001324 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001325 // The Itanium C++ ABI uses the type, scope depth, and scope
1326 // index of a parameter when mangling expressions that involve
1327 // function parameters, so we will use the parameter's type for
1328 // establishing function parameter identity. That way, our
1329 // definition of "equivalent" (per C++ [temp.over.link]) is at
1330 // least as strong as the definition of "equivalent" used for
1331 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001332 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001333 ID.AddInteger(Parm->getFunctionScopeDepth());
1334 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001335 return;
1336 }
Mike Stump11289f42009-09-09 15:08:12 +00001337
Richard Smithd9a1cd82012-04-02 18:53:24 +00001338 if (const TemplateTypeParmDecl *TTP =
1339 dyn_cast<TemplateTypeParmDecl>(D)) {
1340 ID.AddInteger(TTP->getDepth());
1341 ID.AddInteger(TTP->getIndex());
1342 ID.AddBoolean(TTP->isParameterPack());
1343 return;
1344 }
1345
Chandler Carruth631abd92011-06-16 06:47:06 +00001346 if (const TemplateTemplateParmDecl *TTP =
1347 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001348 ID.AddInteger(TTP->getDepth());
1349 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001350 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001351 return;
1352 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001353 }
Mike Stump11289f42009-09-09 15:08:12 +00001354
Craig Topper36250ad2014-05-12 05:36:57 +00001355 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001356}
1357
1358void StmtProfiler::VisitType(QualType T) {
1359 if (Canonical)
1360 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001361
Douglas Gregor5c193b92009-07-28 00:33:38 +00001362 ID.AddPointer(T.getAsOpaquePtr());
1363}
1364
1365void StmtProfiler::VisitName(DeclarationName Name) {
1366 ID.AddPointer(Name.getAsOpaquePtr());
1367}
1368
1369void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1370 if (Canonical)
1371 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1372 ID.AddPointer(NNS);
1373}
1374
1375void StmtProfiler::VisitTemplateName(TemplateName Name) {
1376 if (Canonical)
1377 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001378
Douglas Gregor5c193b92009-07-28 00:33:38 +00001379 Name.Profile(ID);
1380}
1381
John McCall0ad16662009-10-29 08:12:44 +00001382void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001383 unsigned NumArgs) {
1384 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001385 for (unsigned I = 0; I != NumArgs; ++I)
1386 VisitTemplateArgument(Args[I].getArgument());
1387}
Mike Stump11289f42009-09-09 15:08:12 +00001388
John McCall0ad16662009-10-29 08:12:44 +00001389void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1390 // Mostly repetitive with TemplateArgument::Profile!
1391 ID.AddInteger(Arg.getKind());
1392 switch (Arg.getKind()) {
1393 case TemplateArgument::Null:
1394 break;
Mike Stump11289f42009-09-09 15:08:12 +00001395
John McCall0ad16662009-10-29 08:12:44 +00001396 case TemplateArgument::Type:
1397 VisitType(Arg.getAsType());
1398 break;
Mike Stump11289f42009-09-09 15:08:12 +00001399
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001400 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001401 case TemplateArgument::TemplateExpansion:
1402 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001403 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001404
John McCall0ad16662009-10-29 08:12:44 +00001405 case TemplateArgument::Declaration:
1406 VisitDecl(Arg.getAsDecl());
1407 break;
Mike Stump11289f42009-09-09 15:08:12 +00001408
Eli Friedmanb826a002012-09-26 02:36:12 +00001409 case TemplateArgument::NullPtr:
1410 VisitType(Arg.getNullPtrType());
1411 break;
1412
John McCall0ad16662009-10-29 08:12:44 +00001413 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001414 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001415 VisitType(Arg.getIntegralType());
1416 break;
Mike Stump11289f42009-09-09 15:08:12 +00001417
John McCall0ad16662009-10-29 08:12:44 +00001418 case TemplateArgument::Expression:
1419 Visit(Arg.getAsExpr());
1420 break;
Mike Stump11289f42009-09-09 15:08:12 +00001421
John McCall0ad16662009-10-29 08:12:44 +00001422 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001423 for (const auto &P : Arg.pack_elements())
1424 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001425 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001426 }
1427}
1428
Jay Foad39c79802011-01-12 09:06:06 +00001429void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001430 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001431 StmtProfiler Profiler(ID, Context, Canonical);
1432 Profiler.Visit(this);
1433}