blob: c0b0f3b0b064ce8dcc17b5e49ad695485659cfe6 [file] [log] [blame]
Douglas Gregor5c193b92009-07-28 00:33:38 +00001//===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Douglas Gregor5c193b92009-07-28 00:33:38 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the Stmt::Profile method, which builds a unique bit
Douglas Gregor32615a12009-07-28 16:39:25 +000010// representation that identifies a statement/expression.
Douglas Gregor5c193b92009-07-28 00:33:38 +000011//
12//===----------------------------------------------------------------------===//
13#include "clang/AST/ASTContext.h"
Douglas Gregora7095092009-07-28 14:44:31 +000014#include "clang/AST/DeclCXX.h"
15#include "clang/AST/DeclObjC.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000016#include "clang/AST/DeclTemplate.h"
17#include "clang/AST/Expr.h"
18#include "clang/AST/ExprCXX.h"
19#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000020#include "clang/AST/ExprOpenMP.h"
Richard Trieu639d7b62017-02-22 22:22:42 +000021#include "clang/AST/ODRHash.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> {
Richard Trieu639d7b62017-02-22 22:22:42 +000028 protected:
Douglas Gregor5c193b92009-07-28 00:33:38 +000029 llvm::FoldingSetNodeID &ID;
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:
Richard Trieu639d7b62017-02-22 22:22:42 +000033 StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical)
34 : ID(ID), Canonical(Canonical) {}
35
36 virtual ~StmtProfiler() {}
Mike Stump11289f42009-09-09 15:08:12 +000037
Chandler Carruth631abd92011-06-16 06:47:06 +000038 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000039
Richard Trieuf65efae2018-02-22 05:32:25 +000040 virtual void HandleStmtClass(Stmt::StmtClass SC) = 0;
41
Chandler Carruth631abd92011-06-16 06:47:06 +000042#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000043#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000044
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000045 /// Visit a declaration that is referenced within an expression
Douglas Gregor5c193b92009-07-28 00:33:38 +000046 /// or statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000047 virtual void VisitDecl(const Decl *D) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000048
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000049 /// Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000050 /// statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000051 virtual void VisitType(QualType T) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000052
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000053 /// Visit a name that occurs within an expression or statement.
Richard Trieuf65efae2018-02-22 05:32:25 +000054 virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0;
Richard Trieu639d7b62017-02-22 22:22:42 +000055
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000056 /// Visit identifiers that are not in Decl's or Type's.
Richard Trieu639d7b62017-02-22 22:22:42 +000057 virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000058
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000059 /// Visit a nested-name-specifier that occurs within an expression
Douglas Gregor5c193b92009-07-28 00:33:38 +000060 /// or statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000061 virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000062
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000063 /// Visit a template name that occurs within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000064 /// statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000065 virtual void VisitTemplateName(TemplateName Name) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000066
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000067 /// Visit template arguments that occur within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000068 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000069 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
70 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000071
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000072 /// Visit a single template argument.
John McCall0ad16662009-10-29 08:12:44 +000073 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000074 };
Richard Trieu639d7b62017-02-22 22:22:42 +000075
76 class StmtProfilerWithPointers : public StmtProfiler {
77 const ASTContext &Context;
78
79 public:
80 StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID,
81 const ASTContext &Context, bool Canonical)
82 : StmtProfiler(ID, Canonical), Context(Context) {}
83 private:
Richard Trieuf65efae2018-02-22 05:32:25 +000084 void HandleStmtClass(Stmt::StmtClass SC) override {
85 ID.AddInteger(SC);
86 }
87
Richard Trieu639d7b62017-02-22 22:22:42 +000088 void VisitDecl(const Decl *D) override {
89 ID.AddInteger(D ? D->getKind() : 0);
90
91 if (Canonical && D) {
92 if (const NonTypeTemplateParmDecl *NTTP =
93 dyn_cast<NonTypeTemplateParmDecl>(D)) {
94 ID.AddInteger(NTTP->getDepth());
95 ID.AddInteger(NTTP->getIndex());
96 ID.AddBoolean(NTTP->isParameterPack());
97 VisitType(NTTP->getType());
98 return;
99 }
100
101 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
102 // The Itanium C++ ABI uses the type, scope depth, and scope
103 // index of a parameter when mangling expressions that involve
104 // function parameters, so we will use the parameter's type for
105 // establishing function parameter identity. That way, our
106 // definition of "equivalent" (per C++ [temp.over.link]) is at
107 // least as strong as the definition of "equivalent" used for
108 // name mangling.
109 VisitType(Parm->getType());
110 ID.AddInteger(Parm->getFunctionScopeDepth());
111 ID.AddInteger(Parm->getFunctionScopeIndex());
112 return;
113 }
114
115 if (const TemplateTypeParmDecl *TTP =
116 dyn_cast<TemplateTypeParmDecl>(D)) {
117 ID.AddInteger(TTP->getDepth());
118 ID.AddInteger(TTP->getIndex());
119 ID.AddBoolean(TTP->isParameterPack());
120 return;
121 }
122
123 if (const TemplateTemplateParmDecl *TTP =
124 dyn_cast<TemplateTemplateParmDecl>(D)) {
125 ID.AddInteger(TTP->getDepth());
126 ID.AddInteger(TTP->getIndex());
127 ID.AddBoolean(TTP->isParameterPack());
128 return;
129 }
130 }
131
132 ID.AddPointer(D ? D->getCanonicalDecl() : nullptr);
133 }
134
135 void VisitType(QualType T) override {
Richard Trieua5f4ade2017-03-04 02:42:41 +0000136 if (Canonical && !T.isNull())
Richard Trieu639d7b62017-02-22 22:22:42 +0000137 T = Context.getCanonicalType(T);
138
139 ID.AddPointer(T.getAsOpaquePtr());
140 }
141
Richard Trieuf65efae2018-02-22 05:32:25 +0000142 void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override {
Richard Trieu639d7b62017-02-22 22:22:42 +0000143 ID.AddPointer(Name.getAsOpaquePtr());
144 }
145
146 void VisitIdentifierInfo(IdentifierInfo *II) override {
147 ID.AddPointer(II);
148 }
149
150 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
151 if (Canonical)
152 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
153 ID.AddPointer(NNS);
154 }
155
156 void VisitTemplateName(TemplateName Name) override {
157 if (Canonical)
158 Name = Context.getCanonicalTemplateName(Name);
159
160 Name.Profile(ID);
161 }
162 };
163
164 class StmtProfilerWithoutPointers : public StmtProfiler {
165 ODRHash &Hash;
166 public:
167 StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
168 : StmtProfiler(ID, false), Hash(Hash) {}
169
170 private:
Richard Trieuf65efae2018-02-22 05:32:25 +0000171 void HandleStmtClass(Stmt::StmtClass SC) override {
172 if (SC == Stmt::UnresolvedLookupExprClass) {
173 // Pretend that the name looked up is a Decl due to how templates
174 // handle some Decl lookups.
175 ID.AddInteger(Stmt::DeclRefExprClass);
176 } else {
177 ID.AddInteger(SC);
178 }
179 }
180
Richard Trieu639d7b62017-02-22 22:22:42 +0000181 void VisitType(QualType T) override {
182 Hash.AddQualType(T);
183 }
184
Richard Trieuf65efae2018-02-22 05:32:25 +0000185 void VisitName(DeclarationName Name, bool TreatAsDecl) override {
186 if (TreatAsDecl) {
187 // A Decl can be null, so each Decl is preceded by a boolean to
188 // store its nullness. Add a boolean here to match.
189 ID.AddBoolean(true);
190 }
Richard Trieu22ddc282018-09-04 22:53:19 +0000191 Hash.AddDeclarationName(Name, TreatAsDecl);
Richard Trieu639d7b62017-02-22 22:22:42 +0000192 }
193 void VisitIdentifierInfo(IdentifierInfo *II) override {
194 ID.AddBoolean(II);
195 if (II) {
196 Hash.AddIdentifierInfo(II);
197 }
198 }
199 void VisitDecl(const Decl *D) override {
200 ID.AddBoolean(D);
201 if (D) {
202 Hash.AddDecl(D);
203 }
204 }
205 void VisitTemplateName(TemplateName Name) override {
206 Hash.AddTemplateName(Name);
207 }
208 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
Richard Trieu96b41642017-07-01 02:00:05 +0000209 ID.AddBoolean(NNS);
210 if (NNS) {
211 Hash.AddNestedNameSpecifier(NNS);
212 }
Richard Trieu639d7b62017-02-22 22:22:42 +0000213 }
214 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000215}
Douglas Gregor5c193b92009-07-28 00:33:38 +0000216
Chandler Carruth631abd92011-06-16 06:47:06 +0000217void StmtProfiler::VisitStmt(const Stmt *S) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000218 assert(S && "Requires non-null Stmt pointer");
Richard Trieuf65efae2018-02-22 05:32:25 +0000219
220 HandleStmtClass(S->getStmtClass());
221
Benjamin Kramer642f1732015-07-02 21:03:14 +0000222 for (const Stmt *SubStmt : S->children()) {
223 if (SubStmt)
224 Visit(SubStmt);
Peter Collingbournecdb9f302012-03-01 16:34:31 +0000225 else
226 ID.AddInteger(0);
227 }
Douglas Gregor5c193b92009-07-28 00:33:38 +0000228}
229
Chandler Carruth631abd92011-06-16 06:47:06 +0000230void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000231 VisitStmt(S);
Aaron Ballman535bbcc2014-03-14 17:01:24 +0000232 for (const auto *D : S->decls())
233 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +0000234}
235
Chandler Carruth631abd92011-06-16 06:47:06 +0000236void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000237 VisitStmt(S);
238}
239
Chandler Carruth631abd92011-06-16 06:47:06 +0000240void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000241 VisitStmt(S);
242}
243
Chandler Carruth631abd92011-06-16 06:47:06 +0000244void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000245 VisitStmt(S);
246}
247
Chandler Carruth631abd92011-06-16 06:47:06 +0000248void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000249 VisitStmt(S);
250}
251
Chandler Carruth631abd92011-06-16 06:47:06 +0000252void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000253 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000254 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000255}
256
Richard Smithc202b282012-04-14 00:33:13 +0000257void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
258 VisitStmt(S);
259 // TODO: maybe visit attributes?
260}
261
Chandler Carruth631abd92011-06-16 06:47:06 +0000262void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000263 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000264 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000265}
266
Chandler Carruth631abd92011-06-16 06:47:06 +0000267void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000268 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000269 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000270}
271
Chandler Carruth631abd92011-06-16 06:47:06 +0000272void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000273 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000274 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000275}
276
Chandler Carruth631abd92011-06-16 06:47:06 +0000277void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000278 VisitStmt(S);
279}
280
Chandler Carruth631abd92011-06-16 06:47:06 +0000281void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000282 VisitStmt(S);
283}
284
Chandler Carruth631abd92011-06-16 06:47:06 +0000285void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000286 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000287 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000288}
289
Chandler Carruth631abd92011-06-16 06:47:06 +0000290void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000291 VisitStmt(S);
292}
293
Chandler Carruth631abd92011-06-16 06:47:06 +0000294void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000295 VisitStmt(S);
296}
297
Chandler Carruth631abd92011-06-16 06:47:06 +0000298void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000299 VisitStmt(S);
300}
301
Chandler Carruth631abd92011-06-16 06:47:06 +0000302void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000303 VisitStmt(S);
304}
305
Chad Rosierde70e0e2012-08-25 00:11:56 +0000306void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000307 VisitStmt(S);
308 ID.AddBoolean(S->isVolatile());
309 ID.AddBoolean(S->isSimple());
310 VisitStringLiteral(S->getAsmString());
311 ID.AddInteger(S->getNumOutputs());
312 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
313 ID.AddString(S->getOutputName(I));
314 VisitStringLiteral(S->getOutputConstraintLiteral(I));
315 }
316 ID.AddInteger(S->getNumInputs());
317 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
318 ID.AddString(S->getInputName(I));
319 VisitStringLiteral(S->getInputConstraintLiteral(I));
320 }
321 ID.AddInteger(S->getNumClobbers());
322 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000323 VisitStringLiteral(S->getClobberStringLiteral(I));
Jennifer Yub8fee672019-06-03 15:57:25 +0000324 ID.AddInteger(S->getNumLabels());
325 for (auto *L : S->labels())
326 VisitDecl(L->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000327}
328
Chad Rosier32503022012-06-11 20:47:18 +0000329void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
330 // FIXME: Implement MS style inline asm statement profiler.
331 VisitStmt(S);
332}
333
Chandler Carruth631abd92011-06-16 06:47:06 +0000334void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000335 VisitStmt(S);
336 VisitType(S->getCaughtType());
337}
338
Chandler Carruth631abd92011-06-16 06:47:06 +0000339void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000340 VisitStmt(S);
341}
342
Chandler Carruth631abd92011-06-16 06:47:06 +0000343void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000344 VisitStmt(S);
345}
346
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000347void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
348 VisitStmt(S);
349 ID.AddBoolean(S->isIfExists());
350 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
351 VisitName(S->getNameInfo().getName());
352}
353
Chandler Carruth631abd92011-06-16 06:47:06 +0000354void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000355 VisitStmt(S);
356}
357
Chandler Carruth631abd92011-06-16 06:47:06 +0000358void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000359 VisitStmt(S);
360}
361
Chandler Carruth631abd92011-06-16 06:47:06 +0000362void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000363 VisitStmt(S);
364}
365
Nico Weber9b982072014-07-07 00:12:30 +0000366void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
367 VisitStmt(S);
368}
369
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000370void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
371 VisitStmt(S);
372}
373
Chandler Carruth631abd92011-06-16 06:47:06 +0000374void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000375 VisitStmt(S);
376}
377
Chandler Carruth631abd92011-06-16 06:47:06 +0000378void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000379 VisitStmt(S);
380 ID.AddBoolean(S->hasEllipsis());
381 if (S->getCatchParamDecl())
382 VisitType(S->getCatchParamDecl()->getType());
383}
384
Chandler Carruth631abd92011-06-16 06:47:06 +0000385void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000386 VisitStmt(S);
387}
388
Chandler Carruth631abd92011-06-16 06:47:06 +0000389void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000390 VisitStmt(S);
391}
392
Chandler Carruth631abd92011-06-16 06:47:06 +0000393void
394StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000395 VisitStmt(S);
396}
397
Chandler Carruth631abd92011-06-16 06:47:06 +0000398void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000399 VisitStmt(S);
400}
401
Chandler Carruth631abd92011-06-16 06:47:06 +0000402void
403StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000404 VisitStmt(S);
405}
406
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000407namespace {
408class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
409 StmtProfiler *Profiler;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000410 /// Process clauses with list of variables.
Alexey Bataev756c1962013-09-24 03:17:45 +0000411 template <typename T>
412 void VisitOMPClauseList(T *Node);
NAKAMURA Takumiaa13f942015-12-09 07:52:46 +0000413
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000414public:
415 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
416#define OPENMP_CLAUSE(Name, Class) \
417 void Visit##Class(const Class *C);
418#include "clang/Basic/OpenMPKinds.def"
Alexey Bataev3392d762016-02-16 11:18:12 +0000419 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000420 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000421};
422
Alexey Bataev3392d762016-02-16 11:18:12 +0000423void OMPClauseProfiler::VistOMPClauseWithPreInit(
424 const OMPClauseWithPreInit *C) {
425 if (auto *S = C->getPreInitStmt())
426 Profiler->VisitStmt(S);
427}
428
Alexey Bataev005248a2016-02-25 05:25:57 +0000429void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
430 const OMPClauseWithPostUpdate *C) {
Alexey Bataev37e594c2016-03-04 07:21:16 +0000431 VistOMPClauseWithPreInit(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000432 if (auto *E = C->getPostUpdateExpr())
433 Profiler->VisitStmt(E);
434}
435
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000436void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +0000437 VistOMPClauseWithPreInit(C);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000438 if (C->getCondition())
439 Profiler->VisitStmt(C->getCondition());
440}
441
Alexey Bataev3778b602014-07-17 07:32:53 +0000442void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000443 VistOMPClauseWithPreInit(C);
Alexey Bataev3778b602014-07-17 07:32:53 +0000444 if (C->getCondition())
445 Profiler->VisitStmt(C->getCondition());
446}
447
Alexey Bataev568a8332014-03-06 06:15:19 +0000448void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +0000449 VistOMPClauseWithPreInit(C);
Alexey Bataev568a8332014-03-06 06:15:19 +0000450 if (C->getNumThreads())
451 Profiler->VisitStmt(C->getNumThreads());
452}
453
Alexey Bataev62c87d22014-03-21 04:51:18 +0000454void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
455 if (C->getSafelen())
456 Profiler->VisitStmt(C->getSafelen());
457}
458
Alexey Bataev66b15b52015-08-21 11:14:16 +0000459void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
460 if (C->getSimdlen())
461 Profiler->VisitStmt(C->getSimdlen());
462}
463
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000464void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
465 if (C->getAllocator())
466 Profiler->VisitStmt(C->getAllocator());
467}
468
Alexander Musman8bd31e62014-05-27 15:12:19 +0000469void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
470 if (C->getNumForLoops())
471 Profiler->VisitStmt(C->getNumForLoops());
472}
473
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000474void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000475
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000476void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
477
Kelvin Li1408f912018-09-26 04:28:39 +0000478void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
479 const OMPUnifiedAddressClause *C) {}
480
Patrick Lyster4a370b92018-10-01 13:47:43 +0000481void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
482 const OMPUnifiedSharedMemoryClause *C) {}
483
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000484void OMPClauseProfiler::VisitOMPReverseOffloadClause(
485 const OMPReverseOffloadClause *C) {}
486
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000487void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
488 const OMPDynamicAllocatorsClause *C) {}
489
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000490void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
491 const OMPAtomicDefaultMemOrderClause *C) {}
492
Alexey Bataev56dafe82014-06-20 07:16:17 +0000493void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000494 VistOMPClauseWithPreInit(C);
495 if (auto *S = C->getChunkSize())
496 Profiler->VisitStmt(S);
Alexey Bataev56dafe82014-06-20 07:16:17 +0000497}
498
Alexey Bataev10e775f2015-07-30 11:36:16 +0000499void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
500 if (auto *Num = C->getNumForLoops())
501 Profiler->VisitStmt(Num);
502}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000503
Alexey Bataev236070f2014-06-20 11:19:47 +0000504void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
505
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000506void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
507
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000508void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
509
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000510void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
511
Alexey Bataevdea47612014-07-23 07:46:59 +0000512void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
513
Alexey Bataev67a4f222014-07-23 10:25:33 +0000514void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
515
Alexey Bataev459dec02014-07-24 06:46:57 +0000516void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
517
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000518void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
519
Alexey Bataev346265e2015-09-25 10:37:12 +0000520void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
521
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000522void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
523
Alexey Bataevb825de12015-12-07 10:51:44 +0000524void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
525
Alexey Bataev756c1962013-09-24 03:17:45 +0000526template<typename T>
527void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000528 for (auto *E : Node->varlists()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000529 if (E)
530 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000531 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000532}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000533
534void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000535 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000536 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000537 if (E)
538 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000539 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000540}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000541void
542OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000543 VisitOMPClauseList(C);
Alexey Bataev417089f2016-02-17 13:19:37 +0000544 VistOMPClauseWithPreInit(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000545 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000546 if (E)
547 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000548 }
549 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000550 if (E)
551 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000552 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000553}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000554void
555OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
556 VisitOMPClauseList(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000557 VistOMPClauseWithPostUpdate(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000558 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000559 if (E)
560 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000561 }
562 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000563 if (E)
564 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000565 }
566 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000567 if (E)
568 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000569 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000570}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000571void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000572 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000573}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000574void OMPClauseProfiler::VisitOMPReductionClause(
575 const OMPReductionClause *C) {
576 Profiler->VisitNestedNameSpecifier(
577 C->getQualifierLoc().getNestedNameSpecifier());
578 Profiler->VisitName(C->getNameInfo().getName());
579 VisitOMPClauseList(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000580 VistOMPClauseWithPostUpdate(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000581 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000582 if (E)
583 Profiler->VisitStmt(E);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000584 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000585 for (auto *E : C->lhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000586 if (E)
587 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000588 }
589 for (auto *E : C->rhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000590 if (E)
591 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000592 }
593 for (auto *E : C->reduction_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000594 if (E)
595 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000596 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000597}
Alexey Bataev169d96a2017-07-18 20:17:46 +0000598void OMPClauseProfiler::VisitOMPTaskReductionClause(
599 const OMPTaskReductionClause *C) {
600 Profiler->VisitNestedNameSpecifier(
601 C->getQualifierLoc().getNestedNameSpecifier());
602 Profiler->VisitName(C->getNameInfo().getName());
603 VisitOMPClauseList(C);
604 VistOMPClauseWithPostUpdate(C);
605 for (auto *E : C->privates()) {
606 if (E)
607 Profiler->VisitStmt(E);
608 }
609 for (auto *E : C->lhs_exprs()) {
610 if (E)
611 Profiler->VisitStmt(E);
612 }
613 for (auto *E : C->rhs_exprs()) {
614 if (E)
615 Profiler->VisitStmt(E);
616 }
617 for (auto *E : C->reduction_ops()) {
618 if (E)
619 Profiler->VisitStmt(E);
620 }
621}
Alexey Bataevfa312f32017-07-21 18:48:21 +0000622void OMPClauseProfiler::VisitOMPInReductionClause(
623 const OMPInReductionClause *C) {
624 Profiler->VisitNestedNameSpecifier(
625 C->getQualifierLoc().getNestedNameSpecifier());
626 Profiler->VisitName(C->getNameInfo().getName());
627 VisitOMPClauseList(C);
628 VistOMPClauseWithPostUpdate(C);
629 for (auto *E : C->privates()) {
630 if (E)
631 Profiler->VisitStmt(E);
632 }
633 for (auto *E : C->lhs_exprs()) {
634 if (E)
635 Profiler->VisitStmt(E);
636 }
637 for (auto *E : C->rhs_exprs()) {
638 if (E)
639 Profiler->VisitStmt(E);
640 }
641 for (auto *E : C->reduction_ops()) {
642 if (E)
643 Profiler->VisitStmt(E);
644 }
Alexey Bataev88202be2017-07-27 13:20:36 +0000645 for (auto *E : C->taskgroup_descriptors()) {
646 if (E)
647 Profiler->VisitStmt(E);
648 }
Alexey Bataevfa312f32017-07-21 18:48:21 +0000649}
Alexander Musman8dba6642014-04-22 13:09:42 +0000650void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
651 VisitOMPClauseList(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000652 VistOMPClauseWithPostUpdate(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000653 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000654 if (E)
655 Profiler->VisitStmt(E);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000656 }
Alexander Musman3276a272015-03-21 10:12:56 +0000657 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000658 if (E)
659 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000660 }
661 for (auto *E : C->updates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000662 if (E)
663 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000664 }
665 for (auto *E : C->finals()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000666 if (E)
667 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000668 }
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000669 if (C->getStep())
670 Profiler->VisitStmt(C->getStep());
671 if (C->getCalcStep())
672 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000673}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000674void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
675 VisitOMPClauseList(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000676 if (C->getAlignment())
677 Profiler->VisitStmt(C->getAlignment());
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000678}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000679void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
680 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000681 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000682 if (E)
683 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000684 }
685 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000686 if (E)
687 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000688 }
689 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000690 if (E)
691 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000692 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000693}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000694void
695OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
696 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000697 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000698 if (E)
699 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000700 }
701 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000702 if (E)
703 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000704 }
705 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000706 if (E)
707 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000708 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000709}
Alexey Bataev6125da92014-07-21 11:26:11 +0000710void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
711 VisitOMPClauseList(C);
712}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000713void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
714 VisitOMPClauseList(C);
715}
Michael Wonge710d542015-08-07 16:16:36 +0000716void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000717 if (C->getDevice())
718 Profiler->VisitStmt(C->getDevice());
Michael Wonge710d542015-08-07 16:16:36 +0000719}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000720void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
721 VisitOMPClauseList(C);
722}
Alexey Bataeve04483e2019-03-27 14:14:31 +0000723void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
724 if (Expr *Allocator = C->getAllocator())
725 Profiler->VisitStmt(Allocator);
726 VisitOMPClauseList(C);
727}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000728void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +0000729 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000730 if (C->getNumTeams())
731 Profiler->VisitStmt(C->getNumTeams());
Kelvin Li099bb8c2015-11-24 20:50:12 +0000732}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000733void OMPClauseProfiler::VisitOMPThreadLimitClause(
734 const OMPThreadLimitClause *C) {
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +0000735 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000736 if (C->getThreadLimit())
737 Profiler->VisitStmt(C->getThreadLimit());
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000738}
Alexey Bataeva0569352015-12-01 10:17:31 +0000739void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
Alexey Bataev31ba4762019-10-16 18:09:37 +0000740 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000741 if (C->getPriority())
742 Profiler->VisitStmt(C->getPriority());
Alexey Bataeva0569352015-12-01 10:17:31 +0000743}
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000744void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000745 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000746 if (C->getGrainsize())
747 Profiler->VisitStmt(C->getGrainsize());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000748}
Alexey Bataev382967a2015-12-08 12:06:20 +0000749void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000750 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000751 if (C->getNumTasks())
752 Profiler->VisitStmt(C->getNumTasks());
Alexey Bataev382967a2015-12-08 12:06:20 +0000753}
Alexey Bataev28c75412015-12-15 08:19:24 +0000754void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000755 if (C->getHint())
756 Profiler->VisitStmt(C->getHint());
Alexey Bataev28c75412015-12-15 08:19:24 +0000757}
Samuel Antao661c0902016-05-26 17:39:58 +0000758void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
759 VisitOMPClauseList(C);
760}
Samuel Antaoec172c62016-05-26 17:49:04 +0000761void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
762 VisitOMPClauseList(C);
763}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000764void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
765 const OMPUseDevicePtrClause *C) {
766 VisitOMPClauseList(C);
767}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000768void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
769 const OMPIsDevicePtrClause *C) {
770 VisitOMPClauseList(C);
771}
Alexey Bataev0860db92019-12-19 10:01:10 -0500772void OMPClauseProfiler::VisitOMPNontemporalClause(
773 const OMPNontemporalClause *C) {
Alexey Bataevb6e70842019-12-16 15:54:17 -0500774 VisitOMPClauseList(C);
Alexey Bataev0860db92019-12-19 10:01:10 -0500775 for (auto *E : C->private_refs())
776 Profiler->VisitStmt(E);
Alexey Bataevb6e70842019-12-16 15:54:17 -0500777}
Alexey Bataev0860db92019-12-19 10:01:10 -0500778} // namespace
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000779
780void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000781StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000782 VisitStmt(S);
783 OMPClauseProfiler P(this);
784 ArrayRef<OMPClause *> Clauses = S->clauses();
785 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
786 I != E; ++I)
787 if (*I)
788 P.Visit(*I);
789}
790
Alexander Musman3aaab662014-08-19 11:27:13 +0000791void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
792 VisitOMPExecutableDirective(S);
793}
794
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000795void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
796 VisitOMPExecutableDirective(S);
797}
798
799void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000800 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000801}
802
Alexey Bataevf29276e2014-06-18 04:14:57 +0000803void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000804 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000805}
806
Alexander Musmanf82886e2014-09-18 05:12:34 +0000807void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
808 VisitOMPLoopDirective(S);
809}
810
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000811void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
812 VisitOMPExecutableDirective(S);
813}
814
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000815void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
816 VisitOMPExecutableDirective(S);
817}
818
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000819void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
820 VisitOMPExecutableDirective(S);
821}
822
Alexander Musman80c22892014-07-17 08:54:58 +0000823void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
824 VisitOMPExecutableDirective(S);
825}
826
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000827void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
828 VisitOMPExecutableDirective(S);
829 VisitName(S->getDirectiveName().getName());
830}
831
Alexey Bataev4acb8592014-07-07 13:01:15 +0000832void
833StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000834 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000835}
836
Alexander Musmane4e893b2014-09-23 09:33:00 +0000837void StmtProfiler::VisitOMPParallelForSimdDirective(
838 const OMPParallelForSimdDirective *S) {
839 VisitOMPLoopDirective(S);
840}
841
cchen47d60942019-12-05 13:43:48 -0500842void StmtProfiler::VisitOMPParallelMasterDirective(
843 const OMPParallelMasterDirective *S) {
844 VisitOMPExecutableDirective(S);
845}
846
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000847void StmtProfiler::VisitOMPParallelSectionsDirective(
848 const OMPParallelSectionsDirective *S) {
849 VisitOMPExecutableDirective(S);
850}
851
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000852void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
853 VisitOMPExecutableDirective(S);
854}
855
Alexey Bataev68446b72014-07-18 07:47:19 +0000856void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
857 VisitOMPExecutableDirective(S);
858}
859
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000860void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
861 VisitOMPExecutableDirective(S);
862}
863
Alexey Bataev2df347a2014-07-18 10:17:07 +0000864void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
865 VisitOMPExecutableDirective(S);
866}
867
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000868void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
869 VisitOMPExecutableDirective(S);
Alexey Bataev3b1b8952017-07-25 15:53:26 +0000870 if (const Expr *E = S->getReductionRef())
871 VisitStmt(E);
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000872}
873
Alexey Bataev6125da92014-07-21 11:26:11 +0000874void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
875 VisitOMPExecutableDirective(S);
876}
877
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000878void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
879 VisitOMPExecutableDirective(S);
880}
881
Alexey Bataev0162e452014-07-22 10:10:35 +0000882void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
883 VisitOMPExecutableDirective(S);
884}
885
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000886void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
887 VisitOMPExecutableDirective(S);
888}
889
Michael Wong65f367f2015-07-21 13:44:28 +0000890void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
891 VisitOMPExecutableDirective(S);
892}
893
Samuel Antaodf67fc42016-01-19 19:15:56 +0000894void StmtProfiler::VisitOMPTargetEnterDataDirective(
895 const OMPTargetEnterDataDirective *S) {
896 VisitOMPExecutableDirective(S);
897}
898
Samuel Antao72590762016-01-19 20:04:50 +0000899void StmtProfiler::VisitOMPTargetExitDataDirective(
900 const OMPTargetExitDataDirective *S) {
901 VisitOMPExecutableDirective(S);
902}
903
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000904void StmtProfiler::VisitOMPTargetParallelDirective(
905 const OMPTargetParallelDirective *S) {
906 VisitOMPExecutableDirective(S);
907}
908
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000909void StmtProfiler::VisitOMPTargetParallelForDirective(
910 const OMPTargetParallelForDirective *S) {
911 VisitOMPExecutableDirective(S);
912}
913
Alexey Bataev13314bf2014-10-09 04:18:56 +0000914void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
915 VisitOMPExecutableDirective(S);
916}
917
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000918void StmtProfiler::VisitOMPCancellationPointDirective(
919 const OMPCancellationPointDirective *S) {
920 VisitOMPExecutableDirective(S);
921}
922
Alexey Bataev80909872015-07-02 11:25:17 +0000923void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
924 VisitOMPExecutableDirective(S);
925}
926
Alexey Bataev49f6e782015-12-01 04:18:41 +0000927void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
928 VisitOMPLoopDirective(S);
929}
930
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000931void StmtProfiler::VisitOMPTaskLoopSimdDirective(
932 const OMPTaskLoopSimdDirective *S) {
933 VisitOMPLoopDirective(S);
934}
935
Alexey Bataev60e51c42019-10-10 20:13:02 +0000936void StmtProfiler::VisitOMPMasterTaskLoopDirective(
937 const OMPMasterTaskLoopDirective *S) {
938 VisitOMPLoopDirective(S);
939}
940
Alexey Bataevb8552ab2019-10-18 16:47:35 +0000941void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective(
942 const OMPMasterTaskLoopSimdDirective *S) {
943 VisitOMPLoopDirective(S);
944}
945
Alexey Bataev5bbcead2019-10-14 17:17:41 +0000946void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective(
947 const OMPParallelMasterTaskLoopDirective *S) {
948 VisitOMPLoopDirective(S);
949}
950
Alexey Bataev14a388f2019-10-25 10:27:13 -0400951void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective(
952 const OMPParallelMasterTaskLoopSimdDirective *S) {
953 VisitOMPLoopDirective(S);
954}
955
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000956void StmtProfiler::VisitOMPDistributeDirective(
957 const OMPDistributeDirective *S) {
958 VisitOMPLoopDirective(S);
959}
960
Carlo Bertollib4adf552016-01-15 18:50:31 +0000961void OMPClauseProfiler::VisitOMPDistScheduleClause(
962 const OMPDistScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000963 VistOMPClauseWithPreInit(C);
964 if (auto *S = C->getChunkSize())
965 Profiler->VisitStmt(S);
Carlo Bertollib4adf552016-01-15 18:50:31 +0000966}
967
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000968void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
969
Samuel Antao686c70c2016-05-26 17:30:50 +0000970void StmtProfiler::VisitOMPTargetUpdateDirective(
971 const OMPTargetUpdateDirective *S) {
972 VisitOMPExecutableDirective(S);
973}
974
Carlo Bertolli9925f152016-06-27 14:55:37 +0000975void StmtProfiler::VisitOMPDistributeParallelForDirective(
976 const OMPDistributeParallelForDirective *S) {
977 VisitOMPLoopDirective(S);
978}
979
Kelvin Li4a39add2016-07-05 05:00:15 +0000980void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
981 const OMPDistributeParallelForSimdDirective *S) {
982 VisitOMPLoopDirective(S);
983}
984
Kelvin Li787f3fc2016-07-06 04:45:38 +0000985void StmtProfiler::VisitOMPDistributeSimdDirective(
986 const OMPDistributeSimdDirective *S) {
987 VisitOMPLoopDirective(S);
988}
989
Kelvin Lia579b912016-07-14 02:54:56 +0000990void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
991 const OMPTargetParallelForSimdDirective *S) {
992 VisitOMPLoopDirective(S);
993}
994
Kelvin Li986330c2016-07-20 22:57:10 +0000995void StmtProfiler::VisitOMPTargetSimdDirective(
996 const OMPTargetSimdDirective *S) {
997 VisitOMPLoopDirective(S);
998}
999
Kelvin Li02532872016-08-05 14:37:37 +00001000void StmtProfiler::VisitOMPTeamsDistributeDirective(
1001 const OMPTeamsDistributeDirective *S) {
1002 VisitOMPLoopDirective(S);
1003}
1004
Kelvin Li4e325f72016-10-25 12:50:55 +00001005void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
1006 const OMPTeamsDistributeSimdDirective *S) {
1007 VisitOMPLoopDirective(S);
1008}
1009
Kelvin Li579e41c2016-11-30 23:51:03 +00001010void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
1011 const OMPTeamsDistributeParallelForSimdDirective *S) {
1012 VisitOMPLoopDirective(S);
1013}
1014
Kelvin Li7ade93f2016-12-09 03:24:30 +00001015void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
1016 const OMPTeamsDistributeParallelForDirective *S) {
1017 VisitOMPLoopDirective(S);
1018}
1019
Kelvin Libf594a52016-12-17 05:48:59 +00001020void StmtProfiler::VisitOMPTargetTeamsDirective(
1021 const OMPTargetTeamsDirective *S) {
1022 VisitOMPExecutableDirective(S);
1023}
1024
Kelvin Li83c451e2016-12-25 04:52:54 +00001025void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
1026 const OMPTargetTeamsDistributeDirective *S) {
1027 VisitOMPLoopDirective(S);
1028}
1029
Kelvin Li80e8f562016-12-29 22:16:30 +00001030void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
1031 const OMPTargetTeamsDistributeParallelForDirective *S) {
1032 VisitOMPLoopDirective(S);
1033}
1034
Kelvin Li1851df52017-01-03 05:23:48 +00001035void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1036 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
1037 VisitOMPLoopDirective(S);
1038}
1039
Kelvin Lida681182017-01-10 18:08:18 +00001040void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
1041 const OMPTargetTeamsDistributeSimdDirective *S) {
1042 VisitOMPLoopDirective(S);
1043}
1044
Chandler Carruth631abd92011-06-16 06:47:06 +00001045void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001046 VisitStmt(S);
1047}
1048
Bill Wendling7c44da22018-10-31 03:48:47 +00001049void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1050 VisitExpr(S);
1051}
1052
Chandler Carruth631abd92011-06-16 06:47:06 +00001053void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001054 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001055 if (!Canonical)
1056 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001057 VisitDecl(S->getDecl());
Richard Trieu4d06bef2018-02-13 19:53:40 +00001058 if (!Canonical) {
1059 ID.AddBoolean(S->hasExplicitTemplateArgs());
1060 if (S->hasExplicitTemplateArgs())
1061 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1062 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001063}
1064
Chandler Carruth631abd92011-06-16 06:47:06 +00001065void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001066 VisitExpr(S);
Bruno Ricci17ff0262018-10-27 19:21:19 +00001067 ID.AddInteger(S->getIdentKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001068}
1069
Chandler Carruth631abd92011-06-16 06:47:06 +00001070void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001071 VisitExpr(S);
1072 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +00001073 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001074}
1075
Leonard Chandb01c3a2018-06-20 17:19:40 +00001076void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1077 VisitExpr(S);
1078 S->getValue().Profile(ID);
1079 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1080}
1081
Chandler Carruth631abd92011-06-16 06:47:06 +00001082void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001083 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +00001084 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001085 ID.AddInteger(S->getValue());
1086}
1087
Chandler Carruth631abd92011-06-16 06:47:06 +00001088void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001089 VisitExpr(S);
1090 S->getValue().Profile(ID);
1091 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +00001092 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001093}
1094
Chandler Carruth631abd92011-06-16 06:47:06 +00001095void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001096 VisitExpr(S);
1097}
1098
Chandler Carruth631abd92011-06-16 06:47:06 +00001099void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001100 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +00001101 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +00001102 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001103}
1104
Chandler Carruth631abd92011-06-16 06:47:06 +00001105void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001106 VisitExpr(S);
1107}
1108
Chandler Carruth631abd92011-06-16 06:47:06 +00001109void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +00001110 VisitExpr(S);
1111}
1112
Chandler Carruth631abd92011-06-16 06:47:06 +00001113void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001114 VisitExpr(S);
1115 ID.AddInteger(S->getOpcode());
1116}
1117
Chandler Carruth631abd92011-06-16 06:47:06 +00001118void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001119 VisitType(S->getTypeSourceInfo()->getType());
1120 unsigned n = S->getNumComponents();
1121 for (unsigned i = 0; i < n; ++i) {
James Y Knight7281c352015-12-29 22:31:18 +00001122 const OffsetOfNode &ON = S->getComponent(i);
Douglas Gregor882211c2010-04-28 22:16:22 +00001123 ID.AddInteger(ON.getKind());
1124 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00001125 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +00001126 // Expressions handled below.
1127 break;
1128
James Y Knight7281c352015-12-29 22:31:18 +00001129 case OffsetOfNode::Field:
Douglas Gregor882211c2010-04-28 22:16:22 +00001130 VisitDecl(ON.getField());
1131 break;
1132
James Y Knight7281c352015-12-29 22:31:18 +00001133 case OffsetOfNode::Identifier:
Richard Trieu639d7b62017-02-22 22:22:42 +00001134 VisitIdentifierInfo(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +00001135 break;
James Y Knight7281c352015-12-29 22:31:18 +00001136
1137 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00001138 // These nodes are implicit, and therefore don't need profiling.
1139 break;
Douglas Gregor882211c2010-04-28 22:16:22 +00001140 }
1141 }
Richard Trieu639d7b62017-02-22 22:22:42 +00001142
Douglas Gregor882211c2010-04-28 22:16:22 +00001143 VisitExpr(S);
1144}
1145
Chandler Carruth631abd92011-06-16 06:47:06 +00001146void
1147StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001148 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001149 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001150 if (S->isArgumentType())
1151 VisitType(S->getArgumentType());
1152}
1153
Chandler Carruth631abd92011-06-16 06:47:06 +00001154void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001155 VisitExpr(S);
1156}
1157
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001158void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1159 VisitExpr(S);
1160}
1161
Chandler Carruth631abd92011-06-16 06:47:06 +00001162void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001163 VisitExpr(S);
1164}
1165
Chandler Carruth631abd92011-06-16 06:47:06 +00001166void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001167 VisitExpr(S);
1168 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001169 if (!Canonical)
1170 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001171 ID.AddBoolean(S->isArrow());
1172}
1173
Chandler Carruth631abd92011-06-16 06:47:06 +00001174void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001175 VisitExpr(S);
1176 ID.AddBoolean(S->isFileScope());
1177}
1178
Chandler Carruth631abd92011-06-16 06:47:06 +00001179void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001180 VisitExpr(S);
1181}
1182
Chandler Carruth631abd92011-06-16 06:47:06 +00001183void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001184 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +00001185 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001186}
1187
Chandler Carruth631abd92011-06-16 06:47:06 +00001188void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001189 VisitCastExpr(S);
1190 VisitType(S->getTypeAsWritten());
1191}
1192
Chandler Carruth631abd92011-06-16 06:47:06 +00001193void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001194 VisitExplicitCastExpr(S);
1195}
1196
Chandler Carruth631abd92011-06-16 06:47:06 +00001197void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001198 VisitExpr(S);
1199 ID.AddInteger(S->getOpcode());
1200}
1201
Chandler Carruth631abd92011-06-16 06:47:06 +00001202void
1203StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001204 VisitBinaryOperator(S);
1205}
1206
Chandler Carruth631abd92011-06-16 06:47:06 +00001207void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001208 VisitExpr(S);
1209}
1210
Chandler Carruth631abd92011-06-16 06:47:06 +00001211void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +00001212 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +00001213 VisitExpr(S);
1214}
1215
Chandler Carruth631abd92011-06-16 06:47:06 +00001216void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001217 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001219}
1220
Chandler Carruth631abd92011-06-16 06:47:06 +00001221void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001222 VisitExpr(S);
1223}
1224
Chandler Carruth631abd92011-06-16 06:47:06 +00001225void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001226 VisitExpr(S);
1227}
1228
Hal Finkelc4d7c822013-09-18 03:29:45 +00001229void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1230 VisitExpr(S);
1231}
1232
Chandler Carruth631abd92011-06-16 06:47:06 +00001233void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001234 VisitExpr(S);
1235}
1236
Chandler Carruth631abd92011-06-16 06:47:06 +00001237void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001238 VisitExpr(S);
1239}
1240
Chandler Carruth631abd92011-06-16 06:47:06 +00001241void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001242 VisitExpr(S);
1243}
1244
Chandler Carruth631abd92011-06-16 06:47:06 +00001245void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001246 if (S->getSyntacticForm()) {
1247 VisitInitListExpr(S->getSyntacticForm());
1248 return;
1249 }
Mike Stump11289f42009-09-09 15:08:12 +00001250
Douglas Gregor5c193b92009-07-28 00:33:38 +00001251 VisitExpr(S);
1252}
1253
Chandler Carruth631abd92011-06-16 06:47:06 +00001254void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001255 VisitExpr(S);
1256 ID.AddBoolean(S->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +00001257 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1258 if (D.isFieldDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001259 ID.AddInteger(0);
David Majnemerf7e36092016-06-23 00:15:04 +00001260 VisitName(D.getFieldName());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001261 continue;
1262 }
Mike Stump11289f42009-09-09 15:08:12 +00001263
David Majnemerf7e36092016-06-23 00:15:04 +00001264 if (D.isArrayDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001265 ID.AddInteger(1);
1266 } else {
David Majnemerf7e36092016-06-23 00:15:04 +00001267 assert(D.isArrayRangeDesignator());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001268 ID.AddInteger(2);
1269 }
David Majnemerf7e36092016-06-23 00:15:04 +00001270 ID.AddInteger(D.getFirstExprIndex());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001271 }
1272}
1273
Yunzhong Gaocb779302015-06-10 00:27:52 +00001274// Seems that if VisitInitListExpr() only works on the syntactic form of an
1275// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1276void StmtProfiler::VisitDesignatedInitUpdateExpr(
1277 const DesignatedInitUpdateExpr *S) {
1278 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1279 "initializer");
1280}
1281
Richard Smith410306b2016-12-12 02:53:20 +00001282void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1283 VisitExpr(S);
1284}
1285
1286void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1287 VisitExpr(S);
1288}
1289
Yunzhong Gaocb779302015-06-10 00:27:52 +00001290void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1291 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1292}
1293
Chandler Carruth631abd92011-06-16 06:47:06 +00001294void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001295 VisitExpr(S);
1296}
1297
Chandler Carruth631abd92011-06-16 06:47:06 +00001298void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001299 VisitExpr(S);
1300 VisitName(&S->getAccessor());
1301}
1302
Chandler Carruth631abd92011-06-16 06:47:06 +00001303void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001304 VisitExpr(S);
1305 VisitDecl(S->getBlockDecl());
1306}
1307
Chandler Carruth631abd92011-06-16 06:47:06 +00001308void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001309 VisitExpr(S);
Mark de Wever21490282019-11-12 20:46:19 +01001310 for (const GenericSelectionExpr::ConstAssociation Assoc :
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00001311 S->associations()) {
1312 QualType T = Assoc.getType();
Peter Collingbourne91147592011-04-15 00:35:48 +00001313 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +00001314 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00001315 else
1316 VisitType(T);
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00001317 VisitExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00001318 }
1319}
1320
John McCallfe96e0b2011-11-06 09:01:30 +00001321void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1322 VisitExpr(S);
1323 for (PseudoObjectExpr::const_semantics_iterator
1324 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1325 // Normally, we would not profile the source expressions of OVEs.
1326 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1327 Visit(OVE->getSourceExpr());
1328}
1329
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001330void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1331 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +00001332 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001333}
1334
Saar Raz5d98ba62019-10-15 15:24:26 +00001335void StmtProfiler::VisitConceptSpecializationExpr(
1336 const ConceptSpecializationExpr *S) {
1337 VisitExpr(S);
Saar Raz8a344672020-01-16 13:35:20 +02001338 VisitDecl(S->getNamedConcept());
1339 for (const TemplateArgument &Arg : S->getTemplateArguments())
1340 VisitTemplateArgument(Arg);
Saar Raz5d98ba62019-10-15 15:24:26 +00001341}
1342
Chandler Carruth631abd92011-06-16 06:47:06 +00001343static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +00001344 UnaryOperatorKind &UnaryOp,
1345 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001346 switch (S->getOperator()) {
1347 case OO_None:
1348 case OO_New:
1349 case OO_Delete:
1350 case OO_Array_New:
1351 case OO_Array_Delete:
1352 case OO_Arrow:
1353 case OO_Call:
1354 case OO_Conditional:
1355 case NUM_OVERLOADED_OPERATORS:
1356 llvm_unreachable("Invalid operator call kind");
Fangrui Song6907ce22018-07-30 19:24:48 +00001357
Douglas Gregore9ceb312010-05-19 04:13:23 +00001358 case OO_Plus:
1359 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001360 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001361 return Stmt::UnaryOperatorClass;
1362 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001363
John McCalle3027922010-08-25 11:45:40 +00001364 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001365 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001366
Douglas Gregore9ceb312010-05-19 04:13:23 +00001367 case OO_Minus:
1368 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001369 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001370 return Stmt::UnaryOperatorClass;
1371 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001372
John McCalle3027922010-08-25 11:45:40 +00001373 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001374 return Stmt::BinaryOperatorClass;
1375
1376 case OO_Star:
1377 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +00001378 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001379 return Stmt::UnaryOperatorClass;
1380 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001381
Richard Smithf15acc52014-06-05 22:43:40 +00001382 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001383 return Stmt::BinaryOperatorClass;
1384
1385 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +00001386 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001387 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001388
Douglas Gregore9ceb312010-05-19 04:13:23 +00001389 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +00001390 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001391 return Stmt::BinaryOperatorClass;
1392
1393 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +00001394 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001395 return Stmt::BinaryOperatorClass;
1396
1397 case OO_Amp:
1398 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001399 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001400 return Stmt::UnaryOperatorClass;
1401 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001402
John McCalle3027922010-08-25 11:45:40 +00001403 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001404 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001405
Douglas Gregore9ceb312010-05-19 04:13:23 +00001406 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +00001407 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001408 return Stmt::BinaryOperatorClass;
1409
1410 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +00001411 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001412 return Stmt::UnaryOperatorClass;
1413
1414 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +00001415 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001416 return Stmt::UnaryOperatorClass;
1417
1418 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +00001419 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001420 return Stmt::BinaryOperatorClass;
1421
1422 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +00001423 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001424 return Stmt::BinaryOperatorClass;
1425
1426 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +00001427 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001428 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001429
Douglas Gregore9ceb312010-05-19 04:13:23 +00001430 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +00001431 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001432 return Stmt::CompoundAssignOperatorClass;
1433
1434 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +00001435 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001436 return Stmt::CompoundAssignOperatorClass;
1437
1438 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +00001439 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001440 return Stmt::CompoundAssignOperatorClass;
1441
1442 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +00001443 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001444 return Stmt::CompoundAssignOperatorClass;
1445
1446 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +00001447 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001448 return Stmt::CompoundAssignOperatorClass;
1449
1450 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +00001451 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001452 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001453
Douglas Gregore9ceb312010-05-19 04:13:23 +00001454 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +00001455 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001456 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001457
Douglas Gregore9ceb312010-05-19 04:13:23 +00001458 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +00001459 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001460 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001461
Douglas Gregore9ceb312010-05-19 04:13:23 +00001462 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +00001463 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001464 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001465
Douglas Gregore9ceb312010-05-19 04:13:23 +00001466 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +00001467 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001468 return Stmt::BinaryOperatorClass;
1469
1470 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +00001471 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001472 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001473
Douglas Gregore9ceb312010-05-19 04:13:23 +00001474 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001475 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001476 return Stmt::CompoundAssignOperatorClass;
1477
1478 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +00001479 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001480 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001481
Douglas Gregore9ceb312010-05-19 04:13:23 +00001482 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001483 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001484 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001485
Douglas Gregore9ceb312010-05-19 04:13:23 +00001486 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001487 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001488 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001489
Douglas Gregore9ceb312010-05-19 04:13:23 +00001490 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001491 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001492 return Stmt::BinaryOperatorClass;
Richard Smithd30b23d2017-12-01 02:13:10 +00001493
1494 case OO_Spaceship:
1495 // FIXME: Update this once we support <=> expressions.
1496 llvm_unreachable("<=> expressions not supported yet");
Fangrui Song6907ce22018-07-30 19:24:48 +00001497
Douglas Gregore9ceb312010-05-19 04:13:23 +00001498 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001499 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001500 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001501
Douglas Gregore9ceb312010-05-19 04:13:23 +00001502 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001503 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001504 return Stmt::BinaryOperatorClass;
1505
1506 case OO_PlusPlus:
Fangrui Song6907ce22018-07-30 19:24:48 +00001507 UnaryOp = S->getNumArgs() == 1? UO_PreInc
John McCalle3027922010-08-25 11:45:40 +00001508 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001509 return Stmt::UnaryOperatorClass;
1510
1511 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001512 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1513 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001514 return Stmt::UnaryOperatorClass;
1515
1516 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001517 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001518 return Stmt::BinaryOperatorClass;
1519
Douglas Gregore9ceb312010-05-19 04:13:23 +00001520 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001521 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001522 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001523
Douglas Gregore9ceb312010-05-19 04:13:23 +00001524 case OO_Subscript:
1525 return Stmt::ArraySubscriptExprClass;
Richard Smith6fff5c42018-07-31 00:47:41 +00001526
1527 case OO_Coawait:
1528 UnaryOp = UO_Coawait;
1529 return Stmt::UnaryOperatorClass;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001530 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001531
Douglas Gregore9ceb312010-05-19 04:13:23 +00001532 llvm_unreachable("Invalid overloaded operator expression");
1533}
Richard Smithf15acc52014-06-05 22:43:40 +00001534
Reid Klecknere257e182017-10-13 16:18:32 +00001535#if defined(_MSC_VER) && !defined(__clang__)
Nico Weberf56f4462017-07-24 16:54:11 +00001536#if _MSC_VER == 1911
1537// Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1538// MSVC 2017 update 3 miscompiles this function, and a clang built with it
1539// will crash in stage 2 of a bootstrap build.
1540#pragma optimize("", off)
1541#endif
1542#endif
1543
Chandler Carruth631abd92011-06-16 06:47:06 +00001544void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001545 if (S->isTypeDependent()) {
1546 // Type-dependent operator calls are profiled like their underlying
1547 // syntactic operator.
Richard Smithbac0a0d2016-10-24 18:47:04 +00001548 //
1549 // An operator call to operator-> is always implicit, so just skip it. The
1550 // enclosing MemberExpr will profile the actual member access.
1551 if (S->getOperator() == OO_Arrow)
1552 return Visit(S->getArg(0));
1553
John McCalle3027922010-08-25 11:45:40 +00001554 UnaryOperatorKind UnaryOp = UO_Extension;
1555 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001556 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001557
Douglas Gregore9ceb312010-05-19 04:13:23 +00001558 ID.AddInteger(SC);
1559 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1560 Visit(S->getArg(I));
1561 if (SC == Stmt::UnaryOperatorClass)
1562 ID.AddInteger(UnaryOp);
Fangrui Song6907ce22018-07-30 19:24:48 +00001563 else if (SC == Stmt::BinaryOperatorClass ||
Douglas Gregore9ceb312010-05-19 04:13:23 +00001564 SC == Stmt::CompoundAssignOperatorClass)
1565 ID.AddInteger(BinaryOp);
1566 else
1567 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001568
Douglas Gregore9ceb312010-05-19 04:13:23 +00001569 return;
1570 }
Richard Smithf15acc52014-06-05 22:43:40 +00001571
Douglas Gregor5c193b92009-07-28 00:33:38 +00001572 VisitCallExpr(S);
1573 ID.AddInteger(S->getOperator());
1574}
1575
Richard Smith778dc0f2019-10-19 00:04:38 +00001576void StmtProfiler::VisitCXXRewrittenBinaryOperator(
1577 const CXXRewrittenBinaryOperator *S) {
1578 // If a rewritten operator were ever to be type-dependent, we should profile
1579 // it following its syntactic operator.
1580 assert(!S->isTypeDependent() &&
1581 "resolved rewritten operator should never be type-dependent");
1582 ID.AddBoolean(S->isReversed());
1583 VisitExpr(S->getSemanticForm());
1584}
1585
Reid Klecknere257e182017-10-13 16:18:32 +00001586#if defined(_MSC_VER) && !defined(__clang__)
Nico Weberf56f4462017-07-24 16:54:11 +00001587#if _MSC_VER == 1911
1588#pragma optimize("", on)
1589#endif
1590#endif
1591
Chandler Carruth631abd92011-06-16 06:47:06 +00001592void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001593 VisitCallExpr(S);
1594}
1595
Chandler Carruth631abd92011-06-16 06:47:06 +00001596void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001597 VisitCallExpr(S);
1598}
1599
Chandler Carruth631abd92011-06-16 06:47:06 +00001600void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001601 VisitExpr(S);
1602}
1603
Chandler Carruth631abd92011-06-16 06:47:06 +00001604void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001605 VisitExplicitCastExpr(S);
1606}
1607
Chandler Carruth631abd92011-06-16 06:47:06 +00001608void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001609 VisitCXXNamedCastExpr(S);
1610}
1611
Chandler Carruth631abd92011-06-16 06:47:06 +00001612void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001613 VisitCXXNamedCastExpr(S);
1614}
1615
Chandler Carruth631abd92011-06-16 06:47:06 +00001616void
1617StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001618 VisitCXXNamedCastExpr(S);
1619}
1620
Chandler Carruth631abd92011-06-16 06:47:06 +00001621void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001622 VisitCXXNamedCastExpr(S);
1623}
1624
Erik Pilkingtoneee944e2019-07-02 18:28:13 +00001625void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
1626 VisitExpr(S);
1627 VisitType(S->getTypeInfoAsWritten()->getType());
1628}
1629
Richard Smithc67fdd42012-03-07 08:35:16 +00001630void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1631 VisitCallExpr(S);
1632}
1633
Chandler Carruth631abd92011-06-16 06:47:06 +00001634void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001635 VisitExpr(S);
1636 ID.AddBoolean(S->getValue());
1637}
1638
Chandler Carruth631abd92011-06-16 06:47:06 +00001639void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001640 VisitExpr(S);
1641}
1642
Richard Smithcc1b96d2013-06-12 22:31:48 +00001643void StmtProfiler::VisitCXXStdInitializerListExpr(
1644 const CXXStdInitializerListExpr *S) {
1645 VisitExpr(S);
1646}
1647
Chandler Carruth631abd92011-06-16 06:47:06 +00001648void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001649 VisitExpr(S);
1650 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001651 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001652}
1653
Chandler Carruth631abd92011-06-16 06:47:06 +00001654void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001655 VisitExpr(S);
1656 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001657 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001658}
1659
John McCall5e77d762013-04-16 07:28:30 +00001660void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1661 VisitExpr(S);
1662 VisitDecl(S->getPropertyDecl());
1663}
1664
Alexey Bataevf7630272015-11-25 12:01:00 +00001665void StmtProfiler::VisitMSPropertySubscriptExpr(
1666 const MSPropertySubscriptExpr *S) {
1667 VisitExpr(S);
1668}
1669
Chandler Carruth631abd92011-06-16 06:47:06 +00001670void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001671 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001672 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001673}
1674
Chandler Carruth631abd92011-06-16 06:47:06 +00001675void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001676 VisitExpr(S);
1677}
1678
Chandler Carruth631abd92011-06-16 06:47:06 +00001679void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001680 VisitExpr(S);
1681 VisitDecl(S->getParam());
1682}
1683
Richard Smith852c9db2013-04-20 22:23:05 +00001684void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1685 VisitExpr(S);
1686 VisitDecl(S->getField());
1687}
1688
Chandler Carruth631abd92011-06-16 06:47:06 +00001689void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001690 VisitExpr(S);
1691 VisitDecl(
1692 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1693}
1694
Chandler Carruth631abd92011-06-16 06:47:06 +00001695void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001696 VisitExpr(S);
1697 VisitDecl(S->getConstructor());
1698 ID.AddBoolean(S->isElidable());
1699}
1700
Richard Smith5179eb72016-06-28 19:03:57 +00001701void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1702 const CXXInheritedCtorInitExpr *S) {
1703 VisitExpr(S);
1704 VisitDecl(S->getConstructor());
1705}
1706
Chandler Carruth631abd92011-06-16 06:47:06 +00001707void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001708 VisitExplicitCastExpr(S);
1709}
1710
Chandler Carruth631abd92011-06-16 06:47:06 +00001711void
1712StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001713 VisitCXXConstructExpr(S);
1714}
1715
Chandler Carruth631abd92011-06-16 06:47:06 +00001716void
Douglas Gregore31e6062012-02-07 10:09:13 +00001717StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1718 VisitExpr(S);
1719 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1720 CEnd = S->explicit_capture_end();
1721 C != CEnd; ++C) {
Richard Trieu931638e2017-11-11 00:54:25 +00001722 if (C->capturesVLAType())
1723 continue;
1724
Douglas Gregore31e6062012-02-07 10:09:13 +00001725 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001726 switch (C->getCaptureKind()) {
Faisal Validc6b5962016-03-21 09:25:37 +00001727 case LCK_StarThis:
Richard Smithba71c082013-05-16 06:20:58 +00001728 case LCK_This:
1729 break;
1730 case LCK_ByRef:
1731 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001732 VisitDecl(C->getCapturedVar());
1733 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001734 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001735 case LCK_VLAType:
1736 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001737 }
1738 }
1739 // Note: If we actually needed to be able to match lambda
1740 // expressions, we would have to consider parameters and return type
1741 // here, among other things.
1742 VisitStmt(S->getBody());
1743}
1744
1745void
Chandler Carruth631abd92011-06-16 06:47:06 +00001746StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001747 VisitExpr(S);
1748}
1749
Chandler Carruth631abd92011-06-16 06:47:06 +00001750void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001751 VisitExpr(S);
1752 ID.AddBoolean(S->isGlobalDelete());
1753 ID.AddBoolean(S->isArrayForm());
1754 VisitDecl(S->getOperatorDelete());
1755}
1756
Chandler Carruth631abd92011-06-16 06:47:06 +00001757void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001758 VisitExpr(S);
1759 VisitType(S->getAllocatedType());
1760 VisitDecl(S->getOperatorNew());
1761 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001762 ID.AddBoolean(S->isArray());
1763 ID.AddInteger(S->getNumPlacementArgs());
1764 ID.AddBoolean(S->isGlobalNew());
1765 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001766 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001767}
1768
Chandler Carruth631abd92011-06-16 06:47:06 +00001769void
1770StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001771 VisitExpr(S);
1772 ID.AddBoolean(S->isArrow());
1773 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001774 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001775 if (S->getScopeTypeInfo())
1776 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001777 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001778 if (S->getDestroyedTypeInfo())
1779 VisitType(S->getDestroyedType());
1780 else
Richard Trieu639d7b62017-02-22 22:22:42 +00001781 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001782}
1783
Chandler Carruth631abd92011-06-16 06:47:06 +00001784void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001785 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001786 VisitNestedNameSpecifier(S->getQualifier());
Richard Trieuf65efae2018-02-22 05:32:25 +00001787 VisitName(S->getName(), /*TreatAsDecl*/ true);
John McCalle66edc12009-11-24 19:00:30 +00001788 ID.AddBoolean(S->hasExplicitTemplateArgs());
1789 if (S->hasExplicitTemplateArgs())
James Y Knight04ec5bf2015-12-24 02:59:37 +00001790 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001791}
1792
1793void
Chandler Carruth631abd92011-06-16 06:47:06 +00001794StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001795 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001796}
1797
Douglas Gregor29c42f22012-02-24 07:38:34 +00001798void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1799 VisitExpr(S);
1800 ID.AddInteger(S->getTrait());
1801 ID.AddInteger(S->getNumArgs());
1802 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1803 VisitType(S->getArg(I)->getType());
1804}
1805
Chandler Carruth631abd92011-06-16 06:47:06 +00001806void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001807 VisitExpr(S);
1808 ID.AddInteger(S->getTrait());
1809 VisitType(S->getQueriedType());
1810}
1811
Chandler Carruth631abd92011-06-16 06:47:06 +00001812void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001813 VisitExpr(S);
1814 ID.AddInteger(S->getTrait());
1815 VisitExpr(S->getQueriedExpression());
1816}
1817
Chandler Carruth631abd92011-06-16 06:47:06 +00001818void StmtProfiler::VisitDependentScopeDeclRefExpr(
1819 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001820 VisitExpr(S);
1821 VisitName(S->getDeclName());
1822 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001823 ID.AddBoolean(S->hasExplicitTemplateArgs());
1824 if (S->hasExplicitTemplateArgs())
1825 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001826}
1827
Chandler Carruth631abd92011-06-16 06:47:06 +00001828void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001829 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001830}
1831
Chandler Carruth631abd92011-06-16 06:47:06 +00001832void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1833 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001834 VisitExpr(S);
1835 VisitType(S->getTypeAsWritten());
Richard Smith39eca9b2017-08-23 22:12:08 +00001836 ID.AddInteger(S->isListInitialization());
Douglas Gregora7095092009-07-28 14:44:31 +00001837}
1838
Chandler Carruth631abd92011-06-16 06:47:06 +00001839void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1840 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001841 ID.AddBoolean(S->isImplicitAccess());
1842 if (!S->isImplicitAccess()) {
1843 VisitExpr(S);
1844 ID.AddBoolean(S->isArrow());
1845 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001846 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001847 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001848 ID.AddBoolean(S->hasExplicitTemplateArgs());
1849 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001850 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1851}
1852
Chandler Carruth631abd92011-06-16 06:47:06 +00001853void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001854 ID.AddBoolean(S->isImplicitAccess());
1855 if (!S->isImplicitAccess()) {
1856 VisitExpr(S);
1857 ID.AddBoolean(S->isArrow());
1858 }
John McCall10eae182009-11-30 22:42:35 +00001859 VisitNestedNameSpecifier(S->getQualifier());
1860 VisitName(S->getMemberName());
1861 ID.AddBoolean(S->hasExplicitTemplateArgs());
1862 if (S->hasExplicitTemplateArgs())
1863 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001864}
1865
Chandler Carruth631abd92011-06-16 06:47:06 +00001866void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001867 VisitExpr(S);
1868}
1869
Chandler Carruth631abd92011-06-16 06:47:06 +00001870void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001871 VisitExpr(S);
1872}
1873
Chandler Carruth631abd92011-06-16 06:47:06 +00001874void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001875 VisitExpr(S);
1876 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00001877 if (S->isPartiallySubstituted()) {
1878 auto Args = S->getPartialArguments();
1879 ID.AddInteger(Args.size());
1880 for (const auto &TA : Args)
1881 VisitTemplateArgument(TA);
1882 } else {
1883 ID.AddInteger(0);
1884 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001885}
1886
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001887void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001888 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001889 VisitExpr(S);
1890 VisitDecl(S->getParameterPack());
1891 VisitTemplateArgument(S->getArgumentPack());
1892}
1893
John McCall7c454bb2011-07-15 05:09:51 +00001894void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1895 const SubstNonTypeTemplateParmExpr *E) {
1896 // Profile exactly as the replacement expression.
1897 Visit(E->getReplacement());
1898}
1899
Richard Smithb15fe3a2012-09-12 00:56:43 +00001900void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1901 VisitExpr(S);
1902 VisitDecl(S->getParameterPack());
1903 ID.AddInteger(S->getNumExpansions());
1904 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1905 VisitDecl(*I);
1906}
1907
Douglas Gregorfe314812011-06-21 17:03:29 +00001908void StmtProfiler::VisitMaterializeTemporaryExpr(
1909 const MaterializeTemporaryExpr *S) {
1910 VisitExpr(S);
1911}
1912
Richard Smith0f0af192014-11-08 05:07:16 +00001913void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1914 VisitExpr(S);
1915 ID.AddInteger(S->getOperator());
1916}
1917
Richard Smith9f690bd2015-10-27 06:02:45 +00001918void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1919 VisitStmt(S);
1920}
1921
1922void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1923 VisitStmt(S);
1924}
1925
1926void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1927 VisitExpr(S);
1928}
1929
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001930void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
1931 VisitExpr(S);
1932}
1933
Richard Smith9f690bd2015-10-27 06:02:45 +00001934void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1935 VisitExpr(S);
1936}
1937
Chandler Carruth631abd92011-06-16 06:47:06 +00001938void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001939 VisitExpr(E);
John McCall8d69a212010-11-15 23:31:06 +00001940}
1941
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001942void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1943 VisitExpr(E);
1944}
1945
Eric Fiselier708afb52019-05-16 21:04:15 +00001946void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
1947 VisitExpr(E);
1948}
1949
Chandler Carruth631abd92011-06-16 06:47:06 +00001950void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001951 VisitExpr(S);
1952}
1953
Patrick Beard0caa3942012-04-19 00:25:12 +00001954void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001955 VisitExpr(E);
1956}
1957
1958void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1959 VisitExpr(E);
1960}
1961
1962void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1963 VisitExpr(E);
1964}
1965
Chandler Carruth631abd92011-06-16 06:47:06 +00001966void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001967 VisitExpr(S);
1968 VisitType(S->getEncodedType());
1969}
1970
Chandler Carruth631abd92011-06-16 06:47:06 +00001971void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001972 VisitExpr(S);
1973 VisitName(S->getSelector());
1974}
1975
Chandler Carruth631abd92011-06-16 06:47:06 +00001976void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001977 VisitExpr(S);
1978 VisitDecl(S->getProtocol());
1979}
1980
Chandler Carruth631abd92011-06-16 06:47:06 +00001981void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001982 VisitExpr(S);
1983 VisitDecl(S->getDecl());
1984 ID.AddBoolean(S->isArrow());
1985 ID.AddBoolean(S->isFreeIvar());
1986}
1987
Chandler Carruth631abd92011-06-16 06:47:06 +00001988void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001989 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001990 if (S->isImplicitProperty()) {
1991 VisitDecl(S->getImplicitPropertyGetter());
1992 VisitDecl(S->getImplicitPropertySetter());
1993 } else {
1994 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001995 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001996 if (S->isSuperReceiver()) {
1997 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001998 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001999 }
Douglas Gregora7095092009-07-28 14:44:31 +00002000}
2001
Ted Kremeneke65b0862012-03-06 20:05:56 +00002002void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
2003 VisitExpr(S);
2004 VisitDecl(S->getAtIndexMethodDecl());
2005 VisitDecl(S->setAtIndexMethodDecl());
2006}
2007
Chandler Carruth631abd92011-06-16 06:47:06 +00002008void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002009 VisitExpr(S);
2010 VisitName(S->getSelector());
2011 VisitDecl(S->getMethodDecl());
2012}
2013
Chandler Carruth631abd92011-06-16 06:47:06 +00002014void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002015 VisitExpr(S);
2016 ID.AddBoolean(S->isArrow());
2017}
2018
Ted Kremeneke65b0862012-03-06 20:05:56 +00002019void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
2020 VisitExpr(S);
2021 ID.AddBoolean(S->getValue());
2022}
2023
Chandler Carruth631abd92011-06-16 06:47:06 +00002024void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
2025 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00002026 VisitExpr(S);
2027 ID.AddBoolean(S->shouldCopy());
2028}
2029
Chandler Carruth631abd92011-06-16 06:47:06 +00002030void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00002031 VisitExplicitCastExpr(S);
2032 ID.AddBoolean(S->getBridgeKind());
2033}
2034
Erik Pilkington29099de2016-07-16 00:35:23 +00002035void StmtProfiler::VisitObjCAvailabilityCheckExpr(
2036 const ObjCAvailabilityCheckExpr *S) {
2037 VisitExpr(S);
2038}
2039
John McCall0ad16662009-10-29 08:12:44 +00002040void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00002041 unsigned NumArgs) {
2042 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00002043 for (unsigned I = 0; I != NumArgs; ++I)
2044 VisitTemplateArgument(Args[I].getArgument());
2045}
Mike Stump11289f42009-09-09 15:08:12 +00002046
John McCall0ad16662009-10-29 08:12:44 +00002047void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
2048 // Mostly repetitive with TemplateArgument::Profile!
2049 ID.AddInteger(Arg.getKind());
2050 switch (Arg.getKind()) {
2051 case TemplateArgument::Null:
2052 break;
Mike Stump11289f42009-09-09 15:08:12 +00002053
John McCall0ad16662009-10-29 08:12:44 +00002054 case TemplateArgument::Type:
2055 VisitType(Arg.getAsType());
2056 break;
Mike Stump11289f42009-09-09 15:08:12 +00002057
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002058 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002059 case TemplateArgument::TemplateExpansion:
2060 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002061 break;
Fangrui Song6907ce22018-07-30 19:24:48 +00002062
John McCall0ad16662009-10-29 08:12:44 +00002063 case TemplateArgument::Declaration:
2064 VisitDecl(Arg.getAsDecl());
2065 break;
Mike Stump11289f42009-09-09 15:08:12 +00002066
Eli Friedmanb826a002012-09-26 02:36:12 +00002067 case TemplateArgument::NullPtr:
2068 VisitType(Arg.getNullPtrType());
2069 break;
2070
John McCall0ad16662009-10-29 08:12:44 +00002071 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00002072 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00002073 VisitType(Arg.getIntegralType());
2074 break;
Mike Stump11289f42009-09-09 15:08:12 +00002075
John McCall0ad16662009-10-29 08:12:44 +00002076 case TemplateArgument::Expression:
2077 Visit(Arg.getAsExpr());
2078 break;
Mike Stump11289f42009-09-09 15:08:12 +00002079
John McCall0ad16662009-10-29 08:12:44 +00002080 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00002081 for (const auto &P : Arg.pack_elements())
2082 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00002083 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00002084 }
2085}
2086
Jay Foad39c79802011-01-12 09:06:06 +00002087void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00002088 bool Canonical) const {
Richard Trieu639d7b62017-02-22 22:22:42 +00002089 StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2090 Profiler.Visit(this);
2091}
2092
2093void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2094 class ODRHash &Hash) const {
2095 StmtProfilerWithoutPointers Profiler(ID, Hash);
Douglas Gregor5c193b92009-07-28 00:33:38 +00002096 Profiler.Visit(this);
2097}