blob: c66a077996a55c2195306fddbc020f32231a2a6f [file] [log] [blame]
Douglas Gregor5c193b92009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor32615a12009-07-28 16:39:25 +000011// representation that identifies a statement/expression.
Douglas Gregor5c193b92009-07-28 00:33:38 +000012//
13//===----------------------------------------------------------------------===//
14#include "clang/AST/ASTContext.h"
Douglas Gregora7095092009-07-28 14:44:31 +000015#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/Expr.h"
19#include "clang/AST/ExprCXX.h"
20#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000021#include "clang/AST/ExprOpenMP.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000022#include "clang/AST/StmtVisitor.h"
23#include "llvm/ADT/FoldingSet.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000024using namespace clang;
25
26namespace {
Chandler Carruth631abd92011-06-16 06:47:06 +000027 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Douglas Gregor5c193b92009-07-28 00:33:38 +000028 llvm::FoldingSetNodeID &ID;
Jay Foad39c79802011-01-12 09:06:06 +000029 const ASTContext &Context;
Douglas Gregor5c193b92009-07-28 00:33:38 +000030 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000031
Douglas Gregor5c193b92009-07-28 00:33:38 +000032 public:
Jay Foad39c79802011-01-12 09:06:06 +000033 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Mike Stump11289f42009-09-09 15:08:12 +000034 bool Canonical)
Douglas Gregor5c193b92009-07-28 00:33:38 +000035 : ID(ID), Context(Context), Canonical(Canonical) { }
Mike Stump11289f42009-09-09 15:08:12 +000036
Chandler Carruth631abd92011-06-16 06:47:06 +000037 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000038
Chandler Carruth631abd92011-06-16 06:47:06 +000039#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000040#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregor5c193b92009-07-28 00:33:38 +000042 /// \brief Visit a declaration that is referenced within an expression
43 /// or statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000044 void VisitDecl(const Decl *D);
Mike Stump11289f42009-09-09 15:08:12 +000045
46 /// \brief Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000047 /// statement.
48 void VisitType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +000049
Douglas Gregor5c193b92009-07-28 00:33:38 +000050 /// \brief Visit a name that occurs within an expression or statement.
51 void VisitName(DeclarationName Name);
Mike Stump11289f42009-09-09 15:08:12 +000052
Douglas Gregor5c193b92009-07-28 00:33:38 +000053 /// \brief Visit a nested-name-specifier that occurs within an expression
54 /// or statement.
55 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
Mike Stump11289f42009-09-09 15:08:12 +000056
Douglas Gregor5c193b92009-07-28 00:33:38 +000057 /// \brief Visit a template name that occurs within an expression or
58 /// statement.
59 void VisitTemplateName(TemplateName Name);
Mike Stump11289f42009-09-09 15:08:12 +000060
Douglas Gregor5c193b92009-07-28 00:33:38 +000061 /// \brief Visit template arguments that occur within an expression or
62 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000063 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
64 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000065
66 /// \brief Visit a single template argument.
67 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000068 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +000069}
Douglas Gregor5c193b92009-07-28 00:33:38 +000070
Chandler Carruth631abd92011-06-16 06:47:06 +000071void StmtProfiler::VisitStmt(const Stmt *S) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +000072 assert(S && "Requires non-null Stmt pointer");
Douglas Gregor5c193b92009-07-28 00:33:38 +000073 ID.AddInteger(S->getStmtClass());
Benjamin Kramer642f1732015-07-02 21:03:14 +000074 for (const Stmt *SubStmt : S->children()) {
75 if (SubStmt)
76 Visit(SubStmt);
Peter Collingbournecdb9f302012-03-01 16:34:31 +000077 else
78 ID.AddInteger(0);
79 }
Douglas Gregor5c193b92009-07-28 00:33:38 +000080}
81
Chandler Carruth631abd92011-06-16 06:47:06 +000082void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000083 VisitStmt(S);
Aaron Ballman535bbcc2014-03-14 17:01:24 +000084 for (const auto *D : S->decls())
85 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +000086}
87
Chandler Carruth631abd92011-06-16 06:47:06 +000088void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000089 VisitStmt(S);
90}
91
Chandler Carruth631abd92011-06-16 06:47:06 +000092void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000093 VisitStmt(S);
94}
95
Chandler Carruth631abd92011-06-16 06:47:06 +000096void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
Douglas Gregor44882592009-07-28 15:27:13 +000097 VisitStmt(S);
98}
99
Chandler Carruth631abd92011-06-16 06:47:06 +0000100void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000101 VisitStmt(S);
102}
103
Chandler Carruth631abd92011-06-16 06:47:06 +0000104void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000105 VisitStmt(S);
106}
107
Chandler Carruth631abd92011-06-16 06:47:06 +0000108void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000109 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000110 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000111}
112
Richard Smithc202b282012-04-14 00:33:13 +0000113void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
114 VisitStmt(S);
115 // TODO: maybe visit attributes?
116}
117
Chandler Carruth631abd92011-06-16 06:47:06 +0000118void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000119 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000120 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000121}
122
Chandler Carruth631abd92011-06-16 06:47:06 +0000123void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000124 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000125 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000126}
127
Chandler Carruth631abd92011-06-16 06:47:06 +0000128void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000129 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000130 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000131}
132
Chandler Carruth631abd92011-06-16 06:47:06 +0000133void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000134 VisitStmt(S);
135}
136
Chandler Carruth631abd92011-06-16 06:47:06 +0000137void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000138 VisitStmt(S);
139}
140
Chandler Carruth631abd92011-06-16 06:47:06 +0000141void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000142 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000143 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000144}
145
Chandler Carruth631abd92011-06-16 06:47:06 +0000146void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000147 VisitStmt(S);
148}
149
Chandler Carruth631abd92011-06-16 06:47:06 +0000150void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000151 VisitStmt(S);
152}
153
Chandler Carruth631abd92011-06-16 06:47:06 +0000154void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000155 VisitStmt(S);
156}
157
Chandler Carruth631abd92011-06-16 06:47:06 +0000158void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000159 VisitStmt(S);
160}
161
Chad Rosierde70e0e2012-08-25 00:11:56 +0000162void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000163 VisitStmt(S);
164 ID.AddBoolean(S->isVolatile());
165 ID.AddBoolean(S->isSimple());
166 VisitStringLiteral(S->getAsmString());
167 ID.AddInteger(S->getNumOutputs());
168 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
169 ID.AddString(S->getOutputName(I));
170 VisitStringLiteral(S->getOutputConstraintLiteral(I));
171 }
172 ID.AddInteger(S->getNumInputs());
173 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
174 ID.AddString(S->getInputName(I));
175 VisitStringLiteral(S->getInputConstraintLiteral(I));
176 }
177 ID.AddInteger(S->getNumClobbers());
178 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000179 VisitStringLiteral(S->getClobberStringLiteral(I));
Douglas Gregor44882592009-07-28 15:27:13 +0000180}
181
Chad Rosier32503022012-06-11 20:47:18 +0000182void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
183 // FIXME: Implement MS style inline asm statement profiler.
184 VisitStmt(S);
185}
186
Chandler Carruth631abd92011-06-16 06:47:06 +0000187void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000188 VisitStmt(S);
189 VisitType(S->getCaughtType());
190}
191
Chandler Carruth631abd92011-06-16 06:47:06 +0000192void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000193 VisitStmt(S);
194}
195
Chandler Carruth631abd92011-06-16 06:47:06 +0000196void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000197 VisitStmt(S);
198}
199
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000200void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
201 VisitStmt(S);
202 ID.AddBoolean(S->isIfExists());
203 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
204 VisitName(S->getNameInfo().getName());
205}
206
Chandler Carruth631abd92011-06-16 06:47:06 +0000207void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000208 VisitStmt(S);
209}
210
Chandler Carruth631abd92011-06-16 06:47:06 +0000211void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000212 VisitStmt(S);
213}
214
Chandler Carruth631abd92011-06-16 06:47:06 +0000215void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000216 VisitStmt(S);
217}
218
Nico Weber9b982072014-07-07 00:12:30 +0000219void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
220 VisitStmt(S);
221}
222
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000223void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
224 VisitStmt(S);
225}
226
Chandler Carruth631abd92011-06-16 06:47:06 +0000227void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000228 VisitStmt(S);
229}
230
Chandler Carruth631abd92011-06-16 06:47:06 +0000231void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000232 VisitStmt(S);
233 ID.AddBoolean(S->hasEllipsis());
234 if (S->getCatchParamDecl())
235 VisitType(S->getCatchParamDecl()->getType());
236}
237
Chandler Carruth631abd92011-06-16 06:47:06 +0000238void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000239 VisitStmt(S);
240}
241
Chandler Carruth631abd92011-06-16 06:47:06 +0000242void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000243 VisitStmt(S);
244}
245
Chandler Carruth631abd92011-06-16 06:47:06 +0000246void
247StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000248 VisitStmt(S);
249}
250
Chandler Carruth631abd92011-06-16 06:47:06 +0000251void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000252 VisitStmt(S);
253}
254
Chandler Carruth631abd92011-06-16 06:47:06 +0000255void
256StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000257 VisitStmt(S);
258}
259
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000260namespace {
261class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
262 StmtProfiler *Profiler;
Alexey Bataev756c1962013-09-24 03:17:45 +0000263 /// \brief Process clauses with list of variables.
264 template <typename T>
265 void VisitOMPClauseList(T *Node);
NAKAMURA Takumiaa13f942015-12-09 07:52:46 +0000266
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000267public:
268 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
269#define OPENMP_CLAUSE(Name, Class) \
270 void Visit##Class(const Class *C);
271#include "clang/Basic/OpenMPKinds.def"
Alexey Bataev3392d762016-02-16 11:18:12 +0000272 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000273 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000274};
275
Alexey Bataev3392d762016-02-16 11:18:12 +0000276void OMPClauseProfiler::VistOMPClauseWithPreInit(
277 const OMPClauseWithPreInit *C) {
278 if (auto *S = C->getPreInitStmt())
279 Profiler->VisitStmt(S);
280}
281
Alexey Bataev005248a2016-02-25 05:25:57 +0000282void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
283 const OMPClauseWithPostUpdate *C) {
Alexey Bataev37e594c2016-03-04 07:21:16 +0000284 VistOMPClauseWithPreInit(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000285 if (auto *E = C->getPostUpdateExpr())
286 Profiler->VisitStmt(E);
287}
288
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000289void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
290 if (C->getCondition())
291 Profiler->VisitStmt(C->getCondition());
292}
293
Alexey Bataev3778b602014-07-17 07:32:53 +0000294void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
295 if (C->getCondition())
296 Profiler->VisitStmt(C->getCondition());
297}
298
Alexey Bataev568a8332014-03-06 06:15:19 +0000299void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
300 if (C->getNumThreads())
301 Profiler->VisitStmt(C->getNumThreads());
302}
303
Alexey Bataev62c87d22014-03-21 04:51:18 +0000304void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
305 if (C->getSafelen())
306 Profiler->VisitStmt(C->getSafelen());
307}
308
Alexey Bataev66b15b52015-08-21 11:14:16 +0000309void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
310 if (C->getSimdlen())
311 Profiler->VisitStmt(C->getSimdlen());
312}
313
Alexander Musman8bd31e62014-05-27 15:12:19 +0000314void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
315 if (C->getNumForLoops())
316 Profiler->VisitStmt(C->getNumForLoops());
317}
318
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000319void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000320
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000321void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
322
Alexey Bataev56dafe82014-06-20 07:16:17 +0000323void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000324 VistOMPClauseWithPreInit(C);
325 if (auto *S = C->getChunkSize())
326 Profiler->VisitStmt(S);
Alexey Bataev56dafe82014-06-20 07:16:17 +0000327}
328
Alexey Bataev10e775f2015-07-30 11:36:16 +0000329void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
330 if (auto *Num = C->getNumForLoops())
331 Profiler->VisitStmt(Num);
332}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000333
Alexey Bataev236070f2014-06-20 11:19:47 +0000334void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
335
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000336void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
337
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000338void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
339
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000340void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
341
Alexey Bataevdea47612014-07-23 07:46:59 +0000342void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
343
Alexey Bataev67a4f222014-07-23 10:25:33 +0000344void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
345
Alexey Bataev459dec02014-07-24 06:46:57 +0000346void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
347
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000348void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
349
Alexey Bataev346265e2015-09-25 10:37:12 +0000350void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
351
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000352void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
353
Alexey Bataevb825de12015-12-07 10:51:44 +0000354void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
355
Alexey Bataev756c1962013-09-24 03:17:45 +0000356template<typename T>
357void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000358 for (auto *E : Node->varlists()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000359 if (E)
360 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000361 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000362}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000363
364void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000365 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000366 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000367 if (E)
368 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000369 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000370}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000371void
372OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000373 VisitOMPClauseList(C);
Alexey Bataev417089f2016-02-17 13:19:37 +0000374 VistOMPClauseWithPreInit(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000375 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000376 if (E)
377 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000378 }
379 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000380 if (E)
381 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000382 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000383}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000384void
385OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
386 VisitOMPClauseList(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000387 VistOMPClauseWithPostUpdate(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000388 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000389 if (E)
390 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000391 }
392 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000393 if (E)
394 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000395 }
396 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000397 if (E)
398 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000399 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000400}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000401void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000402 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000403}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000404void OMPClauseProfiler::VisitOMPReductionClause(
405 const OMPReductionClause *C) {
406 Profiler->VisitNestedNameSpecifier(
407 C->getQualifierLoc().getNestedNameSpecifier());
408 Profiler->VisitName(C->getNameInfo().getName());
409 VisitOMPClauseList(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000410 VistOMPClauseWithPostUpdate(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000411 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000412 if (E)
413 Profiler->VisitStmt(E);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000414 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000415 for (auto *E : C->lhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000416 if (E)
417 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000418 }
419 for (auto *E : C->rhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000420 if (E)
421 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000422 }
423 for (auto *E : C->reduction_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000424 if (E)
425 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000426 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000427}
Alexander Musman8dba6642014-04-22 13:09:42 +0000428void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
429 VisitOMPClauseList(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000430 VistOMPClauseWithPostUpdate(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000431 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000432 if (E)
433 Profiler->VisitStmt(E);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000434 }
Alexander Musman3276a272015-03-21 10:12:56 +0000435 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000436 if (E)
437 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000438 }
439 for (auto *E : C->updates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000440 if (E)
441 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000442 }
443 for (auto *E : C->finals()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000444 if (E)
445 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000446 }
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000447 if (C->getStep())
448 Profiler->VisitStmt(C->getStep());
449 if (C->getCalcStep())
450 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000451}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000452void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
453 VisitOMPClauseList(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000454 if (C->getAlignment())
455 Profiler->VisitStmt(C->getAlignment());
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000456}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000457void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
458 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000459 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000460 if (E)
461 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000462 }
463 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000464 if (E)
465 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000466 }
467 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000468 if (E)
469 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000470 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000471}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000472void
473OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
474 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000475 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000476 if (E)
477 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000478 }
479 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000480 if (E)
481 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000482 }
483 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000484 if (E)
485 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000486 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000487}
Alexey Bataev6125da92014-07-21 11:26:11 +0000488void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
489 VisitOMPClauseList(C);
490}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000491void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
492 VisitOMPClauseList(C);
493}
Michael Wonge710d542015-08-07 16:16:36 +0000494void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000495 if (C->getDevice())
496 Profiler->VisitStmt(C->getDevice());
Michael Wonge710d542015-08-07 16:16:36 +0000497}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000498void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
499 VisitOMPClauseList(C);
500}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000501void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000502 if (C->getNumTeams())
503 Profiler->VisitStmt(C->getNumTeams());
Kelvin Li099bb8c2015-11-24 20:50:12 +0000504}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000505void OMPClauseProfiler::VisitOMPThreadLimitClause(
506 const OMPThreadLimitClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000507 if (C->getThreadLimit())
508 Profiler->VisitStmt(C->getThreadLimit());
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000509}
Alexey Bataeva0569352015-12-01 10:17:31 +0000510void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000511 if (C->getPriority())
512 Profiler->VisitStmt(C->getPriority());
Alexey Bataeva0569352015-12-01 10:17:31 +0000513}
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000514void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000515 if (C->getGrainsize())
516 Profiler->VisitStmt(C->getGrainsize());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000517}
Alexey Bataev382967a2015-12-08 12:06:20 +0000518void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000519 if (C->getNumTasks())
520 Profiler->VisitStmt(C->getNumTasks());
Alexey Bataev382967a2015-12-08 12:06:20 +0000521}
Alexey Bataev28c75412015-12-15 08:19:24 +0000522void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000523 if (C->getHint())
524 Profiler->VisitStmt(C->getHint());
Alexey Bataev28c75412015-12-15 08:19:24 +0000525}
Samuel Antao661c0902016-05-26 17:39:58 +0000526void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
527 VisitOMPClauseList(C);
528}
Samuel Antaoec172c62016-05-26 17:49:04 +0000529void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
530 VisitOMPClauseList(C);
531}
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000532}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000533
534void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000535StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000536 VisitStmt(S);
537 OMPClauseProfiler P(this);
538 ArrayRef<OMPClause *> Clauses = S->clauses();
539 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
540 I != E; ++I)
541 if (*I)
542 P.Visit(*I);
543}
544
Alexander Musman3aaab662014-08-19 11:27:13 +0000545void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
546 VisitOMPExecutableDirective(S);
547}
548
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000549void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
550 VisitOMPExecutableDirective(S);
551}
552
553void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000554 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000555}
556
Alexey Bataevf29276e2014-06-18 04:14:57 +0000557void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000558 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000559}
560
Alexander Musmanf82886e2014-09-18 05:12:34 +0000561void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
562 VisitOMPLoopDirective(S);
563}
564
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000565void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
566 VisitOMPExecutableDirective(S);
567}
568
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000569void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
570 VisitOMPExecutableDirective(S);
571}
572
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000573void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
574 VisitOMPExecutableDirective(S);
575}
576
Alexander Musman80c22892014-07-17 08:54:58 +0000577void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
578 VisitOMPExecutableDirective(S);
579}
580
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000581void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
582 VisitOMPExecutableDirective(S);
583 VisitName(S->getDirectiveName().getName());
584}
585
Alexey Bataev4acb8592014-07-07 13:01:15 +0000586void
587StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000588 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000589}
590
Alexander Musmane4e893b2014-09-23 09:33:00 +0000591void StmtProfiler::VisitOMPParallelForSimdDirective(
592 const OMPParallelForSimdDirective *S) {
593 VisitOMPLoopDirective(S);
594}
595
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000596void StmtProfiler::VisitOMPParallelSectionsDirective(
597 const OMPParallelSectionsDirective *S) {
598 VisitOMPExecutableDirective(S);
599}
600
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000601void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
602 VisitOMPExecutableDirective(S);
603}
604
Alexey Bataev68446b72014-07-18 07:47:19 +0000605void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
606 VisitOMPExecutableDirective(S);
607}
608
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000609void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
610 VisitOMPExecutableDirective(S);
611}
612
Alexey Bataev2df347a2014-07-18 10:17:07 +0000613void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
614 VisitOMPExecutableDirective(S);
615}
616
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000617void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
618 VisitOMPExecutableDirective(S);
619}
620
Alexey Bataev6125da92014-07-21 11:26:11 +0000621void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
622 VisitOMPExecutableDirective(S);
623}
624
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000625void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
626 VisitOMPExecutableDirective(S);
627}
628
Alexey Bataev0162e452014-07-22 10:10:35 +0000629void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
630 VisitOMPExecutableDirective(S);
631}
632
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000633void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
634 VisitOMPExecutableDirective(S);
635}
636
Michael Wong65f367f2015-07-21 13:44:28 +0000637void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
638 VisitOMPExecutableDirective(S);
639}
640
Samuel Antaodf67fc42016-01-19 19:15:56 +0000641void StmtProfiler::VisitOMPTargetEnterDataDirective(
642 const OMPTargetEnterDataDirective *S) {
643 VisitOMPExecutableDirective(S);
644}
645
Samuel Antao72590762016-01-19 20:04:50 +0000646void StmtProfiler::VisitOMPTargetExitDataDirective(
647 const OMPTargetExitDataDirective *S) {
648 VisitOMPExecutableDirective(S);
649}
650
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000651void StmtProfiler::VisitOMPTargetParallelDirective(
652 const OMPTargetParallelDirective *S) {
653 VisitOMPExecutableDirective(S);
654}
655
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000656void StmtProfiler::VisitOMPTargetParallelForDirective(
657 const OMPTargetParallelForDirective *S) {
658 VisitOMPExecutableDirective(S);
659}
660
Alexey Bataev13314bf2014-10-09 04:18:56 +0000661void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
662 VisitOMPExecutableDirective(S);
663}
664
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000665void StmtProfiler::VisitOMPCancellationPointDirective(
666 const OMPCancellationPointDirective *S) {
667 VisitOMPExecutableDirective(S);
668}
669
Alexey Bataev80909872015-07-02 11:25:17 +0000670void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
671 VisitOMPExecutableDirective(S);
672}
673
Alexey Bataev49f6e782015-12-01 04:18:41 +0000674void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
675 VisitOMPLoopDirective(S);
676}
677
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000678void StmtProfiler::VisitOMPTaskLoopSimdDirective(
679 const OMPTaskLoopSimdDirective *S) {
680 VisitOMPLoopDirective(S);
681}
682
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000683void StmtProfiler::VisitOMPDistributeDirective(
684 const OMPDistributeDirective *S) {
685 VisitOMPLoopDirective(S);
686}
687
Carlo Bertollib4adf552016-01-15 18:50:31 +0000688void OMPClauseProfiler::VisitOMPDistScheduleClause(
689 const OMPDistScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000690 VistOMPClauseWithPreInit(C);
691 if (auto *S = C->getChunkSize())
692 Profiler->VisitStmt(S);
Carlo Bertollib4adf552016-01-15 18:50:31 +0000693}
694
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000695void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
696
Samuel Antao686c70c2016-05-26 17:30:50 +0000697void StmtProfiler::VisitOMPTargetUpdateDirective(
698 const OMPTargetUpdateDirective *S) {
699 VisitOMPExecutableDirective(S);
700}
701
Carlo Bertolli9925f152016-06-27 14:55:37 +0000702void StmtProfiler::VisitOMPDistributeParallelForDirective(
703 const OMPDistributeParallelForDirective *S) {
704 VisitOMPLoopDirective(S);
705}
706
Chandler Carruth631abd92011-06-16 06:47:06 +0000707void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000708 VisitStmt(S);
709}
710
Chandler Carruth631abd92011-06-16 06:47:06 +0000711void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000712 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000713 if (!Canonical)
714 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000715 VisitDecl(S->getDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000716 if (!Canonical)
717 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000718}
719
Chandler Carruth631abd92011-06-16 06:47:06 +0000720void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000721 VisitExpr(S);
722 ID.AddInteger(S->getIdentType());
723}
724
Chandler Carruth631abd92011-06-16 06:47:06 +0000725void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000726 VisitExpr(S);
727 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +0000728 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000729}
730
Chandler Carruth631abd92011-06-16 06:47:06 +0000731void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000732 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +0000733 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000734 ID.AddInteger(S->getValue());
735}
736
Chandler Carruth631abd92011-06-16 06:47:06 +0000737void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000738 VisitExpr(S);
739 S->getValue().Profile(ID);
740 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +0000741 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000742}
743
Chandler Carruth631abd92011-06-16 06:47:06 +0000744void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000745 VisitExpr(S);
746}
747
Chandler Carruth631abd92011-06-16 06:47:06 +0000748void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000749 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +0000750 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +0000751 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000752}
753
Chandler Carruth631abd92011-06-16 06:47:06 +0000754void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000755 VisitExpr(S);
756}
757
Chandler Carruth631abd92011-06-16 06:47:06 +0000758void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +0000759 VisitExpr(S);
760}
761
Chandler Carruth631abd92011-06-16 06:47:06 +0000762void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000763 VisitExpr(S);
764 ID.AddInteger(S->getOpcode());
765}
766
Chandler Carruth631abd92011-06-16 06:47:06 +0000767void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +0000768 VisitType(S->getTypeSourceInfo()->getType());
769 unsigned n = S->getNumComponents();
770 for (unsigned i = 0; i < n; ++i) {
James Y Knight7281c352015-12-29 22:31:18 +0000771 const OffsetOfNode &ON = S->getComponent(i);
Douglas Gregor882211c2010-04-28 22:16:22 +0000772 ID.AddInteger(ON.getKind());
773 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +0000774 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +0000775 // Expressions handled below.
776 break;
777
James Y Knight7281c352015-12-29 22:31:18 +0000778 case OffsetOfNode::Field:
Douglas Gregor882211c2010-04-28 22:16:22 +0000779 VisitDecl(ON.getField());
780 break;
781
James Y Knight7281c352015-12-29 22:31:18 +0000782 case OffsetOfNode::Identifier:
Douglas Gregor882211c2010-04-28 22:16:22 +0000783 ID.AddPointer(ON.getFieldName());
784 break;
James Y Knight7281c352015-12-29 22:31:18 +0000785
786 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +0000787 // These nodes are implicit, and therefore don't need profiling.
788 break;
Douglas Gregor882211c2010-04-28 22:16:22 +0000789 }
790 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000791
Douglas Gregor882211c2010-04-28 22:16:22 +0000792 VisitExpr(S);
793}
794
Chandler Carruth631abd92011-06-16 06:47:06 +0000795void
796StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000797 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +0000798 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000799 if (S->isArgumentType())
800 VisitType(S->getArgumentType());
801}
802
Chandler Carruth631abd92011-06-16 06:47:06 +0000803void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000804 VisitExpr(S);
805}
806
Alexey Bataev1a3320e2015-08-25 14:24:04 +0000807void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
808 VisitExpr(S);
809}
810
Chandler Carruth631abd92011-06-16 06:47:06 +0000811void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000812 VisitExpr(S);
813}
814
Chandler Carruth631abd92011-06-16 06:47:06 +0000815void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000816 VisitExpr(S);
817 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +0000818 if (!Canonical)
819 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000820 ID.AddBoolean(S->isArrow());
821}
822
Chandler Carruth631abd92011-06-16 06:47:06 +0000823void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000824 VisitExpr(S);
825 ID.AddBoolean(S->isFileScope());
826}
827
Chandler Carruth631abd92011-06-16 06:47:06 +0000828void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000829 VisitExpr(S);
830}
831
Chandler Carruth631abd92011-06-16 06:47:06 +0000832void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000833 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +0000834 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000835}
836
Chandler Carruth631abd92011-06-16 06:47:06 +0000837void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000838 VisitCastExpr(S);
839 VisitType(S->getTypeAsWritten());
840}
841
Chandler Carruth631abd92011-06-16 06:47:06 +0000842void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000843 VisitExplicitCastExpr(S);
844}
845
Chandler Carruth631abd92011-06-16 06:47:06 +0000846void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000847 VisitExpr(S);
848 ID.AddInteger(S->getOpcode());
849}
850
Chandler Carruth631abd92011-06-16 06:47:06 +0000851void
852StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000853 VisitBinaryOperator(S);
854}
855
Chandler Carruth631abd92011-06-16 06:47:06 +0000856void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000857 VisitExpr(S);
858}
859
Chandler Carruth631abd92011-06-16 06:47:06 +0000860void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +0000861 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +0000862 VisitExpr(S);
863}
864
Chandler Carruth631abd92011-06-16 06:47:06 +0000865void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000866 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000867 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000868}
869
Chandler Carruth631abd92011-06-16 06:47:06 +0000870void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000871 VisitExpr(S);
872}
873
Chandler Carruth631abd92011-06-16 06:47:06 +0000874void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000875 VisitExpr(S);
876}
877
Hal Finkelc4d7c822013-09-18 03:29:45 +0000878void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
879 VisitExpr(S);
880}
881
Chandler Carruth631abd92011-06-16 06:47:06 +0000882void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000883 VisitExpr(S);
884}
885
Chandler Carruth631abd92011-06-16 06:47:06 +0000886void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000887 VisitExpr(S);
888}
889
Chandler Carruth631abd92011-06-16 06:47:06 +0000890void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000891 VisitExpr(S);
892}
893
Chandler Carruth631abd92011-06-16 06:47:06 +0000894void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000895 if (S->getSyntacticForm()) {
896 VisitInitListExpr(S->getSyntacticForm());
897 return;
898 }
Mike Stump11289f42009-09-09 15:08:12 +0000899
Douglas Gregor5c193b92009-07-28 00:33:38 +0000900 VisitExpr(S);
901}
902
Chandler Carruth631abd92011-06-16 06:47:06 +0000903void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000904 VisitExpr(S);
905 ID.AddBoolean(S->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +0000906 for (const DesignatedInitExpr::Designator &D : S->designators()) {
907 if (D.isFieldDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000908 ID.AddInteger(0);
David Majnemerf7e36092016-06-23 00:15:04 +0000909 VisitName(D.getFieldName());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000910 continue;
911 }
Mike Stump11289f42009-09-09 15:08:12 +0000912
David Majnemerf7e36092016-06-23 00:15:04 +0000913 if (D.isArrayDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000914 ID.AddInteger(1);
915 } else {
David Majnemerf7e36092016-06-23 00:15:04 +0000916 assert(D.isArrayRangeDesignator());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000917 ID.AddInteger(2);
918 }
David Majnemerf7e36092016-06-23 00:15:04 +0000919 ID.AddInteger(D.getFirstExprIndex());
Douglas Gregor5c193b92009-07-28 00:33:38 +0000920 }
921}
922
Yunzhong Gaocb779302015-06-10 00:27:52 +0000923// Seems that if VisitInitListExpr() only works on the syntactic form of an
924// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
925void StmtProfiler::VisitDesignatedInitUpdateExpr(
926 const DesignatedInitUpdateExpr *S) {
927 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
928 "initializer");
929}
930
931void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
932 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
933}
934
Chandler Carruth631abd92011-06-16 06:47:06 +0000935void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000936 VisitExpr(S);
937}
938
Chandler Carruth631abd92011-06-16 06:47:06 +0000939void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000940 VisitExpr(S);
941 VisitName(&S->getAccessor());
942}
943
Chandler Carruth631abd92011-06-16 06:47:06 +0000944void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +0000945 VisitExpr(S);
946 VisitDecl(S->getBlockDecl());
947}
948
Chandler Carruth631abd92011-06-16 06:47:06 +0000949void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +0000950 VisitExpr(S);
951 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
952 QualType T = S->getAssocType(i);
953 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +0000954 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +0000955 else
956 VisitType(T);
957 VisitExpr(S->getAssocExpr(i));
958 }
959}
960
John McCallfe96e0b2011-11-06 09:01:30 +0000961void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
962 VisitExpr(S);
963 for (PseudoObjectExpr::const_semantics_iterator
964 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
965 // Normally, we would not profile the source expressions of OVEs.
966 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
967 Visit(OVE->getSourceExpr());
968}
969
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000970void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
971 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +0000972 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +0000973}
974
Chandler Carruth631abd92011-06-16 06:47:06 +0000975static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +0000976 UnaryOperatorKind &UnaryOp,
977 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +0000978 switch (S->getOperator()) {
979 case OO_None:
980 case OO_New:
981 case OO_Delete:
982 case OO_Array_New:
983 case OO_Array_Delete:
984 case OO_Arrow:
985 case OO_Call:
986 case OO_Conditional:
Richard Smith9be594e2015-10-22 05:12:22 +0000987 case OO_Coawait:
Douglas Gregore9ceb312010-05-19 04:13:23 +0000988 case NUM_OVERLOADED_OPERATORS:
989 llvm_unreachable("Invalid operator call kind");
Douglas Gregore9ceb312010-05-19 04:13:23 +0000990
991 case OO_Plus:
992 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +0000993 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000994 return Stmt::UnaryOperatorClass;
995 }
996
John McCalle3027922010-08-25 11:45:40 +0000997 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +0000998 return Stmt::BinaryOperatorClass;
999
1000 case OO_Minus:
1001 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001002 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001003 return Stmt::UnaryOperatorClass;
1004 }
1005
John McCalle3027922010-08-25 11:45:40 +00001006 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001007 return Stmt::BinaryOperatorClass;
1008
1009 case OO_Star:
1010 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +00001011 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001012 return Stmt::UnaryOperatorClass;
1013 }
1014
Richard Smithf15acc52014-06-05 22:43:40 +00001015 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001016 return Stmt::BinaryOperatorClass;
1017
1018 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +00001019 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001020 return Stmt::BinaryOperatorClass;
1021
1022 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +00001023 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001024 return Stmt::BinaryOperatorClass;
1025
1026 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +00001027 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001028 return Stmt::BinaryOperatorClass;
1029
1030 case OO_Amp:
1031 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001032 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001033 return Stmt::UnaryOperatorClass;
1034 }
1035
John McCalle3027922010-08-25 11:45:40 +00001036 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001037 return Stmt::BinaryOperatorClass;
1038
1039 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +00001040 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001041 return Stmt::BinaryOperatorClass;
1042
1043 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +00001044 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001045 return Stmt::UnaryOperatorClass;
1046
1047 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +00001048 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001049 return Stmt::UnaryOperatorClass;
1050
1051 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +00001052 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001053 return Stmt::BinaryOperatorClass;
1054
1055 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +00001056 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001057 return Stmt::BinaryOperatorClass;
1058
1059 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +00001060 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001061 return Stmt::BinaryOperatorClass;
1062
1063 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +00001064 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001065 return Stmt::CompoundAssignOperatorClass;
1066
1067 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +00001068 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001069 return Stmt::CompoundAssignOperatorClass;
1070
1071 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +00001072 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001073 return Stmt::CompoundAssignOperatorClass;
1074
1075 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +00001076 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001077 return Stmt::CompoundAssignOperatorClass;
1078
1079 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +00001080 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001081 return Stmt::CompoundAssignOperatorClass;
1082
1083 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +00001084 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001085 return Stmt::CompoundAssignOperatorClass;
1086
1087 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +00001088 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001089 return Stmt::CompoundAssignOperatorClass;
1090
1091 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +00001092 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001093 return Stmt::CompoundAssignOperatorClass;
1094
1095 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +00001096 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001097 return Stmt::BinaryOperatorClass;
1098
1099 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +00001100 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001101 return Stmt::BinaryOperatorClass;
1102
1103 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +00001104 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001105 return Stmt::CompoundAssignOperatorClass;
1106
1107 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001108 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001109 return Stmt::CompoundAssignOperatorClass;
1110
1111 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +00001112 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001113 return Stmt::BinaryOperatorClass;
1114
1115 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001116 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001117 return Stmt::BinaryOperatorClass;
1118
1119 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001120 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001121 return Stmt::BinaryOperatorClass;
1122
1123 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001124 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001125 return Stmt::BinaryOperatorClass;
1126
1127 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001128 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001129 return Stmt::BinaryOperatorClass;
1130
1131 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001132 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001133 return Stmt::BinaryOperatorClass;
1134
1135 case OO_PlusPlus:
John McCalle3027922010-08-25 11:45:40 +00001136 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1137 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001138 return Stmt::UnaryOperatorClass;
1139
1140 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001141 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1142 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001143 return Stmt::UnaryOperatorClass;
1144
1145 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001146 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001147 return Stmt::BinaryOperatorClass;
1148
Douglas Gregore9ceb312010-05-19 04:13:23 +00001149 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001150 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001151 return Stmt::BinaryOperatorClass;
1152
1153 case OO_Subscript:
1154 return Stmt::ArraySubscriptExprClass;
1155 }
1156
1157 llvm_unreachable("Invalid overloaded operator expression");
1158}
Richard Smithf15acc52014-06-05 22:43:40 +00001159
Chandler Carruth631abd92011-06-16 06:47:06 +00001160void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001161 if (S->isTypeDependent()) {
1162 // Type-dependent operator calls are profiled like their underlying
1163 // syntactic operator.
John McCalle3027922010-08-25 11:45:40 +00001164 UnaryOperatorKind UnaryOp = UO_Extension;
1165 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001166 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001167
Douglas Gregore9ceb312010-05-19 04:13:23 +00001168 ID.AddInteger(SC);
1169 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1170 Visit(S->getArg(I));
1171 if (SC == Stmt::UnaryOperatorClass)
1172 ID.AddInteger(UnaryOp);
1173 else if (SC == Stmt::BinaryOperatorClass ||
1174 SC == Stmt::CompoundAssignOperatorClass)
1175 ID.AddInteger(BinaryOp);
1176 else
1177 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001178
Douglas Gregore9ceb312010-05-19 04:13:23 +00001179 return;
1180 }
Richard Smithf15acc52014-06-05 22:43:40 +00001181
Douglas Gregor5c193b92009-07-28 00:33:38 +00001182 VisitCallExpr(S);
1183 ID.AddInteger(S->getOperator());
1184}
1185
Chandler Carruth631abd92011-06-16 06:47:06 +00001186void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001187 VisitCallExpr(S);
1188}
1189
Chandler Carruth631abd92011-06-16 06:47:06 +00001190void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001191 VisitCallExpr(S);
1192}
1193
Chandler Carruth631abd92011-06-16 06:47:06 +00001194void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001195 VisitExpr(S);
1196}
1197
Chandler Carruth631abd92011-06-16 06:47:06 +00001198void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001199 VisitExplicitCastExpr(S);
1200}
1201
Chandler Carruth631abd92011-06-16 06:47:06 +00001202void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001203 VisitCXXNamedCastExpr(S);
1204}
1205
Chandler Carruth631abd92011-06-16 06:47:06 +00001206void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001207 VisitCXXNamedCastExpr(S);
1208}
1209
Chandler Carruth631abd92011-06-16 06:47:06 +00001210void
1211StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001212 VisitCXXNamedCastExpr(S);
1213}
1214
Chandler Carruth631abd92011-06-16 06:47:06 +00001215void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001216 VisitCXXNamedCastExpr(S);
1217}
1218
Richard Smithc67fdd42012-03-07 08:35:16 +00001219void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1220 VisitCallExpr(S);
1221}
1222
Chandler Carruth631abd92011-06-16 06:47:06 +00001223void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001224 VisitExpr(S);
1225 ID.AddBoolean(S->getValue());
1226}
1227
Chandler Carruth631abd92011-06-16 06:47:06 +00001228void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001229 VisitExpr(S);
1230}
1231
Richard Smithcc1b96d2013-06-12 22:31:48 +00001232void StmtProfiler::VisitCXXStdInitializerListExpr(
1233 const CXXStdInitializerListExpr *S) {
1234 VisitExpr(S);
1235}
1236
Chandler Carruth631abd92011-06-16 06:47:06 +00001237void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001238 VisitExpr(S);
1239 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001240 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001241}
1242
Chandler Carruth631abd92011-06-16 06:47:06 +00001243void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001244 VisitExpr(S);
1245 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001246 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001247}
1248
John McCall5e77d762013-04-16 07:28:30 +00001249void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1250 VisitExpr(S);
1251 VisitDecl(S->getPropertyDecl());
1252}
1253
Alexey Bataevf7630272015-11-25 12:01:00 +00001254void StmtProfiler::VisitMSPropertySubscriptExpr(
1255 const MSPropertySubscriptExpr *S) {
1256 VisitExpr(S);
1257}
1258
Chandler Carruth631abd92011-06-16 06:47:06 +00001259void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001260 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001261 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001262}
1263
Chandler Carruth631abd92011-06-16 06:47:06 +00001264void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001265 VisitExpr(S);
1266}
1267
Chandler Carruth631abd92011-06-16 06:47:06 +00001268void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001269 VisitExpr(S);
1270 VisitDecl(S->getParam());
1271}
1272
Richard Smith852c9db2013-04-20 22:23:05 +00001273void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1274 VisitExpr(S);
1275 VisitDecl(S->getField());
1276}
1277
Chandler Carruth631abd92011-06-16 06:47:06 +00001278void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001279 VisitExpr(S);
1280 VisitDecl(
1281 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1282}
1283
Chandler Carruth631abd92011-06-16 06:47:06 +00001284void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001285 VisitExpr(S);
1286 VisitDecl(S->getConstructor());
1287 ID.AddBoolean(S->isElidable());
1288}
1289
Richard Smith5179eb72016-06-28 19:03:57 +00001290void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1291 const CXXInheritedCtorInitExpr *S) {
1292 VisitExpr(S);
1293 VisitDecl(S->getConstructor());
1294}
1295
Chandler Carruth631abd92011-06-16 06:47:06 +00001296void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001297 VisitExplicitCastExpr(S);
1298}
1299
Chandler Carruth631abd92011-06-16 06:47:06 +00001300void
1301StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001302 VisitCXXConstructExpr(S);
1303}
1304
Chandler Carruth631abd92011-06-16 06:47:06 +00001305void
Douglas Gregore31e6062012-02-07 10:09:13 +00001306StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1307 VisitExpr(S);
1308 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1309 CEnd = S->explicit_capture_end();
1310 C != CEnd; ++C) {
1311 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001312 switch (C->getCaptureKind()) {
Faisal Validc6b5962016-03-21 09:25:37 +00001313 case LCK_StarThis:
Richard Smithba71c082013-05-16 06:20:58 +00001314 case LCK_This:
1315 break;
1316 case LCK_ByRef:
1317 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001318 VisitDecl(C->getCapturedVar());
1319 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001320 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001321 case LCK_VLAType:
1322 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001323 }
1324 }
1325 // Note: If we actually needed to be able to match lambda
1326 // expressions, we would have to consider parameters and return type
1327 // here, among other things.
1328 VisitStmt(S->getBody());
1329}
1330
1331void
Chandler Carruth631abd92011-06-16 06:47:06 +00001332StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001333 VisitExpr(S);
1334}
1335
Chandler Carruth631abd92011-06-16 06:47:06 +00001336void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001337 VisitExpr(S);
1338 ID.AddBoolean(S->isGlobalDelete());
1339 ID.AddBoolean(S->isArrayForm());
1340 VisitDecl(S->getOperatorDelete());
1341}
1342
Chandler Carruth631abd92011-06-16 06:47:06 +00001343void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001344 VisitExpr(S);
1345 VisitType(S->getAllocatedType());
1346 VisitDecl(S->getOperatorNew());
1347 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001348 ID.AddBoolean(S->isArray());
1349 ID.AddInteger(S->getNumPlacementArgs());
1350 ID.AddBoolean(S->isGlobalNew());
1351 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001352 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001353}
1354
Chandler Carruth631abd92011-06-16 06:47:06 +00001355void
1356StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001357 VisitExpr(S);
1358 ID.AddBoolean(S->isArrow());
1359 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001360 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001361 if (S->getScopeTypeInfo())
1362 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001363 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001364 if (S->getDestroyedTypeInfo())
1365 VisitType(S->getDestroyedType());
1366 else
1367 ID.AddPointer(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001368}
1369
Chandler Carruth631abd92011-06-16 06:47:06 +00001370void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001371 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001372 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001373 VisitName(S->getName());
John McCalle66edc12009-11-24 19:00:30 +00001374 ID.AddBoolean(S->hasExplicitTemplateArgs());
1375 if (S->hasExplicitTemplateArgs())
James Y Knight04ec5bf2015-12-24 02:59:37 +00001376 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001377}
1378
1379void
Chandler Carruth631abd92011-06-16 06:47:06 +00001380StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001381 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001382}
1383
Douglas Gregor29c42f22012-02-24 07:38:34 +00001384void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1385 VisitExpr(S);
1386 ID.AddInteger(S->getTrait());
1387 ID.AddInteger(S->getNumArgs());
1388 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1389 VisitType(S->getArg(I)->getType());
1390}
1391
Chandler Carruth631abd92011-06-16 06:47:06 +00001392void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001393 VisitExpr(S);
1394 ID.AddInteger(S->getTrait());
1395 VisitType(S->getQueriedType());
1396}
1397
Chandler Carruth631abd92011-06-16 06:47:06 +00001398void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001399 VisitExpr(S);
1400 ID.AddInteger(S->getTrait());
1401 VisitExpr(S->getQueriedExpression());
1402}
1403
Chandler Carruth631abd92011-06-16 06:47:06 +00001404void StmtProfiler::VisitDependentScopeDeclRefExpr(
1405 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001406 VisitExpr(S);
1407 VisitName(S->getDeclName());
1408 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001409 ID.AddBoolean(S->hasExplicitTemplateArgs());
1410 if (S->hasExplicitTemplateArgs())
1411 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001412}
1413
Chandler Carruth631abd92011-06-16 06:47:06 +00001414void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001415 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001416}
1417
Chandler Carruth631abd92011-06-16 06:47:06 +00001418void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1419 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001420 VisitExpr(S);
1421 VisitType(S->getTypeAsWritten());
1422}
1423
Chandler Carruth631abd92011-06-16 06:47:06 +00001424void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1425 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001426 ID.AddBoolean(S->isImplicitAccess());
1427 if (!S->isImplicitAccess()) {
1428 VisitExpr(S);
1429 ID.AddBoolean(S->isArrow());
1430 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001431 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001432 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001433 ID.AddBoolean(S->hasExplicitTemplateArgs());
1434 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001435 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1436}
1437
Chandler Carruth631abd92011-06-16 06:47:06 +00001438void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001439 ID.AddBoolean(S->isImplicitAccess());
1440 if (!S->isImplicitAccess()) {
1441 VisitExpr(S);
1442 ID.AddBoolean(S->isArrow());
1443 }
John McCall10eae182009-11-30 22:42:35 +00001444 VisitNestedNameSpecifier(S->getQualifier());
1445 VisitName(S->getMemberName());
1446 ID.AddBoolean(S->hasExplicitTemplateArgs());
1447 if (S->hasExplicitTemplateArgs())
1448 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001449}
1450
Chandler Carruth631abd92011-06-16 06:47:06 +00001451void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001452 VisitExpr(S);
1453}
1454
Chandler Carruth631abd92011-06-16 06:47:06 +00001455void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001456 VisitExpr(S);
1457}
1458
Chandler Carruth631abd92011-06-16 06:47:06 +00001459void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001460 VisitExpr(S);
1461 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00001462 if (S->isPartiallySubstituted()) {
1463 auto Args = S->getPartialArguments();
1464 ID.AddInteger(Args.size());
1465 for (const auto &TA : Args)
1466 VisitTemplateArgument(TA);
1467 } else {
1468 ID.AddInteger(0);
1469 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001470}
1471
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001472void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001473 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001474 VisitExpr(S);
1475 VisitDecl(S->getParameterPack());
1476 VisitTemplateArgument(S->getArgumentPack());
1477}
1478
John McCall7c454bb2011-07-15 05:09:51 +00001479void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1480 const SubstNonTypeTemplateParmExpr *E) {
1481 // Profile exactly as the replacement expression.
1482 Visit(E->getReplacement());
1483}
1484
Richard Smithb15fe3a2012-09-12 00:56:43 +00001485void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1486 VisitExpr(S);
1487 VisitDecl(S->getParameterPack());
1488 ID.AddInteger(S->getNumExpansions());
1489 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1490 VisitDecl(*I);
1491}
1492
Douglas Gregorfe314812011-06-21 17:03:29 +00001493void StmtProfiler::VisitMaterializeTemporaryExpr(
1494 const MaterializeTemporaryExpr *S) {
1495 VisitExpr(S);
1496}
1497
Richard Smith0f0af192014-11-08 05:07:16 +00001498void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1499 VisitExpr(S);
1500 ID.AddInteger(S->getOperator());
1501}
1502
Richard Smith9f690bd2015-10-27 06:02:45 +00001503void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1504 VisitStmt(S);
1505}
1506
1507void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1508 VisitStmt(S);
1509}
1510
1511void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1512 VisitExpr(S);
1513}
1514
1515void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1516 VisitExpr(S);
1517}
1518
Chandler Carruth631abd92011-06-16 06:47:06 +00001519void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
John McCall8d69a212010-11-15 23:31:06 +00001520 VisitExpr(E);
1521}
1522
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001523void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1524 VisitExpr(E);
1525}
1526
Chandler Carruth631abd92011-06-16 06:47:06 +00001527void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001528 VisitExpr(S);
1529}
1530
Patrick Beard0caa3942012-04-19 00:25:12 +00001531void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001532 VisitExpr(E);
1533}
1534
1535void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1536 VisitExpr(E);
1537}
1538
1539void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1540 VisitExpr(E);
1541}
1542
Chandler Carruth631abd92011-06-16 06:47:06 +00001543void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001544 VisitExpr(S);
1545 VisitType(S->getEncodedType());
1546}
1547
Chandler Carruth631abd92011-06-16 06:47:06 +00001548void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001549 VisitExpr(S);
1550 VisitName(S->getSelector());
1551}
1552
Chandler Carruth631abd92011-06-16 06:47:06 +00001553void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001554 VisitExpr(S);
1555 VisitDecl(S->getProtocol());
1556}
1557
Chandler Carruth631abd92011-06-16 06:47:06 +00001558void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001559 VisitExpr(S);
1560 VisitDecl(S->getDecl());
1561 ID.AddBoolean(S->isArrow());
1562 ID.AddBoolean(S->isFreeIvar());
1563}
1564
Chandler Carruth631abd92011-06-16 06:47:06 +00001565void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001566 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001567 if (S->isImplicitProperty()) {
1568 VisitDecl(S->getImplicitPropertyGetter());
1569 VisitDecl(S->getImplicitPropertySetter());
1570 } else {
1571 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001572 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001573 if (S->isSuperReceiver()) {
1574 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001575 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001576 }
Douglas Gregora7095092009-07-28 14:44:31 +00001577}
1578
Ted Kremeneke65b0862012-03-06 20:05:56 +00001579void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1580 VisitExpr(S);
1581 VisitDecl(S->getAtIndexMethodDecl());
1582 VisitDecl(S->setAtIndexMethodDecl());
1583}
1584
Chandler Carruth631abd92011-06-16 06:47:06 +00001585void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001586 VisitExpr(S);
1587 VisitName(S->getSelector());
1588 VisitDecl(S->getMethodDecl());
1589}
1590
Chandler Carruth631abd92011-06-16 06:47:06 +00001591void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001592 VisitExpr(S);
1593 ID.AddBoolean(S->isArrow());
1594}
1595
Ted Kremeneke65b0862012-03-06 20:05:56 +00001596void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1597 VisitExpr(S);
1598 ID.AddBoolean(S->getValue());
1599}
1600
Chandler Carruth631abd92011-06-16 06:47:06 +00001601void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1602 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001603 VisitExpr(S);
1604 ID.AddBoolean(S->shouldCopy());
1605}
1606
Chandler Carruth631abd92011-06-16 06:47:06 +00001607void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001608 VisitExplicitCastExpr(S);
1609 ID.AddBoolean(S->getBridgeKind());
1610}
1611
Chandler Carruth631abd92011-06-16 06:47:06 +00001612void StmtProfiler::VisitDecl(const Decl *D) {
Douglas Gregor70317122009-07-31 15:45:02 +00001613 ID.AddInteger(D? D->getKind() : 0);
Mike Stump11289f42009-09-09 15:08:12 +00001614
Douglas Gregora5dd9f82009-07-30 23:18:24 +00001615 if (Canonical && D) {
Chandler Carruth631abd92011-06-16 06:47:06 +00001616 if (const NonTypeTemplateParmDecl *NTTP =
1617 dyn_cast<NonTypeTemplateParmDecl>(D)) {
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001618 ID.AddInteger(NTTP->getDepth());
1619 ID.AddInteger(NTTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001620 ID.AddBoolean(NTTP->isParameterPack());
Douglas Gregor00044172009-07-29 16:09:57 +00001621 VisitType(NTTP->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001622 return;
1623 }
Mike Stump11289f42009-09-09 15:08:12 +00001624
Chandler Carruth631abd92011-06-16 06:47:06 +00001625 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
John McCall8fb0d9d2011-05-01 22:35:37 +00001626 // The Itanium C++ ABI uses the type, scope depth, and scope
1627 // index of a parameter when mangling expressions that involve
1628 // function parameters, so we will use the parameter's type for
1629 // establishing function parameter identity. That way, our
1630 // definition of "equivalent" (per C++ [temp.over.link]) is at
1631 // least as strong as the definition of "equivalent" used for
1632 // name mangling.
Douglas Gregor70317122009-07-31 15:45:02 +00001633 VisitType(Parm->getType());
John McCall8fb0d9d2011-05-01 22:35:37 +00001634 ID.AddInteger(Parm->getFunctionScopeDepth());
1635 ID.AddInteger(Parm->getFunctionScopeIndex());
Douglas Gregor70317122009-07-31 15:45:02 +00001636 return;
1637 }
Mike Stump11289f42009-09-09 15:08:12 +00001638
Richard Smithd9a1cd82012-04-02 18:53:24 +00001639 if (const TemplateTypeParmDecl *TTP =
1640 dyn_cast<TemplateTypeParmDecl>(D)) {
1641 ID.AddInteger(TTP->getDepth());
1642 ID.AddInteger(TTP->getIndex());
1643 ID.AddBoolean(TTP->isParameterPack());
1644 return;
1645 }
1646
Chandler Carruth631abd92011-06-16 06:47:06 +00001647 if (const TemplateTemplateParmDecl *TTP =
1648 dyn_cast<TemplateTemplateParmDecl>(D)) {
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001649 ID.AddInteger(TTP->getDepth());
1650 ID.AddInteger(TTP->getIndex());
Douglas Gregorf5500772011-01-05 15:48:55 +00001651 ID.AddBoolean(TTP->isParameterPack());
Douglas Gregorc97f09f2009-07-31 15:46:56 +00001652 return;
1653 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001654 }
Mike Stump11289f42009-09-09 15:08:12 +00001655
Craig Topper36250ad2014-05-12 05:36:57 +00001656 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
Douglas Gregord9aedfa2009-07-28 15:32:17 +00001657}
1658
1659void StmtProfiler::VisitType(QualType T) {
1660 if (Canonical)
1661 T = Context.getCanonicalType(T);
Mike Stump11289f42009-09-09 15:08:12 +00001662
Douglas Gregor5c193b92009-07-28 00:33:38 +00001663 ID.AddPointer(T.getAsOpaquePtr());
1664}
1665
1666void StmtProfiler::VisitName(DeclarationName Name) {
1667 ID.AddPointer(Name.getAsOpaquePtr());
1668}
1669
1670void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1671 if (Canonical)
1672 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1673 ID.AddPointer(NNS);
1674}
1675
1676void StmtProfiler::VisitTemplateName(TemplateName Name) {
1677 if (Canonical)
1678 Name = Context.getCanonicalTemplateName(Name);
Mike Stump11289f42009-09-09 15:08:12 +00001679
Douglas Gregor5c193b92009-07-28 00:33:38 +00001680 Name.Profile(ID);
1681}
1682
John McCall0ad16662009-10-29 08:12:44 +00001683void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001684 unsigned NumArgs) {
1685 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001686 for (unsigned I = 0; I != NumArgs; ++I)
1687 VisitTemplateArgument(Args[I].getArgument());
1688}
Mike Stump11289f42009-09-09 15:08:12 +00001689
John McCall0ad16662009-10-29 08:12:44 +00001690void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1691 // Mostly repetitive with TemplateArgument::Profile!
1692 ID.AddInteger(Arg.getKind());
1693 switch (Arg.getKind()) {
1694 case TemplateArgument::Null:
1695 break;
Mike Stump11289f42009-09-09 15:08:12 +00001696
John McCall0ad16662009-10-29 08:12:44 +00001697 case TemplateArgument::Type:
1698 VisitType(Arg.getAsType());
1699 break;
Mike Stump11289f42009-09-09 15:08:12 +00001700
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001701 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001702 case TemplateArgument::TemplateExpansion:
1703 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001704 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00001705
John McCall0ad16662009-10-29 08:12:44 +00001706 case TemplateArgument::Declaration:
1707 VisitDecl(Arg.getAsDecl());
1708 break;
Mike Stump11289f42009-09-09 15:08:12 +00001709
Eli Friedmanb826a002012-09-26 02:36:12 +00001710 case TemplateArgument::NullPtr:
1711 VisitType(Arg.getNullPtrType());
1712 break;
1713
John McCall0ad16662009-10-29 08:12:44 +00001714 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00001715 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00001716 VisitType(Arg.getIntegralType());
1717 break;
Mike Stump11289f42009-09-09 15:08:12 +00001718
John McCall0ad16662009-10-29 08:12:44 +00001719 case TemplateArgument::Expression:
1720 Visit(Arg.getAsExpr());
1721 break;
Mike Stump11289f42009-09-09 15:08:12 +00001722
John McCall0ad16662009-10-29 08:12:44 +00001723 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00001724 for (const auto &P : Arg.pack_elements())
1725 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00001726 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00001727 }
1728}
1729
Jay Foad39c79802011-01-12 09:06:06 +00001730void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00001731 bool Canonical) const {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001732 StmtProfiler Profiler(ID, Context, Canonical);
1733 Profiler.Visit(this);
1734}