blob: 93bdcac8b5496fd06ce5963511598d4b57f53366 [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));
Douglas Gregor44882592009-07-28 15:27:13 +0000324}
325
Chad Rosier32503022012-06-11 20:47:18 +0000326void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
327 // FIXME: Implement MS style inline asm statement profiler.
328 VisitStmt(S);
329}
330
Chandler Carruth631abd92011-06-16 06:47:06 +0000331void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000332 VisitStmt(S);
333 VisitType(S->getCaughtType());
334}
335
Chandler Carruth631abd92011-06-16 06:47:06 +0000336void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000337 VisitStmt(S);
338}
339
Chandler Carruth631abd92011-06-16 06:47:06 +0000340void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000341 VisitStmt(S);
342}
343
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000344void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
345 VisitStmt(S);
346 ID.AddBoolean(S->isIfExists());
347 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
348 VisitName(S->getNameInfo().getName());
349}
350
Chandler Carruth631abd92011-06-16 06:47:06 +0000351void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000352 VisitStmt(S);
353}
354
Chandler Carruth631abd92011-06-16 06:47:06 +0000355void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000356 VisitStmt(S);
357}
358
Chandler Carruth631abd92011-06-16 06:47:06 +0000359void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000360 VisitStmt(S);
361}
362
Nico Weber9b982072014-07-07 00:12:30 +0000363void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
364 VisitStmt(S);
365}
366
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000367void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
368 VisitStmt(S);
369}
370
Chandler Carruth631abd92011-06-16 06:47:06 +0000371void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000372 VisitStmt(S);
373}
374
Chandler Carruth631abd92011-06-16 06:47:06 +0000375void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000376 VisitStmt(S);
377 ID.AddBoolean(S->hasEllipsis());
378 if (S->getCatchParamDecl())
379 VisitType(S->getCatchParamDecl()->getType());
380}
381
Chandler Carruth631abd92011-06-16 06:47:06 +0000382void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000383 VisitStmt(S);
384}
385
Chandler Carruth631abd92011-06-16 06:47:06 +0000386void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000387 VisitStmt(S);
388}
389
Chandler Carruth631abd92011-06-16 06:47:06 +0000390void
391StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000392 VisitStmt(S);
393}
394
Chandler Carruth631abd92011-06-16 06:47:06 +0000395void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000396 VisitStmt(S);
397}
398
Chandler Carruth631abd92011-06-16 06:47:06 +0000399void
400StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000401 VisitStmt(S);
402}
403
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000404namespace {
405class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
406 StmtProfiler *Profiler;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000407 /// Process clauses with list of variables.
Alexey Bataev756c1962013-09-24 03:17:45 +0000408 template <typename T>
409 void VisitOMPClauseList(T *Node);
NAKAMURA Takumiaa13f942015-12-09 07:52:46 +0000410
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000411public:
412 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
413#define OPENMP_CLAUSE(Name, Class) \
414 void Visit##Class(const Class *C);
415#include "clang/Basic/OpenMPKinds.def"
Alexey Bataev3392d762016-02-16 11:18:12 +0000416 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000417 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000418};
419
Alexey Bataev3392d762016-02-16 11:18:12 +0000420void OMPClauseProfiler::VistOMPClauseWithPreInit(
421 const OMPClauseWithPreInit *C) {
422 if (auto *S = C->getPreInitStmt())
423 Profiler->VisitStmt(S);
424}
425
Alexey Bataev005248a2016-02-25 05:25:57 +0000426void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
427 const OMPClauseWithPostUpdate *C) {
Alexey Bataev37e594c2016-03-04 07:21:16 +0000428 VistOMPClauseWithPreInit(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000429 if (auto *E = C->getPostUpdateExpr())
430 Profiler->VisitStmt(E);
431}
432
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000433void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +0000434 VistOMPClauseWithPreInit(C);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000435 if (C->getCondition())
436 Profiler->VisitStmt(C->getCondition());
437}
438
Alexey Bataev3778b602014-07-17 07:32:53 +0000439void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
440 if (C->getCondition())
441 Profiler->VisitStmt(C->getCondition());
442}
443
Alexey Bataev568a8332014-03-06 06:15:19 +0000444void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +0000445 VistOMPClauseWithPreInit(C);
Alexey Bataev568a8332014-03-06 06:15:19 +0000446 if (C->getNumThreads())
447 Profiler->VisitStmt(C->getNumThreads());
448}
449
Alexey Bataev62c87d22014-03-21 04:51:18 +0000450void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
451 if (C->getSafelen())
452 Profiler->VisitStmt(C->getSafelen());
453}
454
Alexey Bataev66b15b52015-08-21 11:14:16 +0000455void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
456 if (C->getSimdlen())
457 Profiler->VisitStmt(C->getSimdlen());
458}
459
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000460void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
461 if (C->getAllocator())
462 Profiler->VisitStmt(C->getAllocator());
463}
464
Alexander Musman8bd31e62014-05-27 15:12:19 +0000465void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
466 if (C->getNumForLoops())
467 Profiler->VisitStmt(C->getNumForLoops());
468}
469
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000470void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000471
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000472void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
473
Kelvin Li1408f912018-09-26 04:28:39 +0000474void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
475 const OMPUnifiedAddressClause *C) {}
476
Patrick Lyster4a370b92018-10-01 13:47:43 +0000477void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
478 const OMPUnifiedSharedMemoryClause *C) {}
479
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000480void OMPClauseProfiler::VisitOMPReverseOffloadClause(
481 const OMPReverseOffloadClause *C) {}
482
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000483void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
484 const OMPDynamicAllocatorsClause *C) {}
485
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000486void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
487 const OMPAtomicDefaultMemOrderClause *C) {}
488
Alexey Bataev56dafe82014-06-20 07:16:17 +0000489void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000490 VistOMPClauseWithPreInit(C);
491 if (auto *S = C->getChunkSize())
492 Profiler->VisitStmt(S);
Alexey Bataev56dafe82014-06-20 07:16:17 +0000493}
494
Alexey Bataev10e775f2015-07-30 11:36:16 +0000495void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
496 if (auto *Num = C->getNumForLoops())
497 Profiler->VisitStmt(Num);
498}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000499
Alexey Bataev236070f2014-06-20 11:19:47 +0000500void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
501
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000502void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
503
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000504void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
505
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000506void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
507
Alexey Bataevdea47612014-07-23 07:46:59 +0000508void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
509
Alexey Bataev67a4f222014-07-23 10:25:33 +0000510void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
511
Alexey Bataev459dec02014-07-24 06:46:57 +0000512void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
513
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000514void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
515
Alexey Bataev346265e2015-09-25 10:37:12 +0000516void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
517
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000518void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
519
Alexey Bataevb825de12015-12-07 10:51:44 +0000520void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
521
Alexey Bataev756c1962013-09-24 03:17:45 +0000522template<typename T>
523void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000524 for (auto *E : Node->varlists()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000525 if (E)
526 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000527 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000528}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000529
530void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000531 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000532 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000533 if (E)
534 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000535 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000536}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000537void
538OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000539 VisitOMPClauseList(C);
Alexey Bataev417089f2016-02-17 13:19:37 +0000540 VistOMPClauseWithPreInit(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000541 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000542 if (E)
543 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000544 }
545 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000546 if (E)
547 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000548 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000549}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000550void
551OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
552 VisitOMPClauseList(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000553 VistOMPClauseWithPostUpdate(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000554 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000555 if (E)
556 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000557 }
558 for (auto *E : C->destination_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->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000563 if (E)
564 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000565 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000566}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000567void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000568 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000569}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000570void OMPClauseProfiler::VisitOMPReductionClause(
571 const OMPReductionClause *C) {
572 Profiler->VisitNestedNameSpecifier(
573 C->getQualifierLoc().getNestedNameSpecifier());
574 Profiler->VisitName(C->getNameInfo().getName());
575 VisitOMPClauseList(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000576 VistOMPClauseWithPostUpdate(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000577 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000578 if (E)
579 Profiler->VisitStmt(E);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000580 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000581 for (auto *E : C->lhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000582 if (E)
583 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000584 }
585 for (auto *E : C->rhs_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->reduction_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000590 if (E)
591 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000592 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000593}
Alexey Bataev169d96a2017-07-18 20:17:46 +0000594void OMPClauseProfiler::VisitOMPTaskReductionClause(
595 const OMPTaskReductionClause *C) {
596 Profiler->VisitNestedNameSpecifier(
597 C->getQualifierLoc().getNestedNameSpecifier());
598 Profiler->VisitName(C->getNameInfo().getName());
599 VisitOMPClauseList(C);
600 VistOMPClauseWithPostUpdate(C);
601 for (auto *E : C->privates()) {
602 if (E)
603 Profiler->VisitStmt(E);
604 }
605 for (auto *E : C->lhs_exprs()) {
606 if (E)
607 Profiler->VisitStmt(E);
608 }
609 for (auto *E : C->rhs_exprs()) {
610 if (E)
611 Profiler->VisitStmt(E);
612 }
613 for (auto *E : C->reduction_ops()) {
614 if (E)
615 Profiler->VisitStmt(E);
616 }
617}
Alexey Bataevfa312f32017-07-21 18:48:21 +0000618void OMPClauseProfiler::VisitOMPInReductionClause(
619 const OMPInReductionClause *C) {
620 Profiler->VisitNestedNameSpecifier(
621 C->getQualifierLoc().getNestedNameSpecifier());
622 Profiler->VisitName(C->getNameInfo().getName());
623 VisitOMPClauseList(C);
624 VistOMPClauseWithPostUpdate(C);
625 for (auto *E : C->privates()) {
626 if (E)
627 Profiler->VisitStmt(E);
628 }
629 for (auto *E : C->lhs_exprs()) {
630 if (E)
631 Profiler->VisitStmt(E);
632 }
633 for (auto *E : C->rhs_exprs()) {
634 if (E)
635 Profiler->VisitStmt(E);
636 }
637 for (auto *E : C->reduction_ops()) {
638 if (E)
639 Profiler->VisitStmt(E);
640 }
Alexey Bataev88202be2017-07-27 13:20:36 +0000641 for (auto *E : C->taskgroup_descriptors()) {
642 if (E)
643 Profiler->VisitStmt(E);
644 }
Alexey Bataevfa312f32017-07-21 18:48:21 +0000645}
Alexander Musman8dba6642014-04-22 13:09:42 +0000646void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
647 VisitOMPClauseList(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000648 VistOMPClauseWithPostUpdate(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000649 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000650 if (E)
651 Profiler->VisitStmt(E);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000652 }
Alexander Musman3276a272015-03-21 10:12:56 +0000653 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000654 if (E)
655 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000656 }
657 for (auto *E : C->updates()) {
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->finals()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000662 if (E)
663 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000664 }
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000665 if (C->getStep())
666 Profiler->VisitStmt(C->getStep());
667 if (C->getCalcStep())
668 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000669}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000670void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
671 VisitOMPClauseList(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000672 if (C->getAlignment())
673 Profiler->VisitStmt(C->getAlignment());
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000674}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000675void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
676 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000677 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000678 if (E)
679 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000680 }
681 for (auto *E : C->destination_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->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000686 if (E)
687 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000688 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000689}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000690void
691OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
692 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000693 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000694 if (E)
695 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000696 }
697 for (auto *E : C->destination_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->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000702 if (E)
703 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000704 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000705}
Alexey Bataev6125da92014-07-21 11:26:11 +0000706void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
707 VisitOMPClauseList(C);
708}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000709void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
710 VisitOMPClauseList(C);
711}
Michael Wonge710d542015-08-07 16:16:36 +0000712void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000713 if (C->getDevice())
714 Profiler->VisitStmt(C->getDevice());
Michael Wonge710d542015-08-07 16:16:36 +0000715}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000716void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
717 VisitOMPClauseList(C);
718}
Alexey Bataeve04483e2019-03-27 14:14:31 +0000719void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
720 if (Expr *Allocator = C->getAllocator())
721 Profiler->VisitStmt(Allocator);
722 VisitOMPClauseList(C);
723}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000724void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +0000725 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000726 if (C->getNumTeams())
727 Profiler->VisitStmt(C->getNumTeams());
Kelvin Li099bb8c2015-11-24 20:50:12 +0000728}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000729void OMPClauseProfiler::VisitOMPThreadLimitClause(
730 const OMPThreadLimitClause *C) {
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +0000731 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000732 if (C->getThreadLimit())
733 Profiler->VisitStmt(C->getThreadLimit());
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000734}
Alexey Bataeva0569352015-12-01 10:17:31 +0000735void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000736 if (C->getPriority())
737 Profiler->VisitStmt(C->getPriority());
Alexey Bataeva0569352015-12-01 10:17:31 +0000738}
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000739void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000740 if (C->getGrainsize())
741 Profiler->VisitStmt(C->getGrainsize());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000742}
Alexey Bataev382967a2015-12-08 12:06:20 +0000743void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000744 if (C->getNumTasks())
745 Profiler->VisitStmt(C->getNumTasks());
Alexey Bataev382967a2015-12-08 12:06:20 +0000746}
Alexey Bataev28c75412015-12-15 08:19:24 +0000747void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000748 if (C->getHint())
749 Profiler->VisitStmt(C->getHint());
Alexey Bataev28c75412015-12-15 08:19:24 +0000750}
Samuel Antao661c0902016-05-26 17:39:58 +0000751void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
752 VisitOMPClauseList(C);
753}
Samuel Antaoec172c62016-05-26 17:49:04 +0000754void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
755 VisitOMPClauseList(C);
756}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000757void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
758 const OMPUseDevicePtrClause *C) {
759 VisitOMPClauseList(C);
760}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000761void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
762 const OMPIsDevicePtrClause *C) {
763 VisitOMPClauseList(C);
764}
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000765}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000766
767void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000768StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000769 VisitStmt(S);
770 OMPClauseProfiler P(this);
771 ArrayRef<OMPClause *> Clauses = S->clauses();
772 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
773 I != E; ++I)
774 if (*I)
775 P.Visit(*I);
776}
777
Alexander Musman3aaab662014-08-19 11:27:13 +0000778void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
779 VisitOMPExecutableDirective(S);
780}
781
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000782void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
783 VisitOMPExecutableDirective(S);
784}
785
786void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000787 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000788}
789
Alexey Bataevf29276e2014-06-18 04:14:57 +0000790void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000791 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000792}
793
Alexander Musmanf82886e2014-09-18 05:12:34 +0000794void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
795 VisitOMPLoopDirective(S);
796}
797
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000798void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
799 VisitOMPExecutableDirective(S);
800}
801
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000802void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
803 VisitOMPExecutableDirective(S);
804}
805
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000806void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
807 VisitOMPExecutableDirective(S);
808}
809
Alexander Musman80c22892014-07-17 08:54:58 +0000810void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
811 VisitOMPExecutableDirective(S);
812}
813
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000814void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
815 VisitOMPExecutableDirective(S);
816 VisitName(S->getDirectiveName().getName());
817}
818
Alexey Bataev4acb8592014-07-07 13:01:15 +0000819void
820StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000821 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000822}
823
Alexander Musmane4e893b2014-09-23 09:33:00 +0000824void StmtProfiler::VisitOMPParallelForSimdDirective(
825 const OMPParallelForSimdDirective *S) {
826 VisitOMPLoopDirective(S);
827}
828
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000829void StmtProfiler::VisitOMPParallelSectionsDirective(
830 const OMPParallelSectionsDirective *S) {
831 VisitOMPExecutableDirective(S);
832}
833
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000834void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
835 VisitOMPExecutableDirective(S);
836}
837
Alexey Bataev68446b72014-07-18 07:47:19 +0000838void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
839 VisitOMPExecutableDirective(S);
840}
841
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000842void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
843 VisitOMPExecutableDirective(S);
844}
845
Alexey Bataev2df347a2014-07-18 10:17:07 +0000846void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
847 VisitOMPExecutableDirective(S);
848}
849
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000850void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
851 VisitOMPExecutableDirective(S);
Alexey Bataev3b1b8952017-07-25 15:53:26 +0000852 if (const Expr *E = S->getReductionRef())
853 VisitStmt(E);
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000854}
855
Alexey Bataev6125da92014-07-21 11:26:11 +0000856void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
857 VisitOMPExecutableDirective(S);
858}
859
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000860void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
861 VisitOMPExecutableDirective(S);
862}
863
Alexey Bataev0162e452014-07-22 10:10:35 +0000864void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
865 VisitOMPExecutableDirective(S);
866}
867
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000868void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
869 VisitOMPExecutableDirective(S);
870}
871
Michael Wong65f367f2015-07-21 13:44:28 +0000872void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
873 VisitOMPExecutableDirective(S);
874}
875
Samuel Antaodf67fc42016-01-19 19:15:56 +0000876void StmtProfiler::VisitOMPTargetEnterDataDirective(
877 const OMPTargetEnterDataDirective *S) {
878 VisitOMPExecutableDirective(S);
879}
880
Samuel Antao72590762016-01-19 20:04:50 +0000881void StmtProfiler::VisitOMPTargetExitDataDirective(
882 const OMPTargetExitDataDirective *S) {
883 VisitOMPExecutableDirective(S);
884}
885
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000886void StmtProfiler::VisitOMPTargetParallelDirective(
887 const OMPTargetParallelDirective *S) {
888 VisitOMPExecutableDirective(S);
889}
890
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000891void StmtProfiler::VisitOMPTargetParallelForDirective(
892 const OMPTargetParallelForDirective *S) {
893 VisitOMPExecutableDirective(S);
894}
895
Alexey Bataev13314bf2014-10-09 04:18:56 +0000896void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
897 VisitOMPExecutableDirective(S);
898}
899
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000900void StmtProfiler::VisitOMPCancellationPointDirective(
901 const OMPCancellationPointDirective *S) {
902 VisitOMPExecutableDirective(S);
903}
904
Alexey Bataev80909872015-07-02 11:25:17 +0000905void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
906 VisitOMPExecutableDirective(S);
907}
908
Alexey Bataev49f6e782015-12-01 04:18:41 +0000909void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
910 VisitOMPLoopDirective(S);
911}
912
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000913void StmtProfiler::VisitOMPTaskLoopSimdDirective(
914 const OMPTaskLoopSimdDirective *S) {
915 VisitOMPLoopDirective(S);
916}
917
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000918void StmtProfiler::VisitOMPDistributeDirective(
919 const OMPDistributeDirective *S) {
920 VisitOMPLoopDirective(S);
921}
922
Carlo Bertollib4adf552016-01-15 18:50:31 +0000923void OMPClauseProfiler::VisitOMPDistScheduleClause(
924 const OMPDistScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000925 VistOMPClauseWithPreInit(C);
926 if (auto *S = C->getChunkSize())
927 Profiler->VisitStmt(S);
Carlo Bertollib4adf552016-01-15 18:50:31 +0000928}
929
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000930void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
931
Samuel Antao686c70c2016-05-26 17:30:50 +0000932void StmtProfiler::VisitOMPTargetUpdateDirective(
933 const OMPTargetUpdateDirective *S) {
934 VisitOMPExecutableDirective(S);
935}
936
Carlo Bertolli9925f152016-06-27 14:55:37 +0000937void StmtProfiler::VisitOMPDistributeParallelForDirective(
938 const OMPDistributeParallelForDirective *S) {
939 VisitOMPLoopDirective(S);
940}
941
Kelvin Li4a39add2016-07-05 05:00:15 +0000942void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
943 const OMPDistributeParallelForSimdDirective *S) {
944 VisitOMPLoopDirective(S);
945}
946
Kelvin Li787f3fc2016-07-06 04:45:38 +0000947void StmtProfiler::VisitOMPDistributeSimdDirective(
948 const OMPDistributeSimdDirective *S) {
949 VisitOMPLoopDirective(S);
950}
951
Kelvin Lia579b912016-07-14 02:54:56 +0000952void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
953 const OMPTargetParallelForSimdDirective *S) {
954 VisitOMPLoopDirective(S);
955}
956
Kelvin Li986330c2016-07-20 22:57:10 +0000957void StmtProfiler::VisitOMPTargetSimdDirective(
958 const OMPTargetSimdDirective *S) {
959 VisitOMPLoopDirective(S);
960}
961
Kelvin Li02532872016-08-05 14:37:37 +0000962void StmtProfiler::VisitOMPTeamsDistributeDirective(
963 const OMPTeamsDistributeDirective *S) {
964 VisitOMPLoopDirective(S);
965}
966
Kelvin Li4e325f72016-10-25 12:50:55 +0000967void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
968 const OMPTeamsDistributeSimdDirective *S) {
969 VisitOMPLoopDirective(S);
970}
971
Kelvin Li579e41c2016-11-30 23:51:03 +0000972void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
973 const OMPTeamsDistributeParallelForSimdDirective *S) {
974 VisitOMPLoopDirective(S);
975}
976
Kelvin Li7ade93f2016-12-09 03:24:30 +0000977void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
978 const OMPTeamsDistributeParallelForDirective *S) {
979 VisitOMPLoopDirective(S);
980}
981
Kelvin Libf594a52016-12-17 05:48:59 +0000982void StmtProfiler::VisitOMPTargetTeamsDirective(
983 const OMPTargetTeamsDirective *S) {
984 VisitOMPExecutableDirective(S);
985}
986
Kelvin Li83c451e2016-12-25 04:52:54 +0000987void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
988 const OMPTargetTeamsDistributeDirective *S) {
989 VisitOMPLoopDirective(S);
990}
991
Kelvin Li80e8f562016-12-29 22:16:30 +0000992void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
993 const OMPTargetTeamsDistributeParallelForDirective *S) {
994 VisitOMPLoopDirective(S);
995}
996
Kelvin Li1851df52017-01-03 05:23:48 +0000997void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
998 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
999 VisitOMPLoopDirective(S);
1000}
1001
Kelvin Lida681182017-01-10 18:08:18 +00001002void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
1003 const OMPTargetTeamsDistributeSimdDirective *S) {
1004 VisitOMPLoopDirective(S);
1005}
1006
Chandler Carruth631abd92011-06-16 06:47:06 +00001007void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001008 VisitStmt(S);
1009}
1010
Bill Wendling7c44da22018-10-31 03:48:47 +00001011void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1012 VisitExpr(S);
1013}
1014
Chandler Carruth631abd92011-06-16 06:47:06 +00001015void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001016 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001017 if (!Canonical)
1018 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001019 VisitDecl(S->getDecl());
Richard Trieu4d06bef2018-02-13 19:53:40 +00001020 if (!Canonical) {
1021 ID.AddBoolean(S->hasExplicitTemplateArgs());
1022 if (S->hasExplicitTemplateArgs())
1023 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1024 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001025}
1026
Chandler Carruth631abd92011-06-16 06:47:06 +00001027void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001028 VisitExpr(S);
Bruno Ricci17ff0262018-10-27 19:21:19 +00001029 ID.AddInteger(S->getIdentKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001030}
1031
Chandler Carruth631abd92011-06-16 06:47:06 +00001032void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001033 VisitExpr(S);
1034 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +00001035 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001036}
1037
Leonard Chandb01c3a2018-06-20 17:19:40 +00001038void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1039 VisitExpr(S);
1040 S->getValue().Profile(ID);
1041 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1042}
1043
Chandler Carruth631abd92011-06-16 06:47:06 +00001044void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001045 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +00001046 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001047 ID.AddInteger(S->getValue());
1048}
1049
Chandler Carruth631abd92011-06-16 06:47:06 +00001050void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001051 VisitExpr(S);
1052 S->getValue().Profile(ID);
1053 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +00001054 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001055}
1056
Chandler Carruth631abd92011-06-16 06:47:06 +00001057void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001058 VisitExpr(S);
1059}
1060
Chandler Carruth631abd92011-06-16 06:47:06 +00001061void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001062 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +00001063 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +00001064 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001065}
1066
Chandler Carruth631abd92011-06-16 06:47:06 +00001067void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001068 VisitExpr(S);
1069}
1070
Chandler Carruth631abd92011-06-16 06:47:06 +00001071void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +00001072 VisitExpr(S);
1073}
1074
Chandler Carruth631abd92011-06-16 06:47:06 +00001075void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001076 VisitExpr(S);
1077 ID.AddInteger(S->getOpcode());
1078}
1079
Chandler Carruth631abd92011-06-16 06:47:06 +00001080void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001081 VisitType(S->getTypeSourceInfo()->getType());
1082 unsigned n = S->getNumComponents();
1083 for (unsigned i = 0; i < n; ++i) {
James Y Knight7281c352015-12-29 22:31:18 +00001084 const OffsetOfNode &ON = S->getComponent(i);
Douglas Gregor882211c2010-04-28 22:16:22 +00001085 ID.AddInteger(ON.getKind());
1086 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00001087 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +00001088 // Expressions handled below.
1089 break;
1090
James Y Knight7281c352015-12-29 22:31:18 +00001091 case OffsetOfNode::Field:
Douglas Gregor882211c2010-04-28 22:16:22 +00001092 VisitDecl(ON.getField());
1093 break;
1094
James Y Knight7281c352015-12-29 22:31:18 +00001095 case OffsetOfNode::Identifier:
Richard Trieu639d7b62017-02-22 22:22:42 +00001096 VisitIdentifierInfo(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +00001097 break;
James Y Knight7281c352015-12-29 22:31:18 +00001098
1099 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00001100 // These nodes are implicit, and therefore don't need profiling.
1101 break;
Douglas Gregor882211c2010-04-28 22:16:22 +00001102 }
1103 }
Richard Trieu639d7b62017-02-22 22:22:42 +00001104
Douglas Gregor882211c2010-04-28 22:16:22 +00001105 VisitExpr(S);
1106}
1107
Chandler Carruth631abd92011-06-16 06:47:06 +00001108void
1109StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001110 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001111 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001112 if (S->isArgumentType())
1113 VisitType(S->getArgumentType());
1114}
1115
Chandler Carruth631abd92011-06-16 06:47:06 +00001116void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001117 VisitExpr(S);
1118}
1119
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001120void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1121 VisitExpr(S);
1122}
1123
Chandler Carruth631abd92011-06-16 06:47:06 +00001124void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001125 VisitExpr(S);
1126}
1127
Chandler Carruth631abd92011-06-16 06:47:06 +00001128void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001129 VisitExpr(S);
1130 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001131 if (!Canonical)
1132 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001133 ID.AddBoolean(S->isArrow());
1134}
1135
Chandler Carruth631abd92011-06-16 06:47:06 +00001136void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001137 VisitExpr(S);
1138 ID.AddBoolean(S->isFileScope());
1139}
1140
Chandler Carruth631abd92011-06-16 06:47:06 +00001141void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001142 VisitExpr(S);
1143}
1144
Chandler Carruth631abd92011-06-16 06:47:06 +00001145void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001146 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +00001147 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001148}
1149
Chandler Carruth631abd92011-06-16 06:47:06 +00001150void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001151 VisitCastExpr(S);
1152 VisitType(S->getTypeAsWritten());
1153}
1154
Chandler Carruth631abd92011-06-16 06:47:06 +00001155void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001156 VisitExplicitCastExpr(S);
1157}
1158
Chandler Carruth631abd92011-06-16 06:47:06 +00001159void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001160 VisitExpr(S);
1161 ID.AddInteger(S->getOpcode());
1162}
1163
Chandler Carruth631abd92011-06-16 06:47:06 +00001164void
1165StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001166 VisitBinaryOperator(S);
1167}
1168
Chandler Carruth631abd92011-06-16 06:47:06 +00001169void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001170 VisitExpr(S);
1171}
1172
Chandler Carruth631abd92011-06-16 06:47:06 +00001173void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +00001174 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +00001175 VisitExpr(S);
1176}
1177
Chandler Carruth631abd92011-06-16 06:47:06 +00001178void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001179 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001180 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001181}
1182
Chandler Carruth631abd92011-06-16 06:47:06 +00001183void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001184 VisitExpr(S);
1185}
1186
Chandler Carruth631abd92011-06-16 06:47:06 +00001187void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001188 VisitExpr(S);
1189}
1190
Hal Finkelc4d7c822013-09-18 03:29:45 +00001191void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1192 VisitExpr(S);
1193}
1194
Chandler Carruth631abd92011-06-16 06:47:06 +00001195void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001196 VisitExpr(S);
1197}
1198
Chandler Carruth631abd92011-06-16 06:47:06 +00001199void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001200 VisitExpr(S);
1201}
1202
Chandler Carruth631abd92011-06-16 06:47:06 +00001203void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001204 VisitExpr(S);
1205}
1206
Chandler Carruth631abd92011-06-16 06:47:06 +00001207void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001208 if (S->getSyntacticForm()) {
1209 VisitInitListExpr(S->getSyntacticForm());
1210 return;
1211 }
Mike Stump11289f42009-09-09 15:08:12 +00001212
Douglas Gregor5c193b92009-07-28 00:33:38 +00001213 VisitExpr(S);
1214}
1215
Chandler Carruth631abd92011-06-16 06:47:06 +00001216void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001217 VisitExpr(S);
1218 ID.AddBoolean(S->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +00001219 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1220 if (D.isFieldDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001221 ID.AddInteger(0);
David Majnemerf7e36092016-06-23 00:15:04 +00001222 VisitName(D.getFieldName());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001223 continue;
1224 }
Mike Stump11289f42009-09-09 15:08:12 +00001225
David Majnemerf7e36092016-06-23 00:15:04 +00001226 if (D.isArrayDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001227 ID.AddInteger(1);
1228 } else {
David Majnemerf7e36092016-06-23 00:15:04 +00001229 assert(D.isArrayRangeDesignator());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001230 ID.AddInteger(2);
1231 }
David Majnemerf7e36092016-06-23 00:15:04 +00001232 ID.AddInteger(D.getFirstExprIndex());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001233 }
1234}
1235
Yunzhong Gaocb779302015-06-10 00:27:52 +00001236// Seems that if VisitInitListExpr() only works on the syntactic form of an
1237// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1238void StmtProfiler::VisitDesignatedInitUpdateExpr(
1239 const DesignatedInitUpdateExpr *S) {
1240 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1241 "initializer");
1242}
1243
Richard Smith410306b2016-12-12 02:53:20 +00001244void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1245 VisitExpr(S);
1246}
1247
1248void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1249 VisitExpr(S);
1250}
1251
Yunzhong Gaocb779302015-06-10 00:27:52 +00001252void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1253 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1254}
1255
Chandler Carruth631abd92011-06-16 06:47:06 +00001256void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001257 VisitExpr(S);
1258}
1259
Chandler Carruth631abd92011-06-16 06:47:06 +00001260void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001261 VisitExpr(S);
1262 VisitName(&S->getAccessor());
1263}
1264
Chandler Carruth631abd92011-06-16 06:47:06 +00001265void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001266 VisitExpr(S);
1267 VisitDecl(S->getBlockDecl());
1268}
1269
Chandler Carruth631abd92011-06-16 06:47:06 +00001270void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001271 VisitExpr(S);
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00001272 for (const GenericSelectionExpr::ConstAssociation &Assoc :
1273 S->associations()) {
1274 QualType T = Assoc.getType();
Peter Collingbourne91147592011-04-15 00:35:48 +00001275 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +00001276 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00001277 else
1278 VisitType(T);
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00001279 VisitExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00001280 }
1281}
1282
John McCallfe96e0b2011-11-06 09:01:30 +00001283void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1284 VisitExpr(S);
1285 for (PseudoObjectExpr::const_semantics_iterator
1286 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1287 // Normally, we would not profile the source expressions of OVEs.
1288 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1289 Visit(OVE->getSourceExpr());
1290}
1291
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001292void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1293 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +00001294 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001295}
1296
Chandler Carruth631abd92011-06-16 06:47:06 +00001297static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +00001298 UnaryOperatorKind &UnaryOp,
1299 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001300 switch (S->getOperator()) {
1301 case OO_None:
1302 case OO_New:
1303 case OO_Delete:
1304 case OO_Array_New:
1305 case OO_Array_Delete:
1306 case OO_Arrow:
1307 case OO_Call:
1308 case OO_Conditional:
1309 case NUM_OVERLOADED_OPERATORS:
1310 llvm_unreachable("Invalid operator call kind");
Fangrui Song6907ce22018-07-30 19:24:48 +00001311
Douglas Gregore9ceb312010-05-19 04:13:23 +00001312 case OO_Plus:
1313 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001314 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001315 return Stmt::UnaryOperatorClass;
1316 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001317
John McCalle3027922010-08-25 11:45:40 +00001318 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001319 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001320
Douglas Gregore9ceb312010-05-19 04:13:23 +00001321 case OO_Minus:
1322 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001323 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001324 return Stmt::UnaryOperatorClass;
1325 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001326
John McCalle3027922010-08-25 11:45:40 +00001327 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001328 return Stmt::BinaryOperatorClass;
1329
1330 case OO_Star:
1331 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +00001332 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001333 return Stmt::UnaryOperatorClass;
1334 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001335
Richard Smithf15acc52014-06-05 22:43:40 +00001336 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001337 return Stmt::BinaryOperatorClass;
1338
1339 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +00001340 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001341 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001342
Douglas Gregore9ceb312010-05-19 04:13:23 +00001343 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +00001344 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001345 return Stmt::BinaryOperatorClass;
1346
1347 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +00001348 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001349 return Stmt::BinaryOperatorClass;
1350
1351 case OO_Amp:
1352 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001353 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001354 return Stmt::UnaryOperatorClass;
1355 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001356
John McCalle3027922010-08-25 11:45:40 +00001357 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001358 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001359
Douglas Gregore9ceb312010-05-19 04:13:23 +00001360 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +00001361 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001362 return Stmt::BinaryOperatorClass;
1363
1364 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +00001365 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001366 return Stmt::UnaryOperatorClass;
1367
1368 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +00001369 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001370 return Stmt::UnaryOperatorClass;
1371
1372 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +00001373 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001374 return Stmt::BinaryOperatorClass;
1375
1376 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +00001377 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001378 return Stmt::BinaryOperatorClass;
1379
1380 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +00001381 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001382 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001383
Douglas Gregore9ceb312010-05-19 04:13:23 +00001384 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +00001385 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001386 return Stmt::CompoundAssignOperatorClass;
1387
1388 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +00001389 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001390 return Stmt::CompoundAssignOperatorClass;
1391
1392 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +00001393 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001394 return Stmt::CompoundAssignOperatorClass;
1395
1396 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +00001397 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001398 return Stmt::CompoundAssignOperatorClass;
1399
1400 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +00001401 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001402 return Stmt::CompoundAssignOperatorClass;
1403
1404 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +00001405 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001406 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001407
Douglas Gregore9ceb312010-05-19 04:13:23 +00001408 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +00001409 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001410 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001411
Douglas Gregore9ceb312010-05-19 04:13:23 +00001412 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +00001413 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001414 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001415
Douglas Gregore9ceb312010-05-19 04:13:23 +00001416 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +00001417 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001418 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001419
Douglas Gregore9ceb312010-05-19 04:13:23 +00001420 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +00001421 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001422 return Stmt::BinaryOperatorClass;
1423
1424 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +00001425 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001426 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001427
Douglas Gregore9ceb312010-05-19 04:13:23 +00001428 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001429 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001430 return Stmt::CompoundAssignOperatorClass;
1431
1432 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +00001433 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001434 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001435
Douglas Gregore9ceb312010-05-19 04:13:23 +00001436 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001437 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001438 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001439
Douglas Gregore9ceb312010-05-19 04:13:23 +00001440 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001441 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001442 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001443
Douglas Gregore9ceb312010-05-19 04:13:23 +00001444 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001445 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001446 return Stmt::BinaryOperatorClass;
Richard Smithd30b23d2017-12-01 02:13:10 +00001447
1448 case OO_Spaceship:
1449 // FIXME: Update this once we support <=> expressions.
1450 llvm_unreachable("<=> expressions not supported yet");
Fangrui Song6907ce22018-07-30 19:24:48 +00001451
Douglas Gregore9ceb312010-05-19 04:13:23 +00001452 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001453 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001454 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001455
Douglas Gregore9ceb312010-05-19 04:13:23 +00001456 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001457 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001458 return Stmt::BinaryOperatorClass;
1459
1460 case OO_PlusPlus:
Fangrui Song6907ce22018-07-30 19:24:48 +00001461 UnaryOp = S->getNumArgs() == 1? UO_PreInc
John McCalle3027922010-08-25 11:45:40 +00001462 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001463 return Stmt::UnaryOperatorClass;
1464
1465 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001466 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1467 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001468 return Stmt::UnaryOperatorClass;
1469
1470 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001471 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001472 return Stmt::BinaryOperatorClass;
1473
Douglas Gregore9ceb312010-05-19 04:13:23 +00001474 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001475 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001476 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001477
Douglas Gregore9ceb312010-05-19 04:13:23 +00001478 case OO_Subscript:
1479 return Stmt::ArraySubscriptExprClass;
Richard Smith6fff5c42018-07-31 00:47:41 +00001480
1481 case OO_Coawait:
1482 UnaryOp = UO_Coawait;
1483 return Stmt::UnaryOperatorClass;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001484 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001485
Douglas Gregore9ceb312010-05-19 04:13:23 +00001486 llvm_unreachable("Invalid overloaded operator expression");
1487}
Richard Smithf15acc52014-06-05 22:43:40 +00001488
Reid Klecknere257e182017-10-13 16:18:32 +00001489#if defined(_MSC_VER) && !defined(__clang__)
Nico Weberf56f4462017-07-24 16:54:11 +00001490#if _MSC_VER == 1911
1491// Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1492// MSVC 2017 update 3 miscompiles this function, and a clang built with it
1493// will crash in stage 2 of a bootstrap build.
1494#pragma optimize("", off)
1495#endif
1496#endif
1497
Chandler Carruth631abd92011-06-16 06:47:06 +00001498void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001499 if (S->isTypeDependent()) {
1500 // Type-dependent operator calls are profiled like their underlying
1501 // syntactic operator.
Richard Smithbac0a0d2016-10-24 18:47:04 +00001502 //
1503 // An operator call to operator-> is always implicit, so just skip it. The
1504 // enclosing MemberExpr will profile the actual member access.
1505 if (S->getOperator() == OO_Arrow)
1506 return Visit(S->getArg(0));
1507
John McCalle3027922010-08-25 11:45:40 +00001508 UnaryOperatorKind UnaryOp = UO_Extension;
1509 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001510 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001511
Douglas Gregore9ceb312010-05-19 04:13:23 +00001512 ID.AddInteger(SC);
1513 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1514 Visit(S->getArg(I));
1515 if (SC == Stmt::UnaryOperatorClass)
1516 ID.AddInteger(UnaryOp);
Fangrui Song6907ce22018-07-30 19:24:48 +00001517 else if (SC == Stmt::BinaryOperatorClass ||
Douglas Gregore9ceb312010-05-19 04:13:23 +00001518 SC == Stmt::CompoundAssignOperatorClass)
1519 ID.AddInteger(BinaryOp);
1520 else
1521 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001522
Douglas Gregore9ceb312010-05-19 04:13:23 +00001523 return;
1524 }
Richard Smithf15acc52014-06-05 22:43:40 +00001525
Douglas Gregor5c193b92009-07-28 00:33:38 +00001526 VisitCallExpr(S);
1527 ID.AddInteger(S->getOperator());
1528}
1529
Reid Klecknere257e182017-10-13 16:18:32 +00001530#if defined(_MSC_VER) && !defined(__clang__)
Nico Weberf56f4462017-07-24 16:54:11 +00001531#if _MSC_VER == 1911
1532#pragma optimize("", on)
1533#endif
1534#endif
1535
Chandler Carruth631abd92011-06-16 06:47:06 +00001536void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001537 VisitCallExpr(S);
1538}
1539
Chandler Carruth631abd92011-06-16 06:47:06 +00001540void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001541 VisitCallExpr(S);
1542}
1543
Chandler Carruth631abd92011-06-16 06:47:06 +00001544void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001545 VisitExpr(S);
1546}
1547
Chandler Carruth631abd92011-06-16 06:47:06 +00001548void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001549 VisitExplicitCastExpr(S);
1550}
1551
Chandler Carruth631abd92011-06-16 06:47:06 +00001552void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001553 VisitCXXNamedCastExpr(S);
1554}
1555
Chandler Carruth631abd92011-06-16 06:47:06 +00001556void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001557 VisitCXXNamedCastExpr(S);
1558}
1559
Chandler Carruth631abd92011-06-16 06:47:06 +00001560void
1561StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001562 VisitCXXNamedCastExpr(S);
1563}
1564
Chandler Carruth631abd92011-06-16 06:47:06 +00001565void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001566 VisitCXXNamedCastExpr(S);
1567}
1568
Richard Smithc67fdd42012-03-07 08:35:16 +00001569void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1570 VisitCallExpr(S);
1571}
1572
Chandler Carruth631abd92011-06-16 06:47:06 +00001573void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001574 VisitExpr(S);
1575 ID.AddBoolean(S->getValue());
1576}
1577
Chandler Carruth631abd92011-06-16 06:47:06 +00001578void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001579 VisitExpr(S);
1580}
1581
Richard Smithcc1b96d2013-06-12 22:31:48 +00001582void StmtProfiler::VisitCXXStdInitializerListExpr(
1583 const CXXStdInitializerListExpr *S) {
1584 VisitExpr(S);
1585}
1586
Chandler Carruth631abd92011-06-16 06:47:06 +00001587void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001588 VisitExpr(S);
1589 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001590 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001591}
1592
Chandler Carruth631abd92011-06-16 06:47:06 +00001593void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001594 VisitExpr(S);
1595 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001596 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001597}
1598
John McCall5e77d762013-04-16 07:28:30 +00001599void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1600 VisitExpr(S);
1601 VisitDecl(S->getPropertyDecl());
1602}
1603
Alexey Bataevf7630272015-11-25 12:01:00 +00001604void StmtProfiler::VisitMSPropertySubscriptExpr(
1605 const MSPropertySubscriptExpr *S) {
1606 VisitExpr(S);
1607}
1608
Chandler Carruth631abd92011-06-16 06:47:06 +00001609void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001610 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001611 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001612}
1613
Chandler Carruth631abd92011-06-16 06:47:06 +00001614void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001615 VisitExpr(S);
1616}
1617
Chandler Carruth631abd92011-06-16 06:47:06 +00001618void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001619 VisitExpr(S);
1620 VisitDecl(S->getParam());
1621}
1622
Richard Smith852c9db2013-04-20 22:23:05 +00001623void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1624 VisitExpr(S);
1625 VisitDecl(S->getField());
1626}
1627
Chandler Carruth631abd92011-06-16 06:47:06 +00001628void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001629 VisitExpr(S);
1630 VisitDecl(
1631 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1632}
1633
Chandler Carruth631abd92011-06-16 06:47:06 +00001634void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001635 VisitExpr(S);
1636 VisitDecl(S->getConstructor());
1637 ID.AddBoolean(S->isElidable());
1638}
1639
Richard Smith5179eb72016-06-28 19:03:57 +00001640void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1641 const CXXInheritedCtorInitExpr *S) {
1642 VisitExpr(S);
1643 VisitDecl(S->getConstructor());
1644}
1645
Chandler Carruth631abd92011-06-16 06:47:06 +00001646void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001647 VisitExplicitCastExpr(S);
1648}
1649
Chandler Carruth631abd92011-06-16 06:47:06 +00001650void
1651StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001652 VisitCXXConstructExpr(S);
1653}
1654
Chandler Carruth631abd92011-06-16 06:47:06 +00001655void
Douglas Gregore31e6062012-02-07 10:09:13 +00001656StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1657 VisitExpr(S);
1658 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1659 CEnd = S->explicit_capture_end();
1660 C != CEnd; ++C) {
Richard Trieu931638e2017-11-11 00:54:25 +00001661 if (C->capturesVLAType())
1662 continue;
1663
Douglas Gregore31e6062012-02-07 10:09:13 +00001664 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001665 switch (C->getCaptureKind()) {
Faisal Validc6b5962016-03-21 09:25:37 +00001666 case LCK_StarThis:
Richard Smithba71c082013-05-16 06:20:58 +00001667 case LCK_This:
1668 break;
1669 case LCK_ByRef:
1670 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001671 VisitDecl(C->getCapturedVar());
1672 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001673 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001674 case LCK_VLAType:
1675 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001676 }
1677 }
1678 // Note: If we actually needed to be able to match lambda
1679 // expressions, we would have to consider parameters and return type
1680 // here, among other things.
1681 VisitStmt(S->getBody());
1682}
1683
1684void
Chandler Carruth631abd92011-06-16 06:47:06 +00001685StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001686 VisitExpr(S);
1687}
1688
Chandler Carruth631abd92011-06-16 06:47:06 +00001689void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001690 VisitExpr(S);
1691 ID.AddBoolean(S->isGlobalDelete());
1692 ID.AddBoolean(S->isArrayForm());
1693 VisitDecl(S->getOperatorDelete());
1694}
1695
Chandler Carruth631abd92011-06-16 06:47:06 +00001696void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001697 VisitExpr(S);
1698 VisitType(S->getAllocatedType());
1699 VisitDecl(S->getOperatorNew());
1700 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001701 ID.AddBoolean(S->isArray());
1702 ID.AddInteger(S->getNumPlacementArgs());
1703 ID.AddBoolean(S->isGlobalNew());
1704 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001705 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001706}
1707
Chandler Carruth631abd92011-06-16 06:47:06 +00001708void
1709StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001710 VisitExpr(S);
1711 ID.AddBoolean(S->isArrow());
1712 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001713 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001714 if (S->getScopeTypeInfo())
1715 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001716 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001717 if (S->getDestroyedTypeInfo())
1718 VisitType(S->getDestroyedType());
1719 else
Richard Trieu639d7b62017-02-22 22:22:42 +00001720 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001721}
1722
Chandler Carruth631abd92011-06-16 06:47:06 +00001723void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001724 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001725 VisitNestedNameSpecifier(S->getQualifier());
Richard Trieuf65efae2018-02-22 05:32:25 +00001726 VisitName(S->getName(), /*TreatAsDecl*/ true);
John McCalle66edc12009-11-24 19:00:30 +00001727 ID.AddBoolean(S->hasExplicitTemplateArgs());
1728 if (S->hasExplicitTemplateArgs())
James Y Knight04ec5bf2015-12-24 02:59:37 +00001729 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001730}
1731
1732void
Chandler Carruth631abd92011-06-16 06:47:06 +00001733StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001734 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001735}
1736
Douglas Gregor29c42f22012-02-24 07:38:34 +00001737void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1738 VisitExpr(S);
1739 ID.AddInteger(S->getTrait());
1740 ID.AddInteger(S->getNumArgs());
1741 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1742 VisitType(S->getArg(I)->getType());
1743}
1744
Chandler Carruth631abd92011-06-16 06:47:06 +00001745void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001746 VisitExpr(S);
1747 ID.AddInteger(S->getTrait());
1748 VisitType(S->getQueriedType());
1749}
1750
Chandler Carruth631abd92011-06-16 06:47:06 +00001751void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001752 VisitExpr(S);
1753 ID.AddInteger(S->getTrait());
1754 VisitExpr(S->getQueriedExpression());
1755}
1756
Chandler Carruth631abd92011-06-16 06:47:06 +00001757void StmtProfiler::VisitDependentScopeDeclRefExpr(
1758 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001759 VisitExpr(S);
1760 VisitName(S->getDeclName());
1761 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001762 ID.AddBoolean(S->hasExplicitTemplateArgs());
1763 if (S->hasExplicitTemplateArgs())
1764 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001765}
1766
Chandler Carruth631abd92011-06-16 06:47:06 +00001767void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001768 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001769}
1770
Chandler Carruth631abd92011-06-16 06:47:06 +00001771void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1772 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001773 VisitExpr(S);
1774 VisitType(S->getTypeAsWritten());
Richard Smith39eca9b2017-08-23 22:12:08 +00001775 ID.AddInteger(S->isListInitialization());
Douglas Gregora7095092009-07-28 14:44:31 +00001776}
1777
Chandler Carruth631abd92011-06-16 06:47:06 +00001778void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1779 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001780 ID.AddBoolean(S->isImplicitAccess());
1781 if (!S->isImplicitAccess()) {
1782 VisitExpr(S);
1783 ID.AddBoolean(S->isArrow());
1784 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001785 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001786 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001787 ID.AddBoolean(S->hasExplicitTemplateArgs());
1788 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001789 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1790}
1791
Chandler Carruth631abd92011-06-16 06:47:06 +00001792void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001793 ID.AddBoolean(S->isImplicitAccess());
1794 if (!S->isImplicitAccess()) {
1795 VisitExpr(S);
1796 ID.AddBoolean(S->isArrow());
1797 }
John McCall10eae182009-11-30 22:42:35 +00001798 VisitNestedNameSpecifier(S->getQualifier());
1799 VisitName(S->getMemberName());
1800 ID.AddBoolean(S->hasExplicitTemplateArgs());
1801 if (S->hasExplicitTemplateArgs())
1802 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001803}
1804
Chandler Carruth631abd92011-06-16 06:47:06 +00001805void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001806 VisitExpr(S);
1807}
1808
Chandler Carruth631abd92011-06-16 06:47:06 +00001809void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001810 VisitExpr(S);
1811}
1812
Chandler Carruth631abd92011-06-16 06:47:06 +00001813void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001814 VisitExpr(S);
1815 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00001816 if (S->isPartiallySubstituted()) {
1817 auto Args = S->getPartialArguments();
1818 ID.AddInteger(Args.size());
1819 for (const auto &TA : Args)
1820 VisitTemplateArgument(TA);
1821 } else {
1822 ID.AddInteger(0);
1823 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001824}
1825
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001826void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001827 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001828 VisitExpr(S);
1829 VisitDecl(S->getParameterPack());
1830 VisitTemplateArgument(S->getArgumentPack());
1831}
1832
John McCall7c454bb2011-07-15 05:09:51 +00001833void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1834 const SubstNonTypeTemplateParmExpr *E) {
1835 // Profile exactly as the replacement expression.
1836 Visit(E->getReplacement());
1837}
1838
Richard Smithb15fe3a2012-09-12 00:56:43 +00001839void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1840 VisitExpr(S);
1841 VisitDecl(S->getParameterPack());
1842 ID.AddInteger(S->getNumExpansions());
1843 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1844 VisitDecl(*I);
1845}
1846
Douglas Gregorfe314812011-06-21 17:03:29 +00001847void StmtProfiler::VisitMaterializeTemporaryExpr(
1848 const MaterializeTemporaryExpr *S) {
1849 VisitExpr(S);
1850}
1851
Richard Smith0f0af192014-11-08 05:07:16 +00001852void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1853 VisitExpr(S);
1854 ID.AddInteger(S->getOperator());
1855}
1856
Richard Smith9f690bd2015-10-27 06:02:45 +00001857void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1858 VisitStmt(S);
1859}
1860
1861void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1862 VisitStmt(S);
1863}
1864
1865void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1866 VisitExpr(S);
1867}
1868
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001869void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
1870 VisitExpr(S);
1871}
1872
Richard Smith9f690bd2015-10-27 06:02:45 +00001873void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1874 VisitExpr(S);
1875}
1876
Chandler Carruth631abd92011-06-16 06:47:06 +00001877void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001878 VisitExpr(E);
John McCall8d69a212010-11-15 23:31:06 +00001879}
1880
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00001881void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1882 VisitExpr(E);
1883}
1884
Eric Fiselier708afb52019-05-16 21:04:15 +00001885void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
1886 VisitExpr(E);
1887}
1888
Chandler Carruth631abd92011-06-16 06:47:06 +00001889void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001890 VisitExpr(S);
1891}
1892
Patrick Beard0caa3942012-04-19 00:25:12 +00001893void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00001894 VisitExpr(E);
1895}
1896
1897void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1898 VisitExpr(E);
1899}
1900
1901void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1902 VisitExpr(E);
1903}
1904
Chandler Carruth631abd92011-06-16 06:47:06 +00001905void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001906 VisitExpr(S);
1907 VisitType(S->getEncodedType());
1908}
1909
Chandler Carruth631abd92011-06-16 06:47:06 +00001910void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001911 VisitExpr(S);
1912 VisitName(S->getSelector());
1913}
1914
Chandler Carruth631abd92011-06-16 06:47:06 +00001915void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001916 VisitExpr(S);
1917 VisitDecl(S->getProtocol());
1918}
1919
Chandler Carruth631abd92011-06-16 06:47:06 +00001920void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001921 VisitExpr(S);
1922 VisitDecl(S->getDecl());
1923 ID.AddBoolean(S->isArrow());
1924 ID.AddBoolean(S->isFreeIvar());
1925}
1926
Chandler Carruth631abd92011-06-16 06:47:06 +00001927void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001928 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00001929 if (S->isImplicitProperty()) {
1930 VisitDecl(S->getImplicitPropertyGetter());
1931 VisitDecl(S->getImplicitPropertySetter());
1932 } else {
1933 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001934 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001935 if (S->isSuperReceiver()) {
1936 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00001937 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00001938 }
Douglas Gregora7095092009-07-28 14:44:31 +00001939}
1940
Ted Kremeneke65b0862012-03-06 20:05:56 +00001941void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1942 VisitExpr(S);
1943 VisitDecl(S->getAtIndexMethodDecl());
1944 VisitDecl(S->setAtIndexMethodDecl());
1945}
1946
Chandler Carruth631abd92011-06-16 06:47:06 +00001947void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001948 VisitExpr(S);
1949 VisitName(S->getSelector());
1950 VisitDecl(S->getMethodDecl());
1951}
1952
Chandler Carruth631abd92011-06-16 06:47:06 +00001953void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001954 VisitExpr(S);
1955 ID.AddBoolean(S->isArrow());
1956}
1957
Ted Kremeneke65b0862012-03-06 20:05:56 +00001958void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1959 VisitExpr(S);
1960 ID.AddBoolean(S->getValue());
1961}
1962
Chandler Carruth631abd92011-06-16 06:47:06 +00001963void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1964 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001965 VisitExpr(S);
1966 ID.AddBoolean(S->shouldCopy());
1967}
1968
Chandler Carruth631abd92011-06-16 06:47:06 +00001969void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00001970 VisitExplicitCastExpr(S);
1971 ID.AddBoolean(S->getBridgeKind());
1972}
1973
Erik Pilkington29099de2016-07-16 00:35:23 +00001974void StmtProfiler::VisitObjCAvailabilityCheckExpr(
1975 const ObjCAvailabilityCheckExpr *S) {
1976 VisitExpr(S);
1977}
1978
John McCall0ad16662009-10-29 08:12:44 +00001979void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00001980 unsigned NumArgs) {
1981 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00001982 for (unsigned I = 0; I != NumArgs; ++I)
1983 VisitTemplateArgument(Args[I].getArgument());
1984}
Mike Stump11289f42009-09-09 15:08:12 +00001985
John McCall0ad16662009-10-29 08:12:44 +00001986void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1987 // Mostly repetitive with TemplateArgument::Profile!
1988 ID.AddInteger(Arg.getKind());
1989 switch (Arg.getKind()) {
1990 case TemplateArgument::Null:
1991 break;
Mike Stump11289f42009-09-09 15:08:12 +00001992
John McCall0ad16662009-10-29 08:12:44 +00001993 case TemplateArgument::Type:
1994 VisitType(Arg.getAsType());
1995 break;
Mike Stump11289f42009-09-09 15:08:12 +00001996
Douglas Gregor9167f8b2009-11-11 01:00:40 +00001997 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00001998 case TemplateArgument::TemplateExpansion:
1999 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002000 break;
Fangrui Song6907ce22018-07-30 19:24:48 +00002001
John McCall0ad16662009-10-29 08:12:44 +00002002 case TemplateArgument::Declaration:
2003 VisitDecl(Arg.getAsDecl());
2004 break;
Mike Stump11289f42009-09-09 15:08:12 +00002005
Eli Friedmanb826a002012-09-26 02:36:12 +00002006 case TemplateArgument::NullPtr:
2007 VisitType(Arg.getNullPtrType());
2008 break;
2009
John McCall0ad16662009-10-29 08:12:44 +00002010 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00002011 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00002012 VisitType(Arg.getIntegralType());
2013 break;
Mike Stump11289f42009-09-09 15:08:12 +00002014
John McCall0ad16662009-10-29 08:12:44 +00002015 case TemplateArgument::Expression:
2016 Visit(Arg.getAsExpr());
2017 break;
Mike Stump11289f42009-09-09 15:08:12 +00002018
John McCall0ad16662009-10-29 08:12:44 +00002019 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00002020 for (const auto &P : Arg.pack_elements())
2021 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00002022 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00002023 }
2024}
2025
Jay Foad39c79802011-01-12 09:06:06 +00002026void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00002027 bool Canonical) const {
Richard Trieu639d7b62017-02-22 22:22:42 +00002028 StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2029 Profiler.Visit(this);
2030}
2031
2032void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2033 class ODRHash &Hash) const {
2034 StmtProfilerWithoutPointers Profiler(ID, Hash);
Douglas Gregor5c193b92009-07-28 00:33:38 +00002035 Profiler.Visit(this);
2036}