blob: bf3b43b816f17b371bab2084ab27f323b269b478 [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"
Alexey Bataev04a830f2020-02-10 14:30:39 -050022#include "clang/AST/OpenMPClause.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000023#include "clang/AST/StmtVisitor.h"
24#include "llvm/ADT/FoldingSet.h"
Douglas Gregor5c193b92009-07-28 00:33:38 +000025using namespace clang;
26
27namespace {
Chandler Carruth631abd92011-06-16 06:47:06 +000028 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
Richard Trieu639d7b62017-02-22 22:22:42 +000029 protected:
Douglas Gregor5c193b92009-07-28 00:33:38 +000030 llvm::FoldingSetNodeID &ID;
Douglas Gregor5c193b92009-07-28 00:33:38 +000031 bool Canonical;
Mike Stump11289f42009-09-09 15:08:12 +000032
Douglas Gregor5c193b92009-07-28 00:33:38 +000033 public:
Richard Trieu639d7b62017-02-22 22:22:42 +000034 StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical)
35 : ID(ID), Canonical(Canonical) {}
36
37 virtual ~StmtProfiler() {}
Mike Stump11289f42009-09-09 15:08:12 +000038
Chandler Carruth631abd92011-06-16 06:47:06 +000039 void VisitStmt(const Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +000040
Richard Trieuf65efae2018-02-22 05:32:25 +000041 virtual void HandleStmtClass(Stmt::StmtClass SC) = 0;
42
Chandler Carruth631abd92011-06-16 06:47:06 +000043#define STMT(Node, Base) void Visit##Node(const Node *S);
Alexis Hunt656bb312010-05-05 15:24:00 +000044#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +000045
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000046 /// Visit a declaration that is referenced within an expression
Douglas Gregor5c193b92009-07-28 00:33:38 +000047 /// or statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000048 virtual void VisitDecl(const Decl *D) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000049
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000050 /// Visit a type that is referenced within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000051 /// statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000052 virtual void VisitType(QualType T) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000053
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000054 /// Visit a name that occurs within an expression or statement.
Richard Trieuf65efae2018-02-22 05:32:25 +000055 virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0;
Richard Trieu639d7b62017-02-22 22:22:42 +000056
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000057 /// Visit identifiers that are not in Decl's or Type's.
Richard Trieu639d7b62017-02-22 22:22:42 +000058 virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000059
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000060 /// Visit a nested-name-specifier that occurs within an expression
Douglas Gregor5c193b92009-07-28 00:33:38 +000061 /// or statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000062 virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000063
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000064 /// Visit a template name that occurs within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000065 /// statement.
Richard Trieu639d7b62017-02-22 22:22:42 +000066 virtual void VisitTemplateName(TemplateName Name) = 0;
Mike Stump11289f42009-09-09 15:08:12 +000067
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000068 /// Visit template arguments that occur within an expression or
Douglas Gregor5c193b92009-07-28 00:33:38 +000069 /// statement.
Chandler Carruth631abd92011-06-16 06:47:06 +000070 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
71 unsigned NumArgs);
John McCall0ad16662009-10-29 08:12:44 +000072
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000073 /// Visit a single template argument.
John McCall0ad16662009-10-29 08:12:44 +000074 void VisitTemplateArgument(const TemplateArgument &Arg);
Douglas Gregor5c193b92009-07-28 00:33:38 +000075 };
Richard Trieu639d7b62017-02-22 22:22:42 +000076
77 class StmtProfilerWithPointers : public StmtProfiler {
78 const ASTContext &Context;
79
80 public:
81 StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID,
82 const ASTContext &Context, bool Canonical)
83 : StmtProfiler(ID, Canonical), Context(Context) {}
84 private:
Richard Trieuf65efae2018-02-22 05:32:25 +000085 void HandleStmtClass(Stmt::StmtClass SC) override {
86 ID.AddInteger(SC);
87 }
88
Richard Trieu639d7b62017-02-22 22:22:42 +000089 void VisitDecl(const Decl *D) override {
90 ID.AddInteger(D ? D->getKind() : 0);
91
92 if (Canonical && D) {
93 if (const NonTypeTemplateParmDecl *NTTP =
94 dyn_cast<NonTypeTemplateParmDecl>(D)) {
95 ID.AddInteger(NTTP->getDepth());
96 ID.AddInteger(NTTP->getIndex());
97 ID.AddBoolean(NTTP->isParameterPack());
98 VisitType(NTTP->getType());
99 return;
100 }
101
102 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
103 // The Itanium C++ ABI uses the type, scope depth, and scope
104 // index of a parameter when mangling expressions that involve
105 // function parameters, so we will use the parameter's type for
106 // establishing function parameter identity. That way, our
107 // definition of "equivalent" (per C++ [temp.over.link]) is at
108 // least as strong as the definition of "equivalent" used for
109 // name mangling.
110 VisitType(Parm->getType());
111 ID.AddInteger(Parm->getFunctionScopeDepth());
112 ID.AddInteger(Parm->getFunctionScopeIndex());
113 return;
114 }
115
116 if (const TemplateTypeParmDecl *TTP =
117 dyn_cast<TemplateTypeParmDecl>(D)) {
118 ID.AddInteger(TTP->getDepth());
119 ID.AddInteger(TTP->getIndex());
120 ID.AddBoolean(TTP->isParameterPack());
121 return;
122 }
123
124 if (const TemplateTemplateParmDecl *TTP =
125 dyn_cast<TemplateTemplateParmDecl>(D)) {
126 ID.AddInteger(TTP->getDepth());
127 ID.AddInteger(TTP->getIndex());
128 ID.AddBoolean(TTP->isParameterPack());
129 return;
130 }
131 }
132
133 ID.AddPointer(D ? D->getCanonicalDecl() : nullptr);
134 }
135
136 void VisitType(QualType T) override {
Richard Trieua5f4ade2017-03-04 02:42:41 +0000137 if (Canonical && !T.isNull())
Richard Trieu639d7b62017-02-22 22:22:42 +0000138 T = Context.getCanonicalType(T);
139
140 ID.AddPointer(T.getAsOpaquePtr());
141 }
142
Richard Trieuf65efae2018-02-22 05:32:25 +0000143 void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override {
Richard Trieu639d7b62017-02-22 22:22:42 +0000144 ID.AddPointer(Name.getAsOpaquePtr());
145 }
146
147 void VisitIdentifierInfo(IdentifierInfo *II) override {
148 ID.AddPointer(II);
149 }
150
151 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
152 if (Canonical)
153 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
154 ID.AddPointer(NNS);
155 }
156
157 void VisitTemplateName(TemplateName Name) override {
158 if (Canonical)
159 Name = Context.getCanonicalTemplateName(Name);
160
161 Name.Profile(ID);
162 }
163 };
164
165 class StmtProfilerWithoutPointers : public StmtProfiler {
166 ODRHash &Hash;
167 public:
168 StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
169 : StmtProfiler(ID, false), Hash(Hash) {}
170
171 private:
Richard Trieuf65efae2018-02-22 05:32:25 +0000172 void HandleStmtClass(Stmt::StmtClass SC) override {
173 if (SC == Stmt::UnresolvedLookupExprClass) {
174 // Pretend that the name looked up is a Decl due to how templates
175 // handle some Decl lookups.
176 ID.AddInteger(Stmt::DeclRefExprClass);
177 } else {
178 ID.AddInteger(SC);
179 }
180 }
181
Richard Trieu639d7b62017-02-22 22:22:42 +0000182 void VisitType(QualType T) override {
183 Hash.AddQualType(T);
184 }
185
Richard Trieuf65efae2018-02-22 05:32:25 +0000186 void VisitName(DeclarationName Name, bool TreatAsDecl) override {
187 if (TreatAsDecl) {
188 // A Decl can be null, so each Decl is preceded by a boolean to
189 // store its nullness. Add a boolean here to match.
190 ID.AddBoolean(true);
191 }
Richard Trieu22ddc282018-09-04 22:53:19 +0000192 Hash.AddDeclarationName(Name, TreatAsDecl);
Richard Trieu639d7b62017-02-22 22:22:42 +0000193 }
194 void VisitIdentifierInfo(IdentifierInfo *II) override {
195 ID.AddBoolean(II);
196 if (II) {
197 Hash.AddIdentifierInfo(II);
198 }
199 }
200 void VisitDecl(const Decl *D) override {
201 ID.AddBoolean(D);
202 if (D) {
203 Hash.AddDecl(D);
204 }
205 }
206 void VisitTemplateName(TemplateName Name) override {
207 Hash.AddTemplateName(Name);
208 }
209 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
Richard Trieu96b41642017-07-01 02:00:05 +0000210 ID.AddBoolean(NNS);
211 if (NNS) {
212 Hash.AddNestedNameSpecifier(NNS);
213 }
Richard Trieu639d7b62017-02-22 22:22:42 +0000214 }
215 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000216}
Douglas Gregor5c193b92009-07-28 00:33:38 +0000217
Chandler Carruth631abd92011-06-16 06:47:06 +0000218void StmtProfiler::VisitStmt(const Stmt *S) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000219 assert(S && "Requires non-null Stmt pointer");
Richard Trieuf65efae2018-02-22 05:32:25 +0000220
221 HandleStmtClass(S->getStmtClass());
222
Benjamin Kramer642f1732015-07-02 21:03:14 +0000223 for (const Stmt *SubStmt : S->children()) {
224 if (SubStmt)
225 Visit(SubStmt);
Peter Collingbournecdb9f302012-03-01 16:34:31 +0000226 else
227 ID.AddInteger(0);
228 }
Douglas Gregor5c193b92009-07-28 00:33:38 +0000229}
230
Chandler Carruth631abd92011-06-16 06:47:06 +0000231void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000232 VisitStmt(S);
Aaron Ballman535bbcc2014-03-14 17:01:24 +0000233 for (const auto *D : S->decls())
234 VisitDecl(D);
Douglas Gregor44882592009-07-28 15:27:13 +0000235}
236
Chandler Carruth631abd92011-06-16 06:47:06 +0000237void StmtProfiler::VisitNullStmt(const NullStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000238 VisitStmt(S);
239}
240
Chandler Carruth631abd92011-06-16 06:47:06 +0000241void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000242 VisitStmt(S);
243}
244
Chandler Carruth631abd92011-06-16 06:47:06 +0000245void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000246 VisitStmt(S);
247}
248
Chandler Carruth631abd92011-06-16 06:47:06 +0000249void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000250 VisitStmt(S);
251}
252
Chandler Carruth631abd92011-06-16 06:47:06 +0000253void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000254 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000255 VisitDecl(S->getDecl());
Douglas Gregor44882592009-07-28 15:27:13 +0000256}
257
Richard Smithc202b282012-04-14 00:33:13 +0000258void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
259 VisitStmt(S);
260 // TODO: maybe visit attributes?
261}
262
Chandler Carruth631abd92011-06-16 06:47:06 +0000263void StmtProfiler::VisitIfStmt(const IfStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000264 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000265 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000266}
267
Chandler Carruth631abd92011-06-16 06:47:06 +0000268void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
Douglas Gregor00044172009-07-29 16:09:57 +0000269 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000270 VisitDecl(S->getConditionVariable());
Douglas Gregor00044172009-07-29 16:09:57 +0000271}
272
Chandler Carruth631abd92011-06-16 06:47:06 +0000273void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000274 VisitStmt(S);
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000275 VisitDecl(S->getConditionVariable());
Douglas Gregor44882592009-07-28 15:27:13 +0000276}
277
Chandler Carruth631abd92011-06-16 06:47:06 +0000278void StmtProfiler::VisitDoStmt(const DoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000279 VisitStmt(S);
280}
281
Chandler Carruth631abd92011-06-16 06:47:06 +0000282void StmtProfiler::VisitForStmt(const ForStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000283 VisitStmt(S);
284}
285
Chandler Carruth631abd92011-06-16 06:47:06 +0000286void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000287 VisitStmt(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000288 VisitDecl(S->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000289}
290
Chandler Carruth631abd92011-06-16 06:47:06 +0000291void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000292 VisitStmt(S);
293}
294
Chandler Carruth631abd92011-06-16 06:47:06 +0000295void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000296 VisitStmt(S);
297}
298
Chandler Carruth631abd92011-06-16 06:47:06 +0000299void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000300 VisitStmt(S);
301}
302
Chandler Carruth631abd92011-06-16 06:47:06 +0000303void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000304 VisitStmt(S);
305}
306
Chad Rosierde70e0e2012-08-25 00:11:56 +0000307void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000308 VisitStmt(S);
309 ID.AddBoolean(S->isVolatile());
310 ID.AddBoolean(S->isSimple());
311 VisitStringLiteral(S->getAsmString());
312 ID.AddInteger(S->getNumOutputs());
313 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
314 ID.AddString(S->getOutputName(I));
315 VisitStringLiteral(S->getOutputConstraintLiteral(I));
316 }
317 ID.AddInteger(S->getNumInputs());
318 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
319 ID.AddString(S->getInputName(I));
320 VisitStringLiteral(S->getInputConstraintLiteral(I));
321 }
322 ID.AddInteger(S->getNumClobbers());
323 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +0000324 VisitStringLiteral(S->getClobberStringLiteral(I));
Jennifer Yub8fee672019-06-03 15:57:25 +0000325 ID.AddInteger(S->getNumLabels());
326 for (auto *L : S->labels())
327 VisitDecl(L->getLabel());
Douglas Gregor44882592009-07-28 15:27:13 +0000328}
329
Chad Rosier32503022012-06-11 20:47:18 +0000330void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
331 // FIXME: Implement MS style inline asm statement profiler.
332 VisitStmt(S);
333}
334
Chandler Carruth631abd92011-06-16 06:47:06 +0000335void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000336 VisitStmt(S);
337 VisitType(S->getCaughtType());
338}
339
Chandler Carruth631abd92011-06-16 06:47:06 +0000340void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000341 VisitStmt(S);
342}
343
Chandler Carruth631abd92011-06-16 06:47:06 +0000344void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
Richard Smith02e85f32011-04-14 22:09:26 +0000345 VisitStmt(S);
346}
347
Douglas Gregordeb4a2be2011-10-25 01:33:02 +0000348void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
349 VisitStmt(S);
350 ID.AddBoolean(S->isIfExists());
351 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
352 VisitName(S->getNameInfo().getName());
353}
354
Chandler Carruth631abd92011-06-16 06:47:06 +0000355void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000356 VisitStmt(S);
357}
358
Chandler Carruth631abd92011-06-16 06:47:06 +0000359void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000360 VisitStmt(S);
361}
362
Chandler Carruth631abd92011-06-16 06:47:06 +0000363void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +0000364 VisitStmt(S);
365}
366
Nico Weber9b982072014-07-07 00:12:30 +0000367void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
368 VisitStmt(S);
369}
370
Tareq A. Siraj24110cc2013-04-16 18:53:08 +0000371void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
372 VisitStmt(S);
373}
374
Chandler Carruth631abd92011-06-16 06:47:06 +0000375void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000376 VisitStmt(S);
377}
378
Chandler Carruth631abd92011-06-16 06:47:06 +0000379void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000380 VisitStmt(S);
381 ID.AddBoolean(S->hasEllipsis());
382 if (S->getCatchParamDecl())
383 VisitType(S->getCatchParamDecl()->getType());
384}
385
Chandler Carruth631abd92011-06-16 06:47:06 +0000386void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000387 VisitStmt(S);
388}
389
Chandler Carruth631abd92011-06-16 06:47:06 +0000390void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000391 VisitStmt(S);
392}
393
Chandler Carruth631abd92011-06-16 06:47:06 +0000394void
395StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000396 VisitStmt(S);
397}
398
Chandler Carruth631abd92011-06-16 06:47:06 +0000399void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
Douglas Gregor44882592009-07-28 15:27:13 +0000400 VisitStmt(S);
401}
402
Chandler Carruth631abd92011-06-16 06:47:06 +0000403void
404StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
John McCall31168b02011-06-15 23:02:42 +0000405 VisitStmt(S);
406}
407
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000408namespace {
409class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
410 StmtProfiler *Profiler;
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000411 /// Process clauses with list of variables.
Alexey Bataev756c1962013-09-24 03:17:45 +0000412 template <typename T>
413 void VisitOMPClauseList(T *Node);
NAKAMURA Takumiaa13f942015-12-09 07:52:46 +0000414
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000415public:
416 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
Johannes Doerfert419a5592020-03-30 19:58:40 -0500417#define OMP_CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C);
418#include "llvm/Frontend/OpenMP/OMPKinds.def"
Alexey Bataev3392d762016-02-16 11:18:12 +0000419 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000420 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000421};
422
Alexey Bataev3392d762016-02-16 11:18:12 +0000423void OMPClauseProfiler::VistOMPClauseWithPreInit(
424 const OMPClauseWithPreInit *C) {
425 if (auto *S = C->getPreInitStmt())
426 Profiler->VisitStmt(S);
427}
428
Alexey Bataev005248a2016-02-25 05:25:57 +0000429void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
430 const OMPClauseWithPostUpdate *C) {
Alexey Bataev37e594c2016-03-04 07:21:16 +0000431 VistOMPClauseWithPreInit(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000432 if (auto *E = C->getPostUpdateExpr())
433 Profiler->VisitStmt(E);
434}
435
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000436void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +0000437 VistOMPClauseWithPreInit(C);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000438 if (C->getCondition())
439 Profiler->VisitStmt(C->getCondition());
440}
441
Alexey Bataev3778b602014-07-17 07:32:53 +0000442void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000443 VistOMPClauseWithPreInit(C);
Alexey Bataev3778b602014-07-17 07:32:53 +0000444 if (C->getCondition())
445 Profiler->VisitStmt(C->getCondition());
446}
447
Alexey Bataev568a8332014-03-06 06:15:19 +0000448void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +0000449 VistOMPClauseWithPreInit(C);
Alexey Bataev568a8332014-03-06 06:15:19 +0000450 if (C->getNumThreads())
451 Profiler->VisitStmt(C->getNumThreads());
452}
453
Alexey Bataev62c87d22014-03-21 04:51:18 +0000454void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
455 if (C->getSafelen())
456 Profiler->VisitStmt(C->getSafelen());
457}
458
Alexey Bataev66b15b52015-08-21 11:14:16 +0000459void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
460 if (C->getSimdlen())
461 Profiler->VisitStmt(C->getSimdlen());
462}
463
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000464void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
465 if (C->getAllocator())
466 Profiler->VisitStmt(C->getAllocator());
467}
468
Alexander Musman8bd31e62014-05-27 15:12:19 +0000469void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
470 if (C->getNumForLoops())
471 Profiler->VisitStmt(C->getNumForLoops());
472}
473
Alexey Bataev0f0564b2020-03-17 09:17:42 -0400474void OMPClauseProfiler::VisitOMPDetachClause(const OMPDetachClause *C) {
475 if (Expr *Evt = C->getEventHandler())
476 Profiler->VisitStmt(Evt);
477}
478
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000479void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000480
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000481void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
482
Kelvin Li1408f912018-09-26 04:28:39 +0000483void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
484 const OMPUnifiedAddressClause *C) {}
485
Patrick Lyster4a370b92018-10-01 13:47:43 +0000486void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
487 const OMPUnifiedSharedMemoryClause *C) {}
488
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000489void OMPClauseProfiler::VisitOMPReverseOffloadClause(
490 const OMPReverseOffloadClause *C) {}
491
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000492void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
493 const OMPDynamicAllocatorsClause *C) {}
494
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000495void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
496 const OMPAtomicDefaultMemOrderClause *C) {}
497
Alexey Bataev56dafe82014-06-20 07:16:17 +0000498void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000499 VistOMPClauseWithPreInit(C);
500 if (auto *S = C->getChunkSize())
501 Profiler->VisitStmt(S);
Alexey Bataev56dafe82014-06-20 07:16:17 +0000502}
503
Alexey Bataev10e775f2015-07-30 11:36:16 +0000504void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
505 if (auto *Num = C->getNumForLoops())
506 Profiler->VisitStmt(Num);
507}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000508
Alexey Bataev236070f2014-06-20 11:19:47 +0000509void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
510
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000511void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
512
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000513void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
514
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000515void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
516
Alexey Bataevdea47612014-07-23 07:46:59 +0000517void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
518
Alexey Bataev67a4f222014-07-23 10:25:33 +0000519void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
520
Alexey Bataev459dec02014-07-24 06:46:57 +0000521void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
522
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000523void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
524
Alexey Bataevea9166b2020-02-06 16:30:23 -0500525void OMPClauseProfiler::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
526
Alexey Bataev04a830f2020-02-10 14:30:39 -0500527void OMPClauseProfiler::VisitOMPAcquireClause(const OMPAcquireClause *) {}
528
Alexey Bataev95598342020-02-10 15:49:05 -0500529void OMPClauseProfiler::VisitOMPReleaseClause(const OMPReleaseClause *) {}
530
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500531void OMPClauseProfiler::VisitOMPRelaxedClause(const OMPRelaxedClause *) {}
532
Alexey Bataev346265e2015-09-25 10:37:12 +0000533void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
534
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000535void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
536
Alexey Bataevb825de12015-12-07 10:51:44 +0000537void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
538
Alexey Bataev375437a2020-03-02 14:21:20 -0500539void OMPClauseProfiler::VisitOMPDestroyClause(const OMPDestroyClause *) {}
540
Alexey Bataev756c1962013-09-24 03:17:45 +0000541template<typename T>
542void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000543 for (auto *E : Node->varlists()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000544 if (E)
545 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000546 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000547}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000548
549void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000550 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000551 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000552 if (E)
553 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000554 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000555}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000556void
557OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000558 VisitOMPClauseList(C);
Alexey Bataev417089f2016-02-17 13:19:37 +0000559 VistOMPClauseWithPreInit(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000560 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000561 if (E)
562 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000563 }
564 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000565 if (E)
566 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000567 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000568}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000569void
570OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
571 VisitOMPClauseList(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000572 VistOMPClauseWithPostUpdate(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000573 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000574 if (E)
575 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000576 }
577 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000578 if (E)
579 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000580 }
581 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000582 if (E)
583 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000584 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000585}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000586void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000587 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000588}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000589void OMPClauseProfiler::VisitOMPReductionClause(
590 const OMPReductionClause *C) {
591 Profiler->VisitNestedNameSpecifier(
592 C->getQualifierLoc().getNestedNameSpecifier());
593 Profiler->VisitName(C->getNameInfo().getName());
594 VisitOMPClauseList(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000595 VistOMPClauseWithPostUpdate(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000596 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000597 if (E)
598 Profiler->VisitStmt(E);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000599 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000600 for (auto *E : C->lhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000601 if (E)
602 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000603 }
604 for (auto *E : C->rhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000605 if (E)
606 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000607 }
608 for (auto *E : C->reduction_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000609 if (E)
610 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000611 }
Alexey Bataevbd1c03d2020-05-04 16:19:31 -0400612 if (C->getModifier() == clang::OMPC_REDUCTION_inscan) {
613 for (auto *E : C->copy_ops()) {
614 if (E)
615 Profiler->VisitStmt(E);
616 }
617 for (auto *E : C->copy_array_temps()) {
618 if (E)
619 Profiler->VisitStmt(E);
620 }
621 for (auto *E : C->copy_array_elems()) {
622 if (E)
623 Profiler->VisitStmt(E);
624 }
625 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000626}
Alexey Bataev169d96a2017-07-18 20:17:46 +0000627void OMPClauseProfiler::VisitOMPTaskReductionClause(
628 const OMPTaskReductionClause *C) {
629 Profiler->VisitNestedNameSpecifier(
630 C->getQualifierLoc().getNestedNameSpecifier());
631 Profiler->VisitName(C->getNameInfo().getName());
632 VisitOMPClauseList(C);
633 VistOMPClauseWithPostUpdate(C);
634 for (auto *E : C->privates()) {
635 if (E)
636 Profiler->VisitStmt(E);
637 }
638 for (auto *E : C->lhs_exprs()) {
639 if (E)
640 Profiler->VisitStmt(E);
641 }
642 for (auto *E : C->rhs_exprs()) {
643 if (E)
644 Profiler->VisitStmt(E);
645 }
646 for (auto *E : C->reduction_ops()) {
647 if (E)
648 Profiler->VisitStmt(E);
649 }
650}
Alexey Bataevfa312f32017-07-21 18:48:21 +0000651void OMPClauseProfiler::VisitOMPInReductionClause(
652 const OMPInReductionClause *C) {
653 Profiler->VisitNestedNameSpecifier(
654 C->getQualifierLoc().getNestedNameSpecifier());
655 Profiler->VisitName(C->getNameInfo().getName());
656 VisitOMPClauseList(C);
657 VistOMPClauseWithPostUpdate(C);
658 for (auto *E : C->privates()) {
659 if (E)
660 Profiler->VisitStmt(E);
661 }
662 for (auto *E : C->lhs_exprs()) {
663 if (E)
664 Profiler->VisitStmt(E);
665 }
666 for (auto *E : C->rhs_exprs()) {
667 if (E)
668 Profiler->VisitStmt(E);
669 }
670 for (auto *E : C->reduction_ops()) {
671 if (E)
672 Profiler->VisitStmt(E);
673 }
Alexey Bataev88202be2017-07-27 13:20:36 +0000674 for (auto *E : C->taskgroup_descriptors()) {
675 if (E)
676 Profiler->VisitStmt(E);
677 }
Alexey Bataevfa312f32017-07-21 18:48:21 +0000678}
Alexander Musman8dba6642014-04-22 13:09:42 +0000679void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
680 VisitOMPClauseList(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000681 VistOMPClauseWithPostUpdate(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000682 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000683 if (E)
684 Profiler->VisitStmt(E);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000685 }
Alexander Musman3276a272015-03-21 10:12:56 +0000686 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000687 if (E)
688 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000689 }
690 for (auto *E : C->updates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000691 if (E)
692 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000693 }
694 for (auto *E : C->finals()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000695 if (E)
696 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000697 }
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000698 if (C->getStep())
699 Profiler->VisitStmt(C->getStep());
700 if (C->getCalcStep())
701 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000702}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000703void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
704 VisitOMPClauseList(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000705 if (C->getAlignment())
706 Profiler->VisitStmt(C->getAlignment());
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000707}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000708void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
709 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000710 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000711 if (E)
712 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000713 }
714 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000715 if (E)
716 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000717 }
718 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000719 if (E)
720 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000721 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000722}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000723void
724OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
725 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000726 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000727 if (E)
728 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000729 }
730 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000731 if (E)
732 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000733 }
734 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000735 if (E)
736 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000737 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000738}
Alexey Bataev6125da92014-07-21 11:26:11 +0000739void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
740 VisitOMPClauseList(C);
741}
Alexey Bataevc112e942020-02-28 09:52:15 -0500742void OMPClauseProfiler::VisitOMPDepobjClause(const OMPDepobjClause *C) {
743 if (const Expr *Depobj = C->getDepobj())
744 Profiler->VisitStmt(Depobj);
745}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000746void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
747 VisitOMPClauseList(C);
748}
Michael Wonge710d542015-08-07 16:16:36 +0000749void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000750 if (C->getDevice())
751 Profiler->VisitStmt(C->getDevice());
Michael Wonge710d542015-08-07 16:16:36 +0000752}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000753void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
754 VisitOMPClauseList(C);
755}
Alexey Bataeve04483e2019-03-27 14:14:31 +0000756void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
757 if (Expr *Allocator = C->getAllocator())
758 Profiler->VisitStmt(Allocator);
759 VisitOMPClauseList(C);
760}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000761void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +0000762 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000763 if (C->getNumTeams())
764 Profiler->VisitStmt(C->getNumTeams());
Kelvin Li099bb8c2015-11-24 20:50:12 +0000765}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000766void OMPClauseProfiler::VisitOMPThreadLimitClause(
767 const OMPThreadLimitClause *C) {
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +0000768 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000769 if (C->getThreadLimit())
770 Profiler->VisitStmt(C->getThreadLimit());
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000771}
Alexey Bataeva0569352015-12-01 10:17:31 +0000772void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
Alexey Bataev31ba4762019-10-16 18:09:37 +0000773 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000774 if (C->getPriority())
775 Profiler->VisitStmt(C->getPriority());
Alexey Bataeva0569352015-12-01 10:17:31 +0000776}
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000777void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000778 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000779 if (C->getGrainsize())
780 Profiler->VisitStmt(C->getGrainsize());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000781}
Alexey Bataev382967a2015-12-08 12:06:20 +0000782void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000783 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000784 if (C->getNumTasks())
785 Profiler->VisitStmt(C->getNumTasks());
Alexey Bataev382967a2015-12-08 12:06:20 +0000786}
Alexey Bataev28c75412015-12-15 08:19:24 +0000787void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000788 if (C->getHint())
789 Profiler->VisitStmt(C->getHint());
Alexey Bataev28c75412015-12-15 08:19:24 +0000790}
Samuel Antao661c0902016-05-26 17:39:58 +0000791void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
792 VisitOMPClauseList(C);
793}
Samuel Antaoec172c62016-05-26 17:49:04 +0000794void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
795 VisitOMPClauseList(C);
796}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000797void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
798 const OMPUseDevicePtrClause *C) {
799 VisitOMPClauseList(C);
800}
Alexey Bataeva888fc62020-05-21 08:30:23 -0400801void OMPClauseProfiler::VisitOMPUseDeviceAddrClause(
802 const OMPUseDeviceAddrClause *C) {
803 VisitOMPClauseList(C);
804}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000805void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
806 const OMPIsDevicePtrClause *C) {
807 VisitOMPClauseList(C);
808}
Alexey Bataev0860db92019-12-19 10:01:10 -0500809void OMPClauseProfiler::VisitOMPNontemporalClause(
810 const OMPNontemporalClause *C) {
Alexey Bataevb6e70842019-12-16 15:54:17 -0500811 VisitOMPClauseList(C);
Alexey Bataev0860db92019-12-19 10:01:10 -0500812 for (auto *E : C->private_refs())
813 Profiler->VisitStmt(E);
Alexey Bataevb6e70842019-12-16 15:54:17 -0500814}
Alexey Bataev06dea732020-03-20 09:41:22 -0400815void OMPClauseProfiler::VisitOMPInclusiveClause(const OMPInclusiveClause *C) {
816 VisitOMPClauseList(C);
817}
Alexey Bataev63828a32020-03-23 10:41:08 -0400818void OMPClauseProfiler::VisitOMPExclusiveClause(const OMPExclusiveClause *C) {
819 VisitOMPClauseList(C);
820}
Alexey Bataevb5be1c52020-04-21 13:21:00 -0400821void OMPClauseProfiler::VisitOMPUsesAllocatorsClause(
822 const OMPUsesAllocatorsClause *C) {
823 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
824 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
825 Profiler->VisitStmt(D.Allocator);
826 if (D.AllocatorTraits)
827 Profiler->VisitStmt(D.AllocatorTraits);
828 }
829}
Alexey Bataev2e499ee2020-05-18 13:37:53 -0400830void OMPClauseProfiler::VisitOMPAffinityClause(const OMPAffinityClause *C) {
831 if (const Expr *Modifier = C->getModifier())
832 Profiler->VisitStmt(Modifier);
833 for (const Expr *E : C->varlists())
834 Profiler->VisitStmt(E);
835}
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500836void OMPClauseProfiler::VisitOMPOrderClause(const OMPOrderClause *C) {}
Alexey Bataev0860db92019-12-19 10:01:10 -0500837} // namespace
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000838
839void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000840StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000841 VisitStmt(S);
842 OMPClauseProfiler P(this);
843 ArrayRef<OMPClause *> Clauses = S->clauses();
844 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
845 I != E; ++I)
846 if (*I)
847 P.Visit(*I);
848}
849
Alexander Musman3aaab662014-08-19 11:27:13 +0000850void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
851 VisitOMPExecutableDirective(S);
852}
853
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000854void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
855 VisitOMPExecutableDirective(S);
856}
857
858void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000859 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000860}
861
Alexey Bataevf29276e2014-06-18 04:14:57 +0000862void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000863 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000864}
865
Alexander Musmanf82886e2014-09-18 05:12:34 +0000866void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
867 VisitOMPLoopDirective(S);
868}
869
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000870void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
871 VisitOMPExecutableDirective(S);
872}
873
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000874void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
875 VisitOMPExecutableDirective(S);
876}
877
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000878void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
879 VisitOMPExecutableDirective(S);
880}
881
Alexander Musman80c22892014-07-17 08:54:58 +0000882void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
883 VisitOMPExecutableDirective(S);
884}
885
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000886void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
887 VisitOMPExecutableDirective(S);
888 VisitName(S->getDirectiveName().getName());
889}
890
Alexey Bataev4acb8592014-07-07 13:01:15 +0000891void
892StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000893 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000894}
895
Alexander Musmane4e893b2014-09-23 09:33:00 +0000896void StmtProfiler::VisitOMPParallelForSimdDirective(
897 const OMPParallelForSimdDirective *S) {
898 VisitOMPLoopDirective(S);
899}
900
cchen47d60942019-12-05 13:43:48 -0500901void StmtProfiler::VisitOMPParallelMasterDirective(
902 const OMPParallelMasterDirective *S) {
903 VisitOMPExecutableDirective(S);
904}
905
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000906void StmtProfiler::VisitOMPParallelSectionsDirective(
907 const OMPParallelSectionsDirective *S) {
908 VisitOMPExecutableDirective(S);
909}
910
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000911void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
912 VisitOMPExecutableDirective(S);
913}
914
Alexey Bataev68446b72014-07-18 07:47:19 +0000915void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
916 VisitOMPExecutableDirective(S);
917}
918
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000919void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
920 VisitOMPExecutableDirective(S);
921}
922
Alexey Bataev2df347a2014-07-18 10:17:07 +0000923void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
924 VisitOMPExecutableDirective(S);
925}
926
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000927void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
928 VisitOMPExecutableDirective(S);
Alexey Bataev3b1b8952017-07-25 15:53:26 +0000929 if (const Expr *E = S->getReductionRef())
930 VisitStmt(E);
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000931}
932
Alexey Bataev6125da92014-07-21 11:26:11 +0000933void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
934 VisitOMPExecutableDirective(S);
935}
936
Alexey Bataevc112e942020-02-28 09:52:15 -0500937void StmtProfiler::VisitOMPDepobjDirective(const OMPDepobjDirective *S) {
938 VisitOMPExecutableDirective(S);
939}
940
Alexey Bataevfcba7c32020-03-20 07:03:01 -0400941void StmtProfiler::VisitOMPScanDirective(const OMPScanDirective *S) {
942 VisitOMPExecutableDirective(S);
943}
944
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000945void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
946 VisitOMPExecutableDirective(S);
947}
948
Alexey Bataev0162e452014-07-22 10:10:35 +0000949void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
950 VisitOMPExecutableDirective(S);
951}
952
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000953void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
954 VisitOMPExecutableDirective(S);
955}
956
Michael Wong65f367f2015-07-21 13:44:28 +0000957void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
958 VisitOMPExecutableDirective(S);
959}
960
Samuel Antaodf67fc42016-01-19 19:15:56 +0000961void StmtProfiler::VisitOMPTargetEnterDataDirective(
962 const OMPTargetEnterDataDirective *S) {
963 VisitOMPExecutableDirective(S);
964}
965
Samuel Antao72590762016-01-19 20:04:50 +0000966void StmtProfiler::VisitOMPTargetExitDataDirective(
967 const OMPTargetExitDataDirective *S) {
968 VisitOMPExecutableDirective(S);
969}
970
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000971void StmtProfiler::VisitOMPTargetParallelDirective(
972 const OMPTargetParallelDirective *S) {
973 VisitOMPExecutableDirective(S);
974}
975
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000976void StmtProfiler::VisitOMPTargetParallelForDirective(
977 const OMPTargetParallelForDirective *S) {
978 VisitOMPExecutableDirective(S);
979}
980
Alexey Bataev13314bf2014-10-09 04:18:56 +0000981void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
982 VisitOMPExecutableDirective(S);
983}
984
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000985void StmtProfiler::VisitOMPCancellationPointDirective(
986 const OMPCancellationPointDirective *S) {
987 VisitOMPExecutableDirective(S);
988}
989
Alexey Bataev80909872015-07-02 11:25:17 +0000990void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
991 VisitOMPExecutableDirective(S);
992}
993
Alexey Bataev49f6e782015-12-01 04:18:41 +0000994void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
995 VisitOMPLoopDirective(S);
996}
997
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000998void StmtProfiler::VisitOMPTaskLoopSimdDirective(
999 const OMPTaskLoopSimdDirective *S) {
1000 VisitOMPLoopDirective(S);
1001}
1002
Alexey Bataev60e51c42019-10-10 20:13:02 +00001003void StmtProfiler::VisitOMPMasterTaskLoopDirective(
1004 const OMPMasterTaskLoopDirective *S) {
1005 VisitOMPLoopDirective(S);
1006}
1007
Alexey Bataevb8552ab2019-10-18 16:47:35 +00001008void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective(
1009 const OMPMasterTaskLoopSimdDirective *S) {
1010 VisitOMPLoopDirective(S);
1011}
1012
Alexey Bataev5bbcead2019-10-14 17:17:41 +00001013void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective(
1014 const OMPParallelMasterTaskLoopDirective *S) {
1015 VisitOMPLoopDirective(S);
1016}
1017
Alexey Bataev14a388f2019-10-25 10:27:13 -04001018void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective(
1019 const OMPParallelMasterTaskLoopSimdDirective *S) {
1020 VisitOMPLoopDirective(S);
1021}
1022
Carlo Bertolli6200a3d2015-12-14 14:51:25 +00001023void StmtProfiler::VisitOMPDistributeDirective(
1024 const OMPDistributeDirective *S) {
1025 VisitOMPLoopDirective(S);
1026}
1027
Carlo Bertollib4adf552016-01-15 18:50:31 +00001028void OMPClauseProfiler::VisitOMPDistScheduleClause(
1029 const OMPDistScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +00001030 VistOMPClauseWithPreInit(C);
1031 if (auto *S = C->getChunkSize())
1032 Profiler->VisitStmt(S);
Carlo Bertollib4adf552016-01-15 18:50:31 +00001033}
1034
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +00001035void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
1036
Samuel Antao686c70c2016-05-26 17:30:50 +00001037void StmtProfiler::VisitOMPTargetUpdateDirective(
1038 const OMPTargetUpdateDirective *S) {
1039 VisitOMPExecutableDirective(S);
1040}
1041
Carlo Bertolli9925f152016-06-27 14:55:37 +00001042void StmtProfiler::VisitOMPDistributeParallelForDirective(
1043 const OMPDistributeParallelForDirective *S) {
1044 VisitOMPLoopDirective(S);
1045}
1046
Kelvin Li4a39add2016-07-05 05:00:15 +00001047void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
1048 const OMPDistributeParallelForSimdDirective *S) {
1049 VisitOMPLoopDirective(S);
1050}
1051
Kelvin Li787f3fc2016-07-06 04:45:38 +00001052void StmtProfiler::VisitOMPDistributeSimdDirective(
1053 const OMPDistributeSimdDirective *S) {
1054 VisitOMPLoopDirective(S);
1055}
1056
Kelvin Lia579b912016-07-14 02:54:56 +00001057void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
1058 const OMPTargetParallelForSimdDirective *S) {
1059 VisitOMPLoopDirective(S);
1060}
1061
Kelvin Li986330c2016-07-20 22:57:10 +00001062void StmtProfiler::VisitOMPTargetSimdDirective(
1063 const OMPTargetSimdDirective *S) {
1064 VisitOMPLoopDirective(S);
1065}
1066
Kelvin Li02532872016-08-05 14:37:37 +00001067void StmtProfiler::VisitOMPTeamsDistributeDirective(
1068 const OMPTeamsDistributeDirective *S) {
1069 VisitOMPLoopDirective(S);
1070}
1071
Kelvin Li4e325f72016-10-25 12:50:55 +00001072void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
1073 const OMPTeamsDistributeSimdDirective *S) {
1074 VisitOMPLoopDirective(S);
1075}
1076
Kelvin Li579e41c2016-11-30 23:51:03 +00001077void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
1078 const OMPTeamsDistributeParallelForSimdDirective *S) {
1079 VisitOMPLoopDirective(S);
1080}
1081
Kelvin Li7ade93f2016-12-09 03:24:30 +00001082void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
1083 const OMPTeamsDistributeParallelForDirective *S) {
1084 VisitOMPLoopDirective(S);
1085}
1086
Kelvin Libf594a52016-12-17 05:48:59 +00001087void StmtProfiler::VisitOMPTargetTeamsDirective(
1088 const OMPTargetTeamsDirective *S) {
1089 VisitOMPExecutableDirective(S);
1090}
1091
Kelvin Li83c451e2016-12-25 04:52:54 +00001092void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
1093 const OMPTargetTeamsDistributeDirective *S) {
1094 VisitOMPLoopDirective(S);
1095}
1096
Kelvin Li80e8f562016-12-29 22:16:30 +00001097void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
1098 const OMPTargetTeamsDistributeParallelForDirective *S) {
1099 VisitOMPLoopDirective(S);
1100}
1101
Kelvin Li1851df52017-01-03 05:23:48 +00001102void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1103 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
1104 VisitOMPLoopDirective(S);
1105}
1106
Kelvin Lida681182017-01-10 18:08:18 +00001107void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
1108 const OMPTargetTeamsDistributeSimdDirective *S) {
1109 VisitOMPLoopDirective(S);
1110}
1111
Chandler Carruth631abd92011-06-16 06:47:06 +00001112void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001113 VisitStmt(S);
1114}
1115
Bill Wendling7c44da22018-10-31 03:48:47 +00001116void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1117 VisitExpr(S);
1118}
1119
Chandler Carruth631abd92011-06-16 06:47:06 +00001120void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001121 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001122 if (!Canonical)
1123 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001124 VisitDecl(S->getDecl());
Richard Trieu4d06bef2018-02-13 19:53:40 +00001125 if (!Canonical) {
1126 ID.AddBoolean(S->hasExplicitTemplateArgs());
1127 if (S->hasExplicitTemplateArgs())
1128 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1129 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001130}
1131
Chandler Carruth631abd92011-06-16 06:47:06 +00001132void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001133 VisitExpr(S);
Bruno Ricci17ff0262018-10-27 19:21:19 +00001134 ID.AddInteger(S->getIdentKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001135}
1136
Chandler Carruth631abd92011-06-16 06:47:06 +00001137void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001138 VisitExpr(S);
1139 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +00001140 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001141}
1142
Leonard Chandb01c3a2018-06-20 17:19:40 +00001143void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1144 VisitExpr(S);
1145 S->getValue().Profile(ID);
1146 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1147}
1148
Chandler Carruth631abd92011-06-16 06:47:06 +00001149void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001150 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +00001151 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001152 ID.AddInteger(S->getValue());
1153}
1154
Chandler Carruth631abd92011-06-16 06:47:06 +00001155void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001156 VisitExpr(S);
1157 S->getValue().Profile(ID);
1158 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +00001159 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001160}
1161
Chandler Carruth631abd92011-06-16 06:47:06 +00001162void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001163 VisitExpr(S);
1164}
1165
Chandler Carruth631abd92011-06-16 06:47:06 +00001166void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001167 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +00001168 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +00001169 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001170}
1171
Chandler Carruth631abd92011-06-16 06:47:06 +00001172void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001173 VisitExpr(S);
1174}
1175
Chandler Carruth631abd92011-06-16 06:47:06 +00001176void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +00001177 VisitExpr(S);
1178}
1179
Chandler Carruth631abd92011-06-16 06:47:06 +00001180void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001181 VisitExpr(S);
1182 ID.AddInteger(S->getOpcode());
1183}
1184
Chandler Carruth631abd92011-06-16 06:47:06 +00001185void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001186 VisitType(S->getTypeSourceInfo()->getType());
1187 unsigned n = S->getNumComponents();
1188 for (unsigned i = 0; i < n; ++i) {
James Y Knight7281c352015-12-29 22:31:18 +00001189 const OffsetOfNode &ON = S->getComponent(i);
Douglas Gregor882211c2010-04-28 22:16:22 +00001190 ID.AddInteger(ON.getKind());
1191 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00001192 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +00001193 // Expressions handled below.
1194 break;
1195
James Y Knight7281c352015-12-29 22:31:18 +00001196 case OffsetOfNode::Field:
Douglas Gregor882211c2010-04-28 22:16:22 +00001197 VisitDecl(ON.getField());
1198 break;
1199
James Y Knight7281c352015-12-29 22:31:18 +00001200 case OffsetOfNode::Identifier:
Richard Trieu639d7b62017-02-22 22:22:42 +00001201 VisitIdentifierInfo(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +00001202 break;
James Y Knight7281c352015-12-29 22:31:18 +00001203
1204 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00001205 // These nodes are implicit, and therefore don't need profiling.
1206 break;
Douglas Gregor882211c2010-04-28 22:16:22 +00001207 }
1208 }
Richard Trieu639d7b62017-02-22 22:22:42 +00001209
Douglas Gregor882211c2010-04-28 22:16:22 +00001210 VisitExpr(S);
1211}
1212
Chandler Carruth631abd92011-06-16 06:47:06 +00001213void
1214StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001215 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001216 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001217 if (S->isArgumentType())
1218 VisitType(S->getArgumentType());
1219}
1220
Chandler Carruth631abd92011-06-16 06:47:06 +00001221void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001222 VisitExpr(S);
1223}
1224
Florian Hahn8f3f88d2020-06-01 19:42:03 +01001225void StmtProfiler::VisitMatrixSubscriptExpr(const MatrixSubscriptExpr *S) {
1226 VisitExpr(S);
1227}
1228
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001229void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1230 VisitExpr(S);
1231}
1232
Alexey Bataev7ac9efb2020-02-05 09:33:05 -05001233void StmtProfiler::VisitOMPArrayShapingExpr(const OMPArrayShapingExpr *S) {
1234 VisitExpr(S);
1235}
1236
Alexey Bataev13a15042020-04-01 15:06:38 -04001237void StmtProfiler::VisitOMPIteratorExpr(const OMPIteratorExpr *S) {
1238 VisitExpr(S);
1239 for (unsigned I = 0, E = S->numOfIterators(); I < E; ++I)
1240 VisitDecl(S->getIteratorDecl(I));
1241}
1242
Chandler Carruth631abd92011-06-16 06:47:06 +00001243void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001244 VisitExpr(S);
1245}
1246
Chandler Carruth631abd92011-06-16 06:47:06 +00001247void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001248 VisitExpr(S);
1249 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001250 if (!Canonical)
1251 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001252 ID.AddBoolean(S->isArrow());
1253}
1254
Chandler Carruth631abd92011-06-16 06:47:06 +00001255void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001256 VisitExpr(S);
1257 ID.AddBoolean(S->isFileScope());
1258}
1259
Chandler Carruth631abd92011-06-16 06:47:06 +00001260void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001261 VisitExpr(S);
1262}
1263
Chandler Carruth631abd92011-06-16 06:47:06 +00001264void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001265 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +00001266 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001267}
1268
Chandler Carruth631abd92011-06-16 06:47:06 +00001269void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001270 VisitCastExpr(S);
1271 VisitType(S->getTypeAsWritten());
1272}
1273
Chandler Carruth631abd92011-06-16 06:47:06 +00001274void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001275 VisitExplicitCastExpr(S);
1276}
1277
Chandler Carruth631abd92011-06-16 06:47:06 +00001278void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001279 VisitExpr(S);
1280 ID.AddInteger(S->getOpcode());
1281}
1282
Chandler Carruth631abd92011-06-16 06:47:06 +00001283void
1284StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001285 VisitBinaryOperator(S);
1286}
1287
Chandler Carruth631abd92011-06-16 06:47:06 +00001288void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001289 VisitExpr(S);
1290}
1291
Chandler Carruth631abd92011-06-16 06:47:06 +00001292void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +00001293 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +00001294 VisitExpr(S);
1295}
1296
Chandler Carruth631abd92011-06-16 06:47:06 +00001297void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001298 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001299 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001300}
1301
Chandler Carruth631abd92011-06-16 06:47:06 +00001302void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001303 VisitExpr(S);
1304}
1305
Chandler Carruth631abd92011-06-16 06:47:06 +00001306void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001307 VisitExpr(S);
1308}
1309
Hal Finkelc4d7c822013-09-18 03:29:45 +00001310void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1311 VisitExpr(S);
1312}
1313
Chandler Carruth631abd92011-06-16 06:47:06 +00001314void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001315 VisitExpr(S);
1316}
1317
Chandler Carruth631abd92011-06-16 06:47:06 +00001318void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001319 VisitExpr(S);
1320}
1321
Chandler Carruth631abd92011-06-16 06:47:06 +00001322void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001323 VisitExpr(S);
1324}
1325
Chandler Carruth631abd92011-06-16 06:47:06 +00001326void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001327 if (S->getSyntacticForm()) {
1328 VisitInitListExpr(S->getSyntacticForm());
1329 return;
1330 }
Mike Stump11289f42009-09-09 15:08:12 +00001331
Douglas Gregor5c193b92009-07-28 00:33:38 +00001332 VisitExpr(S);
1333}
1334
Chandler Carruth631abd92011-06-16 06:47:06 +00001335void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001336 VisitExpr(S);
1337 ID.AddBoolean(S->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +00001338 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1339 if (D.isFieldDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001340 ID.AddInteger(0);
David Majnemerf7e36092016-06-23 00:15:04 +00001341 VisitName(D.getFieldName());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001342 continue;
1343 }
Mike Stump11289f42009-09-09 15:08:12 +00001344
David Majnemerf7e36092016-06-23 00:15:04 +00001345 if (D.isArrayDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001346 ID.AddInteger(1);
1347 } else {
David Majnemerf7e36092016-06-23 00:15:04 +00001348 assert(D.isArrayRangeDesignator());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001349 ID.AddInteger(2);
1350 }
David Majnemerf7e36092016-06-23 00:15:04 +00001351 ID.AddInteger(D.getFirstExprIndex());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001352 }
1353}
1354
Yunzhong Gaocb779302015-06-10 00:27:52 +00001355// Seems that if VisitInitListExpr() only works on the syntactic form of an
1356// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1357void StmtProfiler::VisitDesignatedInitUpdateExpr(
1358 const DesignatedInitUpdateExpr *S) {
1359 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1360 "initializer");
1361}
1362
Richard Smith410306b2016-12-12 02:53:20 +00001363void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1364 VisitExpr(S);
1365}
1366
1367void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1368 VisitExpr(S);
1369}
1370
Yunzhong Gaocb779302015-06-10 00:27:52 +00001371void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1372 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1373}
1374
Chandler Carruth631abd92011-06-16 06:47:06 +00001375void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001376 VisitExpr(S);
1377}
1378
Chandler Carruth631abd92011-06-16 06:47:06 +00001379void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001380 VisitExpr(S);
1381 VisitName(&S->getAccessor());
1382}
1383
Chandler Carruth631abd92011-06-16 06:47:06 +00001384void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001385 VisitExpr(S);
1386 VisitDecl(S->getBlockDecl());
1387}
1388
Chandler Carruth631abd92011-06-16 06:47:06 +00001389void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001390 VisitExpr(S);
Mark de Wever21490282019-11-12 20:46:19 +01001391 for (const GenericSelectionExpr::ConstAssociation Assoc :
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00001392 S->associations()) {
1393 QualType T = Assoc.getType();
Peter Collingbourne91147592011-04-15 00:35:48 +00001394 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +00001395 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00001396 else
1397 VisitType(T);
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00001398 VisitExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00001399 }
1400}
1401
John McCallfe96e0b2011-11-06 09:01:30 +00001402void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1403 VisitExpr(S);
1404 for (PseudoObjectExpr::const_semantics_iterator
1405 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1406 // Normally, we would not profile the source expressions of OVEs.
1407 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1408 Visit(OVE->getSourceExpr());
1409}
1410
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001411void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1412 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +00001413 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001414}
1415
Saar Raz5d98ba62019-10-15 15:24:26 +00001416void StmtProfiler::VisitConceptSpecializationExpr(
1417 const ConceptSpecializationExpr *S) {
1418 VisitExpr(S);
Saar Raz8a344672020-01-16 13:35:20 +02001419 VisitDecl(S->getNamedConcept());
1420 for (const TemplateArgument &Arg : S->getTemplateArguments())
1421 VisitTemplateArgument(Arg);
Saar Raz5d98ba62019-10-15 15:24:26 +00001422}
1423
Saar Raza0f50d72020-01-18 09:11:43 +02001424void StmtProfiler::VisitRequiresExpr(const RequiresExpr *S) {
1425 VisitExpr(S);
1426 ID.AddInteger(S->getLocalParameters().size());
1427 for (ParmVarDecl *LocalParam : S->getLocalParameters())
1428 VisitDecl(LocalParam);
1429 ID.AddInteger(S->getRequirements().size());
1430 for (concepts::Requirement *Req : S->getRequirements()) {
1431 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
1432 ID.AddInteger(concepts::Requirement::RK_Type);
1433 ID.AddBoolean(TypeReq->isSubstitutionFailure());
1434 if (!TypeReq->isSubstitutionFailure())
1435 VisitType(TypeReq->getType()->getType());
1436 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
1437 ID.AddInteger(concepts::Requirement::RK_Compound);
1438 ID.AddBoolean(ExprReq->isExprSubstitutionFailure());
1439 if (!ExprReq->isExprSubstitutionFailure())
1440 Visit(ExprReq->getExpr());
1441 // C++2a [expr.prim.req.compound]p1 Example:
1442 // [...] The compound-requirement in C1 requires that x++ is a valid
1443 // expression. It is equivalent to the simple-requirement x++; [...]
1444 // We therefore do not profile isSimple() here.
1445 ID.AddBoolean(ExprReq->getNoexceptLoc().isValid());
1446 const concepts::ExprRequirement::ReturnTypeRequirement &RetReq =
1447 ExprReq->getReturnTypeRequirement();
1448 if (RetReq.isEmpty()) {
1449 ID.AddInteger(0);
1450 } else if (RetReq.isTypeConstraint()) {
1451 ID.AddInteger(1);
1452 Visit(RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint());
1453 } else {
1454 assert(RetReq.isSubstitutionFailure());
1455 ID.AddInteger(2);
1456 }
1457 } else {
1458 ID.AddInteger(concepts::Requirement::RK_Nested);
1459 auto *NestedReq = cast<concepts::NestedRequirement>(Req);
1460 ID.AddBoolean(NestedReq->isSubstitutionFailure());
Jim Lin466f8842020-02-18 10:48:38 +08001461 if (!NestedReq->isSubstitutionFailure())
Saar Raza0f50d72020-01-18 09:11:43 +02001462 Visit(NestedReq->getConstraintExpr());
1463 }
1464 }
1465}
1466
Chandler Carruth631abd92011-06-16 06:47:06 +00001467static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +00001468 UnaryOperatorKind &UnaryOp,
1469 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001470 switch (S->getOperator()) {
1471 case OO_None:
1472 case OO_New:
1473 case OO_Delete:
1474 case OO_Array_New:
1475 case OO_Array_Delete:
1476 case OO_Arrow:
Douglas Gregore9ceb312010-05-19 04:13:23 +00001477 case OO_Conditional:
1478 case NUM_OVERLOADED_OPERATORS:
1479 llvm_unreachable("Invalid operator call kind");
Fangrui Song6907ce22018-07-30 19:24:48 +00001480
Douglas Gregore9ceb312010-05-19 04:13:23 +00001481 case OO_Plus:
1482 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001483 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001484 return Stmt::UnaryOperatorClass;
1485 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001486
John McCalle3027922010-08-25 11:45:40 +00001487 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001488 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001489
Douglas Gregore9ceb312010-05-19 04:13:23 +00001490 case OO_Minus:
1491 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001492 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001493 return Stmt::UnaryOperatorClass;
1494 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001495
John McCalle3027922010-08-25 11:45:40 +00001496 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001497 return Stmt::BinaryOperatorClass;
1498
1499 case OO_Star:
1500 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +00001501 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001502 return Stmt::UnaryOperatorClass;
1503 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001504
Richard Smithf15acc52014-06-05 22:43:40 +00001505 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001506 return Stmt::BinaryOperatorClass;
1507
1508 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +00001509 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001510 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001511
Douglas Gregore9ceb312010-05-19 04:13:23 +00001512 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +00001513 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001514 return Stmt::BinaryOperatorClass;
1515
1516 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +00001517 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001518 return Stmt::BinaryOperatorClass;
1519
1520 case OO_Amp:
1521 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001522 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001523 return Stmt::UnaryOperatorClass;
1524 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001525
John McCalle3027922010-08-25 11:45:40 +00001526 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001527 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001528
Douglas Gregore9ceb312010-05-19 04:13:23 +00001529 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +00001530 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001531 return Stmt::BinaryOperatorClass;
1532
1533 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +00001534 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001535 return Stmt::UnaryOperatorClass;
1536
1537 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +00001538 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001539 return Stmt::UnaryOperatorClass;
1540
1541 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +00001542 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001543 return Stmt::BinaryOperatorClass;
1544
1545 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +00001546 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001547 return Stmt::BinaryOperatorClass;
1548
1549 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +00001550 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001551 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001552
Douglas Gregore9ceb312010-05-19 04:13:23 +00001553 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +00001554 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001555 return Stmt::CompoundAssignOperatorClass;
1556
1557 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +00001558 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001559 return Stmt::CompoundAssignOperatorClass;
1560
1561 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +00001562 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001563 return Stmt::CompoundAssignOperatorClass;
1564
1565 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +00001566 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001567 return Stmt::CompoundAssignOperatorClass;
1568
1569 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +00001570 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001571 return Stmt::CompoundAssignOperatorClass;
1572
1573 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +00001574 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001575 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001576
Douglas Gregore9ceb312010-05-19 04:13:23 +00001577 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +00001578 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001579 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001580
Douglas Gregore9ceb312010-05-19 04:13:23 +00001581 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +00001582 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001583 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001584
Douglas Gregore9ceb312010-05-19 04:13:23 +00001585 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +00001586 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001587 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001588
Douglas Gregore9ceb312010-05-19 04:13:23 +00001589 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +00001590 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001591 return Stmt::BinaryOperatorClass;
1592
1593 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +00001594 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001595 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001596
Douglas Gregore9ceb312010-05-19 04:13:23 +00001597 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001598 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001599 return Stmt::CompoundAssignOperatorClass;
1600
1601 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +00001602 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001603 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001604
Douglas Gregore9ceb312010-05-19 04:13:23 +00001605 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001606 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001607 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001608
Douglas Gregore9ceb312010-05-19 04:13:23 +00001609 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001610 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001611 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001612
Douglas Gregore9ceb312010-05-19 04:13:23 +00001613 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001614 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001615 return Stmt::BinaryOperatorClass;
Richard Smithd30b23d2017-12-01 02:13:10 +00001616
1617 case OO_Spaceship:
Richard Smithb96c6b62020-02-04 18:28:36 -08001618 BinaryOp = BO_Cmp;
1619 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001620
Douglas Gregore9ceb312010-05-19 04:13:23 +00001621 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001622 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001623 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001624
Douglas Gregore9ceb312010-05-19 04:13:23 +00001625 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001626 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001627 return Stmt::BinaryOperatorClass;
1628
1629 case OO_PlusPlus:
Fangrui Song6907ce22018-07-30 19:24:48 +00001630 UnaryOp = S->getNumArgs() == 1? UO_PreInc
John McCalle3027922010-08-25 11:45:40 +00001631 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001632 return Stmt::UnaryOperatorClass;
1633
1634 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001635 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1636 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001637 return Stmt::UnaryOperatorClass;
1638
1639 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001640 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001641 return Stmt::BinaryOperatorClass;
1642
Douglas Gregore9ceb312010-05-19 04:13:23 +00001643 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001644 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001645 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001646
Douglas Gregore9ceb312010-05-19 04:13:23 +00001647 case OO_Subscript:
1648 return Stmt::ArraySubscriptExprClass;
Richard Smith6fff5c42018-07-31 00:47:41 +00001649
Sam McCall1d579f52020-05-18 17:22:59 +02001650 case OO_Call:
1651 return Stmt::CallExprClass;
1652
Richard Smith6fff5c42018-07-31 00:47:41 +00001653 case OO_Coawait:
1654 UnaryOp = UO_Coawait;
1655 return Stmt::UnaryOperatorClass;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001656 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001657
Douglas Gregore9ceb312010-05-19 04:13:23 +00001658 llvm_unreachable("Invalid overloaded operator expression");
1659}
Richard Smithf15acc52014-06-05 22:43:40 +00001660
Reid Klecknere257e182017-10-13 16:18:32 +00001661#if defined(_MSC_VER) && !defined(__clang__)
Nico Weberf56f4462017-07-24 16:54:11 +00001662#if _MSC_VER == 1911
1663// Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1664// MSVC 2017 update 3 miscompiles this function, and a clang built with it
1665// will crash in stage 2 of a bootstrap build.
1666#pragma optimize("", off)
1667#endif
1668#endif
1669
Chandler Carruth631abd92011-06-16 06:47:06 +00001670void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001671 if (S->isTypeDependent()) {
1672 // Type-dependent operator calls are profiled like their underlying
1673 // syntactic operator.
Richard Smithbac0a0d2016-10-24 18:47:04 +00001674 //
1675 // An operator call to operator-> is always implicit, so just skip it. The
1676 // enclosing MemberExpr will profile the actual member access.
1677 if (S->getOperator() == OO_Arrow)
1678 return Visit(S->getArg(0));
1679
John McCalle3027922010-08-25 11:45:40 +00001680 UnaryOperatorKind UnaryOp = UO_Extension;
1681 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001682 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001683
Douglas Gregore9ceb312010-05-19 04:13:23 +00001684 ID.AddInteger(SC);
1685 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1686 Visit(S->getArg(I));
1687 if (SC == Stmt::UnaryOperatorClass)
1688 ID.AddInteger(UnaryOp);
Fangrui Song6907ce22018-07-30 19:24:48 +00001689 else if (SC == Stmt::BinaryOperatorClass ||
Douglas Gregore9ceb312010-05-19 04:13:23 +00001690 SC == Stmt::CompoundAssignOperatorClass)
1691 ID.AddInteger(BinaryOp);
1692 else
Sam McCall1d579f52020-05-18 17:22:59 +02001693 assert(SC == Stmt::ArraySubscriptExprClass || SC == Stmt::CallExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001694
Douglas Gregore9ceb312010-05-19 04:13:23 +00001695 return;
1696 }
Richard Smithf15acc52014-06-05 22:43:40 +00001697
Douglas Gregor5c193b92009-07-28 00:33:38 +00001698 VisitCallExpr(S);
1699 ID.AddInteger(S->getOperator());
1700}
1701
Richard Smith778dc0f2019-10-19 00:04:38 +00001702void StmtProfiler::VisitCXXRewrittenBinaryOperator(
1703 const CXXRewrittenBinaryOperator *S) {
1704 // If a rewritten operator were ever to be type-dependent, we should profile
1705 // it following its syntactic operator.
1706 assert(!S->isTypeDependent() &&
1707 "resolved rewritten operator should never be type-dependent");
1708 ID.AddBoolean(S->isReversed());
1709 VisitExpr(S->getSemanticForm());
1710}
1711
Reid Klecknere257e182017-10-13 16:18:32 +00001712#if defined(_MSC_VER) && !defined(__clang__)
Nico Weberf56f4462017-07-24 16:54:11 +00001713#if _MSC_VER == 1911
1714#pragma optimize("", on)
1715#endif
1716#endif
1717
Chandler Carruth631abd92011-06-16 06:47:06 +00001718void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001719 VisitCallExpr(S);
1720}
1721
Chandler Carruth631abd92011-06-16 06:47:06 +00001722void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001723 VisitCallExpr(S);
1724}
1725
Chandler Carruth631abd92011-06-16 06:47:06 +00001726void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001727 VisitExpr(S);
1728}
1729
Chandler Carruth631abd92011-06-16 06:47:06 +00001730void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001731 VisitExplicitCastExpr(S);
1732}
1733
Chandler Carruth631abd92011-06-16 06:47:06 +00001734void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001735 VisitCXXNamedCastExpr(S);
1736}
1737
Chandler Carruth631abd92011-06-16 06:47:06 +00001738void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001739 VisitCXXNamedCastExpr(S);
1740}
1741
Chandler Carruth631abd92011-06-16 06:47:06 +00001742void
1743StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001744 VisitCXXNamedCastExpr(S);
1745}
1746
Chandler Carruth631abd92011-06-16 06:47:06 +00001747void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001748 VisitCXXNamedCastExpr(S);
1749}
1750
Erik Pilkingtoneee944e2019-07-02 18:28:13 +00001751void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
1752 VisitExpr(S);
1753 VisitType(S->getTypeInfoAsWritten()->getType());
1754}
1755
Anastasia Stulovaa6a237f2020-05-18 11:02:01 +01001756void StmtProfiler::VisitCXXAddrspaceCastExpr(const CXXAddrspaceCastExpr *S) {
1757 VisitCXXNamedCastExpr(S);
1758}
1759
Richard Smithc67fdd42012-03-07 08:35:16 +00001760void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1761 VisitCallExpr(S);
1762}
1763
Chandler Carruth631abd92011-06-16 06:47:06 +00001764void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001765 VisitExpr(S);
1766 ID.AddBoolean(S->getValue());
1767}
1768
Chandler Carruth631abd92011-06-16 06:47:06 +00001769void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001770 VisitExpr(S);
1771}
1772
Richard Smithcc1b96d2013-06-12 22:31:48 +00001773void StmtProfiler::VisitCXXStdInitializerListExpr(
1774 const CXXStdInitializerListExpr *S) {
1775 VisitExpr(S);
1776}
1777
Chandler Carruth631abd92011-06-16 06:47:06 +00001778void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001779 VisitExpr(S);
1780 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001781 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001782}
1783
Chandler Carruth631abd92011-06-16 06:47:06 +00001784void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001785 VisitExpr(S);
1786 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001787 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001788}
1789
John McCall5e77d762013-04-16 07:28:30 +00001790void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1791 VisitExpr(S);
1792 VisitDecl(S->getPropertyDecl());
1793}
1794
Alexey Bataevf7630272015-11-25 12:01:00 +00001795void StmtProfiler::VisitMSPropertySubscriptExpr(
1796 const MSPropertySubscriptExpr *S) {
1797 VisitExpr(S);
1798}
1799
Chandler Carruth631abd92011-06-16 06:47:06 +00001800void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001801 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001802 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001803}
1804
Chandler Carruth631abd92011-06-16 06:47:06 +00001805void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001806 VisitExpr(S);
1807}
1808
Chandler Carruth631abd92011-06-16 06:47:06 +00001809void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001810 VisitExpr(S);
1811 VisitDecl(S->getParam());
1812}
1813
Richard Smith852c9db2013-04-20 22:23:05 +00001814void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1815 VisitExpr(S);
1816 VisitDecl(S->getField());
1817}
1818
Chandler Carruth631abd92011-06-16 06:47:06 +00001819void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001820 VisitExpr(S);
1821 VisitDecl(
1822 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1823}
1824
Chandler Carruth631abd92011-06-16 06:47:06 +00001825void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001826 VisitExpr(S);
1827 VisitDecl(S->getConstructor());
1828 ID.AddBoolean(S->isElidable());
1829}
1830
Richard Smith5179eb72016-06-28 19:03:57 +00001831void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1832 const CXXInheritedCtorInitExpr *S) {
1833 VisitExpr(S);
1834 VisitDecl(S->getConstructor());
1835}
1836
Chandler Carruth631abd92011-06-16 06:47:06 +00001837void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001838 VisitExplicitCastExpr(S);
1839}
1840
Chandler Carruth631abd92011-06-16 06:47:06 +00001841void
1842StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001843 VisitCXXConstructExpr(S);
1844}
1845
Chandler Carruth631abd92011-06-16 06:47:06 +00001846void
Douglas Gregore31e6062012-02-07 10:09:13 +00001847StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1848 VisitExpr(S);
1849 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1850 CEnd = S->explicit_capture_end();
1851 C != CEnd; ++C) {
Richard Trieu931638e2017-11-11 00:54:25 +00001852 if (C->capturesVLAType())
1853 continue;
1854
Douglas Gregore31e6062012-02-07 10:09:13 +00001855 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001856 switch (C->getCaptureKind()) {
Faisal Validc6b5962016-03-21 09:25:37 +00001857 case LCK_StarThis:
Richard Smithba71c082013-05-16 06:20:58 +00001858 case LCK_This:
1859 break;
1860 case LCK_ByRef:
1861 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001862 VisitDecl(C->getCapturedVar());
1863 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001864 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001865 case LCK_VLAType:
1866 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001867 }
1868 }
1869 // Note: If we actually needed to be able to match lambda
1870 // expressions, we would have to consider parameters and return type
1871 // here, among other things.
1872 VisitStmt(S->getBody());
1873}
1874
1875void
Chandler Carruth631abd92011-06-16 06:47:06 +00001876StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001877 VisitExpr(S);
1878}
1879
Chandler Carruth631abd92011-06-16 06:47:06 +00001880void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001881 VisitExpr(S);
1882 ID.AddBoolean(S->isGlobalDelete());
1883 ID.AddBoolean(S->isArrayForm());
1884 VisitDecl(S->getOperatorDelete());
1885}
1886
Chandler Carruth631abd92011-06-16 06:47:06 +00001887void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001888 VisitExpr(S);
1889 VisitType(S->getAllocatedType());
1890 VisitDecl(S->getOperatorNew());
1891 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001892 ID.AddBoolean(S->isArray());
1893 ID.AddInteger(S->getNumPlacementArgs());
1894 ID.AddBoolean(S->isGlobalNew());
1895 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001896 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001897}
1898
Chandler Carruth631abd92011-06-16 06:47:06 +00001899void
1900StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001901 VisitExpr(S);
1902 ID.AddBoolean(S->isArrow());
1903 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001904 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001905 if (S->getScopeTypeInfo())
1906 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001907 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001908 if (S->getDestroyedTypeInfo())
1909 VisitType(S->getDestroyedType());
1910 else
Richard Trieu639d7b62017-02-22 22:22:42 +00001911 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001912}
1913
Chandler Carruth631abd92011-06-16 06:47:06 +00001914void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001915 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001916 VisitNestedNameSpecifier(S->getQualifier());
Richard Trieuf65efae2018-02-22 05:32:25 +00001917 VisitName(S->getName(), /*TreatAsDecl*/ true);
John McCalle66edc12009-11-24 19:00:30 +00001918 ID.AddBoolean(S->hasExplicitTemplateArgs());
1919 if (S->hasExplicitTemplateArgs())
James Y Knight04ec5bf2015-12-24 02:59:37 +00001920 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001921}
1922
1923void
Chandler Carruth631abd92011-06-16 06:47:06 +00001924StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001925 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001926}
1927
Douglas Gregor29c42f22012-02-24 07:38:34 +00001928void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1929 VisitExpr(S);
1930 ID.AddInteger(S->getTrait());
1931 ID.AddInteger(S->getNumArgs());
1932 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1933 VisitType(S->getArg(I)->getType());
1934}
1935
Chandler Carruth631abd92011-06-16 06:47:06 +00001936void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001937 VisitExpr(S);
1938 ID.AddInteger(S->getTrait());
1939 VisitType(S->getQueriedType());
1940}
1941
Chandler Carruth631abd92011-06-16 06:47:06 +00001942void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001943 VisitExpr(S);
1944 ID.AddInteger(S->getTrait());
1945 VisitExpr(S->getQueriedExpression());
1946}
1947
Chandler Carruth631abd92011-06-16 06:47:06 +00001948void StmtProfiler::VisitDependentScopeDeclRefExpr(
1949 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001950 VisitExpr(S);
1951 VisitName(S->getDeclName());
1952 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001953 ID.AddBoolean(S->hasExplicitTemplateArgs());
1954 if (S->hasExplicitTemplateArgs())
1955 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001956}
1957
Chandler Carruth631abd92011-06-16 06:47:06 +00001958void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001959 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001960}
1961
Chandler Carruth631abd92011-06-16 06:47:06 +00001962void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1963 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001964 VisitExpr(S);
1965 VisitType(S->getTypeAsWritten());
Richard Smith39eca9b2017-08-23 22:12:08 +00001966 ID.AddInteger(S->isListInitialization());
Douglas Gregora7095092009-07-28 14:44:31 +00001967}
1968
Chandler Carruth631abd92011-06-16 06:47:06 +00001969void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1970 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001971 ID.AddBoolean(S->isImplicitAccess());
1972 if (!S->isImplicitAccess()) {
1973 VisitExpr(S);
1974 ID.AddBoolean(S->isArrow());
1975 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001976 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001977 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001978 ID.AddBoolean(S->hasExplicitTemplateArgs());
1979 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001980 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1981}
1982
Chandler Carruth631abd92011-06-16 06:47:06 +00001983void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001984 ID.AddBoolean(S->isImplicitAccess());
1985 if (!S->isImplicitAccess()) {
1986 VisitExpr(S);
1987 ID.AddBoolean(S->isArrow());
1988 }
John McCall10eae182009-11-30 22:42:35 +00001989 VisitNestedNameSpecifier(S->getQualifier());
1990 VisitName(S->getMemberName());
1991 ID.AddBoolean(S->hasExplicitTemplateArgs());
1992 if (S->hasExplicitTemplateArgs())
1993 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001994}
1995
Chandler Carruth631abd92011-06-16 06:47:06 +00001996void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001997 VisitExpr(S);
1998}
1999
Chandler Carruth631abd92011-06-16 06:47:06 +00002000void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00002001 VisitExpr(S);
2002}
2003
Chandler Carruth631abd92011-06-16 06:47:06 +00002004void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002005 VisitExpr(S);
2006 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00002007 if (S->isPartiallySubstituted()) {
2008 auto Args = S->getPartialArguments();
2009 ID.AddInteger(Args.size());
2010 for (const auto &TA : Args)
2011 VisitTemplateArgument(TA);
2012 } else {
2013 ID.AddInteger(0);
2014 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002015}
2016
Douglas Gregorcdbc5392011-01-15 01:15:58 +00002017void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00002018 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00002019 VisitExpr(S);
2020 VisitDecl(S->getParameterPack());
2021 VisitTemplateArgument(S->getArgumentPack());
2022}
2023
John McCall7c454bb2011-07-15 05:09:51 +00002024void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
2025 const SubstNonTypeTemplateParmExpr *E) {
2026 // Profile exactly as the replacement expression.
2027 Visit(E->getReplacement());
2028}
2029
Richard Smithb15fe3a2012-09-12 00:56:43 +00002030void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
2031 VisitExpr(S);
2032 VisitDecl(S->getParameterPack());
2033 ID.AddInteger(S->getNumExpansions());
2034 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
2035 VisitDecl(*I);
2036}
2037
Douglas Gregorfe314812011-06-21 17:03:29 +00002038void StmtProfiler::VisitMaterializeTemporaryExpr(
2039 const MaterializeTemporaryExpr *S) {
2040 VisitExpr(S);
2041}
2042
Richard Smith0f0af192014-11-08 05:07:16 +00002043void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
2044 VisitExpr(S);
2045 ID.AddInteger(S->getOperator());
2046}
2047
Richard Smith9f690bd2015-10-27 06:02:45 +00002048void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
2049 VisitStmt(S);
2050}
2051
2052void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
2053 VisitStmt(S);
2054}
2055
2056void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
2057 VisitExpr(S);
2058}
2059
Eric Fiselier20f25cb2017-03-06 23:38:15 +00002060void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
2061 VisitExpr(S);
2062}
2063
Richard Smith9f690bd2015-10-27 06:02:45 +00002064void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
2065 VisitExpr(S);
2066}
2067
Chandler Carruth631abd92011-06-16 06:47:06 +00002068void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
Fangrui Song6907ce22018-07-30 19:24:48 +00002069 VisitExpr(E);
John McCall8d69a212010-11-15 23:31:06 +00002070}
2071
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00002072void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
2073 VisitExpr(E);
2074}
2075
Eric Fiselier708afb52019-05-16 21:04:15 +00002076void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
2077 VisitExpr(E);
2078}
2079
Haojian Wu733edf92020-03-19 16:30:40 +01002080void StmtProfiler::VisitRecoveryExpr(const RecoveryExpr *E) { VisitExpr(E); }
2081
Chandler Carruth631abd92011-06-16 06:47:06 +00002082void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002083 VisitExpr(S);
2084}
2085
Patrick Beard0caa3942012-04-19 00:25:12 +00002086void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00002087 VisitExpr(E);
2088}
2089
2090void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
2091 VisitExpr(E);
2092}
2093
2094void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
2095 VisitExpr(E);
2096}
2097
Chandler Carruth631abd92011-06-16 06:47:06 +00002098void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002099 VisitExpr(S);
2100 VisitType(S->getEncodedType());
2101}
2102
Chandler Carruth631abd92011-06-16 06:47:06 +00002103void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002104 VisitExpr(S);
2105 VisitName(S->getSelector());
2106}
2107
Chandler Carruth631abd92011-06-16 06:47:06 +00002108void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002109 VisitExpr(S);
2110 VisitDecl(S->getProtocol());
2111}
2112
Chandler Carruth631abd92011-06-16 06:47:06 +00002113void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002114 VisitExpr(S);
2115 VisitDecl(S->getDecl());
2116 ID.AddBoolean(S->isArrow());
2117 ID.AddBoolean(S->isFreeIvar());
2118}
2119
Chandler Carruth631abd92011-06-16 06:47:06 +00002120void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002121 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00002122 if (S->isImplicitProperty()) {
2123 VisitDecl(S->getImplicitPropertyGetter());
2124 VisitDecl(S->getImplicitPropertySetter());
2125 } else {
2126 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002127 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002128 if (S->isSuperReceiver()) {
2129 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00002130 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002131 }
Douglas Gregora7095092009-07-28 14:44:31 +00002132}
2133
Ted Kremeneke65b0862012-03-06 20:05:56 +00002134void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
2135 VisitExpr(S);
2136 VisitDecl(S->getAtIndexMethodDecl());
2137 VisitDecl(S->setAtIndexMethodDecl());
2138}
2139
Chandler Carruth631abd92011-06-16 06:47:06 +00002140void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002141 VisitExpr(S);
2142 VisitName(S->getSelector());
2143 VisitDecl(S->getMethodDecl());
2144}
2145
Chandler Carruth631abd92011-06-16 06:47:06 +00002146void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002147 VisitExpr(S);
2148 ID.AddBoolean(S->isArrow());
2149}
2150
Ted Kremeneke65b0862012-03-06 20:05:56 +00002151void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
2152 VisitExpr(S);
2153 ID.AddBoolean(S->getValue());
2154}
2155
Chandler Carruth631abd92011-06-16 06:47:06 +00002156void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
2157 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00002158 VisitExpr(S);
2159 ID.AddBoolean(S->shouldCopy());
2160}
2161
Chandler Carruth631abd92011-06-16 06:47:06 +00002162void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00002163 VisitExplicitCastExpr(S);
2164 ID.AddBoolean(S->getBridgeKind());
2165}
2166
Erik Pilkington29099de2016-07-16 00:35:23 +00002167void StmtProfiler::VisitObjCAvailabilityCheckExpr(
2168 const ObjCAvailabilityCheckExpr *S) {
2169 VisitExpr(S);
2170}
2171
John McCall0ad16662009-10-29 08:12:44 +00002172void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00002173 unsigned NumArgs) {
2174 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00002175 for (unsigned I = 0; I != NumArgs; ++I)
2176 VisitTemplateArgument(Args[I].getArgument());
2177}
Mike Stump11289f42009-09-09 15:08:12 +00002178
John McCall0ad16662009-10-29 08:12:44 +00002179void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
2180 // Mostly repetitive with TemplateArgument::Profile!
2181 ID.AddInteger(Arg.getKind());
2182 switch (Arg.getKind()) {
2183 case TemplateArgument::Null:
2184 break;
Mike Stump11289f42009-09-09 15:08:12 +00002185
John McCall0ad16662009-10-29 08:12:44 +00002186 case TemplateArgument::Type:
2187 VisitType(Arg.getAsType());
2188 break;
Mike Stump11289f42009-09-09 15:08:12 +00002189
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002190 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002191 case TemplateArgument::TemplateExpansion:
2192 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002193 break;
Fangrui Song6907ce22018-07-30 19:24:48 +00002194
John McCall0ad16662009-10-29 08:12:44 +00002195 case TemplateArgument::Declaration:
2196 VisitDecl(Arg.getAsDecl());
2197 break;
Mike Stump11289f42009-09-09 15:08:12 +00002198
Eli Friedmanb826a002012-09-26 02:36:12 +00002199 case TemplateArgument::NullPtr:
2200 VisitType(Arg.getNullPtrType());
2201 break;
2202
John McCall0ad16662009-10-29 08:12:44 +00002203 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00002204 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00002205 VisitType(Arg.getIntegralType());
2206 break;
Mike Stump11289f42009-09-09 15:08:12 +00002207
John McCall0ad16662009-10-29 08:12:44 +00002208 case TemplateArgument::Expression:
2209 Visit(Arg.getAsExpr());
2210 break;
Mike Stump11289f42009-09-09 15:08:12 +00002211
John McCall0ad16662009-10-29 08:12:44 +00002212 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00002213 for (const auto &P : Arg.pack_elements())
2214 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00002215 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00002216 }
2217}
2218
Jay Foad39c79802011-01-12 09:06:06 +00002219void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00002220 bool Canonical) const {
Richard Trieu639d7b62017-02-22 22:22:42 +00002221 StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2222 Profiler.Visit(this);
2223}
2224
2225void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2226 class ODRHash &Hash) const {
2227 StmtProfilerWithoutPointers Profiler(ID, Hash);
Douglas Gregor5c193b92009-07-28 00:33:38 +00002228 Profiler.Visit(this);
2229}