blob: 8d43491ea8f4c2b718912352ae8603922921128b [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) { }
417#define OPENMP_CLAUSE(Name, Class) \
418 void Visit##Class(const Class *C);
419#include "clang/Basic/OpenMPKinds.def"
Alexey Bataev3392d762016-02-16 11:18:12 +0000420 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000421 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000422};
423
Alexey Bataev3392d762016-02-16 11:18:12 +0000424void OMPClauseProfiler::VistOMPClauseWithPreInit(
425 const OMPClauseWithPreInit *C) {
426 if (auto *S = C->getPreInitStmt())
427 Profiler->VisitStmt(S);
428}
429
Alexey Bataev005248a2016-02-25 05:25:57 +0000430void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
431 const OMPClauseWithPostUpdate *C) {
Alexey Bataev37e594c2016-03-04 07:21:16 +0000432 VistOMPClauseWithPreInit(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000433 if (auto *E = C->getPostUpdateExpr())
434 Profiler->VisitStmt(E);
435}
436
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000437void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
Arpith Chacko Jacobfe4890a2017-01-18 20:40:48 +0000438 VistOMPClauseWithPreInit(C);
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000439 if (C->getCondition())
440 Profiler->VisitStmt(C->getCondition());
441}
442
Alexey Bataev3778b602014-07-17 07:32:53 +0000443void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
Alexey Bataev3a842ec2019-10-15 19:37:05 +0000444 VistOMPClauseWithPreInit(C);
Alexey Bataev3778b602014-07-17 07:32:53 +0000445 if (C->getCondition())
446 Profiler->VisitStmt(C->getCondition());
447}
448
Alexey Bataev568a8332014-03-06 06:15:19 +0000449void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
Arpith Chacko Jacob33c849a2017-01-25 00:57:16 +0000450 VistOMPClauseWithPreInit(C);
Alexey Bataev568a8332014-03-06 06:15:19 +0000451 if (C->getNumThreads())
452 Profiler->VisitStmt(C->getNumThreads());
453}
454
Alexey Bataev62c87d22014-03-21 04:51:18 +0000455void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
456 if (C->getSafelen())
457 Profiler->VisitStmt(C->getSafelen());
458}
459
Alexey Bataev66b15b52015-08-21 11:14:16 +0000460void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
461 if (C->getSimdlen())
462 Profiler->VisitStmt(C->getSimdlen());
463}
464
Alexey Bataev9cc10fc2019-03-12 18:52:33 +0000465void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
466 if (C->getAllocator())
467 Profiler->VisitStmt(C->getAllocator());
468}
469
Alexander Musman8bd31e62014-05-27 15:12:19 +0000470void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
471 if (C->getNumForLoops())
472 Profiler->VisitStmt(C->getNumForLoops());
473}
474
Alexey Bataev0f0564b2020-03-17 09:17:42 -0400475void OMPClauseProfiler::VisitOMPDetachClause(const OMPDetachClause *C) {
476 if (Expr *Evt = C->getEventHandler())
477 Profiler->VisitStmt(Evt);
478}
479
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000480void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
Alexey Bataev756c1962013-09-24 03:17:45 +0000481
Alexey Bataevbcbadb62014-05-06 06:04:14 +0000482void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
483
Kelvin Li1408f912018-09-26 04:28:39 +0000484void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
485 const OMPUnifiedAddressClause *C) {}
486
Patrick Lyster4a370b92018-10-01 13:47:43 +0000487void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
488 const OMPUnifiedSharedMemoryClause *C) {}
489
Patrick Lyster6bdf63b2018-10-03 20:07:58 +0000490void OMPClauseProfiler::VisitOMPReverseOffloadClause(
491 const OMPReverseOffloadClause *C) {}
492
Patrick Lyster3fe9e392018-10-11 14:41:10 +0000493void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
494 const OMPDynamicAllocatorsClause *C) {}
495
Patrick Lyster7a2a27c2018-11-02 12:18:11 +0000496void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
497 const OMPAtomicDefaultMemOrderClause *C) {}
498
Alexey Bataev56dafe82014-06-20 07:16:17 +0000499void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000500 VistOMPClauseWithPreInit(C);
501 if (auto *S = C->getChunkSize())
502 Profiler->VisitStmt(S);
Alexey Bataev56dafe82014-06-20 07:16:17 +0000503}
504
Alexey Bataev10e775f2015-07-30 11:36:16 +0000505void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
506 if (auto *Num = C->getNumForLoops())
507 Profiler->VisitStmt(Num);
508}
Alexey Bataev142e1fc2014-06-20 09:44:06 +0000509
Alexey Bataev236070f2014-06-20 11:19:47 +0000510void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
511
Alexey Bataev7aea99a2014-07-17 12:19:31 +0000512void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
513
Alexey Bataev74ba3a52014-07-17 12:47:03 +0000514void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
515
Alexey Bataevf98b00c2014-07-23 02:27:21 +0000516void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
517
Alexey Bataevdea47612014-07-23 07:46:59 +0000518void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
519
Alexey Bataev67a4f222014-07-23 10:25:33 +0000520void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
521
Alexey Bataev459dec02014-07-24 06:46:57 +0000522void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
523
Alexey Bataev82bad8b2014-07-24 08:55:34 +0000524void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
525
Alexey Bataevea9166b2020-02-06 16:30:23 -0500526void OMPClauseProfiler::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
527
Alexey Bataev04a830f2020-02-10 14:30:39 -0500528void OMPClauseProfiler::VisitOMPAcquireClause(const OMPAcquireClause *) {}
529
Alexey Bataev95598342020-02-10 15:49:05 -0500530void OMPClauseProfiler::VisitOMPReleaseClause(const OMPReleaseClause *) {}
531
Alexey Bataev9a8defc2020-02-11 11:10:43 -0500532void OMPClauseProfiler::VisitOMPRelaxedClause(const OMPRelaxedClause *) {}
533
Alexey Bataev346265e2015-09-25 10:37:12 +0000534void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
535
Alexey Bataevd14d1e62015-09-28 06:39:35 +0000536void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
537
Alexey Bataevb825de12015-12-07 10:51:44 +0000538void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
539
Alexey Bataev375437a2020-03-02 14:21:20 -0500540void OMPClauseProfiler::VisitOMPDestroyClause(const OMPDestroyClause *) {}
541
Alexey Bataev756c1962013-09-24 03:17:45 +0000542template<typename T>
543void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
Alexey Bataev03b340a2014-10-21 03:16:40 +0000544 for (auto *E : Node->varlists()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000545 if (E)
546 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000547 }
Alexey Bataev756c1962013-09-24 03:17:45 +0000548}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000549
550void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000551 VisitOMPClauseList(C);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000552 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000553 if (E)
554 Profiler->VisitStmt(E);
Alexey Bataev03b340a2014-10-21 03:16:40 +0000555 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000556}
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000557void
558OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000559 VisitOMPClauseList(C);
Alexey Bataev417089f2016-02-17 13:19:37 +0000560 VistOMPClauseWithPreInit(C);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000561 for (auto *E : C->private_copies()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000562 if (E)
563 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000564 }
565 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000566 if (E)
567 Profiler->VisitStmt(E);
Alexey Bataev4a5bb772014-10-08 14:01:46 +0000568 }
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000569}
Alexander Musman1bb328c2014-06-04 13:06:39 +0000570void
571OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
572 VisitOMPClauseList(C);
Alexey Bataev005248a2016-02-25 05:25:57 +0000573 VistOMPClauseWithPostUpdate(C);
Alexey Bataev38e89532015-04-16 04:54:05 +0000574 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000575 if (E)
576 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000577 }
578 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000579 if (E)
580 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000581 }
582 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000583 if (E)
584 Profiler->VisitStmt(E);
Alexey Bataev38e89532015-04-16 04:54:05 +0000585 }
Alexander Musman1bb328c2014-06-04 13:06:39 +0000586}
Alexey Bataev758e55e2013-09-06 18:03:48 +0000587void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
Alexey Bataev756c1962013-09-24 03:17:45 +0000588 VisitOMPClauseList(C);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000589}
Alexey Bataevc5e02582014-06-16 07:08:35 +0000590void OMPClauseProfiler::VisitOMPReductionClause(
591 const OMPReductionClause *C) {
592 Profiler->VisitNestedNameSpecifier(
593 C->getQualifierLoc().getNestedNameSpecifier());
594 Profiler->VisitName(C->getNameInfo().getName());
595 VisitOMPClauseList(C);
Alexey Bataev61205072016-03-02 04:57:40 +0000596 VistOMPClauseWithPostUpdate(C);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000597 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000598 if (E)
599 Profiler->VisitStmt(E);
Alexey Bataevf24e7b12015-10-08 09:10:53 +0000600 }
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000601 for (auto *E : C->lhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000602 if (E)
603 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000604 }
605 for (auto *E : C->rhs_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000606 if (E)
607 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000608 }
609 for (auto *E : C->reduction_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000610 if (E)
611 Profiler->VisitStmt(E);
Alexey Bataev794ba0d2015-04-10 10:43:45 +0000612 }
Alexey Bataevc5e02582014-06-16 07:08:35 +0000613}
Alexey Bataev169d96a2017-07-18 20:17:46 +0000614void OMPClauseProfiler::VisitOMPTaskReductionClause(
615 const OMPTaskReductionClause *C) {
616 Profiler->VisitNestedNameSpecifier(
617 C->getQualifierLoc().getNestedNameSpecifier());
618 Profiler->VisitName(C->getNameInfo().getName());
619 VisitOMPClauseList(C);
620 VistOMPClauseWithPostUpdate(C);
621 for (auto *E : C->privates()) {
622 if (E)
623 Profiler->VisitStmt(E);
624 }
625 for (auto *E : C->lhs_exprs()) {
626 if (E)
627 Profiler->VisitStmt(E);
628 }
629 for (auto *E : C->rhs_exprs()) {
630 if (E)
631 Profiler->VisitStmt(E);
632 }
633 for (auto *E : C->reduction_ops()) {
634 if (E)
635 Profiler->VisitStmt(E);
636 }
637}
Alexey Bataevfa312f32017-07-21 18:48:21 +0000638void OMPClauseProfiler::VisitOMPInReductionClause(
639 const OMPInReductionClause *C) {
640 Profiler->VisitNestedNameSpecifier(
641 C->getQualifierLoc().getNestedNameSpecifier());
642 Profiler->VisitName(C->getNameInfo().getName());
643 VisitOMPClauseList(C);
644 VistOMPClauseWithPostUpdate(C);
645 for (auto *E : C->privates()) {
646 if (E)
647 Profiler->VisitStmt(E);
648 }
649 for (auto *E : C->lhs_exprs()) {
650 if (E)
651 Profiler->VisitStmt(E);
652 }
653 for (auto *E : C->rhs_exprs()) {
654 if (E)
655 Profiler->VisitStmt(E);
656 }
657 for (auto *E : C->reduction_ops()) {
658 if (E)
659 Profiler->VisitStmt(E);
660 }
Alexey Bataev88202be2017-07-27 13:20:36 +0000661 for (auto *E : C->taskgroup_descriptors()) {
662 if (E)
663 Profiler->VisitStmt(E);
664 }
Alexey Bataevfa312f32017-07-21 18:48:21 +0000665}
Alexander Musman8dba6642014-04-22 13:09:42 +0000666void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
667 VisitOMPClauseList(C);
Alexey Bataev78849fb2016-03-09 09:49:00 +0000668 VistOMPClauseWithPostUpdate(C);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000669 for (auto *E : C->privates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000670 if (E)
671 Profiler->VisitStmt(E);
Alexey Bataevbd9fec12015-08-18 06:47:21 +0000672 }
Alexander Musman3276a272015-03-21 10:12:56 +0000673 for (auto *E : C->inits()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000674 if (E)
675 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000676 }
677 for (auto *E : C->updates()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000678 if (E)
679 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000680 }
681 for (auto *E : C->finals()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000682 if (E)
683 Profiler->VisitStmt(E);
Alexander Musman3276a272015-03-21 10:12:56 +0000684 }
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000685 if (C->getStep())
686 Profiler->VisitStmt(C->getStep());
687 if (C->getCalcStep())
688 Profiler->VisitStmt(C->getCalcStep());
Alexander Musman8dba6642014-04-22 13:09:42 +0000689}
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000690void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
691 VisitOMPClauseList(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000692 if (C->getAlignment())
693 Profiler->VisitStmt(C->getAlignment());
Alexander Musmanf0d76e72014-05-29 14:36:25 +0000694}
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000695void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
696 VisitOMPClauseList(C);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000697 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000698 if (E)
699 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000700 }
701 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000702 if (E)
703 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000704 }
705 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000706 if (E)
707 Profiler->VisitStmt(E);
Alexey Bataevf56f98c2015-04-16 05:39:01 +0000708 }
Alexey Bataevd48bcd82014-03-31 03:36:38 +0000709}
Alexey Bataevbae9a792014-06-27 10:37:06 +0000710void
711OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
712 VisitOMPClauseList(C);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000713 for (auto *E : C->source_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000714 if (E)
715 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000716 }
717 for (auto *E : C->destination_exprs()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000718 if (E)
719 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000720 }
721 for (auto *E : C->assignment_ops()) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000722 if (E)
723 Profiler->VisitStmt(E);
Alexey Bataeva63048e2015-03-23 06:18:07 +0000724 }
Alexey Bataevbae9a792014-06-27 10:37:06 +0000725}
Alexey Bataev6125da92014-07-21 11:26:11 +0000726void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
727 VisitOMPClauseList(C);
728}
Alexey Bataevc112e942020-02-28 09:52:15 -0500729void OMPClauseProfiler::VisitOMPDepobjClause(const OMPDepobjClause *C) {
730 if (const Expr *Depobj = C->getDepobj())
731 Profiler->VisitStmt(Depobj);
732}
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +0000733void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
734 VisitOMPClauseList(C);
735}
Michael Wonge710d542015-08-07 16:16:36 +0000736void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000737 if (C->getDevice())
738 Profiler->VisitStmt(C->getDevice());
Michael Wonge710d542015-08-07 16:16:36 +0000739}
Kelvin Li0bff7af2015-11-23 05:32:03 +0000740void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
741 VisitOMPClauseList(C);
742}
Alexey Bataeve04483e2019-03-27 14:14:31 +0000743void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
744 if (Expr *Allocator = C->getAllocator())
745 Profiler->VisitStmt(Allocator);
746 VisitOMPClauseList(C);
747}
Kelvin Li099bb8c2015-11-24 20:50:12 +0000748void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
Arpith Chacko Jacobbc126342017-01-25 11:28:18 +0000749 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000750 if (C->getNumTeams())
751 Profiler->VisitStmt(C->getNumTeams());
Kelvin Li099bb8c2015-11-24 20:50:12 +0000752}
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000753void OMPClauseProfiler::VisitOMPThreadLimitClause(
754 const OMPThreadLimitClause *C) {
Arpith Chacko Jacob7ecc0b72017-01-25 11:44:35 +0000755 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000756 if (C->getThreadLimit())
757 Profiler->VisitStmt(C->getThreadLimit());
Kelvin Lia15fb1a2015-11-27 18:47:36 +0000758}
Alexey Bataeva0569352015-12-01 10:17:31 +0000759void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
Alexey Bataev31ba4762019-10-16 18:09:37 +0000760 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000761 if (C->getPriority())
762 Profiler->VisitStmt(C->getPriority());
Alexey Bataeva0569352015-12-01 10:17:31 +0000763}
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000764void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
Alexey Bataevb9c55e22019-10-14 19:29:52 +0000765 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000766 if (C->getGrainsize())
767 Profiler->VisitStmt(C->getGrainsize());
Alexey Bataev1fd4aed2015-12-07 12:52:51 +0000768}
Alexey Bataev382967a2015-12-08 12:06:20 +0000769void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
Alexey Bataevd88c7de2019-10-14 20:44:34 +0000770 VistOMPClauseWithPreInit(C);
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000771 if (C->getNumTasks())
772 Profiler->VisitStmt(C->getNumTasks());
Alexey Bataev382967a2015-12-08 12:06:20 +0000773}
Alexey Bataev28c75412015-12-15 08:19:24 +0000774void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
Richard Trieu6a77a1c2016-06-10 04:52:09 +0000775 if (C->getHint())
776 Profiler->VisitStmt(C->getHint());
Alexey Bataev28c75412015-12-15 08:19:24 +0000777}
Samuel Antao661c0902016-05-26 17:39:58 +0000778void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
779 VisitOMPClauseList(C);
780}
Samuel Antaoec172c62016-05-26 17:49:04 +0000781void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
782 VisitOMPClauseList(C);
783}
Carlo Bertolli2404b172016-07-13 15:37:16 +0000784void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
785 const OMPUseDevicePtrClause *C) {
786 VisitOMPClauseList(C);
787}
Carlo Bertolli70594e92016-07-13 17:16:49 +0000788void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
789 const OMPIsDevicePtrClause *C) {
790 VisitOMPClauseList(C);
791}
Alexey Bataev0860db92019-12-19 10:01:10 -0500792void OMPClauseProfiler::VisitOMPNontemporalClause(
793 const OMPNontemporalClause *C) {
Alexey Bataevb6e70842019-12-16 15:54:17 -0500794 VisitOMPClauseList(C);
Alexey Bataev0860db92019-12-19 10:01:10 -0500795 for (auto *E : C->private_refs())
796 Profiler->VisitStmt(E);
Alexey Bataevb6e70842019-12-16 15:54:17 -0500797}
Alexey Bataevcb8e6912020-01-31 16:09:26 -0500798void OMPClauseProfiler::VisitOMPOrderClause(const OMPOrderClause *C) {}
Alexey Bataev0860db92019-12-19 10:01:10 -0500799} // namespace
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000800
801void
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000802StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000803 VisitStmt(S);
804 OMPClauseProfiler P(this);
805 ArrayRef<OMPClause *> Clauses = S->clauses();
806 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
807 I != E; ++I)
808 if (*I)
809 P.Visit(*I);
810}
811
Alexander Musman3aaab662014-08-19 11:27:13 +0000812void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
813 VisitOMPExecutableDirective(S);
814}
815
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000816void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
817 VisitOMPExecutableDirective(S);
818}
819
820void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000821 VisitOMPLoopDirective(S);
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000822}
823
Alexey Bataevf29276e2014-06-18 04:14:57 +0000824void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000825 VisitOMPLoopDirective(S);
Alexey Bataevf29276e2014-06-18 04:14:57 +0000826}
827
Alexander Musmanf82886e2014-09-18 05:12:34 +0000828void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
829 VisitOMPLoopDirective(S);
830}
831
Alexey Bataevd3f8dd22014-06-25 11:44:49 +0000832void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
833 VisitOMPExecutableDirective(S);
834}
835
Alexey Bataev1e0498a2014-06-26 08:21:58 +0000836void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
837 VisitOMPExecutableDirective(S);
838}
839
Alexey Bataevd1e40fb2014-06-26 12:05:45 +0000840void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
841 VisitOMPExecutableDirective(S);
842}
843
Alexander Musman80c22892014-07-17 08:54:58 +0000844void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
845 VisitOMPExecutableDirective(S);
846}
847
Alexander Musmand9ed09f2014-07-21 09:42:05 +0000848void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
849 VisitOMPExecutableDirective(S);
850 VisitName(S->getDirectiveName().getName());
851}
852
Alexey Bataev4acb8592014-07-07 13:01:15 +0000853void
854StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
Alexander Musman3aaab662014-08-19 11:27:13 +0000855 VisitOMPLoopDirective(S);
Alexey Bataev4acb8592014-07-07 13:01:15 +0000856}
857
Alexander Musmane4e893b2014-09-23 09:33:00 +0000858void StmtProfiler::VisitOMPParallelForSimdDirective(
859 const OMPParallelForSimdDirective *S) {
860 VisitOMPLoopDirective(S);
861}
862
cchen47d60942019-12-05 13:43:48 -0500863void StmtProfiler::VisitOMPParallelMasterDirective(
864 const OMPParallelMasterDirective *S) {
865 VisitOMPExecutableDirective(S);
866}
867
Alexey Bataev84d0b3e2014-07-08 08:12:03 +0000868void StmtProfiler::VisitOMPParallelSectionsDirective(
869 const OMPParallelSectionsDirective *S) {
870 VisitOMPExecutableDirective(S);
871}
872
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +0000873void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
874 VisitOMPExecutableDirective(S);
875}
876
Alexey Bataev68446b72014-07-18 07:47:19 +0000877void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
878 VisitOMPExecutableDirective(S);
879}
880
Alexey Bataev4d1dfea2014-07-18 09:11:51 +0000881void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
882 VisitOMPExecutableDirective(S);
883}
884
Alexey Bataev2df347a2014-07-18 10:17:07 +0000885void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
886 VisitOMPExecutableDirective(S);
887}
888
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000889void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
890 VisitOMPExecutableDirective(S);
Alexey Bataev3b1b8952017-07-25 15:53:26 +0000891 if (const Expr *E = S->getReductionRef())
892 VisitStmt(E);
Alexey Bataevc30dd2d2015-06-18 12:14:09 +0000893}
894
Alexey Bataev6125da92014-07-21 11:26:11 +0000895void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
896 VisitOMPExecutableDirective(S);
897}
898
Alexey Bataevc112e942020-02-28 09:52:15 -0500899void StmtProfiler::VisitOMPDepobjDirective(const OMPDepobjDirective *S) {
900 VisitOMPExecutableDirective(S);
901}
902
Alexey Bataev9fb6e642014-07-22 06:45:04 +0000903void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
904 VisitOMPExecutableDirective(S);
905}
906
Alexey Bataev0162e452014-07-22 10:10:35 +0000907void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
908 VisitOMPExecutableDirective(S);
909}
910
Alexey Bataev0bd520b2014-09-19 08:19:49 +0000911void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
912 VisitOMPExecutableDirective(S);
913}
914
Michael Wong65f367f2015-07-21 13:44:28 +0000915void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
916 VisitOMPExecutableDirective(S);
917}
918
Samuel Antaodf67fc42016-01-19 19:15:56 +0000919void StmtProfiler::VisitOMPTargetEnterDataDirective(
920 const OMPTargetEnterDataDirective *S) {
921 VisitOMPExecutableDirective(S);
922}
923
Samuel Antao72590762016-01-19 20:04:50 +0000924void StmtProfiler::VisitOMPTargetExitDataDirective(
925 const OMPTargetExitDataDirective *S) {
926 VisitOMPExecutableDirective(S);
927}
928
Arpith Chacko Jacobe955b3d2016-01-26 18:48:41 +0000929void StmtProfiler::VisitOMPTargetParallelDirective(
930 const OMPTargetParallelDirective *S) {
931 VisitOMPExecutableDirective(S);
932}
933
Arpith Chacko Jacob05bebb52016-02-03 15:46:42 +0000934void StmtProfiler::VisitOMPTargetParallelForDirective(
935 const OMPTargetParallelForDirective *S) {
936 VisitOMPExecutableDirective(S);
937}
938
Alexey Bataev13314bf2014-10-09 04:18:56 +0000939void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
940 VisitOMPExecutableDirective(S);
941}
942
Alexey Bataev6d4ed052015-07-01 06:57:41 +0000943void StmtProfiler::VisitOMPCancellationPointDirective(
944 const OMPCancellationPointDirective *S) {
945 VisitOMPExecutableDirective(S);
946}
947
Alexey Bataev80909872015-07-02 11:25:17 +0000948void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
949 VisitOMPExecutableDirective(S);
950}
951
Alexey Bataev49f6e782015-12-01 04:18:41 +0000952void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
953 VisitOMPLoopDirective(S);
954}
955
Alexey Bataev0a6ed842015-12-03 09:40:15 +0000956void StmtProfiler::VisitOMPTaskLoopSimdDirective(
957 const OMPTaskLoopSimdDirective *S) {
958 VisitOMPLoopDirective(S);
959}
960
Alexey Bataev60e51c42019-10-10 20:13:02 +0000961void StmtProfiler::VisitOMPMasterTaskLoopDirective(
962 const OMPMasterTaskLoopDirective *S) {
963 VisitOMPLoopDirective(S);
964}
965
Alexey Bataevb8552ab2019-10-18 16:47:35 +0000966void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective(
967 const OMPMasterTaskLoopSimdDirective *S) {
968 VisitOMPLoopDirective(S);
969}
970
Alexey Bataev5bbcead2019-10-14 17:17:41 +0000971void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective(
972 const OMPParallelMasterTaskLoopDirective *S) {
973 VisitOMPLoopDirective(S);
974}
975
Alexey Bataev14a388f2019-10-25 10:27:13 -0400976void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective(
977 const OMPParallelMasterTaskLoopSimdDirective *S) {
978 VisitOMPLoopDirective(S);
979}
980
Carlo Bertolli6200a3d2015-12-14 14:51:25 +0000981void StmtProfiler::VisitOMPDistributeDirective(
982 const OMPDistributeDirective *S) {
983 VisitOMPLoopDirective(S);
984}
985
Carlo Bertollib4adf552016-01-15 18:50:31 +0000986void OMPClauseProfiler::VisitOMPDistScheduleClause(
987 const OMPDistScheduleClause *C) {
Alexey Bataev3392d762016-02-16 11:18:12 +0000988 VistOMPClauseWithPreInit(C);
989 if (auto *S = C->getChunkSize())
990 Profiler->VisitStmt(S);
Carlo Bertollib4adf552016-01-15 18:50:31 +0000991}
992
Arpith Chacko Jacob3cf89042016-01-26 16:37:23 +0000993void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
994
Samuel Antao686c70c2016-05-26 17:30:50 +0000995void StmtProfiler::VisitOMPTargetUpdateDirective(
996 const OMPTargetUpdateDirective *S) {
997 VisitOMPExecutableDirective(S);
998}
999
Carlo Bertolli9925f152016-06-27 14:55:37 +00001000void StmtProfiler::VisitOMPDistributeParallelForDirective(
1001 const OMPDistributeParallelForDirective *S) {
1002 VisitOMPLoopDirective(S);
1003}
1004
Kelvin Li4a39add2016-07-05 05:00:15 +00001005void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
1006 const OMPDistributeParallelForSimdDirective *S) {
1007 VisitOMPLoopDirective(S);
1008}
1009
Kelvin Li787f3fc2016-07-06 04:45:38 +00001010void StmtProfiler::VisitOMPDistributeSimdDirective(
1011 const OMPDistributeSimdDirective *S) {
1012 VisitOMPLoopDirective(S);
1013}
1014
Kelvin Lia579b912016-07-14 02:54:56 +00001015void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
1016 const OMPTargetParallelForSimdDirective *S) {
1017 VisitOMPLoopDirective(S);
1018}
1019
Kelvin Li986330c2016-07-20 22:57:10 +00001020void StmtProfiler::VisitOMPTargetSimdDirective(
1021 const OMPTargetSimdDirective *S) {
1022 VisitOMPLoopDirective(S);
1023}
1024
Kelvin Li02532872016-08-05 14:37:37 +00001025void StmtProfiler::VisitOMPTeamsDistributeDirective(
1026 const OMPTeamsDistributeDirective *S) {
1027 VisitOMPLoopDirective(S);
1028}
1029
Kelvin Li4e325f72016-10-25 12:50:55 +00001030void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
1031 const OMPTeamsDistributeSimdDirective *S) {
1032 VisitOMPLoopDirective(S);
1033}
1034
Kelvin Li579e41c2016-11-30 23:51:03 +00001035void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
1036 const OMPTeamsDistributeParallelForSimdDirective *S) {
1037 VisitOMPLoopDirective(S);
1038}
1039
Kelvin Li7ade93f2016-12-09 03:24:30 +00001040void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
1041 const OMPTeamsDistributeParallelForDirective *S) {
1042 VisitOMPLoopDirective(S);
1043}
1044
Kelvin Libf594a52016-12-17 05:48:59 +00001045void StmtProfiler::VisitOMPTargetTeamsDirective(
1046 const OMPTargetTeamsDirective *S) {
1047 VisitOMPExecutableDirective(S);
1048}
1049
Kelvin Li83c451e2016-12-25 04:52:54 +00001050void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
1051 const OMPTargetTeamsDistributeDirective *S) {
1052 VisitOMPLoopDirective(S);
1053}
1054
Kelvin Li80e8f562016-12-29 22:16:30 +00001055void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
1056 const OMPTargetTeamsDistributeParallelForDirective *S) {
1057 VisitOMPLoopDirective(S);
1058}
1059
Kelvin Li1851df52017-01-03 05:23:48 +00001060void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1061 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
1062 VisitOMPLoopDirective(S);
1063}
1064
Kelvin Lida681182017-01-10 18:08:18 +00001065void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
1066 const OMPTargetTeamsDistributeSimdDirective *S) {
1067 VisitOMPLoopDirective(S);
1068}
1069
Chandler Carruth631abd92011-06-16 06:47:06 +00001070void StmtProfiler::VisitExpr(const Expr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001071 VisitStmt(S);
1072}
1073
Bill Wendling7c44da22018-10-31 03:48:47 +00001074void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1075 VisitExpr(S);
1076}
1077
Chandler Carruth631abd92011-06-16 06:47:06 +00001078void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001079 VisitExpr(S);
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001080 if (!Canonical)
1081 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001082 VisitDecl(S->getDecl());
Richard Trieu4d06bef2018-02-13 19:53:40 +00001083 if (!Canonical) {
1084 ID.AddBoolean(S->hasExplicitTemplateArgs());
1085 if (S->hasExplicitTemplateArgs())
1086 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1087 }
Douglas Gregor5c193b92009-07-28 00:33:38 +00001088}
1089
Chandler Carruth631abd92011-06-16 06:47:06 +00001090void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001091 VisitExpr(S);
Bruno Ricci17ff0262018-10-27 19:21:19 +00001092 ID.AddInteger(S->getIdentKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001093}
1094
Chandler Carruth631abd92011-06-16 06:47:06 +00001095void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001096 VisitExpr(S);
1097 S->getValue().Profile(ID);
Richard Smithe9f130c2014-11-20 03:37:32 +00001098 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001099}
1100
Leonard Chandb01c3a2018-06-20 17:19:40 +00001101void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1102 VisitExpr(S);
1103 S->getValue().Profile(ID);
1104 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1105}
1106
Chandler Carruth631abd92011-06-16 06:47:06 +00001107void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001108 VisitExpr(S);
Douglas Gregorfb65e592011-07-27 05:40:30 +00001109 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001110 ID.AddInteger(S->getValue());
1111}
1112
Chandler Carruth631abd92011-06-16 06:47:06 +00001113void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001114 VisitExpr(S);
1115 S->getValue().Profile(ID);
1116 ID.AddBoolean(S->isExact());
Richard Smithe9f130c2014-11-20 03:37:32 +00001117 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001118}
1119
Chandler Carruth631abd92011-06-16 06:47:06 +00001120void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001121 VisitExpr(S);
1122}
1123
Chandler Carruth631abd92011-06-16 06:47:06 +00001124void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001125 VisitExpr(S);
Douglas Gregor9d0eb8f2011-11-02 17:26:05 +00001126 ID.AddString(S->getBytes());
Douglas Gregorfb65e592011-07-27 05:40:30 +00001127 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001128}
1129
Chandler Carruth631abd92011-06-16 06:47:06 +00001130void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001131 VisitExpr(S);
1132}
1133
Chandler Carruth631abd92011-06-16 06:47:06 +00001134void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
Nate Begeman5ec4b312009-08-10 23:49:36 +00001135 VisitExpr(S);
1136}
1137
Chandler Carruth631abd92011-06-16 06:47:06 +00001138void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001139 VisitExpr(S);
1140 ID.AddInteger(S->getOpcode());
1141}
1142
Chandler Carruth631abd92011-06-16 06:47:06 +00001143void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001144 VisitType(S->getTypeSourceInfo()->getType());
1145 unsigned n = S->getNumComponents();
1146 for (unsigned i = 0; i < n; ++i) {
James Y Knight7281c352015-12-29 22:31:18 +00001147 const OffsetOfNode &ON = S->getComponent(i);
Douglas Gregor882211c2010-04-28 22:16:22 +00001148 ID.AddInteger(ON.getKind());
1149 switch (ON.getKind()) {
James Y Knight7281c352015-12-29 22:31:18 +00001150 case OffsetOfNode::Array:
Douglas Gregor882211c2010-04-28 22:16:22 +00001151 // Expressions handled below.
1152 break;
1153
James Y Knight7281c352015-12-29 22:31:18 +00001154 case OffsetOfNode::Field:
Douglas Gregor882211c2010-04-28 22:16:22 +00001155 VisitDecl(ON.getField());
1156 break;
1157
James Y Knight7281c352015-12-29 22:31:18 +00001158 case OffsetOfNode::Identifier:
Richard Trieu639d7b62017-02-22 22:22:42 +00001159 VisitIdentifierInfo(ON.getFieldName());
Douglas Gregor882211c2010-04-28 22:16:22 +00001160 break;
James Y Knight7281c352015-12-29 22:31:18 +00001161
1162 case OffsetOfNode::Base:
Douglas Gregord1702062010-04-29 00:18:15 +00001163 // These nodes are implicit, and therefore don't need profiling.
1164 break;
Douglas Gregor882211c2010-04-28 22:16:22 +00001165 }
1166 }
Richard Trieu639d7b62017-02-22 22:22:42 +00001167
Douglas Gregor882211c2010-04-28 22:16:22 +00001168 VisitExpr(S);
1169}
1170
Chandler Carruth631abd92011-06-16 06:47:06 +00001171void
1172StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001173 VisitExpr(S);
Peter Collingbournee190dee2011-03-11 19:24:49 +00001174 ID.AddInteger(S->getKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001175 if (S->isArgumentType())
1176 VisitType(S->getArgumentType());
1177}
1178
Chandler Carruth631abd92011-06-16 06:47:06 +00001179void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001180 VisitExpr(S);
1181}
1182
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001183void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1184 VisitExpr(S);
1185}
1186
Chandler Carruth631abd92011-06-16 06:47:06 +00001187void StmtProfiler::VisitCallExpr(const CallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001188 VisitExpr(S);
1189}
1190
Chandler Carruth631abd92011-06-16 06:47:06 +00001191void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001192 VisitExpr(S);
1193 VisitDecl(S->getMemberDecl());
Douglas Gregorf5b160f2010-07-13 08:37:11 +00001194 if (!Canonical)
1195 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001196 ID.AddBoolean(S->isArrow());
1197}
1198
Chandler Carruth631abd92011-06-16 06:47:06 +00001199void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001200 VisitExpr(S);
1201 ID.AddBoolean(S->isFileScope());
1202}
1203
Chandler Carruth631abd92011-06-16 06:47:06 +00001204void StmtProfiler::VisitCastExpr(const CastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001205 VisitExpr(S);
1206}
1207
Chandler Carruth631abd92011-06-16 06:47:06 +00001208void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001209 VisitCastExpr(S);
John McCall2536c6d2010-08-25 10:28:54 +00001210 ID.AddInteger(S->getValueKind());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001211}
1212
Chandler Carruth631abd92011-06-16 06:47:06 +00001213void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001214 VisitCastExpr(S);
1215 VisitType(S->getTypeAsWritten());
1216}
1217
Chandler Carruth631abd92011-06-16 06:47:06 +00001218void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001219 VisitExplicitCastExpr(S);
1220}
1221
Chandler Carruth631abd92011-06-16 06:47:06 +00001222void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001223 VisitExpr(S);
1224 ID.AddInteger(S->getOpcode());
1225}
1226
Chandler Carruth631abd92011-06-16 06:47:06 +00001227void
1228StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001229 VisitBinaryOperator(S);
1230}
1231
Chandler Carruth631abd92011-06-16 06:47:06 +00001232void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001233 VisitExpr(S);
1234}
1235
Chandler Carruth631abd92011-06-16 06:47:06 +00001236void StmtProfiler::VisitBinaryConditionalOperator(
Chandler Carruthcf5f43c2011-06-21 23:26:32 +00001237 const BinaryConditionalOperator *S) {
John McCallc07a0c72011-02-17 10:25:35 +00001238 VisitExpr(S);
1239}
1240
Chandler Carruth631abd92011-06-16 06:47:06 +00001241void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001242 VisitExpr(S);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001243 VisitDecl(S->getLabel());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001244}
1245
Chandler Carruth631abd92011-06-16 06:47:06 +00001246void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001247 VisitExpr(S);
1248}
1249
Chandler Carruth631abd92011-06-16 06:47:06 +00001250void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001251 VisitExpr(S);
1252}
1253
Hal Finkelc4d7c822013-09-18 03:29:45 +00001254void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1255 VisitExpr(S);
1256}
1257
Chandler Carruth631abd92011-06-16 06:47:06 +00001258void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001259 VisitExpr(S);
1260}
1261
Chandler Carruth631abd92011-06-16 06:47:06 +00001262void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001263 VisitExpr(S);
1264}
1265
Chandler Carruth631abd92011-06-16 06:47:06 +00001266void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001267 VisitExpr(S);
1268}
1269
Chandler Carruth631abd92011-06-16 06:47:06 +00001270void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001271 if (S->getSyntacticForm()) {
1272 VisitInitListExpr(S->getSyntacticForm());
1273 return;
1274 }
Mike Stump11289f42009-09-09 15:08:12 +00001275
Douglas Gregor5c193b92009-07-28 00:33:38 +00001276 VisitExpr(S);
1277}
1278
Chandler Carruth631abd92011-06-16 06:47:06 +00001279void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001280 VisitExpr(S);
1281 ID.AddBoolean(S->usesGNUSyntax());
David Majnemerf7e36092016-06-23 00:15:04 +00001282 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1283 if (D.isFieldDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001284 ID.AddInteger(0);
David Majnemerf7e36092016-06-23 00:15:04 +00001285 VisitName(D.getFieldName());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001286 continue;
1287 }
Mike Stump11289f42009-09-09 15:08:12 +00001288
David Majnemerf7e36092016-06-23 00:15:04 +00001289 if (D.isArrayDesignator()) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001290 ID.AddInteger(1);
1291 } else {
David Majnemerf7e36092016-06-23 00:15:04 +00001292 assert(D.isArrayRangeDesignator());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001293 ID.AddInteger(2);
1294 }
David Majnemerf7e36092016-06-23 00:15:04 +00001295 ID.AddInteger(D.getFirstExprIndex());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001296 }
1297}
1298
Yunzhong Gaocb779302015-06-10 00:27:52 +00001299// Seems that if VisitInitListExpr() only works on the syntactic form of an
1300// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1301void StmtProfiler::VisitDesignatedInitUpdateExpr(
1302 const DesignatedInitUpdateExpr *S) {
1303 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1304 "initializer");
1305}
1306
Richard Smith410306b2016-12-12 02:53:20 +00001307void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1308 VisitExpr(S);
1309}
1310
1311void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1312 VisitExpr(S);
1313}
1314
Yunzhong Gaocb779302015-06-10 00:27:52 +00001315void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1316 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1317}
1318
Chandler Carruth631abd92011-06-16 06:47:06 +00001319void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001320 VisitExpr(S);
1321}
1322
Chandler Carruth631abd92011-06-16 06:47:06 +00001323void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001324 VisitExpr(S);
1325 VisitName(&S->getAccessor());
1326}
1327
Chandler Carruth631abd92011-06-16 06:47:06 +00001328void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001329 VisitExpr(S);
1330 VisitDecl(S->getBlockDecl());
1331}
1332
Chandler Carruth631abd92011-06-16 06:47:06 +00001333void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
Peter Collingbourne91147592011-04-15 00:35:48 +00001334 VisitExpr(S);
Mark de Wever21490282019-11-12 20:46:19 +01001335 for (const GenericSelectionExpr::ConstAssociation Assoc :
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00001336 S->associations()) {
1337 QualType T = Assoc.getType();
Peter Collingbourne91147592011-04-15 00:35:48 +00001338 if (T.isNull())
Craig Topper36250ad2014-05-12 05:36:57 +00001339 ID.AddPointer(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00001340 else
1341 VisitType(T);
Bruno Ricci1ec7fd32019-01-29 12:57:11 +00001342 VisitExpr(Assoc.getAssociationExpr());
Peter Collingbourne91147592011-04-15 00:35:48 +00001343 }
1344}
1345
John McCallfe96e0b2011-11-06 09:01:30 +00001346void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1347 VisitExpr(S);
1348 for (PseudoObjectExpr::const_semantics_iterator
1349 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1350 // Normally, we would not profile the source expressions of OVEs.
1351 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1352 Visit(OVE->getSourceExpr());
1353}
1354
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001355void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1356 VisitExpr(S);
Eli Friedman4b72fdd2011-10-14 20:59:01 +00001357 ID.AddInteger(S->getOp());
Eli Friedmandf14b3a2011-10-11 02:20:01 +00001358}
1359
Saar Raz5d98ba62019-10-15 15:24:26 +00001360void StmtProfiler::VisitConceptSpecializationExpr(
1361 const ConceptSpecializationExpr *S) {
1362 VisitExpr(S);
Saar Raz8a344672020-01-16 13:35:20 +02001363 VisitDecl(S->getNamedConcept());
1364 for (const TemplateArgument &Arg : S->getTemplateArguments())
1365 VisitTemplateArgument(Arg);
Saar Raz5d98ba62019-10-15 15:24:26 +00001366}
1367
Saar Raza0f50d72020-01-18 09:11:43 +02001368void StmtProfiler::VisitRequiresExpr(const RequiresExpr *S) {
1369 VisitExpr(S);
1370 ID.AddInteger(S->getLocalParameters().size());
1371 for (ParmVarDecl *LocalParam : S->getLocalParameters())
1372 VisitDecl(LocalParam);
1373 ID.AddInteger(S->getRequirements().size());
1374 for (concepts::Requirement *Req : S->getRequirements()) {
1375 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
1376 ID.AddInteger(concepts::Requirement::RK_Type);
1377 ID.AddBoolean(TypeReq->isSubstitutionFailure());
1378 if (!TypeReq->isSubstitutionFailure())
1379 VisitType(TypeReq->getType()->getType());
1380 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
1381 ID.AddInteger(concepts::Requirement::RK_Compound);
1382 ID.AddBoolean(ExprReq->isExprSubstitutionFailure());
1383 if (!ExprReq->isExprSubstitutionFailure())
1384 Visit(ExprReq->getExpr());
1385 // C++2a [expr.prim.req.compound]p1 Example:
1386 // [...] The compound-requirement in C1 requires that x++ is a valid
1387 // expression. It is equivalent to the simple-requirement x++; [...]
1388 // We therefore do not profile isSimple() here.
1389 ID.AddBoolean(ExprReq->getNoexceptLoc().isValid());
1390 const concepts::ExprRequirement::ReturnTypeRequirement &RetReq =
1391 ExprReq->getReturnTypeRequirement();
1392 if (RetReq.isEmpty()) {
1393 ID.AddInteger(0);
1394 } else if (RetReq.isTypeConstraint()) {
1395 ID.AddInteger(1);
1396 Visit(RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint());
1397 } else {
1398 assert(RetReq.isSubstitutionFailure());
1399 ID.AddInteger(2);
1400 }
1401 } else {
1402 ID.AddInteger(concepts::Requirement::RK_Nested);
1403 auto *NestedReq = cast<concepts::NestedRequirement>(Req);
1404 ID.AddBoolean(NestedReq->isSubstitutionFailure());
Jim Lin466f8842020-02-18 10:48:38 +08001405 if (!NestedReq->isSubstitutionFailure())
Saar Raza0f50d72020-01-18 09:11:43 +02001406 Visit(NestedReq->getConstraintExpr());
1407 }
1408 }
1409}
1410
Chandler Carruth631abd92011-06-16 06:47:06 +00001411static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
John McCalle3027922010-08-25 11:45:40 +00001412 UnaryOperatorKind &UnaryOp,
1413 BinaryOperatorKind &BinaryOp) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001414 switch (S->getOperator()) {
1415 case OO_None:
1416 case OO_New:
1417 case OO_Delete:
1418 case OO_Array_New:
1419 case OO_Array_Delete:
1420 case OO_Arrow:
1421 case OO_Call:
1422 case OO_Conditional:
1423 case NUM_OVERLOADED_OPERATORS:
1424 llvm_unreachable("Invalid operator call kind");
Fangrui Song6907ce22018-07-30 19:24:48 +00001425
Douglas Gregore9ceb312010-05-19 04:13:23 +00001426 case OO_Plus:
1427 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001428 UnaryOp = UO_Plus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001429 return Stmt::UnaryOperatorClass;
1430 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001431
John McCalle3027922010-08-25 11:45:40 +00001432 BinaryOp = BO_Add;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001433 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001434
Douglas Gregore9ceb312010-05-19 04:13:23 +00001435 case OO_Minus:
1436 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001437 UnaryOp = UO_Minus;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001438 return Stmt::UnaryOperatorClass;
1439 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001440
John McCalle3027922010-08-25 11:45:40 +00001441 BinaryOp = BO_Sub;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001442 return Stmt::BinaryOperatorClass;
1443
1444 case OO_Star:
1445 if (S->getNumArgs() == 1) {
Richard Smithf15acc52014-06-05 22:43:40 +00001446 UnaryOp = UO_Deref;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001447 return Stmt::UnaryOperatorClass;
1448 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001449
Richard Smithf15acc52014-06-05 22:43:40 +00001450 BinaryOp = BO_Mul;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001451 return Stmt::BinaryOperatorClass;
1452
1453 case OO_Slash:
John McCalle3027922010-08-25 11:45:40 +00001454 BinaryOp = BO_Div;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001455 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001456
Douglas Gregore9ceb312010-05-19 04:13:23 +00001457 case OO_Percent:
John McCalle3027922010-08-25 11:45:40 +00001458 BinaryOp = BO_Rem;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001459 return Stmt::BinaryOperatorClass;
1460
1461 case OO_Caret:
John McCalle3027922010-08-25 11:45:40 +00001462 BinaryOp = BO_Xor;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001463 return Stmt::BinaryOperatorClass;
1464
1465 case OO_Amp:
1466 if (S->getNumArgs() == 1) {
John McCalle3027922010-08-25 11:45:40 +00001467 UnaryOp = UO_AddrOf;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001468 return Stmt::UnaryOperatorClass;
1469 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001470
John McCalle3027922010-08-25 11:45:40 +00001471 BinaryOp = BO_And;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001472 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001473
Douglas Gregore9ceb312010-05-19 04:13:23 +00001474 case OO_Pipe:
John McCalle3027922010-08-25 11:45:40 +00001475 BinaryOp = BO_Or;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001476 return Stmt::BinaryOperatorClass;
1477
1478 case OO_Tilde:
John McCalle3027922010-08-25 11:45:40 +00001479 UnaryOp = UO_Not;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001480 return Stmt::UnaryOperatorClass;
1481
1482 case OO_Exclaim:
John McCalle3027922010-08-25 11:45:40 +00001483 UnaryOp = UO_LNot;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001484 return Stmt::UnaryOperatorClass;
1485
1486 case OO_Equal:
John McCalle3027922010-08-25 11:45:40 +00001487 BinaryOp = BO_Assign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001488 return Stmt::BinaryOperatorClass;
1489
1490 case OO_Less:
John McCalle3027922010-08-25 11:45:40 +00001491 BinaryOp = BO_LT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001492 return Stmt::BinaryOperatorClass;
1493
1494 case OO_Greater:
John McCalle3027922010-08-25 11:45:40 +00001495 BinaryOp = BO_GT;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001496 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001497
Douglas Gregore9ceb312010-05-19 04:13:23 +00001498 case OO_PlusEqual:
John McCalle3027922010-08-25 11:45:40 +00001499 BinaryOp = BO_AddAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001500 return Stmt::CompoundAssignOperatorClass;
1501
1502 case OO_MinusEqual:
John McCalle3027922010-08-25 11:45:40 +00001503 BinaryOp = BO_SubAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001504 return Stmt::CompoundAssignOperatorClass;
1505
1506 case OO_StarEqual:
John McCalle3027922010-08-25 11:45:40 +00001507 BinaryOp = BO_MulAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001508 return Stmt::CompoundAssignOperatorClass;
1509
1510 case OO_SlashEqual:
John McCalle3027922010-08-25 11:45:40 +00001511 BinaryOp = BO_DivAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001512 return Stmt::CompoundAssignOperatorClass;
1513
1514 case OO_PercentEqual:
John McCalle3027922010-08-25 11:45:40 +00001515 BinaryOp = BO_RemAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001516 return Stmt::CompoundAssignOperatorClass;
1517
1518 case OO_CaretEqual:
John McCalle3027922010-08-25 11:45:40 +00001519 BinaryOp = BO_XorAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001520 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001521
Douglas Gregore9ceb312010-05-19 04:13:23 +00001522 case OO_AmpEqual:
John McCalle3027922010-08-25 11:45:40 +00001523 BinaryOp = BO_AndAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001524 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001525
Douglas Gregore9ceb312010-05-19 04:13:23 +00001526 case OO_PipeEqual:
John McCalle3027922010-08-25 11:45:40 +00001527 BinaryOp = BO_OrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001528 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001529
Douglas Gregore9ceb312010-05-19 04:13:23 +00001530 case OO_LessLess:
John McCalle3027922010-08-25 11:45:40 +00001531 BinaryOp = BO_Shl;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001532 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001533
Douglas Gregore9ceb312010-05-19 04:13:23 +00001534 case OO_GreaterGreater:
John McCalle3027922010-08-25 11:45:40 +00001535 BinaryOp = BO_Shr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001536 return Stmt::BinaryOperatorClass;
1537
1538 case OO_LessLessEqual:
John McCalle3027922010-08-25 11:45:40 +00001539 BinaryOp = BO_ShlAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001540 return Stmt::CompoundAssignOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001541
Douglas Gregore9ceb312010-05-19 04:13:23 +00001542 case OO_GreaterGreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001543 BinaryOp = BO_ShrAssign;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001544 return Stmt::CompoundAssignOperatorClass;
1545
1546 case OO_EqualEqual:
John McCalle3027922010-08-25 11:45:40 +00001547 BinaryOp = BO_EQ;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001548 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001549
Douglas Gregore9ceb312010-05-19 04:13:23 +00001550 case OO_ExclaimEqual:
John McCalle3027922010-08-25 11:45:40 +00001551 BinaryOp = BO_NE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001552 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001553
Douglas Gregore9ceb312010-05-19 04:13:23 +00001554 case OO_LessEqual:
John McCalle3027922010-08-25 11:45:40 +00001555 BinaryOp = BO_LE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001556 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001557
Douglas Gregore9ceb312010-05-19 04:13:23 +00001558 case OO_GreaterEqual:
John McCalle3027922010-08-25 11:45:40 +00001559 BinaryOp = BO_GE;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001560 return Stmt::BinaryOperatorClass;
Richard Smithd30b23d2017-12-01 02:13:10 +00001561
1562 case OO_Spaceship:
Richard Smithb96c6b62020-02-04 18:28:36 -08001563 BinaryOp = BO_Cmp;
1564 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001565
Douglas Gregore9ceb312010-05-19 04:13:23 +00001566 case OO_AmpAmp:
John McCalle3027922010-08-25 11:45:40 +00001567 BinaryOp = BO_LAnd;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001568 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001569
Douglas Gregore9ceb312010-05-19 04:13:23 +00001570 case OO_PipePipe:
John McCalle3027922010-08-25 11:45:40 +00001571 BinaryOp = BO_LOr;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001572 return Stmt::BinaryOperatorClass;
1573
1574 case OO_PlusPlus:
Fangrui Song6907ce22018-07-30 19:24:48 +00001575 UnaryOp = S->getNumArgs() == 1? UO_PreInc
John McCalle3027922010-08-25 11:45:40 +00001576 : UO_PostInc;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001577 return Stmt::UnaryOperatorClass;
1578
1579 case OO_MinusMinus:
John McCalle3027922010-08-25 11:45:40 +00001580 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1581 : UO_PostDec;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001582 return Stmt::UnaryOperatorClass;
1583
1584 case OO_Comma:
John McCalle3027922010-08-25 11:45:40 +00001585 BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001586 return Stmt::BinaryOperatorClass;
1587
Douglas Gregore9ceb312010-05-19 04:13:23 +00001588 case OO_ArrowStar:
John McCalle3027922010-08-25 11:45:40 +00001589 BinaryOp = BO_PtrMemI;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001590 return Stmt::BinaryOperatorClass;
Fangrui Song6907ce22018-07-30 19:24:48 +00001591
Douglas Gregore9ceb312010-05-19 04:13:23 +00001592 case OO_Subscript:
1593 return Stmt::ArraySubscriptExprClass;
Richard Smith6fff5c42018-07-31 00:47:41 +00001594
1595 case OO_Coawait:
1596 UnaryOp = UO_Coawait;
1597 return Stmt::UnaryOperatorClass;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001598 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001599
Douglas Gregore9ceb312010-05-19 04:13:23 +00001600 llvm_unreachable("Invalid overloaded operator expression");
1601}
Richard Smithf15acc52014-06-05 22:43:40 +00001602
Reid Klecknere257e182017-10-13 16:18:32 +00001603#if defined(_MSC_VER) && !defined(__clang__)
Nico Weberf56f4462017-07-24 16:54:11 +00001604#if _MSC_VER == 1911
1605// Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1606// MSVC 2017 update 3 miscompiles this function, and a clang built with it
1607// will crash in stage 2 of a bootstrap build.
1608#pragma optimize("", off)
1609#endif
1610#endif
1611
Chandler Carruth631abd92011-06-16 06:47:06 +00001612void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
Douglas Gregore9ceb312010-05-19 04:13:23 +00001613 if (S->isTypeDependent()) {
1614 // Type-dependent operator calls are profiled like their underlying
1615 // syntactic operator.
Richard Smithbac0a0d2016-10-24 18:47:04 +00001616 //
1617 // An operator call to operator-> is always implicit, so just skip it. The
1618 // enclosing MemberExpr will profile the actual member access.
1619 if (S->getOperator() == OO_Arrow)
1620 return Visit(S->getArg(0));
1621
John McCalle3027922010-08-25 11:45:40 +00001622 UnaryOperatorKind UnaryOp = UO_Extension;
1623 BinaryOperatorKind BinaryOp = BO_Comma;
Douglas Gregore9ceb312010-05-19 04:13:23 +00001624 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
Richard Smithf15acc52014-06-05 22:43:40 +00001625
Douglas Gregore9ceb312010-05-19 04:13:23 +00001626 ID.AddInteger(SC);
1627 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1628 Visit(S->getArg(I));
1629 if (SC == Stmt::UnaryOperatorClass)
1630 ID.AddInteger(UnaryOp);
Fangrui Song6907ce22018-07-30 19:24:48 +00001631 else if (SC == Stmt::BinaryOperatorClass ||
Douglas Gregore9ceb312010-05-19 04:13:23 +00001632 SC == Stmt::CompoundAssignOperatorClass)
1633 ID.AddInteger(BinaryOp);
1634 else
1635 assert(SC == Stmt::ArraySubscriptExprClass);
Richard Smithf15acc52014-06-05 22:43:40 +00001636
Douglas Gregore9ceb312010-05-19 04:13:23 +00001637 return;
1638 }
Richard Smithf15acc52014-06-05 22:43:40 +00001639
Douglas Gregor5c193b92009-07-28 00:33:38 +00001640 VisitCallExpr(S);
1641 ID.AddInteger(S->getOperator());
1642}
1643
Richard Smith778dc0f2019-10-19 00:04:38 +00001644void StmtProfiler::VisitCXXRewrittenBinaryOperator(
1645 const CXXRewrittenBinaryOperator *S) {
1646 // If a rewritten operator were ever to be type-dependent, we should profile
1647 // it following its syntactic operator.
1648 assert(!S->isTypeDependent() &&
1649 "resolved rewritten operator should never be type-dependent");
1650 ID.AddBoolean(S->isReversed());
1651 VisitExpr(S->getSemanticForm());
1652}
1653
Reid Klecknere257e182017-10-13 16:18:32 +00001654#if defined(_MSC_VER) && !defined(__clang__)
Nico Weberf56f4462017-07-24 16:54:11 +00001655#if _MSC_VER == 1911
1656#pragma optimize("", on)
1657#endif
1658#endif
1659
Chandler Carruth631abd92011-06-16 06:47:06 +00001660void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001661 VisitCallExpr(S);
1662}
1663
Chandler Carruth631abd92011-06-16 06:47:06 +00001664void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
Peter Collingbourne41f85462011-02-09 21:07:24 +00001665 VisitCallExpr(S);
1666}
1667
Chandler Carruth631abd92011-06-16 06:47:06 +00001668void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
Tanya Lattner55808c12011-06-04 00:47:47 +00001669 VisitExpr(S);
1670}
1671
Chandler Carruth631abd92011-06-16 06:47:06 +00001672void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001673 VisitExplicitCastExpr(S);
1674}
1675
Chandler Carruth631abd92011-06-16 06:47:06 +00001676void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001677 VisitCXXNamedCastExpr(S);
1678}
1679
Chandler Carruth631abd92011-06-16 06:47:06 +00001680void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001681 VisitCXXNamedCastExpr(S);
1682}
1683
Chandler Carruth631abd92011-06-16 06:47:06 +00001684void
1685StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001686 VisitCXXNamedCastExpr(S);
1687}
1688
Chandler Carruth631abd92011-06-16 06:47:06 +00001689void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001690 VisitCXXNamedCastExpr(S);
1691}
1692
Erik Pilkingtoneee944e2019-07-02 18:28:13 +00001693void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
1694 VisitExpr(S);
1695 VisitType(S->getTypeInfoAsWritten()->getType());
1696}
1697
Richard Smithc67fdd42012-03-07 08:35:16 +00001698void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1699 VisitCallExpr(S);
1700}
1701
Chandler Carruth631abd92011-06-16 06:47:06 +00001702void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001703 VisitExpr(S);
1704 ID.AddBoolean(S->getValue());
1705}
1706
Chandler Carruth631abd92011-06-16 06:47:06 +00001707void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
Douglas Gregor00044172009-07-29 16:09:57 +00001708 VisitExpr(S);
1709}
1710
Richard Smithcc1b96d2013-06-12 22:31:48 +00001711void StmtProfiler::VisitCXXStdInitializerListExpr(
1712 const CXXStdInitializerListExpr *S) {
1713 VisitExpr(S);
1714}
1715
Chandler Carruth631abd92011-06-16 06:47:06 +00001716void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001717 VisitExpr(S);
1718 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001719 VisitType(S->getTypeOperandSourceInfo()->getType());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001720}
1721
Chandler Carruth631abd92011-06-16 06:47:06 +00001722void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
Francois Pichet9f4f2072010-09-08 12:20:18 +00001723 VisitExpr(S);
1724 if (S->isTypeOperand())
David Majnemer143c55e2013-09-27 07:04:31 +00001725 VisitType(S->getTypeOperandSourceInfo()->getType());
Francois Pichet9f4f2072010-09-08 12:20:18 +00001726}
1727
John McCall5e77d762013-04-16 07:28:30 +00001728void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1729 VisitExpr(S);
1730 VisitDecl(S->getPropertyDecl());
1731}
1732
Alexey Bataevf7630272015-11-25 12:01:00 +00001733void StmtProfiler::VisitMSPropertySubscriptExpr(
1734 const MSPropertySubscriptExpr *S) {
1735 VisitExpr(S);
1736}
1737
Chandler Carruth631abd92011-06-16 06:47:06 +00001738void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001739 VisitExpr(S);
Douglas Gregor3024f072012-04-16 07:05:22 +00001740 ID.AddBoolean(S->isImplicit());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001741}
1742
Chandler Carruth631abd92011-06-16 06:47:06 +00001743void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001744 VisitExpr(S);
1745}
1746
Chandler Carruth631abd92011-06-16 06:47:06 +00001747void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001748 VisitExpr(S);
1749 VisitDecl(S->getParam());
1750}
1751
Richard Smith852c9db2013-04-20 22:23:05 +00001752void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1753 VisitExpr(S);
1754 VisitDecl(S->getField());
1755}
1756
Chandler Carruth631abd92011-06-16 06:47:06 +00001757void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001758 VisitExpr(S);
1759 VisitDecl(
1760 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1761}
1762
Chandler Carruth631abd92011-06-16 06:47:06 +00001763void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001764 VisitExpr(S);
1765 VisitDecl(S->getConstructor());
1766 ID.AddBoolean(S->isElidable());
1767}
1768
Richard Smith5179eb72016-06-28 19:03:57 +00001769void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1770 const CXXInheritedCtorInitExpr *S) {
1771 VisitExpr(S);
1772 VisitDecl(S->getConstructor());
1773}
1774
Chandler Carruth631abd92011-06-16 06:47:06 +00001775void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001776 VisitExplicitCastExpr(S);
1777}
1778
Chandler Carruth631abd92011-06-16 06:47:06 +00001779void
1780StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001781 VisitCXXConstructExpr(S);
1782}
1783
Chandler Carruth631abd92011-06-16 06:47:06 +00001784void
Douglas Gregore31e6062012-02-07 10:09:13 +00001785StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1786 VisitExpr(S);
1787 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1788 CEnd = S->explicit_capture_end();
1789 C != CEnd; ++C) {
Richard Trieu931638e2017-11-11 00:54:25 +00001790 if (C->capturesVLAType())
1791 continue;
1792
Douglas Gregore31e6062012-02-07 10:09:13 +00001793 ID.AddInteger(C->getCaptureKind());
Richard Smithba71c082013-05-16 06:20:58 +00001794 switch (C->getCaptureKind()) {
Faisal Validc6b5962016-03-21 09:25:37 +00001795 case LCK_StarThis:
Richard Smithba71c082013-05-16 06:20:58 +00001796 case LCK_This:
1797 break;
1798 case LCK_ByRef:
1799 case LCK_ByCopy:
Douglas Gregore31e6062012-02-07 10:09:13 +00001800 VisitDecl(C->getCapturedVar());
1801 ID.AddBoolean(C->isPackExpansion());
Richard Smithba71c082013-05-16 06:20:58 +00001802 break;
Alexey Bataev39c81e22014-08-28 04:28:19 +00001803 case LCK_VLAType:
1804 llvm_unreachable("VLA type in explicit captures.");
Douglas Gregore31e6062012-02-07 10:09:13 +00001805 }
1806 }
1807 // Note: If we actually needed to be able to match lambda
1808 // expressions, we would have to consider parameters and return type
1809 // here, among other things.
1810 VisitStmt(S->getBody());
1811}
1812
1813void
Chandler Carruth631abd92011-06-16 06:47:06 +00001814StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001815 VisitExpr(S);
1816}
1817
Chandler Carruth631abd92011-06-16 06:47:06 +00001818void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001819 VisitExpr(S);
1820 ID.AddBoolean(S->isGlobalDelete());
1821 ID.AddBoolean(S->isArrayForm());
1822 VisitDecl(S->getOperatorDelete());
1823}
1824
Chandler Carruth631abd92011-06-16 06:47:06 +00001825void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001826 VisitExpr(S);
1827 VisitType(S->getAllocatedType());
1828 VisitDecl(S->getOperatorNew());
1829 VisitDecl(S->getOperatorDelete());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001830 ID.AddBoolean(S->isArray());
1831 ID.AddInteger(S->getNumPlacementArgs());
1832 ID.AddBoolean(S->isGlobalNew());
1833 ID.AddBoolean(S->isParenTypeId());
Sebastian Redl6047f072012-02-16 12:22:20 +00001834 ID.AddInteger(S->getInitializationStyle());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001835}
1836
Chandler Carruth631abd92011-06-16 06:47:06 +00001837void
1838StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
Douglas Gregorad8a3362009-09-04 17:36:40 +00001839 VisitExpr(S);
1840 ID.AddBoolean(S->isArrow());
1841 VisitNestedNameSpecifier(S->getQualifier());
Craig Topper36250ad2014-05-12 05:36:57 +00001842 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001843 if (S->getScopeTypeInfo())
1844 VisitType(S->getScopeTypeInfo()->getType());
Craig Topper36250ad2014-05-12 05:36:57 +00001845 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
Eli Friedman85641392013-08-09 23:37:05 +00001846 if (S->getDestroyedTypeInfo())
1847 VisitType(S->getDestroyedType());
1848 else
Richard Trieu639d7b62017-02-22 22:22:42 +00001849 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
Douglas Gregorad8a3362009-09-04 17:36:40 +00001850}
1851
Chandler Carruth631abd92011-06-16 06:47:06 +00001852void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
Argyrios Kyrtzidisb482eb82010-08-15 20:53:20 +00001853 VisitExpr(S);
John McCalle66edc12009-11-24 19:00:30 +00001854 VisitNestedNameSpecifier(S->getQualifier());
Richard Trieuf65efae2018-02-22 05:32:25 +00001855 VisitName(S->getName(), /*TreatAsDecl*/ true);
John McCalle66edc12009-11-24 19:00:30 +00001856 ID.AddBoolean(S->hasExplicitTemplateArgs());
1857 if (S->hasExplicitTemplateArgs())
James Y Knight04ec5bf2015-12-24 02:59:37 +00001858 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001859}
1860
1861void
Chandler Carruth631abd92011-06-16 06:47:06 +00001862StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
Argyrios Kyrtzidisf4505452010-08-15 01:15:38 +00001863 VisitOverloadExpr(S);
Douglas Gregor5c193b92009-07-28 00:33:38 +00001864}
1865
Douglas Gregor29c42f22012-02-24 07:38:34 +00001866void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1867 VisitExpr(S);
1868 ID.AddInteger(S->getTrait());
1869 ID.AddInteger(S->getNumArgs());
1870 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1871 VisitType(S->getArg(I)->getType());
1872}
1873
Chandler Carruth631abd92011-06-16 06:47:06 +00001874void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
John Wiegley6242b6a2011-04-28 00:16:57 +00001875 VisitExpr(S);
1876 ID.AddInteger(S->getTrait());
1877 VisitType(S->getQueriedType());
1878}
1879
Chandler Carruth631abd92011-06-16 06:47:06 +00001880void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
John Wiegleyf9f65842011-04-25 06:54:41 +00001881 VisitExpr(S);
1882 ID.AddInteger(S->getTrait());
1883 VisitExpr(S->getQueriedExpression());
1884}
1885
Chandler Carruth631abd92011-06-16 06:47:06 +00001886void StmtProfiler::VisitDependentScopeDeclRefExpr(
1887 const DependentScopeDeclRefExpr *S) {
Douglas Gregor5c193b92009-07-28 00:33:38 +00001888 VisitExpr(S);
1889 VisitName(S->getDeclName());
1890 VisitNestedNameSpecifier(S->getQualifier());
John McCalle66edc12009-11-24 19:00:30 +00001891 ID.AddBoolean(S->hasExplicitTemplateArgs());
1892 if (S->hasExplicitTemplateArgs())
1893 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregor5c193b92009-07-28 00:33:38 +00001894}
1895
Chandler Carruth631abd92011-06-16 06:47:06 +00001896void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001897 VisitExpr(S);
Douglas Gregora7095092009-07-28 14:44:31 +00001898}
1899
Chandler Carruth631abd92011-06-16 06:47:06 +00001900void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1901 const CXXUnresolvedConstructExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00001902 VisitExpr(S);
1903 VisitType(S->getTypeAsWritten());
Richard Smith39eca9b2017-08-23 22:12:08 +00001904 ID.AddInteger(S->isListInitialization());
Douglas Gregora7095092009-07-28 14:44:31 +00001905}
1906
Chandler Carruth631abd92011-06-16 06:47:06 +00001907void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1908 const CXXDependentScopeMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001909 ID.AddBoolean(S->isImplicitAccess());
1910 if (!S->isImplicitAccess()) {
1911 VisitExpr(S);
1912 ID.AddBoolean(S->isArrow());
1913 }
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001914 VisitNestedNameSpecifier(S->getQualifier());
Douglas Gregora7095092009-07-28 14:44:31 +00001915 VisitName(S->getMember());
John McCall2d74de92009-12-01 22:10:20 +00001916 ID.AddBoolean(S->hasExplicitTemplateArgs());
1917 if (S->hasExplicitTemplateArgs())
John McCall10eae182009-11-30 22:42:35 +00001918 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1919}
1920
Chandler Carruth631abd92011-06-16 06:47:06 +00001921void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
John McCall2d74de92009-12-01 22:10:20 +00001922 ID.AddBoolean(S->isImplicitAccess());
1923 if (!S->isImplicitAccess()) {
1924 VisitExpr(S);
1925 ID.AddBoolean(S->isArrow());
1926 }
John McCall10eae182009-11-30 22:42:35 +00001927 VisitNestedNameSpecifier(S->getQualifier());
1928 VisitName(S->getMemberName());
1929 ID.AddBoolean(S->hasExplicitTemplateArgs());
1930 if (S->hasExplicitTemplateArgs())
1931 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
Douglas Gregora7095092009-07-28 14:44:31 +00001932}
1933
Chandler Carruth631abd92011-06-16 06:47:06 +00001934void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001935 VisitExpr(S);
1936}
1937
Chandler Carruth631abd92011-06-16 06:47:06 +00001938void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
Douglas Gregore8e9dd62011-01-03 17:17:50 +00001939 VisitExpr(S);
1940}
1941
Chandler Carruth631abd92011-06-16 06:47:06 +00001942void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001943 VisitExpr(S);
1944 VisitDecl(S->getPack());
Richard Smithd784e682015-09-23 21:41:42 +00001945 if (S->isPartiallySubstituted()) {
1946 auto Args = S->getPartialArguments();
1947 ID.AddInteger(Args.size());
1948 for (const auto &TA : Args)
1949 VisitTemplateArgument(TA);
1950 } else {
1951 ID.AddInteger(0);
1952 }
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001953}
1954
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001955void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
Chandler Carruth631abd92011-06-16 06:47:06 +00001956 const SubstNonTypeTemplateParmPackExpr *S) {
Douglas Gregorcdbc5392011-01-15 01:15:58 +00001957 VisitExpr(S);
1958 VisitDecl(S->getParameterPack());
1959 VisitTemplateArgument(S->getArgumentPack());
1960}
1961
John McCall7c454bb2011-07-15 05:09:51 +00001962void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1963 const SubstNonTypeTemplateParmExpr *E) {
1964 // Profile exactly as the replacement expression.
1965 Visit(E->getReplacement());
1966}
1967
Richard Smithb15fe3a2012-09-12 00:56:43 +00001968void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1969 VisitExpr(S);
1970 VisitDecl(S->getParameterPack());
1971 ID.AddInteger(S->getNumExpansions());
1972 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1973 VisitDecl(*I);
1974}
1975
Douglas Gregorfe314812011-06-21 17:03:29 +00001976void StmtProfiler::VisitMaterializeTemporaryExpr(
1977 const MaterializeTemporaryExpr *S) {
1978 VisitExpr(S);
1979}
1980
Richard Smith0f0af192014-11-08 05:07:16 +00001981void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1982 VisitExpr(S);
1983 ID.AddInteger(S->getOperator());
1984}
1985
Richard Smith9f690bd2015-10-27 06:02:45 +00001986void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1987 VisitStmt(S);
1988}
1989
1990void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1991 VisitStmt(S);
1992}
1993
1994void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1995 VisitExpr(S);
1996}
1997
Eric Fiselier20f25cb2017-03-06 23:38:15 +00001998void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
1999 VisitExpr(S);
2000}
2001
Richard Smith9f690bd2015-10-27 06:02:45 +00002002void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
2003 VisitExpr(S);
2004}
2005
Chandler Carruth631abd92011-06-16 06:47:06 +00002006void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
Fangrui Song6907ce22018-07-30 19:24:48 +00002007 VisitExpr(E);
John McCall8d69a212010-11-15 23:31:06 +00002008}
2009
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00002010void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
2011 VisitExpr(E);
2012}
2013
Eric Fiselier708afb52019-05-16 21:04:15 +00002014void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
2015 VisitExpr(E);
2016}
2017
Chandler Carruth631abd92011-06-16 06:47:06 +00002018void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002019 VisitExpr(S);
2020}
2021
Patrick Beard0caa3942012-04-19 00:25:12 +00002022void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +00002023 VisitExpr(E);
2024}
2025
2026void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
2027 VisitExpr(E);
2028}
2029
2030void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
2031 VisitExpr(E);
2032}
2033
Chandler Carruth631abd92011-06-16 06:47:06 +00002034void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002035 VisitExpr(S);
2036 VisitType(S->getEncodedType());
2037}
2038
Chandler Carruth631abd92011-06-16 06:47:06 +00002039void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002040 VisitExpr(S);
2041 VisitName(S->getSelector());
2042}
2043
Chandler Carruth631abd92011-06-16 06:47:06 +00002044void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002045 VisitExpr(S);
2046 VisitDecl(S->getProtocol());
2047}
2048
Chandler Carruth631abd92011-06-16 06:47:06 +00002049void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002050 VisitExpr(S);
2051 VisitDecl(S->getDecl());
2052 ID.AddBoolean(S->isArrow());
2053 ID.AddBoolean(S->isFreeIvar());
2054}
2055
Chandler Carruth631abd92011-06-16 06:47:06 +00002056void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002057 VisitExpr(S);
John McCallb7bd14f2010-12-02 01:19:52 +00002058 if (S->isImplicitProperty()) {
2059 VisitDecl(S->getImplicitPropertyGetter());
2060 VisitDecl(S->getImplicitPropertySetter());
2061 } else {
2062 VisitDecl(S->getExplicitProperty());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002063 }
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002064 if (S->isSuperReceiver()) {
2065 ID.AddBoolean(S->isSuperReceiver());
John McCallb7bd14f2010-12-02 01:19:52 +00002066 VisitType(S->getSuperReceiverType());
Fariborz Jahanian681c0752010-10-14 16:04:05 +00002067 }
Douglas Gregora7095092009-07-28 14:44:31 +00002068}
2069
Ted Kremeneke65b0862012-03-06 20:05:56 +00002070void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
2071 VisitExpr(S);
2072 VisitDecl(S->getAtIndexMethodDecl());
2073 VisitDecl(S->setAtIndexMethodDecl());
2074}
2075
Chandler Carruth631abd92011-06-16 06:47:06 +00002076void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002077 VisitExpr(S);
2078 VisitName(S->getSelector());
2079 VisitDecl(S->getMethodDecl());
2080}
2081
Chandler Carruth631abd92011-06-16 06:47:06 +00002082void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
Douglas Gregora7095092009-07-28 14:44:31 +00002083 VisitExpr(S);
2084 ID.AddBoolean(S->isArrow());
2085}
2086
Ted Kremeneke65b0862012-03-06 20:05:56 +00002087void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
2088 VisitExpr(S);
2089 ID.AddBoolean(S->getValue());
2090}
2091
Chandler Carruth631abd92011-06-16 06:47:06 +00002092void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
2093 const ObjCIndirectCopyRestoreExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00002094 VisitExpr(S);
2095 ID.AddBoolean(S->shouldCopy());
2096}
2097
Chandler Carruth631abd92011-06-16 06:47:06 +00002098void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
John McCall31168b02011-06-15 23:02:42 +00002099 VisitExplicitCastExpr(S);
2100 ID.AddBoolean(S->getBridgeKind());
2101}
2102
Erik Pilkington29099de2016-07-16 00:35:23 +00002103void StmtProfiler::VisitObjCAvailabilityCheckExpr(
2104 const ObjCAvailabilityCheckExpr *S) {
2105 VisitExpr(S);
2106}
2107
John McCall0ad16662009-10-29 08:12:44 +00002108void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
Douglas Gregor5c193b92009-07-28 00:33:38 +00002109 unsigned NumArgs) {
2110 ID.AddInteger(NumArgs);
John McCall0ad16662009-10-29 08:12:44 +00002111 for (unsigned I = 0; I != NumArgs; ++I)
2112 VisitTemplateArgument(Args[I].getArgument());
2113}
Mike Stump11289f42009-09-09 15:08:12 +00002114
John McCall0ad16662009-10-29 08:12:44 +00002115void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
2116 // Mostly repetitive with TemplateArgument::Profile!
2117 ID.AddInteger(Arg.getKind());
2118 switch (Arg.getKind()) {
2119 case TemplateArgument::Null:
2120 break;
Mike Stump11289f42009-09-09 15:08:12 +00002121
John McCall0ad16662009-10-29 08:12:44 +00002122 case TemplateArgument::Type:
2123 VisitType(Arg.getAsType());
2124 break;
Mike Stump11289f42009-09-09 15:08:12 +00002125
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002126 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002127 case TemplateArgument::TemplateExpansion:
2128 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002129 break;
Fangrui Song6907ce22018-07-30 19:24:48 +00002130
John McCall0ad16662009-10-29 08:12:44 +00002131 case TemplateArgument::Declaration:
2132 VisitDecl(Arg.getAsDecl());
2133 break;
Mike Stump11289f42009-09-09 15:08:12 +00002134
Eli Friedmanb826a002012-09-26 02:36:12 +00002135 case TemplateArgument::NullPtr:
2136 VisitType(Arg.getNullPtrType());
2137 break;
2138
John McCall0ad16662009-10-29 08:12:44 +00002139 case TemplateArgument::Integral:
Benjamin Kramer6003ad52012-06-07 15:09:51 +00002140 Arg.getAsIntegral().Profile(ID);
John McCall0ad16662009-10-29 08:12:44 +00002141 VisitType(Arg.getIntegralType());
2142 break;
Mike Stump11289f42009-09-09 15:08:12 +00002143
John McCall0ad16662009-10-29 08:12:44 +00002144 case TemplateArgument::Expression:
2145 Visit(Arg.getAsExpr());
2146 break;
Mike Stump11289f42009-09-09 15:08:12 +00002147
John McCall0ad16662009-10-29 08:12:44 +00002148 case TemplateArgument::Pack:
Aaron Ballman2a89e852014-07-15 21:32:31 +00002149 for (const auto &P : Arg.pack_elements())
2150 VisitTemplateArgument(P);
John McCall0ad16662009-10-29 08:12:44 +00002151 break;
Douglas Gregor5c193b92009-07-28 00:33:38 +00002152 }
2153}
2154
Jay Foad39c79802011-01-12 09:06:06 +00002155void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
Chandler Carruth631abd92011-06-16 06:47:06 +00002156 bool Canonical) const {
Richard Trieu639d7b62017-02-22 22:22:42 +00002157 StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2158 Profiler.Visit(this);
2159}
2160
2161void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2162 class ODRHash &Hash) const {
2163 StmtProfilerWithoutPointers Profiler(ID, Hash);
Douglas Gregor5c193b92009-07-28 00:33:38 +00002164 Profiler.Visit(this);
2165}