1 //===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Stmt::Profile method, which builds a unique bit
10 // representation that identifies a statement/expression.
11 //
12 //===----------------------------------------------------------------------===//
13 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/DeclCXX.h"
15 #include "clang/AST/DeclObjC.h"
16 #include "clang/AST/DeclTemplate.h"
17 #include "clang/AST/Expr.h"
18 #include "clang/AST/ExprCXX.h"
19 #include "clang/AST/ExprObjC.h"
20 #include "clang/AST/ExprOpenMP.h"
21 #include "clang/AST/ODRHash.h"
22 #include "clang/AST/OpenMPClause.h"
23 #include "clang/AST/StmtVisitor.h"
24 #include "llvm/ADT/FoldingSet.h"
25 using namespace clang;
26
27 namespace {
28 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
29 protected:
30 llvm::FoldingSetNodeID &ID;
31 bool Canonical;
32 bool ProfileLambdaExpr;
33
34 public:
StmtProfiler(llvm::FoldingSetNodeID & ID,bool Canonical,bool ProfileLambdaExpr)35 StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical,
36 bool ProfileLambdaExpr)
37 : ID(ID), Canonical(Canonical), ProfileLambdaExpr(ProfileLambdaExpr) {}
38
~StmtProfiler()39 virtual ~StmtProfiler() {}
40
41 void VisitStmt(const Stmt *S);
42
VisitStmtNoChildren(const Stmt * S)43 void VisitStmtNoChildren(const Stmt *S) {
44 HandleStmtClass(S->getStmtClass());
45 }
46
47 virtual void HandleStmtClass(Stmt::StmtClass SC) = 0;
48
49 #define STMT(Node, Base) void Visit##Node(const Node *S);
50 #include "clang/AST/StmtNodes.inc"
51
52 /// Visit a declaration that is referenced within an expression
53 /// or statement.
54 virtual void VisitDecl(const Decl *D) = 0;
55
56 /// Visit a type that is referenced within an expression or
57 /// statement.
58 virtual void VisitType(QualType T) = 0;
59
60 /// Visit a name that occurs within an expression or statement.
61 virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0;
62
63 /// Visit identifiers that are not in Decl's or Type's.
64 virtual void VisitIdentifierInfo(const IdentifierInfo *II) = 0;
65
66 /// Visit a nested-name-specifier that occurs within an expression
67 /// or statement.
68 virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0;
69
70 /// Visit a template name that occurs within an expression or
71 /// statement.
72 virtual void VisitTemplateName(TemplateName Name) = 0;
73
74 /// Visit template arguments that occur within an expression or
75 /// statement.
76 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
77 unsigned NumArgs);
78
79 /// Visit a single template argument.
80 void VisitTemplateArgument(const TemplateArgument &Arg);
81 };
82
83 class StmtProfilerWithPointers : public StmtProfiler {
84 const ASTContext &Context;
85
86 public:
StmtProfilerWithPointers(llvm::FoldingSetNodeID & ID,const ASTContext & Context,bool Canonical,bool ProfileLambdaExpr)87 StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID,
88 const ASTContext &Context, bool Canonical,
89 bool ProfileLambdaExpr)
90 : StmtProfiler(ID, Canonical, ProfileLambdaExpr), Context(Context) {}
91
92 private:
HandleStmtClass(Stmt::StmtClass SC)93 void HandleStmtClass(Stmt::StmtClass SC) override {
94 ID.AddInteger(SC);
95 }
96
VisitDecl(const Decl * D)97 void VisitDecl(const Decl *D) override {
98 ID.AddInteger(D ? D->getKind() : 0);
99
100 if (Canonical && D) {
101 if (const NonTypeTemplateParmDecl *NTTP =
102 dyn_cast<NonTypeTemplateParmDecl>(D)) {
103 ID.AddInteger(NTTP->getDepth());
104 ID.AddInteger(NTTP->getIndex());
105 ID.AddBoolean(NTTP->isParameterPack());
106 // C++20 [temp.over.link]p6:
107 // Two template-parameters are equivalent under the following
108 // conditions: [...] if they declare non-type template parameters,
109 // they have equivalent types ignoring the use of type-constraints
110 // for placeholder types
111 //
112 // TODO: Why do we need to include the type in the profile? It's not
113 // part of the mangling.
114 VisitType(Context.getUnconstrainedType(NTTP->getType()));
115 return;
116 }
117
118 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
119 // The Itanium C++ ABI uses the type, scope depth, and scope
120 // index of a parameter when mangling expressions that involve
121 // function parameters, so we will use the parameter's type for
122 // establishing function parameter identity. That way, our
123 // definition of "equivalent" (per C++ [temp.over.link]) is at
124 // least as strong as the definition of "equivalent" used for
125 // name mangling.
126 //
127 // TODO: The Itanium C++ ABI only uses the top-level cv-qualifiers,
128 // not the entirety of the type.
129 VisitType(Parm->getType());
130 ID.AddInteger(Parm->getFunctionScopeDepth());
131 ID.AddInteger(Parm->getFunctionScopeIndex());
132 return;
133 }
134
135 if (const TemplateTypeParmDecl *TTP =
136 dyn_cast<TemplateTypeParmDecl>(D)) {
137 ID.AddInteger(TTP->getDepth());
138 ID.AddInteger(TTP->getIndex());
139 ID.AddBoolean(TTP->isParameterPack());
140 return;
141 }
142
143 if (const TemplateTemplateParmDecl *TTP =
144 dyn_cast<TemplateTemplateParmDecl>(D)) {
145 ID.AddInteger(TTP->getDepth());
146 ID.AddInteger(TTP->getIndex());
147 ID.AddBoolean(TTP->isParameterPack());
148 return;
149 }
150 }
151
152 ID.AddPointer(D ? D->getCanonicalDecl() : nullptr);
153 }
154
VisitType(QualType T)155 void VisitType(QualType T) override {
156 if (Canonical && !T.isNull())
157 T = Context.getCanonicalType(T);
158
159 ID.AddPointer(T.getAsOpaquePtr());
160 }
161
VisitName(DeclarationName Name,bool)162 void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override {
163 ID.AddPointer(Name.getAsOpaquePtr());
164 }
165
VisitIdentifierInfo(const IdentifierInfo * II)166 void VisitIdentifierInfo(const IdentifierInfo *II) override {
167 ID.AddPointer(II);
168 }
169
VisitNestedNameSpecifier(NestedNameSpecifier * NNS)170 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
171 if (Canonical)
172 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
173 ID.AddPointer(NNS);
174 }
175
VisitTemplateName(TemplateName Name)176 void VisitTemplateName(TemplateName Name) override {
177 if (Canonical)
178 Name = Context.getCanonicalTemplateName(Name);
179
180 Name.Profile(ID);
181 }
182 };
183
184 class StmtProfilerWithoutPointers : public StmtProfiler {
185 ODRHash &Hash;
186 public:
StmtProfilerWithoutPointers(llvm::FoldingSetNodeID & ID,ODRHash & Hash)187 StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
188 : StmtProfiler(ID, /*Canonical=*/false, /*ProfileLambdaExpr=*/false),
189 Hash(Hash) {}
190
191 private:
HandleStmtClass(Stmt::StmtClass SC)192 void HandleStmtClass(Stmt::StmtClass SC) override {
193 if (SC == Stmt::UnresolvedLookupExprClass) {
194 // Pretend that the name looked up is a Decl due to how templates
195 // handle some Decl lookups.
196 ID.AddInteger(Stmt::DeclRefExprClass);
197 } else {
198 ID.AddInteger(SC);
199 }
200 }
201
VisitType(QualType T)202 void VisitType(QualType T) override {
203 Hash.AddQualType(T);
204 }
205
VisitName(DeclarationName Name,bool TreatAsDecl)206 void VisitName(DeclarationName Name, bool TreatAsDecl) override {
207 if (TreatAsDecl) {
208 // A Decl can be null, so each Decl is preceded by a boolean to
209 // store its nullness. Add a boolean here to match.
210 ID.AddBoolean(true);
211 }
212 Hash.AddDeclarationName(Name, TreatAsDecl);
213 }
VisitIdentifierInfo(const IdentifierInfo * II)214 void VisitIdentifierInfo(const IdentifierInfo *II) override {
215 ID.AddBoolean(II);
216 if (II) {
217 Hash.AddIdentifierInfo(II);
218 }
219 }
VisitDecl(const Decl * D)220 void VisitDecl(const Decl *D) override {
221 ID.AddBoolean(D);
222 if (D) {
223 Hash.AddDecl(D);
224 }
225 }
VisitTemplateName(TemplateName Name)226 void VisitTemplateName(TemplateName Name) override {
227 Hash.AddTemplateName(Name);
228 }
VisitNestedNameSpecifier(NestedNameSpecifier * NNS)229 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
230 ID.AddBoolean(NNS);
231 if (NNS) {
232 Hash.AddNestedNameSpecifier(NNS);
233 }
234 }
235 };
236 }
237
VisitStmt(const Stmt * S)238 void StmtProfiler::VisitStmt(const Stmt *S) {
239 assert(S && "Requires non-null Stmt pointer");
240
241 VisitStmtNoChildren(S);
242
243 for (const Stmt *SubStmt : S->children()) {
244 if (SubStmt)
245 Visit(SubStmt);
246 else
247 ID.AddInteger(0);
248 }
249 }
250
VisitDeclStmt(const DeclStmt * S)251 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
252 VisitStmt(S);
253 for (const auto *D : S->decls())
254 VisitDecl(D);
255 }
256
VisitNullStmt(const NullStmt * S)257 void StmtProfiler::VisitNullStmt(const NullStmt *S) {
258 VisitStmt(S);
259 }
260
VisitCompoundStmt(const CompoundStmt * S)261 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
262 VisitStmt(S);
263 }
264
VisitCaseStmt(const CaseStmt * S)265 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
266 VisitStmt(S);
267 }
268
VisitDefaultStmt(const DefaultStmt * S)269 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
270 VisitStmt(S);
271 }
272
VisitLabelStmt(const LabelStmt * S)273 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
274 VisitStmt(S);
275 VisitDecl(S->getDecl());
276 }
277
VisitAttributedStmt(const AttributedStmt * S)278 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
279 VisitStmt(S);
280 // TODO: maybe visit attributes?
281 }
282
VisitIfStmt(const IfStmt * S)283 void StmtProfiler::VisitIfStmt(const IfStmt *S) {
284 VisitStmt(S);
285 VisitDecl(S->getConditionVariable());
286 }
287
VisitSwitchStmt(const SwitchStmt * S)288 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
289 VisitStmt(S);
290 VisitDecl(S->getConditionVariable());
291 }
292
VisitWhileStmt(const WhileStmt * S)293 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
294 VisitStmt(S);
295 VisitDecl(S->getConditionVariable());
296 }
297
VisitDoStmt(const DoStmt * S)298 void StmtProfiler::VisitDoStmt(const DoStmt *S) {
299 VisitStmt(S);
300 }
301
VisitForStmt(const ForStmt * S)302 void StmtProfiler::VisitForStmt(const ForStmt *S) {
303 VisitStmt(S);
304 }
305
VisitGotoStmt(const GotoStmt * S)306 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
307 VisitStmt(S);
308 VisitDecl(S->getLabel());
309 }
310
VisitIndirectGotoStmt(const IndirectGotoStmt * S)311 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
312 VisitStmt(S);
313 }
314
VisitContinueStmt(const ContinueStmt * S)315 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
316 VisitStmt(S);
317 }
318
VisitBreakStmt(const BreakStmt * S)319 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
320 VisitStmt(S);
321 }
322
VisitReturnStmt(const ReturnStmt * S)323 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
324 VisitStmt(S);
325 }
326
VisitGCCAsmStmt(const GCCAsmStmt * S)327 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
328 VisitStmt(S);
329 ID.AddBoolean(S->isVolatile());
330 ID.AddBoolean(S->isSimple());
331 VisitStringLiteral(S->getAsmString());
332 ID.AddInteger(S->getNumOutputs());
333 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
334 ID.AddString(S->getOutputName(I));
335 VisitStringLiteral(S->getOutputConstraintLiteral(I));
336 }
337 ID.AddInteger(S->getNumInputs());
338 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
339 ID.AddString(S->getInputName(I));
340 VisitStringLiteral(S->getInputConstraintLiteral(I));
341 }
342 ID.AddInteger(S->getNumClobbers());
343 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
344 VisitStringLiteral(S->getClobberStringLiteral(I));
345 ID.AddInteger(S->getNumLabels());
346 for (auto *L : S->labels())
347 VisitDecl(L->getLabel());
348 }
349
VisitMSAsmStmt(const MSAsmStmt * S)350 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
351 // FIXME: Implement MS style inline asm statement profiler.
352 VisitStmt(S);
353 }
354
VisitCXXCatchStmt(const CXXCatchStmt * S)355 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
356 VisitStmt(S);
357 VisitType(S->getCaughtType());
358 }
359
VisitCXXTryStmt(const CXXTryStmt * S)360 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
361 VisitStmt(S);
362 }
363
VisitCXXForRangeStmt(const CXXForRangeStmt * S)364 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
365 VisitStmt(S);
366 }
367
VisitMSDependentExistsStmt(const MSDependentExistsStmt * S)368 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
369 VisitStmt(S);
370 ID.AddBoolean(S->isIfExists());
371 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
372 VisitName(S->getNameInfo().getName());
373 }
374
VisitSEHTryStmt(const SEHTryStmt * S)375 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
376 VisitStmt(S);
377 }
378
VisitSEHFinallyStmt(const SEHFinallyStmt * S)379 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
380 VisitStmt(S);
381 }
382
VisitSEHExceptStmt(const SEHExceptStmt * S)383 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
384 VisitStmt(S);
385 }
386
VisitSEHLeaveStmt(const SEHLeaveStmt * S)387 void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
388 VisitStmt(S);
389 }
390
VisitCapturedStmt(const CapturedStmt * S)391 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
392 VisitStmt(S);
393 }
394
VisitObjCForCollectionStmt(const ObjCForCollectionStmt * S)395 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
396 VisitStmt(S);
397 }
398
VisitObjCAtCatchStmt(const ObjCAtCatchStmt * S)399 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
400 VisitStmt(S);
401 ID.AddBoolean(S->hasEllipsis());
402 if (S->getCatchParamDecl())
403 VisitType(S->getCatchParamDecl()->getType());
404 }
405
VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt * S)406 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
407 VisitStmt(S);
408 }
409
VisitObjCAtTryStmt(const ObjCAtTryStmt * S)410 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
411 VisitStmt(S);
412 }
413
414 void
VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt * S)415 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
416 VisitStmt(S);
417 }
418
VisitObjCAtThrowStmt(const ObjCAtThrowStmt * S)419 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
420 VisitStmt(S);
421 }
422
423 void
VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt * S)424 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
425 VisitStmt(S);
426 }
427
428 namespace {
429 class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
430 StmtProfiler *Profiler;
431 /// Process clauses with list of variables.
432 template <typename T>
433 void VisitOMPClauseList(T *Node);
434
435 public:
OMPClauseProfiler(StmtProfiler * P)436 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
437 #define GEN_CLANG_CLAUSE_CLASS
438 #define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(const Class *C);
439 #include "llvm/Frontend/OpenMP/OMP.inc"
440 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
441 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
442 };
443
VistOMPClauseWithPreInit(const OMPClauseWithPreInit * C)444 void OMPClauseProfiler::VistOMPClauseWithPreInit(
445 const OMPClauseWithPreInit *C) {
446 if (auto *S = C->getPreInitStmt())
447 Profiler->VisitStmt(S);
448 }
449
VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate * C)450 void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
451 const OMPClauseWithPostUpdate *C) {
452 VistOMPClauseWithPreInit(C);
453 if (auto *E = C->getPostUpdateExpr())
454 Profiler->VisitStmt(E);
455 }
456
VisitOMPIfClause(const OMPIfClause * C)457 void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
458 VistOMPClauseWithPreInit(C);
459 if (C->getCondition())
460 Profiler->VisitStmt(C->getCondition());
461 }
462
VisitOMPFinalClause(const OMPFinalClause * C)463 void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
464 VistOMPClauseWithPreInit(C);
465 if (C->getCondition())
466 Profiler->VisitStmt(C->getCondition());
467 }
468
VisitOMPNumThreadsClause(const OMPNumThreadsClause * C)469 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
470 VistOMPClauseWithPreInit(C);
471 if (C->getNumThreads())
472 Profiler->VisitStmt(C->getNumThreads());
473 }
474
VisitOMPAlignClause(const OMPAlignClause * C)475 void OMPClauseProfiler::VisitOMPAlignClause(const OMPAlignClause *C) {
476 if (C->getAlignment())
477 Profiler->VisitStmt(C->getAlignment());
478 }
479
VisitOMPSafelenClause(const OMPSafelenClause * C)480 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
481 if (C->getSafelen())
482 Profiler->VisitStmt(C->getSafelen());
483 }
484
VisitOMPSimdlenClause(const OMPSimdlenClause * C)485 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
486 if (C->getSimdlen())
487 Profiler->VisitStmt(C->getSimdlen());
488 }
489
VisitOMPSizesClause(const OMPSizesClause * C)490 void OMPClauseProfiler::VisitOMPSizesClause(const OMPSizesClause *C) {
491 for (auto *E : C->getSizesRefs())
492 if (E)
493 Profiler->VisitExpr(E);
494 }
495
VisitOMPFullClause(const OMPFullClause * C)496 void OMPClauseProfiler::VisitOMPFullClause(const OMPFullClause *C) {}
497
VisitOMPPartialClause(const OMPPartialClause * C)498 void OMPClauseProfiler::VisitOMPPartialClause(const OMPPartialClause *C) {
499 if (const Expr *Factor = C->getFactor())
500 Profiler->VisitExpr(Factor);
501 }
502
VisitOMPAllocatorClause(const OMPAllocatorClause * C)503 void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
504 if (C->getAllocator())
505 Profiler->VisitStmt(C->getAllocator());
506 }
507
VisitOMPCollapseClause(const OMPCollapseClause * C)508 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
509 if (C->getNumForLoops())
510 Profiler->VisitStmt(C->getNumForLoops());
511 }
512
VisitOMPDetachClause(const OMPDetachClause * C)513 void OMPClauseProfiler::VisitOMPDetachClause(const OMPDetachClause *C) {
514 if (Expr *Evt = C->getEventHandler())
515 Profiler->VisitStmt(Evt);
516 }
517
VisitOMPNovariantsClause(const OMPNovariantsClause * C)518 void OMPClauseProfiler::VisitOMPNovariantsClause(const OMPNovariantsClause *C) {
519 VistOMPClauseWithPreInit(C);
520 if (C->getCondition())
521 Profiler->VisitStmt(C->getCondition());
522 }
523
VisitOMPNocontextClause(const OMPNocontextClause * C)524 void OMPClauseProfiler::VisitOMPNocontextClause(const OMPNocontextClause *C) {
525 VistOMPClauseWithPreInit(C);
526 if (C->getCondition())
527 Profiler->VisitStmt(C->getCondition());
528 }
529
VisitOMPDefaultClause(const OMPDefaultClause * C)530 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
531
VisitOMPProcBindClause(const OMPProcBindClause * C)532 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
533
VisitOMPUnifiedAddressClause(const OMPUnifiedAddressClause * C)534 void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
535 const OMPUnifiedAddressClause *C) {}
536
VisitOMPUnifiedSharedMemoryClause(const OMPUnifiedSharedMemoryClause * C)537 void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
538 const OMPUnifiedSharedMemoryClause *C) {}
539
VisitOMPReverseOffloadClause(const OMPReverseOffloadClause * C)540 void OMPClauseProfiler::VisitOMPReverseOffloadClause(
541 const OMPReverseOffloadClause *C) {}
542
VisitOMPDynamicAllocatorsClause(const OMPDynamicAllocatorsClause * C)543 void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
544 const OMPDynamicAllocatorsClause *C) {}
545
VisitOMPAtomicDefaultMemOrderClause(const OMPAtomicDefaultMemOrderClause * C)546 void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
547 const OMPAtomicDefaultMemOrderClause *C) {}
548
VisitOMPAtClause(const OMPAtClause * C)549 void OMPClauseProfiler::VisitOMPAtClause(const OMPAtClause *C) {}
550
VisitOMPSeverityClause(const OMPSeverityClause * C)551 void OMPClauseProfiler::VisitOMPSeverityClause(const OMPSeverityClause *C) {}
552
VisitOMPMessageClause(const OMPMessageClause * C)553 void OMPClauseProfiler::VisitOMPMessageClause(const OMPMessageClause *C) {
554 if (C->getMessageString())
555 Profiler->VisitStmt(C->getMessageString());
556 }
557
VisitOMPScheduleClause(const OMPScheduleClause * C)558 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
559 VistOMPClauseWithPreInit(C);
560 if (auto *S = C->getChunkSize())
561 Profiler->VisitStmt(S);
562 }
563
VisitOMPOrderedClause(const OMPOrderedClause * C)564 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
565 if (auto *Num = C->getNumForLoops())
566 Profiler->VisitStmt(Num);
567 }
568
VisitOMPNowaitClause(const OMPNowaitClause *)569 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
570
VisitOMPUntiedClause(const OMPUntiedClause *)571 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
572
VisitOMPMergeableClause(const OMPMergeableClause *)573 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
574
VisitOMPReadClause(const OMPReadClause *)575 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
576
VisitOMPWriteClause(const OMPWriteClause *)577 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
578
VisitOMPUpdateClause(const OMPUpdateClause *)579 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
580
VisitOMPCaptureClause(const OMPCaptureClause *)581 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
582
VisitOMPCompareClause(const OMPCompareClause *)583 void OMPClauseProfiler::VisitOMPCompareClause(const OMPCompareClause *) {}
584
VisitOMPFailClause(const OMPFailClause *)585 void OMPClauseProfiler::VisitOMPFailClause(const OMPFailClause *) {}
586
VisitOMPSeqCstClause(const OMPSeqCstClause *)587 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
588
VisitOMPAcqRelClause(const OMPAcqRelClause *)589 void OMPClauseProfiler::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
590
VisitOMPAcquireClause(const OMPAcquireClause *)591 void OMPClauseProfiler::VisitOMPAcquireClause(const OMPAcquireClause *) {}
592
VisitOMPReleaseClause(const OMPReleaseClause *)593 void OMPClauseProfiler::VisitOMPReleaseClause(const OMPReleaseClause *) {}
594
VisitOMPRelaxedClause(const OMPRelaxedClause *)595 void OMPClauseProfiler::VisitOMPRelaxedClause(const OMPRelaxedClause *) {}
596
VisitOMPWeakClause(const OMPWeakClause *)597 void OMPClauseProfiler::VisitOMPWeakClause(const OMPWeakClause *) {}
598
VisitOMPThreadsClause(const OMPThreadsClause *)599 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
600
VisitOMPSIMDClause(const OMPSIMDClause *)601 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
602
VisitOMPNogroupClause(const OMPNogroupClause *)603 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
604
VisitOMPInitClause(const OMPInitClause * C)605 void OMPClauseProfiler::VisitOMPInitClause(const OMPInitClause *C) {
606 VisitOMPClauseList(C);
607 }
608
VisitOMPUseClause(const OMPUseClause * C)609 void OMPClauseProfiler::VisitOMPUseClause(const OMPUseClause *C) {
610 if (C->getInteropVar())
611 Profiler->VisitStmt(C->getInteropVar());
612 }
613
VisitOMPDestroyClause(const OMPDestroyClause * C)614 void OMPClauseProfiler::VisitOMPDestroyClause(const OMPDestroyClause *C) {
615 if (C->getInteropVar())
616 Profiler->VisitStmt(C->getInteropVar());
617 }
618
VisitOMPFilterClause(const OMPFilterClause * C)619 void OMPClauseProfiler::VisitOMPFilterClause(const OMPFilterClause *C) {
620 VistOMPClauseWithPreInit(C);
621 if (C->getThreadID())
622 Profiler->VisitStmt(C->getThreadID());
623 }
624
625 template<typename T>
VisitOMPClauseList(T * Node)626 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
627 for (auto *E : Node->varlists()) {
628 if (E)
629 Profiler->VisitStmt(E);
630 }
631 }
632
VisitOMPPrivateClause(const OMPPrivateClause * C)633 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
634 VisitOMPClauseList(C);
635 for (auto *E : C->private_copies()) {
636 if (E)
637 Profiler->VisitStmt(E);
638 }
639 }
640 void
VisitOMPFirstprivateClause(const OMPFirstprivateClause * C)641 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
642 VisitOMPClauseList(C);
643 VistOMPClauseWithPreInit(C);
644 for (auto *E : C->private_copies()) {
645 if (E)
646 Profiler->VisitStmt(E);
647 }
648 for (auto *E : C->inits()) {
649 if (E)
650 Profiler->VisitStmt(E);
651 }
652 }
653 void
VisitOMPLastprivateClause(const OMPLastprivateClause * C)654 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
655 VisitOMPClauseList(C);
656 VistOMPClauseWithPostUpdate(C);
657 for (auto *E : C->source_exprs()) {
658 if (E)
659 Profiler->VisitStmt(E);
660 }
661 for (auto *E : C->destination_exprs()) {
662 if (E)
663 Profiler->VisitStmt(E);
664 }
665 for (auto *E : C->assignment_ops()) {
666 if (E)
667 Profiler->VisitStmt(E);
668 }
669 }
VisitOMPSharedClause(const OMPSharedClause * C)670 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
671 VisitOMPClauseList(C);
672 }
VisitOMPReductionClause(const OMPReductionClause * C)673 void OMPClauseProfiler::VisitOMPReductionClause(
674 const OMPReductionClause *C) {
675 Profiler->VisitNestedNameSpecifier(
676 C->getQualifierLoc().getNestedNameSpecifier());
677 Profiler->VisitName(C->getNameInfo().getName());
678 VisitOMPClauseList(C);
679 VistOMPClauseWithPostUpdate(C);
680 for (auto *E : C->privates()) {
681 if (E)
682 Profiler->VisitStmt(E);
683 }
684 for (auto *E : C->lhs_exprs()) {
685 if (E)
686 Profiler->VisitStmt(E);
687 }
688 for (auto *E : C->rhs_exprs()) {
689 if (E)
690 Profiler->VisitStmt(E);
691 }
692 for (auto *E : C->reduction_ops()) {
693 if (E)
694 Profiler->VisitStmt(E);
695 }
696 if (C->getModifier() == clang::OMPC_REDUCTION_inscan) {
697 for (auto *E : C->copy_ops()) {
698 if (E)
699 Profiler->VisitStmt(E);
700 }
701 for (auto *E : C->copy_array_temps()) {
702 if (E)
703 Profiler->VisitStmt(E);
704 }
705 for (auto *E : C->copy_array_elems()) {
706 if (E)
707 Profiler->VisitStmt(E);
708 }
709 }
710 }
VisitOMPTaskReductionClause(const OMPTaskReductionClause * C)711 void OMPClauseProfiler::VisitOMPTaskReductionClause(
712 const OMPTaskReductionClause *C) {
713 Profiler->VisitNestedNameSpecifier(
714 C->getQualifierLoc().getNestedNameSpecifier());
715 Profiler->VisitName(C->getNameInfo().getName());
716 VisitOMPClauseList(C);
717 VistOMPClauseWithPostUpdate(C);
718 for (auto *E : C->privates()) {
719 if (E)
720 Profiler->VisitStmt(E);
721 }
722 for (auto *E : C->lhs_exprs()) {
723 if (E)
724 Profiler->VisitStmt(E);
725 }
726 for (auto *E : C->rhs_exprs()) {
727 if (E)
728 Profiler->VisitStmt(E);
729 }
730 for (auto *E : C->reduction_ops()) {
731 if (E)
732 Profiler->VisitStmt(E);
733 }
734 }
VisitOMPInReductionClause(const OMPInReductionClause * C)735 void OMPClauseProfiler::VisitOMPInReductionClause(
736 const OMPInReductionClause *C) {
737 Profiler->VisitNestedNameSpecifier(
738 C->getQualifierLoc().getNestedNameSpecifier());
739 Profiler->VisitName(C->getNameInfo().getName());
740 VisitOMPClauseList(C);
741 VistOMPClauseWithPostUpdate(C);
742 for (auto *E : C->privates()) {
743 if (E)
744 Profiler->VisitStmt(E);
745 }
746 for (auto *E : C->lhs_exprs()) {
747 if (E)
748 Profiler->VisitStmt(E);
749 }
750 for (auto *E : C->rhs_exprs()) {
751 if (E)
752 Profiler->VisitStmt(E);
753 }
754 for (auto *E : C->reduction_ops()) {
755 if (E)
756 Profiler->VisitStmt(E);
757 }
758 for (auto *E : C->taskgroup_descriptors()) {
759 if (E)
760 Profiler->VisitStmt(E);
761 }
762 }
VisitOMPLinearClause(const OMPLinearClause * C)763 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
764 VisitOMPClauseList(C);
765 VistOMPClauseWithPostUpdate(C);
766 for (auto *E : C->privates()) {
767 if (E)
768 Profiler->VisitStmt(E);
769 }
770 for (auto *E : C->inits()) {
771 if (E)
772 Profiler->VisitStmt(E);
773 }
774 for (auto *E : C->updates()) {
775 if (E)
776 Profiler->VisitStmt(E);
777 }
778 for (auto *E : C->finals()) {
779 if (E)
780 Profiler->VisitStmt(E);
781 }
782 if (C->getStep())
783 Profiler->VisitStmt(C->getStep());
784 if (C->getCalcStep())
785 Profiler->VisitStmt(C->getCalcStep());
786 }
VisitOMPAlignedClause(const OMPAlignedClause * C)787 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
788 VisitOMPClauseList(C);
789 if (C->getAlignment())
790 Profiler->VisitStmt(C->getAlignment());
791 }
VisitOMPCopyinClause(const OMPCopyinClause * C)792 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
793 VisitOMPClauseList(C);
794 for (auto *E : C->source_exprs()) {
795 if (E)
796 Profiler->VisitStmt(E);
797 }
798 for (auto *E : C->destination_exprs()) {
799 if (E)
800 Profiler->VisitStmt(E);
801 }
802 for (auto *E : C->assignment_ops()) {
803 if (E)
804 Profiler->VisitStmt(E);
805 }
806 }
807 void
VisitOMPCopyprivateClause(const OMPCopyprivateClause * C)808 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
809 VisitOMPClauseList(C);
810 for (auto *E : C->source_exprs()) {
811 if (E)
812 Profiler->VisitStmt(E);
813 }
814 for (auto *E : C->destination_exprs()) {
815 if (E)
816 Profiler->VisitStmt(E);
817 }
818 for (auto *E : C->assignment_ops()) {
819 if (E)
820 Profiler->VisitStmt(E);
821 }
822 }
VisitOMPFlushClause(const OMPFlushClause * C)823 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
824 VisitOMPClauseList(C);
825 }
VisitOMPDepobjClause(const OMPDepobjClause * C)826 void OMPClauseProfiler::VisitOMPDepobjClause(const OMPDepobjClause *C) {
827 if (const Expr *Depobj = C->getDepobj())
828 Profiler->VisitStmt(Depobj);
829 }
VisitOMPDependClause(const OMPDependClause * C)830 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
831 VisitOMPClauseList(C);
832 }
VisitOMPDeviceClause(const OMPDeviceClause * C)833 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
834 if (C->getDevice())
835 Profiler->VisitStmt(C->getDevice());
836 }
VisitOMPMapClause(const OMPMapClause * C)837 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
838 VisitOMPClauseList(C);
839 }
VisitOMPAllocateClause(const OMPAllocateClause * C)840 void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
841 if (Expr *Allocator = C->getAllocator())
842 Profiler->VisitStmt(Allocator);
843 VisitOMPClauseList(C);
844 }
VisitOMPNumTeamsClause(const OMPNumTeamsClause * C)845 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
846 VistOMPClauseWithPreInit(C);
847 if (C->getNumTeams())
848 Profiler->VisitStmt(C->getNumTeams());
849 }
VisitOMPThreadLimitClause(const OMPThreadLimitClause * C)850 void OMPClauseProfiler::VisitOMPThreadLimitClause(
851 const OMPThreadLimitClause *C) {
852 VistOMPClauseWithPreInit(C);
853 if (C->getThreadLimit())
854 Profiler->VisitStmt(C->getThreadLimit());
855 }
VisitOMPPriorityClause(const OMPPriorityClause * C)856 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
857 VistOMPClauseWithPreInit(C);
858 if (C->getPriority())
859 Profiler->VisitStmt(C->getPriority());
860 }
VisitOMPGrainsizeClause(const OMPGrainsizeClause * C)861 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
862 VistOMPClauseWithPreInit(C);
863 if (C->getGrainsize())
864 Profiler->VisitStmt(C->getGrainsize());
865 }
VisitOMPNumTasksClause(const OMPNumTasksClause * C)866 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
867 VistOMPClauseWithPreInit(C);
868 if (C->getNumTasks())
869 Profiler->VisitStmt(C->getNumTasks());
870 }
VisitOMPHintClause(const OMPHintClause * C)871 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
872 if (C->getHint())
873 Profiler->VisitStmt(C->getHint());
874 }
VisitOMPToClause(const OMPToClause * C)875 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
876 VisitOMPClauseList(C);
877 }
VisitOMPFromClause(const OMPFromClause * C)878 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
879 VisitOMPClauseList(C);
880 }
VisitOMPUseDevicePtrClause(const OMPUseDevicePtrClause * C)881 void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
882 const OMPUseDevicePtrClause *C) {
883 VisitOMPClauseList(C);
884 }
VisitOMPUseDeviceAddrClause(const OMPUseDeviceAddrClause * C)885 void OMPClauseProfiler::VisitOMPUseDeviceAddrClause(
886 const OMPUseDeviceAddrClause *C) {
887 VisitOMPClauseList(C);
888 }
VisitOMPIsDevicePtrClause(const OMPIsDevicePtrClause * C)889 void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
890 const OMPIsDevicePtrClause *C) {
891 VisitOMPClauseList(C);
892 }
VisitOMPHasDeviceAddrClause(const OMPHasDeviceAddrClause * C)893 void OMPClauseProfiler::VisitOMPHasDeviceAddrClause(
894 const OMPHasDeviceAddrClause *C) {
895 VisitOMPClauseList(C);
896 }
VisitOMPNontemporalClause(const OMPNontemporalClause * C)897 void OMPClauseProfiler::VisitOMPNontemporalClause(
898 const OMPNontemporalClause *C) {
899 VisitOMPClauseList(C);
900 for (auto *E : C->private_refs())
901 Profiler->VisitStmt(E);
902 }
VisitOMPInclusiveClause(const OMPInclusiveClause * C)903 void OMPClauseProfiler::VisitOMPInclusiveClause(const OMPInclusiveClause *C) {
904 VisitOMPClauseList(C);
905 }
VisitOMPExclusiveClause(const OMPExclusiveClause * C)906 void OMPClauseProfiler::VisitOMPExclusiveClause(const OMPExclusiveClause *C) {
907 VisitOMPClauseList(C);
908 }
VisitOMPUsesAllocatorsClause(const OMPUsesAllocatorsClause * C)909 void OMPClauseProfiler::VisitOMPUsesAllocatorsClause(
910 const OMPUsesAllocatorsClause *C) {
911 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
912 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
913 Profiler->VisitStmt(D.Allocator);
914 if (D.AllocatorTraits)
915 Profiler->VisitStmt(D.AllocatorTraits);
916 }
917 }
VisitOMPAffinityClause(const OMPAffinityClause * C)918 void OMPClauseProfiler::VisitOMPAffinityClause(const OMPAffinityClause *C) {
919 if (const Expr *Modifier = C->getModifier())
920 Profiler->VisitStmt(Modifier);
921 for (const Expr *E : C->varlists())
922 Profiler->VisitStmt(E);
923 }
VisitOMPOrderClause(const OMPOrderClause * C)924 void OMPClauseProfiler::VisitOMPOrderClause(const OMPOrderClause *C) {}
VisitOMPBindClause(const OMPBindClause * C)925 void OMPClauseProfiler::VisitOMPBindClause(const OMPBindClause *C) {}
VisitOMPXDynCGroupMemClause(const OMPXDynCGroupMemClause * C)926 void OMPClauseProfiler::VisitOMPXDynCGroupMemClause(
927 const OMPXDynCGroupMemClause *C) {
928 VistOMPClauseWithPreInit(C);
929 if (Expr *Size = C->getSize())
930 Profiler->VisitStmt(Size);
931 }
VisitOMPDoacrossClause(const OMPDoacrossClause * C)932 void OMPClauseProfiler::VisitOMPDoacrossClause(const OMPDoacrossClause *C) {
933 VisitOMPClauseList(C);
934 }
VisitOMPXAttributeClause(const OMPXAttributeClause * C)935 void OMPClauseProfiler::VisitOMPXAttributeClause(const OMPXAttributeClause *C) {
936 }
VisitOMPXBareClause(const OMPXBareClause * C)937 void OMPClauseProfiler::VisitOMPXBareClause(const OMPXBareClause *C) {}
938 } // namespace
939
940 void
VisitOMPExecutableDirective(const OMPExecutableDirective * S)941 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
942 VisitStmt(S);
943 OMPClauseProfiler P(this);
944 ArrayRef<OMPClause *> Clauses = S->clauses();
945 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
946 I != E; ++I)
947 if (*I)
948 P.Visit(*I);
949 }
950
VisitOMPCanonicalLoop(const OMPCanonicalLoop * L)951 void StmtProfiler::VisitOMPCanonicalLoop(const OMPCanonicalLoop *L) {
952 VisitStmt(L);
953 }
954
VisitOMPLoopBasedDirective(const OMPLoopBasedDirective * S)955 void StmtProfiler::VisitOMPLoopBasedDirective(const OMPLoopBasedDirective *S) {
956 VisitOMPExecutableDirective(S);
957 }
958
VisitOMPLoopDirective(const OMPLoopDirective * S)959 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
960 VisitOMPLoopBasedDirective(S);
961 }
962
VisitOMPMetaDirective(const OMPMetaDirective * S)963 void StmtProfiler::VisitOMPMetaDirective(const OMPMetaDirective *S) {
964 VisitOMPExecutableDirective(S);
965 }
966
VisitOMPParallelDirective(const OMPParallelDirective * S)967 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
968 VisitOMPExecutableDirective(S);
969 }
970
VisitOMPSimdDirective(const OMPSimdDirective * S)971 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
972 VisitOMPLoopDirective(S);
973 }
974
VisitOMPLoopTransformationDirective(const OMPLoopTransformationDirective * S)975 void StmtProfiler::VisitOMPLoopTransformationDirective(
976 const OMPLoopTransformationDirective *S) {
977 VisitOMPLoopBasedDirective(S);
978 }
979
VisitOMPTileDirective(const OMPTileDirective * S)980 void StmtProfiler::VisitOMPTileDirective(const OMPTileDirective *S) {
981 VisitOMPLoopTransformationDirective(S);
982 }
983
VisitOMPUnrollDirective(const OMPUnrollDirective * S)984 void StmtProfiler::VisitOMPUnrollDirective(const OMPUnrollDirective *S) {
985 VisitOMPLoopTransformationDirective(S);
986 }
987
VisitOMPReverseDirective(const OMPReverseDirective * S)988 void StmtProfiler::VisitOMPReverseDirective(const OMPReverseDirective *S) {
989 VisitOMPLoopTransformationDirective(S);
990 }
991
VisitOMPInterchangeDirective(const OMPInterchangeDirective * S)992 void StmtProfiler::VisitOMPInterchangeDirective(
993 const OMPInterchangeDirective *S) {
994 VisitOMPLoopTransformationDirective(S);
995 }
996
VisitOMPForDirective(const OMPForDirective * S)997 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
998 VisitOMPLoopDirective(S);
999 }
1000
VisitOMPForSimdDirective(const OMPForSimdDirective * S)1001 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
1002 VisitOMPLoopDirective(S);
1003 }
1004
VisitOMPSectionsDirective(const OMPSectionsDirective * S)1005 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
1006 VisitOMPExecutableDirective(S);
1007 }
1008
VisitOMPSectionDirective(const OMPSectionDirective * S)1009 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
1010 VisitOMPExecutableDirective(S);
1011 }
1012
VisitOMPScopeDirective(const OMPScopeDirective * S)1013 void StmtProfiler::VisitOMPScopeDirective(const OMPScopeDirective *S) {
1014 VisitOMPExecutableDirective(S);
1015 }
1016
VisitOMPSingleDirective(const OMPSingleDirective * S)1017 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
1018 VisitOMPExecutableDirective(S);
1019 }
1020
VisitOMPMasterDirective(const OMPMasterDirective * S)1021 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
1022 VisitOMPExecutableDirective(S);
1023 }
1024
VisitOMPCriticalDirective(const OMPCriticalDirective * S)1025 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
1026 VisitOMPExecutableDirective(S);
1027 VisitName(S->getDirectiveName().getName());
1028 }
1029
1030 void
VisitOMPParallelForDirective(const OMPParallelForDirective * S)1031 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
1032 VisitOMPLoopDirective(S);
1033 }
1034
VisitOMPParallelForSimdDirective(const OMPParallelForSimdDirective * S)1035 void StmtProfiler::VisitOMPParallelForSimdDirective(
1036 const OMPParallelForSimdDirective *S) {
1037 VisitOMPLoopDirective(S);
1038 }
1039
VisitOMPParallelMasterDirective(const OMPParallelMasterDirective * S)1040 void StmtProfiler::VisitOMPParallelMasterDirective(
1041 const OMPParallelMasterDirective *S) {
1042 VisitOMPExecutableDirective(S);
1043 }
1044
VisitOMPParallelMaskedDirective(const OMPParallelMaskedDirective * S)1045 void StmtProfiler::VisitOMPParallelMaskedDirective(
1046 const OMPParallelMaskedDirective *S) {
1047 VisitOMPExecutableDirective(S);
1048 }
1049
VisitOMPParallelSectionsDirective(const OMPParallelSectionsDirective * S)1050 void StmtProfiler::VisitOMPParallelSectionsDirective(
1051 const OMPParallelSectionsDirective *S) {
1052 VisitOMPExecutableDirective(S);
1053 }
1054
VisitOMPTaskDirective(const OMPTaskDirective * S)1055 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
1056 VisitOMPExecutableDirective(S);
1057 }
1058
VisitOMPTaskyieldDirective(const OMPTaskyieldDirective * S)1059 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
1060 VisitOMPExecutableDirective(S);
1061 }
1062
VisitOMPBarrierDirective(const OMPBarrierDirective * S)1063 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
1064 VisitOMPExecutableDirective(S);
1065 }
1066
VisitOMPTaskwaitDirective(const OMPTaskwaitDirective * S)1067 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
1068 VisitOMPExecutableDirective(S);
1069 }
1070
VisitOMPErrorDirective(const OMPErrorDirective * S)1071 void StmtProfiler::VisitOMPErrorDirective(const OMPErrorDirective *S) {
1072 VisitOMPExecutableDirective(S);
1073 }
VisitOMPTaskgroupDirective(const OMPTaskgroupDirective * S)1074 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
1075 VisitOMPExecutableDirective(S);
1076 if (const Expr *E = S->getReductionRef())
1077 VisitStmt(E);
1078 }
1079
VisitOMPFlushDirective(const OMPFlushDirective * S)1080 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
1081 VisitOMPExecutableDirective(S);
1082 }
1083
VisitOMPDepobjDirective(const OMPDepobjDirective * S)1084 void StmtProfiler::VisitOMPDepobjDirective(const OMPDepobjDirective *S) {
1085 VisitOMPExecutableDirective(S);
1086 }
1087
VisitOMPScanDirective(const OMPScanDirective * S)1088 void StmtProfiler::VisitOMPScanDirective(const OMPScanDirective *S) {
1089 VisitOMPExecutableDirective(S);
1090 }
1091
VisitOMPOrderedDirective(const OMPOrderedDirective * S)1092 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
1093 VisitOMPExecutableDirective(S);
1094 }
1095
VisitOMPAtomicDirective(const OMPAtomicDirective * S)1096 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
1097 VisitOMPExecutableDirective(S);
1098 }
1099
VisitOMPTargetDirective(const OMPTargetDirective * S)1100 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
1101 VisitOMPExecutableDirective(S);
1102 }
1103
VisitOMPTargetDataDirective(const OMPTargetDataDirective * S)1104 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
1105 VisitOMPExecutableDirective(S);
1106 }
1107
VisitOMPTargetEnterDataDirective(const OMPTargetEnterDataDirective * S)1108 void StmtProfiler::VisitOMPTargetEnterDataDirective(
1109 const OMPTargetEnterDataDirective *S) {
1110 VisitOMPExecutableDirective(S);
1111 }
1112
VisitOMPTargetExitDataDirective(const OMPTargetExitDataDirective * S)1113 void StmtProfiler::VisitOMPTargetExitDataDirective(
1114 const OMPTargetExitDataDirective *S) {
1115 VisitOMPExecutableDirective(S);
1116 }
1117
VisitOMPTargetParallelDirective(const OMPTargetParallelDirective * S)1118 void StmtProfiler::VisitOMPTargetParallelDirective(
1119 const OMPTargetParallelDirective *S) {
1120 VisitOMPExecutableDirective(S);
1121 }
1122
VisitOMPTargetParallelForDirective(const OMPTargetParallelForDirective * S)1123 void StmtProfiler::VisitOMPTargetParallelForDirective(
1124 const OMPTargetParallelForDirective *S) {
1125 VisitOMPExecutableDirective(S);
1126 }
1127
VisitOMPTeamsDirective(const OMPTeamsDirective * S)1128 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
1129 VisitOMPExecutableDirective(S);
1130 }
1131
VisitOMPCancellationPointDirective(const OMPCancellationPointDirective * S)1132 void StmtProfiler::VisitOMPCancellationPointDirective(
1133 const OMPCancellationPointDirective *S) {
1134 VisitOMPExecutableDirective(S);
1135 }
1136
VisitOMPCancelDirective(const OMPCancelDirective * S)1137 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
1138 VisitOMPExecutableDirective(S);
1139 }
1140
VisitOMPTaskLoopDirective(const OMPTaskLoopDirective * S)1141 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
1142 VisitOMPLoopDirective(S);
1143 }
1144
VisitOMPTaskLoopSimdDirective(const OMPTaskLoopSimdDirective * S)1145 void StmtProfiler::VisitOMPTaskLoopSimdDirective(
1146 const OMPTaskLoopSimdDirective *S) {
1147 VisitOMPLoopDirective(S);
1148 }
1149
VisitOMPMasterTaskLoopDirective(const OMPMasterTaskLoopDirective * S)1150 void StmtProfiler::VisitOMPMasterTaskLoopDirective(
1151 const OMPMasterTaskLoopDirective *S) {
1152 VisitOMPLoopDirective(S);
1153 }
1154
VisitOMPMaskedTaskLoopDirective(const OMPMaskedTaskLoopDirective * S)1155 void StmtProfiler::VisitOMPMaskedTaskLoopDirective(
1156 const OMPMaskedTaskLoopDirective *S) {
1157 VisitOMPLoopDirective(S);
1158 }
1159
VisitOMPMasterTaskLoopSimdDirective(const OMPMasterTaskLoopSimdDirective * S)1160 void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective(
1161 const OMPMasterTaskLoopSimdDirective *S) {
1162 VisitOMPLoopDirective(S);
1163 }
1164
VisitOMPMaskedTaskLoopSimdDirective(const OMPMaskedTaskLoopSimdDirective * S)1165 void StmtProfiler::VisitOMPMaskedTaskLoopSimdDirective(
1166 const OMPMaskedTaskLoopSimdDirective *S) {
1167 VisitOMPLoopDirective(S);
1168 }
1169
VisitOMPParallelMasterTaskLoopDirective(const OMPParallelMasterTaskLoopDirective * S)1170 void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective(
1171 const OMPParallelMasterTaskLoopDirective *S) {
1172 VisitOMPLoopDirective(S);
1173 }
1174
VisitOMPParallelMaskedTaskLoopDirective(const OMPParallelMaskedTaskLoopDirective * S)1175 void StmtProfiler::VisitOMPParallelMaskedTaskLoopDirective(
1176 const OMPParallelMaskedTaskLoopDirective *S) {
1177 VisitOMPLoopDirective(S);
1178 }
1179
VisitOMPParallelMasterTaskLoopSimdDirective(const OMPParallelMasterTaskLoopSimdDirective * S)1180 void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective(
1181 const OMPParallelMasterTaskLoopSimdDirective *S) {
1182 VisitOMPLoopDirective(S);
1183 }
1184
VisitOMPParallelMaskedTaskLoopSimdDirective(const OMPParallelMaskedTaskLoopSimdDirective * S)1185 void StmtProfiler::VisitOMPParallelMaskedTaskLoopSimdDirective(
1186 const OMPParallelMaskedTaskLoopSimdDirective *S) {
1187 VisitOMPLoopDirective(S);
1188 }
1189
VisitOMPDistributeDirective(const OMPDistributeDirective * S)1190 void StmtProfiler::VisitOMPDistributeDirective(
1191 const OMPDistributeDirective *S) {
1192 VisitOMPLoopDirective(S);
1193 }
1194
VisitOMPDistScheduleClause(const OMPDistScheduleClause * C)1195 void OMPClauseProfiler::VisitOMPDistScheduleClause(
1196 const OMPDistScheduleClause *C) {
1197 VistOMPClauseWithPreInit(C);
1198 if (auto *S = C->getChunkSize())
1199 Profiler->VisitStmt(S);
1200 }
1201
VisitOMPDefaultmapClause(const OMPDefaultmapClause *)1202 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
1203
VisitOMPTargetUpdateDirective(const OMPTargetUpdateDirective * S)1204 void StmtProfiler::VisitOMPTargetUpdateDirective(
1205 const OMPTargetUpdateDirective *S) {
1206 VisitOMPExecutableDirective(S);
1207 }
1208
VisitOMPDistributeParallelForDirective(const OMPDistributeParallelForDirective * S)1209 void StmtProfiler::VisitOMPDistributeParallelForDirective(
1210 const OMPDistributeParallelForDirective *S) {
1211 VisitOMPLoopDirective(S);
1212 }
1213
VisitOMPDistributeParallelForSimdDirective(const OMPDistributeParallelForSimdDirective * S)1214 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
1215 const OMPDistributeParallelForSimdDirective *S) {
1216 VisitOMPLoopDirective(S);
1217 }
1218
VisitOMPDistributeSimdDirective(const OMPDistributeSimdDirective * S)1219 void StmtProfiler::VisitOMPDistributeSimdDirective(
1220 const OMPDistributeSimdDirective *S) {
1221 VisitOMPLoopDirective(S);
1222 }
1223
VisitOMPTargetParallelForSimdDirective(const OMPTargetParallelForSimdDirective * S)1224 void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
1225 const OMPTargetParallelForSimdDirective *S) {
1226 VisitOMPLoopDirective(S);
1227 }
1228
VisitOMPTargetSimdDirective(const OMPTargetSimdDirective * S)1229 void StmtProfiler::VisitOMPTargetSimdDirective(
1230 const OMPTargetSimdDirective *S) {
1231 VisitOMPLoopDirective(S);
1232 }
1233
VisitOMPTeamsDistributeDirective(const OMPTeamsDistributeDirective * S)1234 void StmtProfiler::VisitOMPTeamsDistributeDirective(
1235 const OMPTeamsDistributeDirective *S) {
1236 VisitOMPLoopDirective(S);
1237 }
1238
VisitOMPTeamsDistributeSimdDirective(const OMPTeamsDistributeSimdDirective * S)1239 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
1240 const OMPTeamsDistributeSimdDirective *S) {
1241 VisitOMPLoopDirective(S);
1242 }
1243
VisitOMPTeamsDistributeParallelForSimdDirective(const OMPTeamsDistributeParallelForSimdDirective * S)1244 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
1245 const OMPTeamsDistributeParallelForSimdDirective *S) {
1246 VisitOMPLoopDirective(S);
1247 }
1248
VisitOMPTeamsDistributeParallelForDirective(const OMPTeamsDistributeParallelForDirective * S)1249 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
1250 const OMPTeamsDistributeParallelForDirective *S) {
1251 VisitOMPLoopDirective(S);
1252 }
1253
VisitOMPTargetTeamsDirective(const OMPTargetTeamsDirective * S)1254 void StmtProfiler::VisitOMPTargetTeamsDirective(
1255 const OMPTargetTeamsDirective *S) {
1256 VisitOMPExecutableDirective(S);
1257 }
1258
VisitOMPTargetTeamsDistributeDirective(const OMPTargetTeamsDistributeDirective * S)1259 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
1260 const OMPTargetTeamsDistributeDirective *S) {
1261 VisitOMPLoopDirective(S);
1262 }
1263
VisitOMPTargetTeamsDistributeParallelForDirective(const OMPTargetTeamsDistributeParallelForDirective * S)1264 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
1265 const OMPTargetTeamsDistributeParallelForDirective *S) {
1266 VisitOMPLoopDirective(S);
1267 }
1268
VisitOMPTargetTeamsDistributeParallelForSimdDirective(const OMPTargetTeamsDistributeParallelForSimdDirective * S)1269 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1270 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
1271 VisitOMPLoopDirective(S);
1272 }
1273
VisitOMPTargetTeamsDistributeSimdDirective(const OMPTargetTeamsDistributeSimdDirective * S)1274 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
1275 const OMPTargetTeamsDistributeSimdDirective *S) {
1276 VisitOMPLoopDirective(S);
1277 }
1278
VisitOMPInteropDirective(const OMPInteropDirective * S)1279 void StmtProfiler::VisitOMPInteropDirective(const OMPInteropDirective *S) {
1280 VisitOMPExecutableDirective(S);
1281 }
1282
VisitOMPDispatchDirective(const OMPDispatchDirective * S)1283 void StmtProfiler::VisitOMPDispatchDirective(const OMPDispatchDirective *S) {
1284 VisitOMPExecutableDirective(S);
1285 }
1286
VisitOMPMaskedDirective(const OMPMaskedDirective * S)1287 void StmtProfiler::VisitOMPMaskedDirective(const OMPMaskedDirective *S) {
1288 VisitOMPExecutableDirective(S);
1289 }
1290
VisitOMPGenericLoopDirective(const OMPGenericLoopDirective * S)1291 void StmtProfiler::VisitOMPGenericLoopDirective(
1292 const OMPGenericLoopDirective *S) {
1293 VisitOMPLoopDirective(S);
1294 }
1295
VisitOMPTeamsGenericLoopDirective(const OMPTeamsGenericLoopDirective * S)1296 void StmtProfiler::VisitOMPTeamsGenericLoopDirective(
1297 const OMPTeamsGenericLoopDirective *S) {
1298 VisitOMPLoopDirective(S);
1299 }
1300
VisitOMPTargetTeamsGenericLoopDirective(const OMPTargetTeamsGenericLoopDirective * S)1301 void StmtProfiler::VisitOMPTargetTeamsGenericLoopDirective(
1302 const OMPTargetTeamsGenericLoopDirective *S) {
1303 VisitOMPLoopDirective(S);
1304 }
1305
VisitOMPParallelGenericLoopDirective(const OMPParallelGenericLoopDirective * S)1306 void StmtProfiler::VisitOMPParallelGenericLoopDirective(
1307 const OMPParallelGenericLoopDirective *S) {
1308 VisitOMPLoopDirective(S);
1309 }
1310
VisitOMPTargetParallelGenericLoopDirective(const OMPTargetParallelGenericLoopDirective * S)1311 void StmtProfiler::VisitOMPTargetParallelGenericLoopDirective(
1312 const OMPTargetParallelGenericLoopDirective *S) {
1313 VisitOMPLoopDirective(S);
1314 }
1315
VisitExpr(const Expr * S)1316 void StmtProfiler::VisitExpr(const Expr *S) {
1317 VisitStmt(S);
1318 }
1319
VisitConstantExpr(const ConstantExpr * S)1320 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1321 VisitExpr(S);
1322 }
1323
VisitDeclRefExpr(const DeclRefExpr * S)1324 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
1325 VisitExpr(S);
1326 if (!Canonical)
1327 VisitNestedNameSpecifier(S->getQualifier());
1328 VisitDecl(S->getDecl());
1329 if (!Canonical) {
1330 ID.AddBoolean(S->hasExplicitTemplateArgs());
1331 if (S->hasExplicitTemplateArgs())
1332 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1333 }
1334 }
1335
VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr * S)1336 void StmtProfiler::VisitSYCLUniqueStableNameExpr(
1337 const SYCLUniqueStableNameExpr *S) {
1338 VisitExpr(S);
1339 VisitType(S->getTypeSourceInfo()->getType());
1340 }
1341
VisitPredefinedExpr(const PredefinedExpr * S)1342 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
1343 VisitExpr(S);
1344 ID.AddInteger(llvm::to_underlying(S->getIdentKind()));
1345 }
1346
VisitIntegerLiteral(const IntegerLiteral * S)1347 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
1348 VisitExpr(S);
1349 S->getValue().Profile(ID);
1350
1351 QualType T = S->getType();
1352 if (Canonical)
1353 T = T.getCanonicalType();
1354 ID.AddInteger(T->getTypeClass());
1355 if (auto BitIntT = T->getAs<BitIntType>())
1356 BitIntT->Profile(ID);
1357 else
1358 ID.AddInteger(T->castAs<BuiltinType>()->getKind());
1359 }
1360
VisitFixedPointLiteral(const FixedPointLiteral * S)1361 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1362 VisitExpr(S);
1363 S->getValue().Profile(ID);
1364 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1365 }
1366
VisitCharacterLiteral(const CharacterLiteral * S)1367 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
1368 VisitExpr(S);
1369 ID.AddInteger(llvm::to_underlying(S->getKind()));
1370 ID.AddInteger(S->getValue());
1371 }
1372
VisitFloatingLiteral(const FloatingLiteral * S)1373 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
1374 VisitExpr(S);
1375 S->getValue().Profile(ID);
1376 ID.AddBoolean(S->isExact());
1377 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1378 }
1379
VisitImaginaryLiteral(const ImaginaryLiteral * S)1380 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
1381 VisitExpr(S);
1382 }
1383
VisitStringLiteral(const StringLiteral * S)1384 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
1385 VisitExpr(S);
1386 ID.AddString(S->getBytes());
1387 ID.AddInteger(llvm::to_underlying(S->getKind()));
1388 }
1389
VisitParenExpr(const ParenExpr * S)1390 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
1391 VisitExpr(S);
1392 }
1393
VisitParenListExpr(const ParenListExpr * S)1394 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
1395 VisitExpr(S);
1396 }
1397
VisitUnaryOperator(const UnaryOperator * S)1398 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
1399 VisitExpr(S);
1400 ID.AddInteger(S->getOpcode());
1401 }
1402
VisitOffsetOfExpr(const OffsetOfExpr * S)1403 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
1404 VisitType(S->getTypeSourceInfo()->getType());
1405 unsigned n = S->getNumComponents();
1406 for (unsigned i = 0; i < n; ++i) {
1407 const OffsetOfNode &ON = S->getComponent(i);
1408 ID.AddInteger(ON.getKind());
1409 switch (ON.getKind()) {
1410 case OffsetOfNode::Array:
1411 // Expressions handled below.
1412 break;
1413
1414 case OffsetOfNode::Field:
1415 VisitDecl(ON.getField());
1416 break;
1417
1418 case OffsetOfNode::Identifier:
1419 VisitIdentifierInfo(ON.getFieldName());
1420 break;
1421
1422 case OffsetOfNode::Base:
1423 // These nodes are implicit, and therefore don't need profiling.
1424 break;
1425 }
1426 }
1427
1428 VisitExpr(S);
1429 }
1430
1431 void
VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr * S)1432 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
1433 VisitExpr(S);
1434 ID.AddInteger(S->getKind());
1435 if (S->isArgumentType())
1436 VisitType(S->getArgumentType());
1437 }
1438
VisitArraySubscriptExpr(const ArraySubscriptExpr * S)1439 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
1440 VisitExpr(S);
1441 }
1442
VisitMatrixSubscriptExpr(const MatrixSubscriptExpr * S)1443 void StmtProfiler::VisitMatrixSubscriptExpr(const MatrixSubscriptExpr *S) {
1444 VisitExpr(S);
1445 }
1446
VisitArraySectionExpr(const ArraySectionExpr * S)1447 void StmtProfiler::VisitArraySectionExpr(const ArraySectionExpr *S) {
1448 VisitExpr(S);
1449 }
1450
VisitOMPArrayShapingExpr(const OMPArrayShapingExpr * S)1451 void StmtProfiler::VisitOMPArrayShapingExpr(const OMPArrayShapingExpr *S) {
1452 VisitExpr(S);
1453 }
1454
VisitOMPIteratorExpr(const OMPIteratorExpr * S)1455 void StmtProfiler::VisitOMPIteratorExpr(const OMPIteratorExpr *S) {
1456 VisitExpr(S);
1457 for (unsigned I = 0, E = S->numOfIterators(); I < E; ++I)
1458 VisitDecl(S->getIteratorDecl(I));
1459 }
1460
VisitCallExpr(const CallExpr * S)1461 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
1462 VisitExpr(S);
1463 }
1464
VisitMemberExpr(const MemberExpr * S)1465 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
1466 VisitExpr(S);
1467 VisitDecl(S->getMemberDecl());
1468 if (!Canonical)
1469 VisitNestedNameSpecifier(S->getQualifier());
1470 ID.AddBoolean(S->isArrow());
1471 }
1472
VisitCompoundLiteralExpr(const CompoundLiteralExpr * S)1473 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
1474 VisitExpr(S);
1475 ID.AddBoolean(S->isFileScope());
1476 }
1477
VisitCastExpr(const CastExpr * S)1478 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
1479 VisitExpr(S);
1480 }
1481
VisitImplicitCastExpr(const ImplicitCastExpr * S)1482 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
1483 VisitCastExpr(S);
1484 ID.AddInteger(S->getValueKind());
1485 }
1486
VisitExplicitCastExpr(const ExplicitCastExpr * S)1487 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
1488 VisitCastExpr(S);
1489 VisitType(S->getTypeAsWritten());
1490 }
1491
VisitCStyleCastExpr(const CStyleCastExpr * S)1492 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
1493 VisitExplicitCastExpr(S);
1494 }
1495
VisitBinaryOperator(const BinaryOperator * S)1496 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
1497 VisitExpr(S);
1498 ID.AddInteger(S->getOpcode());
1499 }
1500
1501 void
VisitCompoundAssignOperator(const CompoundAssignOperator * S)1502 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
1503 VisitBinaryOperator(S);
1504 }
1505
VisitConditionalOperator(const ConditionalOperator * S)1506 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
1507 VisitExpr(S);
1508 }
1509
VisitBinaryConditionalOperator(const BinaryConditionalOperator * S)1510 void StmtProfiler::VisitBinaryConditionalOperator(
1511 const BinaryConditionalOperator *S) {
1512 VisitExpr(S);
1513 }
1514
VisitAddrLabelExpr(const AddrLabelExpr * S)1515 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
1516 VisitExpr(S);
1517 VisitDecl(S->getLabel());
1518 }
1519
VisitStmtExpr(const StmtExpr * S)1520 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
1521 VisitExpr(S);
1522 }
1523
VisitShuffleVectorExpr(const ShuffleVectorExpr * S)1524 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
1525 VisitExpr(S);
1526 }
1527
VisitConvertVectorExpr(const ConvertVectorExpr * S)1528 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1529 VisitExpr(S);
1530 }
1531
VisitChooseExpr(const ChooseExpr * S)1532 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
1533 VisitExpr(S);
1534 }
1535
VisitGNUNullExpr(const GNUNullExpr * S)1536 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
1537 VisitExpr(S);
1538 }
1539
VisitVAArgExpr(const VAArgExpr * S)1540 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
1541 VisitExpr(S);
1542 }
1543
VisitInitListExpr(const InitListExpr * S)1544 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
1545 if (S->getSyntacticForm()) {
1546 VisitInitListExpr(S->getSyntacticForm());
1547 return;
1548 }
1549
1550 VisitExpr(S);
1551 }
1552
VisitDesignatedInitExpr(const DesignatedInitExpr * S)1553 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
1554 VisitExpr(S);
1555 ID.AddBoolean(S->usesGNUSyntax());
1556 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1557 if (D.isFieldDesignator()) {
1558 ID.AddInteger(0);
1559 VisitName(D.getFieldName());
1560 continue;
1561 }
1562
1563 if (D.isArrayDesignator()) {
1564 ID.AddInteger(1);
1565 } else {
1566 assert(D.isArrayRangeDesignator());
1567 ID.AddInteger(2);
1568 }
1569 ID.AddInteger(D.getArrayIndex());
1570 }
1571 }
1572
1573 // Seems that if VisitInitListExpr() only works on the syntactic form of an
1574 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
VisitDesignatedInitUpdateExpr(const DesignatedInitUpdateExpr * S)1575 void StmtProfiler::VisitDesignatedInitUpdateExpr(
1576 const DesignatedInitUpdateExpr *S) {
1577 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1578 "initializer");
1579 }
1580
VisitArrayInitLoopExpr(const ArrayInitLoopExpr * S)1581 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1582 VisitExpr(S);
1583 }
1584
VisitArrayInitIndexExpr(const ArrayInitIndexExpr * S)1585 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1586 VisitExpr(S);
1587 }
1588
VisitNoInitExpr(const NoInitExpr * S)1589 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1590 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1591 }
1592
VisitImplicitValueInitExpr(const ImplicitValueInitExpr * S)1593 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
1594 VisitExpr(S);
1595 }
1596
VisitExtVectorElementExpr(const ExtVectorElementExpr * S)1597 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
1598 VisitExpr(S);
1599 VisitName(&S->getAccessor());
1600 }
1601
VisitBlockExpr(const BlockExpr * S)1602 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
1603 VisitExpr(S);
1604 VisitDecl(S->getBlockDecl());
1605 }
1606
VisitGenericSelectionExpr(const GenericSelectionExpr * S)1607 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
1608 VisitExpr(S);
1609 for (const GenericSelectionExpr::ConstAssociation Assoc :
1610 S->associations()) {
1611 QualType T = Assoc.getType();
1612 if (T.isNull())
1613 ID.AddPointer(nullptr);
1614 else
1615 VisitType(T);
1616 VisitExpr(Assoc.getAssociationExpr());
1617 }
1618 }
1619
VisitPseudoObjectExpr(const PseudoObjectExpr * S)1620 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1621 VisitExpr(S);
1622 for (PseudoObjectExpr::const_semantics_iterator
1623 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1624 // Normally, we would not profile the source expressions of OVEs.
1625 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1626 Visit(OVE->getSourceExpr());
1627 }
1628
VisitAtomicExpr(const AtomicExpr * S)1629 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1630 VisitExpr(S);
1631 ID.AddInteger(S->getOp());
1632 }
1633
VisitConceptSpecializationExpr(const ConceptSpecializationExpr * S)1634 void StmtProfiler::VisitConceptSpecializationExpr(
1635 const ConceptSpecializationExpr *S) {
1636 VisitExpr(S);
1637 VisitDecl(S->getNamedConcept());
1638 for (const TemplateArgument &Arg : S->getTemplateArguments())
1639 VisitTemplateArgument(Arg);
1640 }
1641
VisitRequiresExpr(const RequiresExpr * S)1642 void StmtProfiler::VisitRequiresExpr(const RequiresExpr *S) {
1643 VisitExpr(S);
1644 ID.AddInteger(S->getLocalParameters().size());
1645 for (ParmVarDecl *LocalParam : S->getLocalParameters())
1646 VisitDecl(LocalParam);
1647 ID.AddInteger(S->getRequirements().size());
1648 for (concepts::Requirement *Req : S->getRequirements()) {
1649 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
1650 ID.AddInteger(concepts::Requirement::RK_Type);
1651 ID.AddBoolean(TypeReq->isSubstitutionFailure());
1652 if (!TypeReq->isSubstitutionFailure())
1653 VisitType(TypeReq->getType()->getType());
1654 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
1655 ID.AddInteger(concepts::Requirement::RK_Compound);
1656 ID.AddBoolean(ExprReq->isExprSubstitutionFailure());
1657 if (!ExprReq->isExprSubstitutionFailure())
1658 Visit(ExprReq->getExpr());
1659 // C++2a [expr.prim.req.compound]p1 Example:
1660 // [...] The compound-requirement in C1 requires that x++ is a valid
1661 // expression. It is equivalent to the simple-requirement x++; [...]
1662 // We therefore do not profile isSimple() here.
1663 ID.AddBoolean(ExprReq->getNoexceptLoc().isValid());
1664 const concepts::ExprRequirement::ReturnTypeRequirement &RetReq =
1665 ExprReq->getReturnTypeRequirement();
1666 if (RetReq.isEmpty()) {
1667 ID.AddInteger(0);
1668 } else if (RetReq.isTypeConstraint()) {
1669 ID.AddInteger(1);
1670 Visit(RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint());
1671 } else {
1672 assert(RetReq.isSubstitutionFailure());
1673 ID.AddInteger(2);
1674 }
1675 } else {
1676 ID.AddInteger(concepts::Requirement::RK_Nested);
1677 auto *NestedReq = cast<concepts::NestedRequirement>(Req);
1678 ID.AddBoolean(NestedReq->hasInvalidConstraint());
1679 if (!NestedReq->hasInvalidConstraint())
1680 Visit(NestedReq->getConstraintExpr());
1681 }
1682 }
1683 }
1684
DecodeOperatorCall(const CXXOperatorCallExpr * S,UnaryOperatorKind & UnaryOp,BinaryOperatorKind & BinaryOp,unsigned & NumArgs)1685 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
1686 UnaryOperatorKind &UnaryOp,
1687 BinaryOperatorKind &BinaryOp,
1688 unsigned &NumArgs) {
1689 switch (S->getOperator()) {
1690 case OO_None:
1691 case OO_New:
1692 case OO_Delete:
1693 case OO_Array_New:
1694 case OO_Array_Delete:
1695 case OO_Arrow:
1696 case OO_Conditional:
1697 case NUM_OVERLOADED_OPERATORS:
1698 llvm_unreachable("Invalid operator call kind");
1699
1700 case OO_Plus:
1701 if (NumArgs == 1) {
1702 UnaryOp = UO_Plus;
1703 return Stmt::UnaryOperatorClass;
1704 }
1705
1706 BinaryOp = BO_Add;
1707 return Stmt::BinaryOperatorClass;
1708
1709 case OO_Minus:
1710 if (NumArgs == 1) {
1711 UnaryOp = UO_Minus;
1712 return Stmt::UnaryOperatorClass;
1713 }
1714
1715 BinaryOp = BO_Sub;
1716 return Stmt::BinaryOperatorClass;
1717
1718 case OO_Star:
1719 if (NumArgs == 1) {
1720 UnaryOp = UO_Deref;
1721 return Stmt::UnaryOperatorClass;
1722 }
1723
1724 BinaryOp = BO_Mul;
1725 return Stmt::BinaryOperatorClass;
1726
1727 case OO_Slash:
1728 BinaryOp = BO_Div;
1729 return Stmt::BinaryOperatorClass;
1730
1731 case OO_Percent:
1732 BinaryOp = BO_Rem;
1733 return Stmt::BinaryOperatorClass;
1734
1735 case OO_Caret:
1736 BinaryOp = BO_Xor;
1737 return Stmt::BinaryOperatorClass;
1738
1739 case OO_Amp:
1740 if (NumArgs == 1) {
1741 UnaryOp = UO_AddrOf;
1742 return Stmt::UnaryOperatorClass;
1743 }
1744
1745 BinaryOp = BO_And;
1746 return Stmt::BinaryOperatorClass;
1747
1748 case OO_Pipe:
1749 BinaryOp = BO_Or;
1750 return Stmt::BinaryOperatorClass;
1751
1752 case OO_Tilde:
1753 UnaryOp = UO_Not;
1754 return Stmt::UnaryOperatorClass;
1755
1756 case OO_Exclaim:
1757 UnaryOp = UO_LNot;
1758 return Stmt::UnaryOperatorClass;
1759
1760 case OO_Equal:
1761 BinaryOp = BO_Assign;
1762 return Stmt::BinaryOperatorClass;
1763
1764 case OO_Less:
1765 BinaryOp = BO_LT;
1766 return Stmt::BinaryOperatorClass;
1767
1768 case OO_Greater:
1769 BinaryOp = BO_GT;
1770 return Stmt::BinaryOperatorClass;
1771
1772 case OO_PlusEqual:
1773 BinaryOp = BO_AddAssign;
1774 return Stmt::CompoundAssignOperatorClass;
1775
1776 case OO_MinusEqual:
1777 BinaryOp = BO_SubAssign;
1778 return Stmt::CompoundAssignOperatorClass;
1779
1780 case OO_StarEqual:
1781 BinaryOp = BO_MulAssign;
1782 return Stmt::CompoundAssignOperatorClass;
1783
1784 case OO_SlashEqual:
1785 BinaryOp = BO_DivAssign;
1786 return Stmt::CompoundAssignOperatorClass;
1787
1788 case OO_PercentEqual:
1789 BinaryOp = BO_RemAssign;
1790 return Stmt::CompoundAssignOperatorClass;
1791
1792 case OO_CaretEqual:
1793 BinaryOp = BO_XorAssign;
1794 return Stmt::CompoundAssignOperatorClass;
1795
1796 case OO_AmpEqual:
1797 BinaryOp = BO_AndAssign;
1798 return Stmt::CompoundAssignOperatorClass;
1799
1800 case OO_PipeEqual:
1801 BinaryOp = BO_OrAssign;
1802 return Stmt::CompoundAssignOperatorClass;
1803
1804 case OO_LessLess:
1805 BinaryOp = BO_Shl;
1806 return Stmt::BinaryOperatorClass;
1807
1808 case OO_GreaterGreater:
1809 BinaryOp = BO_Shr;
1810 return Stmt::BinaryOperatorClass;
1811
1812 case OO_LessLessEqual:
1813 BinaryOp = BO_ShlAssign;
1814 return Stmt::CompoundAssignOperatorClass;
1815
1816 case OO_GreaterGreaterEqual:
1817 BinaryOp = BO_ShrAssign;
1818 return Stmt::CompoundAssignOperatorClass;
1819
1820 case OO_EqualEqual:
1821 BinaryOp = BO_EQ;
1822 return Stmt::BinaryOperatorClass;
1823
1824 case OO_ExclaimEqual:
1825 BinaryOp = BO_NE;
1826 return Stmt::BinaryOperatorClass;
1827
1828 case OO_LessEqual:
1829 BinaryOp = BO_LE;
1830 return Stmt::BinaryOperatorClass;
1831
1832 case OO_GreaterEqual:
1833 BinaryOp = BO_GE;
1834 return Stmt::BinaryOperatorClass;
1835
1836 case OO_Spaceship:
1837 BinaryOp = BO_Cmp;
1838 return Stmt::BinaryOperatorClass;
1839
1840 case OO_AmpAmp:
1841 BinaryOp = BO_LAnd;
1842 return Stmt::BinaryOperatorClass;
1843
1844 case OO_PipePipe:
1845 BinaryOp = BO_LOr;
1846 return Stmt::BinaryOperatorClass;
1847
1848 case OO_PlusPlus:
1849 UnaryOp = NumArgs == 1 ? UO_PreInc : UO_PostInc;
1850 NumArgs = 1;
1851 return Stmt::UnaryOperatorClass;
1852
1853 case OO_MinusMinus:
1854 UnaryOp = NumArgs == 1 ? UO_PreDec : UO_PostDec;
1855 NumArgs = 1;
1856 return Stmt::UnaryOperatorClass;
1857
1858 case OO_Comma:
1859 BinaryOp = BO_Comma;
1860 return Stmt::BinaryOperatorClass;
1861
1862 case OO_ArrowStar:
1863 BinaryOp = BO_PtrMemI;
1864 return Stmt::BinaryOperatorClass;
1865
1866 case OO_Subscript:
1867 return Stmt::ArraySubscriptExprClass;
1868
1869 case OO_Call:
1870 return Stmt::CallExprClass;
1871
1872 case OO_Coawait:
1873 UnaryOp = UO_Coawait;
1874 return Stmt::UnaryOperatorClass;
1875 }
1876
1877 llvm_unreachable("Invalid overloaded operator expression");
1878 }
1879
1880 #if defined(_MSC_VER) && !defined(__clang__)
1881 #if _MSC_VER == 1911
1882 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1883 // MSVC 2017 update 3 miscompiles this function, and a clang built with it
1884 // will crash in stage 2 of a bootstrap build.
1885 #pragma optimize("", off)
1886 #endif
1887 #endif
1888
VisitCXXOperatorCallExpr(const CXXOperatorCallExpr * S)1889 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
1890 if (S->isTypeDependent()) {
1891 // Type-dependent operator calls are profiled like their underlying
1892 // syntactic operator.
1893 //
1894 // An operator call to operator-> is always implicit, so just skip it. The
1895 // enclosing MemberExpr will profile the actual member access.
1896 if (S->getOperator() == OO_Arrow)
1897 return Visit(S->getArg(0));
1898
1899 UnaryOperatorKind UnaryOp = UO_Extension;
1900 BinaryOperatorKind BinaryOp = BO_Comma;
1901 unsigned NumArgs = S->getNumArgs();
1902 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp, NumArgs);
1903
1904 ID.AddInteger(SC);
1905 for (unsigned I = 0; I != NumArgs; ++I)
1906 Visit(S->getArg(I));
1907 if (SC == Stmt::UnaryOperatorClass)
1908 ID.AddInteger(UnaryOp);
1909 else if (SC == Stmt::BinaryOperatorClass ||
1910 SC == Stmt::CompoundAssignOperatorClass)
1911 ID.AddInteger(BinaryOp);
1912 else
1913 assert(SC == Stmt::ArraySubscriptExprClass || SC == Stmt::CallExprClass);
1914
1915 return;
1916 }
1917
1918 VisitCallExpr(S);
1919 ID.AddInteger(S->getOperator());
1920 }
1921
VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator * S)1922 void StmtProfiler::VisitCXXRewrittenBinaryOperator(
1923 const CXXRewrittenBinaryOperator *S) {
1924 // If a rewritten operator were ever to be type-dependent, we should profile
1925 // it following its syntactic operator.
1926 assert(!S->isTypeDependent() &&
1927 "resolved rewritten operator should never be type-dependent");
1928 ID.AddBoolean(S->isReversed());
1929 VisitExpr(S->getSemanticForm());
1930 }
1931
1932 #if defined(_MSC_VER) && !defined(__clang__)
1933 #if _MSC_VER == 1911
1934 #pragma optimize("", on)
1935 #endif
1936 #endif
1937
VisitCXXMemberCallExpr(const CXXMemberCallExpr * S)1938 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
1939 VisitCallExpr(S);
1940 }
1941
VisitCUDAKernelCallExpr(const CUDAKernelCallExpr * S)1942 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
1943 VisitCallExpr(S);
1944 }
1945
VisitAsTypeExpr(const AsTypeExpr * S)1946 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
1947 VisitExpr(S);
1948 }
1949
VisitCXXNamedCastExpr(const CXXNamedCastExpr * S)1950 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
1951 VisitExplicitCastExpr(S);
1952 }
1953
VisitCXXStaticCastExpr(const CXXStaticCastExpr * S)1954 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
1955 VisitCXXNamedCastExpr(S);
1956 }
1957
VisitCXXDynamicCastExpr(const CXXDynamicCastExpr * S)1958 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
1959 VisitCXXNamedCastExpr(S);
1960 }
1961
1962 void
VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr * S)1963 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
1964 VisitCXXNamedCastExpr(S);
1965 }
1966
VisitCXXConstCastExpr(const CXXConstCastExpr * S)1967 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
1968 VisitCXXNamedCastExpr(S);
1969 }
1970
VisitBuiltinBitCastExpr(const BuiltinBitCastExpr * S)1971 void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
1972 VisitExpr(S);
1973 VisitType(S->getTypeInfoAsWritten()->getType());
1974 }
1975
VisitCXXAddrspaceCastExpr(const CXXAddrspaceCastExpr * S)1976 void StmtProfiler::VisitCXXAddrspaceCastExpr(const CXXAddrspaceCastExpr *S) {
1977 VisitCXXNamedCastExpr(S);
1978 }
1979
VisitUserDefinedLiteral(const UserDefinedLiteral * S)1980 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1981 VisitCallExpr(S);
1982 }
1983
VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr * S)1984 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
1985 VisitExpr(S);
1986 ID.AddBoolean(S->getValue());
1987 }
1988
VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr * S)1989 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
1990 VisitExpr(S);
1991 }
1992
VisitCXXStdInitializerListExpr(const CXXStdInitializerListExpr * S)1993 void StmtProfiler::VisitCXXStdInitializerListExpr(
1994 const CXXStdInitializerListExpr *S) {
1995 VisitExpr(S);
1996 }
1997
VisitCXXTypeidExpr(const CXXTypeidExpr * S)1998 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
1999 VisitExpr(S);
2000 if (S->isTypeOperand())
2001 VisitType(S->getTypeOperandSourceInfo()->getType());
2002 }
2003
VisitCXXUuidofExpr(const CXXUuidofExpr * S)2004 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
2005 VisitExpr(S);
2006 if (S->isTypeOperand())
2007 VisitType(S->getTypeOperandSourceInfo()->getType());
2008 }
2009
VisitMSPropertyRefExpr(const MSPropertyRefExpr * S)2010 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
2011 VisitExpr(S);
2012 VisitDecl(S->getPropertyDecl());
2013 }
2014
VisitMSPropertySubscriptExpr(const MSPropertySubscriptExpr * S)2015 void StmtProfiler::VisitMSPropertySubscriptExpr(
2016 const MSPropertySubscriptExpr *S) {
2017 VisitExpr(S);
2018 }
2019
VisitCXXThisExpr(const CXXThisExpr * S)2020 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
2021 VisitExpr(S);
2022 ID.AddBoolean(S->isImplicit());
2023 ID.AddBoolean(S->isCapturedByCopyInLambdaWithExplicitObjectParameter());
2024 }
2025
VisitCXXThrowExpr(const CXXThrowExpr * S)2026 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
2027 VisitExpr(S);
2028 }
2029
VisitCXXDefaultArgExpr(const CXXDefaultArgExpr * S)2030 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
2031 VisitExpr(S);
2032 VisitDecl(S->getParam());
2033 }
2034
VisitCXXDefaultInitExpr(const CXXDefaultInitExpr * S)2035 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
2036 VisitExpr(S);
2037 VisitDecl(S->getField());
2038 }
2039
VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr * S)2040 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
2041 VisitExpr(S);
2042 VisitDecl(
2043 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
2044 }
2045
VisitCXXConstructExpr(const CXXConstructExpr * S)2046 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
2047 VisitExpr(S);
2048 VisitDecl(S->getConstructor());
2049 ID.AddBoolean(S->isElidable());
2050 }
2051
VisitCXXInheritedCtorInitExpr(const CXXInheritedCtorInitExpr * S)2052 void StmtProfiler::VisitCXXInheritedCtorInitExpr(
2053 const CXXInheritedCtorInitExpr *S) {
2054 VisitExpr(S);
2055 VisitDecl(S->getConstructor());
2056 }
2057
VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr * S)2058 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
2059 VisitExplicitCastExpr(S);
2060 }
2061
2062 void
VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr * S)2063 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
2064 VisitCXXConstructExpr(S);
2065 }
2066
2067 void
VisitLambdaExpr(const LambdaExpr * S)2068 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
2069 if (!ProfileLambdaExpr) {
2070 // Do not recursively visit the children of this expression. Profiling the
2071 // body would result in unnecessary work, and is not safe to do during
2072 // deserialization.
2073 VisitStmtNoChildren(S);
2074
2075 // C++20 [temp.over.link]p5:
2076 // Two lambda-expressions are never considered equivalent.
2077 VisitDecl(S->getLambdaClass());
2078
2079 return;
2080 }
2081
2082 CXXRecordDecl *Lambda = S->getLambdaClass();
2083 for (const auto &Capture : Lambda->captures()) {
2084 ID.AddInteger(Capture.getCaptureKind());
2085 if (Capture.capturesVariable())
2086 VisitDecl(Capture.getCapturedVar());
2087 }
2088
2089 // Profiling the body of the lambda may be dangerous during deserialization.
2090 // So we'd like only to profile the signature here.
2091 ODRHash Hasher;
2092 // FIXME: We can't get the operator call easily by
2093 // `CXXRecordDecl::getLambdaCallOperator()` if we're in deserialization.
2094 // So we have to do something raw here.
2095 for (auto *SubDecl : Lambda->decls()) {
2096 FunctionDecl *Call = nullptr;
2097 if (auto *FTD = dyn_cast<FunctionTemplateDecl>(SubDecl))
2098 Call = FTD->getTemplatedDecl();
2099 else if (auto *FD = dyn_cast<FunctionDecl>(SubDecl))
2100 Call = FD;
2101
2102 if (!Call)
2103 continue;
2104
2105 Hasher.AddFunctionDecl(Call, /*SkipBody=*/true);
2106 }
2107 ID.AddInteger(Hasher.CalculateHash());
2108 }
2109
2110 void
VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr * S)2111 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
2112 VisitExpr(S);
2113 }
2114
VisitCXXDeleteExpr(const CXXDeleteExpr * S)2115 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
2116 VisitExpr(S);
2117 ID.AddBoolean(S->isGlobalDelete());
2118 ID.AddBoolean(S->isArrayForm());
2119 VisitDecl(S->getOperatorDelete());
2120 }
2121
VisitCXXNewExpr(const CXXNewExpr * S)2122 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
2123 VisitExpr(S);
2124 VisitType(S->getAllocatedType());
2125 VisitDecl(S->getOperatorNew());
2126 VisitDecl(S->getOperatorDelete());
2127 ID.AddBoolean(S->isArray());
2128 ID.AddInteger(S->getNumPlacementArgs());
2129 ID.AddBoolean(S->isGlobalNew());
2130 ID.AddBoolean(S->isParenTypeId());
2131 ID.AddInteger(llvm::to_underlying(S->getInitializationStyle()));
2132 }
2133
2134 void
VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr * S)2135 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
2136 VisitExpr(S);
2137 ID.AddBoolean(S->isArrow());
2138 VisitNestedNameSpecifier(S->getQualifier());
2139 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
2140 if (S->getScopeTypeInfo())
2141 VisitType(S->getScopeTypeInfo()->getType());
2142 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
2143 if (S->getDestroyedTypeInfo())
2144 VisitType(S->getDestroyedType());
2145 else
2146 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
2147 }
2148
VisitOverloadExpr(const OverloadExpr * S)2149 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
2150 VisitExpr(S);
2151 VisitNestedNameSpecifier(S->getQualifier());
2152 VisitName(S->getName(), /*TreatAsDecl*/ true);
2153 ID.AddBoolean(S->hasExplicitTemplateArgs());
2154 if (S->hasExplicitTemplateArgs())
2155 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
2156 }
2157
2158 void
VisitUnresolvedLookupExpr(const UnresolvedLookupExpr * S)2159 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
2160 VisitOverloadExpr(S);
2161 }
2162
VisitTypeTraitExpr(const TypeTraitExpr * S)2163 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
2164 VisitExpr(S);
2165 ID.AddInteger(S->getTrait());
2166 ID.AddInteger(S->getNumArgs());
2167 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
2168 VisitType(S->getArg(I)->getType());
2169 }
2170
VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr * S)2171 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
2172 VisitExpr(S);
2173 ID.AddInteger(S->getTrait());
2174 VisitType(S->getQueriedType());
2175 }
2176
VisitExpressionTraitExpr(const ExpressionTraitExpr * S)2177 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
2178 VisitExpr(S);
2179 ID.AddInteger(S->getTrait());
2180 VisitExpr(S->getQueriedExpression());
2181 }
2182
VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr * S)2183 void StmtProfiler::VisitDependentScopeDeclRefExpr(
2184 const DependentScopeDeclRefExpr *S) {
2185 VisitExpr(S);
2186 VisitName(S->getDeclName());
2187 VisitNestedNameSpecifier(S->getQualifier());
2188 ID.AddBoolean(S->hasExplicitTemplateArgs());
2189 if (S->hasExplicitTemplateArgs())
2190 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
2191 }
2192
VisitExprWithCleanups(const ExprWithCleanups * S)2193 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
2194 VisitExpr(S);
2195 }
2196
VisitCXXUnresolvedConstructExpr(const CXXUnresolvedConstructExpr * S)2197 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
2198 const CXXUnresolvedConstructExpr *S) {
2199 VisitExpr(S);
2200 VisitType(S->getTypeAsWritten());
2201 ID.AddInteger(S->isListInitialization());
2202 }
2203
VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr * S)2204 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
2205 const CXXDependentScopeMemberExpr *S) {
2206 ID.AddBoolean(S->isImplicitAccess());
2207 if (!S->isImplicitAccess()) {
2208 VisitExpr(S);
2209 ID.AddBoolean(S->isArrow());
2210 }
2211 VisitNestedNameSpecifier(S->getQualifier());
2212 VisitName(S->getMember());
2213 ID.AddBoolean(S->hasExplicitTemplateArgs());
2214 if (S->hasExplicitTemplateArgs())
2215 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
2216 }
2217
VisitUnresolvedMemberExpr(const UnresolvedMemberExpr * S)2218 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
2219 ID.AddBoolean(S->isImplicitAccess());
2220 if (!S->isImplicitAccess()) {
2221 VisitExpr(S);
2222 ID.AddBoolean(S->isArrow());
2223 }
2224 VisitNestedNameSpecifier(S->getQualifier());
2225 VisitName(S->getMemberName());
2226 ID.AddBoolean(S->hasExplicitTemplateArgs());
2227 if (S->hasExplicitTemplateArgs())
2228 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
2229 }
2230
VisitCXXNoexceptExpr(const CXXNoexceptExpr * S)2231 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
2232 VisitExpr(S);
2233 }
2234
VisitPackExpansionExpr(const PackExpansionExpr * S)2235 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
2236 VisitExpr(S);
2237 }
2238
VisitSizeOfPackExpr(const SizeOfPackExpr * S)2239 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
2240 VisitExpr(S);
2241 VisitDecl(S->getPack());
2242 if (S->isPartiallySubstituted()) {
2243 auto Args = S->getPartialArguments();
2244 ID.AddInteger(Args.size());
2245 for (const auto &TA : Args)
2246 VisitTemplateArgument(TA);
2247 } else {
2248 ID.AddInteger(0);
2249 }
2250 }
2251
VisitPackIndexingExpr(const PackIndexingExpr * E)2252 void StmtProfiler::VisitPackIndexingExpr(const PackIndexingExpr *E) {
2253 VisitExpr(E);
2254 VisitExpr(E->getPackIdExpression());
2255 VisitExpr(E->getIndexExpr());
2256 }
2257
VisitSubstNonTypeTemplateParmPackExpr(const SubstNonTypeTemplateParmPackExpr * S)2258 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
2259 const SubstNonTypeTemplateParmPackExpr *S) {
2260 VisitExpr(S);
2261 VisitDecl(S->getParameterPack());
2262 VisitTemplateArgument(S->getArgumentPack());
2263 }
2264
VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr * E)2265 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
2266 const SubstNonTypeTemplateParmExpr *E) {
2267 // Profile exactly as the replacement expression.
2268 Visit(E->getReplacement());
2269 }
2270
VisitFunctionParmPackExpr(const FunctionParmPackExpr * S)2271 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
2272 VisitExpr(S);
2273 VisitDecl(S->getParameterPack());
2274 ID.AddInteger(S->getNumExpansions());
2275 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
2276 VisitDecl(*I);
2277 }
2278
VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr * S)2279 void StmtProfiler::VisitMaterializeTemporaryExpr(
2280 const MaterializeTemporaryExpr *S) {
2281 VisitExpr(S);
2282 }
2283
VisitCXXFoldExpr(const CXXFoldExpr * S)2284 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
2285 VisitExpr(S);
2286 ID.AddInteger(S->getOperator());
2287 }
2288
VisitCXXParenListInitExpr(const CXXParenListInitExpr * S)2289 void StmtProfiler::VisitCXXParenListInitExpr(const CXXParenListInitExpr *S) {
2290 VisitExpr(S);
2291 }
2292
VisitCoroutineBodyStmt(const CoroutineBodyStmt * S)2293 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
2294 VisitStmt(S);
2295 }
2296
VisitCoreturnStmt(const CoreturnStmt * S)2297 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
2298 VisitStmt(S);
2299 }
2300
VisitCoawaitExpr(const CoawaitExpr * S)2301 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
2302 VisitExpr(S);
2303 }
2304
VisitDependentCoawaitExpr(const DependentCoawaitExpr * S)2305 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
2306 VisitExpr(S);
2307 }
2308
VisitCoyieldExpr(const CoyieldExpr * S)2309 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
2310 VisitExpr(S);
2311 }
2312
VisitOpaqueValueExpr(const OpaqueValueExpr * E)2313 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
2314 VisitExpr(E);
2315 }
2316
VisitTypoExpr(const TypoExpr * E)2317 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
2318 VisitExpr(E);
2319 }
2320
VisitSourceLocExpr(const SourceLocExpr * E)2321 void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
2322 VisitExpr(E);
2323 }
2324
VisitEmbedExpr(const EmbedExpr * E)2325 void StmtProfiler::VisitEmbedExpr(const EmbedExpr *E) { VisitExpr(E); }
2326
VisitRecoveryExpr(const RecoveryExpr * E)2327 void StmtProfiler::VisitRecoveryExpr(const RecoveryExpr *E) { VisitExpr(E); }
2328
VisitObjCStringLiteral(const ObjCStringLiteral * S)2329 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
2330 VisitExpr(S);
2331 }
2332
VisitObjCBoxedExpr(const ObjCBoxedExpr * E)2333 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
2334 VisitExpr(E);
2335 }
2336
VisitObjCArrayLiteral(const ObjCArrayLiteral * E)2337 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
2338 VisitExpr(E);
2339 }
2340
VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral * E)2341 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
2342 VisitExpr(E);
2343 }
2344
VisitObjCEncodeExpr(const ObjCEncodeExpr * S)2345 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
2346 VisitExpr(S);
2347 VisitType(S->getEncodedType());
2348 }
2349
VisitObjCSelectorExpr(const ObjCSelectorExpr * S)2350 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
2351 VisitExpr(S);
2352 VisitName(S->getSelector());
2353 }
2354
VisitObjCProtocolExpr(const ObjCProtocolExpr * S)2355 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
2356 VisitExpr(S);
2357 VisitDecl(S->getProtocol());
2358 }
2359
VisitObjCIvarRefExpr(const ObjCIvarRefExpr * S)2360 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
2361 VisitExpr(S);
2362 VisitDecl(S->getDecl());
2363 ID.AddBoolean(S->isArrow());
2364 ID.AddBoolean(S->isFreeIvar());
2365 }
2366
VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr * S)2367 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
2368 VisitExpr(S);
2369 if (S->isImplicitProperty()) {
2370 VisitDecl(S->getImplicitPropertyGetter());
2371 VisitDecl(S->getImplicitPropertySetter());
2372 } else {
2373 VisitDecl(S->getExplicitProperty());
2374 }
2375 if (S->isSuperReceiver()) {
2376 ID.AddBoolean(S->isSuperReceiver());
2377 VisitType(S->getSuperReceiverType());
2378 }
2379 }
2380
VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr * S)2381 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
2382 VisitExpr(S);
2383 VisitDecl(S->getAtIndexMethodDecl());
2384 VisitDecl(S->setAtIndexMethodDecl());
2385 }
2386
VisitObjCMessageExpr(const ObjCMessageExpr * S)2387 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
2388 VisitExpr(S);
2389 VisitName(S->getSelector());
2390 VisitDecl(S->getMethodDecl());
2391 }
2392
VisitObjCIsaExpr(const ObjCIsaExpr * S)2393 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
2394 VisitExpr(S);
2395 ID.AddBoolean(S->isArrow());
2396 }
2397
VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr * S)2398 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
2399 VisitExpr(S);
2400 ID.AddBoolean(S->getValue());
2401 }
2402
VisitObjCIndirectCopyRestoreExpr(const ObjCIndirectCopyRestoreExpr * S)2403 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
2404 const ObjCIndirectCopyRestoreExpr *S) {
2405 VisitExpr(S);
2406 ID.AddBoolean(S->shouldCopy());
2407 }
2408
VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr * S)2409 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
2410 VisitExplicitCastExpr(S);
2411 ID.AddBoolean(S->getBridgeKind());
2412 }
2413
VisitObjCAvailabilityCheckExpr(const ObjCAvailabilityCheckExpr * S)2414 void StmtProfiler::VisitObjCAvailabilityCheckExpr(
2415 const ObjCAvailabilityCheckExpr *S) {
2416 VisitExpr(S);
2417 }
2418
VisitTemplateArguments(const TemplateArgumentLoc * Args,unsigned NumArgs)2419 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
2420 unsigned NumArgs) {
2421 ID.AddInteger(NumArgs);
2422 for (unsigned I = 0; I != NumArgs; ++I)
2423 VisitTemplateArgument(Args[I].getArgument());
2424 }
2425
VisitTemplateArgument(const TemplateArgument & Arg)2426 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
2427 // Mostly repetitive with TemplateArgument::Profile!
2428 ID.AddInteger(Arg.getKind());
2429 switch (Arg.getKind()) {
2430 case TemplateArgument::Null:
2431 break;
2432
2433 case TemplateArgument::Type:
2434 VisitType(Arg.getAsType());
2435 break;
2436
2437 case TemplateArgument::Template:
2438 case TemplateArgument::TemplateExpansion:
2439 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
2440 break;
2441
2442 case TemplateArgument::Declaration:
2443 VisitType(Arg.getParamTypeForDecl());
2444 // FIXME: Do we need to recursively decompose template parameter objects?
2445 VisitDecl(Arg.getAsDecl());
2446 break;
2447
2448 case TemplateArgument::NullPtr:
2449 VisitType(Arg.getNullPtrType());
2450 break;
2451
2452 case TemplateArgument::Integral:
2453 VisitType(Arg.getIntegralType());
2454 Arg.getAsIntegral().Profile(ID);
2455 break;
2456
2457 case TemplateArgument::StructuralValue:
2458 VisitType(Arg.getStructuralValueType());
2459 // FIXME: Do we need to recursively decompose this ourselves?
2460 Arg.getAsStructuralValue().Profile(ID);
2461 break;
2462
2463 case TemplateArgument::Expression:
2464 Visit(Arg.getAsExpr());
2465 break;
2466
2467 case TemplateArgument::Pack:
2468 for (const auto &P : Arg.pack_elements())
2469 VisitTemplateArgument(P);
2470 break;
2471 }
2472 }
2473
2474 namespace {
2475 class OpenACCClauseProfiler
2476 : public OpenACCClauseVisitor<OpenACCClauseProfiler> {
2477 StmtProfiler &Profiler;
2478
2479 public:
OpenACCClauseProfiler(StmtProfiler & P)2480 OpenACCClauseProfiler(StmtProfiler &P) : Profiler(P) {}
2481
VisitOpenACCClauseList(ArrayRef<const OpenACCClause * > Clauses)2482 void VisitOpenACCClauseList(ArrayRef<const OpenACCClause *> Clauses) {
2483 for (const OpenACCClause *Clause : Clauses) {
2484 // TODO OpenACC: When we have clauses with expressions, we should
2485 // profile them too.
2486 Visit(Clause);
2487 }
2488 }
2489
2490 #define VISIT_CLAUSE(CLAUSE_NAME) \
2491 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
2492
2493 #include "clang/Basic/OpenACCClauses.def"
2494 };
2495
2496 /// Nothing to do here, there are no sub-statements.
VisitDefaultClause(const OpenACCDefaultClause & Clause)2497 void OpenACCClauseProfiler::VisitDefaultClause(
2498 const OpenACCDefaultClause &Clause) {}
2499
VisitIfClause(const OpenACCIfClause & Clause)2500 void OpenACCClauseProfiler::VisitIfClause(const OpenACCIfClause &Clause) {
2501 assert(Clause.hasConditionExpr() &&
2502 "if clause requires a valid condition expr");
2503 Profiler.VisitStmt(Clause.getConditionExpr());
2504 }
2505
VisitCopyClause(const OpenACCCopyClause & Clause)2506 void OpenACCClauseProfiler::VisitCopyClause(const OpenACCCopyClause &Clause) {
2507 for (auto *E : Clause.getVarList())
2508 Profiler.VisitStmt(E);
2509 }
VisitCopyInClause(const OpenACCCopyInClause & Clause)2510 void OpenACCClauseProfiler::VisitCopyInClause(
2511 const OpenACCCopyInClause &Clause) {
2512 for (auto *E : Clause.getVarList())
2513 Profiler.VisitStmt(E);
2514 }
2515
VisitCopyOutClause(const OpenACCCopyOutClause & Clause)2516 void OpenACCClauseProfiler::VisitCopyOutClause(
2517 const OpenACCCopyOutClause &Clause) {
2518 for (auto *E : Clause.getVarList())
2519 Profiler.VisitStmt(E);
2520 }
2521
VisitCreateClause(const OpenACCCreateClause & Clause)2522 void OpenACCClauseProfiler::VisitCreateClause(
2523 const OpenACCCreateClause &Clause) {
2524 for (auto *E : Clause.getVarList())
2525 Profiler.VisitStmt(E);
2526 }
2527
VisitSelfClause(const OpenACCSelfClause & Clause)2528 void OpenACCClauseProfiler::VisitSelfClause(const OpenACCSelfClause &Clause) {
2529 if (Clause.hasConditionExpr())
2530 Profiler.VisitStmt(Clause.getConditionExpr());
2531 }
2532
VisitNumGangsClause(const OpenACCNumGangsClause & Clause)2533 void OpenACCClauseProfiler::VisitNumGangsClause(
2534 const OpenACCNumGangsClause &Clause) {
2535 for (auto *E : Clause.getIntExprs())
2536 Profiler.VisitStmt(E);
2537 }
2538
VisitNumWorkersClause(const OpenACCNumWorkersClause & Clause)2539 void OpenACCClauseProfiler::VisitNumWorkersClause(
2540 const OpenACCNumWorkersClause &Clause) {
2541 assert(Clause.hasIntExpr() && "num_workers clause requires a valid int expr");
2542 Profiler.VisitStmt(Clause.getIntExpr());
2543 }
2544
VisitPrivateClause(const OpenACCPrivateClause & Clause)2545 void OpenACCClauseProfiler::VisitPrivateClause(
2546 const OpenACCPrivateClause &Clause) {
2547 for (auto *E : Clause.getVarList())
2548 Profiler.VisitStmt(E);
2549 }
2550
VisitFirstPrivateClause(const OpenACCFirstPrivateClause & Clause)2551 void OpenACCClauseProfiler::VisitFirstPrivateClause(
2552 const OpenACCFirstPrivateClause &Clause) {
2553 for (auto *E : Clause.getVarList())
2554 Profiler.VisitStmt(E);
2555 }
2556
VisitAttachClause(const OpenACCAttachClause & Clause)2557 void OpenACCClauseProfiler::VisitAttachClause(
2558 const OpenACCAttachClause &Clause) {
2559 for (auto *E : Clause.getVarList())
2560 Profiler.VisitStmt(E);
2561 }
2562
VisitDevicePtrClause(const OpenACCDevicePtrClause & Clause)2563 void OpenACCClauseProfiler::VisitDevicePtrClause(
2564 const OpenACCDevicePtrClause &Clause) {
2565 for (auto *E : Clause.getVarList())
2566 Profiler.VisitStmt(E);
2567 }
2568
VisitNoCreateClause(const OpenACCNoCreateClause & Clause)2569 void OpenACCClauseProfiler::VisitNoCreateClause(
2570 const OpenACCNoCreateClause &Clause) {
2571 for (auto *E : Clause.getVarList())
2572 Profiler.VisitStmt(E);
2573 }
2574
VisitPresentClause(const OpenACCPresentClause & Clause)2575 void OpenACCClauseProfiler::VisitPresentClause(
2576 const OpenACCPresentClause &Clause) {
2577 for (auto *E : Clause.getVarList())
2578 Profiler.VisitStmt(E);
2579 }
2580
VisitVectorLengthClause(const OpenACCVectorLengthClause & Clause)2581 void OpenACCClauseProfiler::VisitVectorLengthClause(
2582 const OpenACCVectorLengthClause &Clause) {
2583 assert(Clause.hasIntExpr() &&
2584 "vector_length clause requires a valid int expr");
2585 Profiler.VisitStmt(Clause.getIntExpr());
2586 }
2587
VisitAsyncClause(const OpenACCAsyncClause & Clause)2588 void OpenACCClauseProfiler::VisitAsyncClause(const OpenACCAsyncClause &Clause) {
2589 if (Clause.hasIntExpr())
2590 Profiler.VisitStmt(Clause.getIntExpr());
2591 }
2592
VisitWaitClause(const OpenACCWaitClause & Clause)2593 void OpenACCClauseProfiler::VisitWaitClause(const OpenACCWaitClause &Clause) {
2594 if (Clause.hasDevNumExpr())
2595 Profiler.VisitStmt(Clause.getDevNumExpr());
2596 for (auto *E : Clause.getQueueIdExprs())
2597 Profiler.VisitStmt(E);
2598 }
2599 /// Nothing to do here, there are no sub-statements.
VisitDeviceTypeClause(const OpenACCDeviceTypeClause & Clause)2600 void OpenACCClauseProfiler::VisitDeviceTypeClause(
2601 const OpenACCDeviceTypeClause &Clause) {}
2602
VisitAutoClause(const OpenACCAutoClause & Clause)2603 void OpenACCClauseProfiler::VisitAutoClause(const OpenACCAutoClause &Clause) {}
2604
VisitIndependentClause(const OpenACCIndependentClause & Clause)2605 void OpenACCClauseProfiler::VisitIndependentClause(
2606 const OpenACCIndependentClause &Clause) {}
2607
VisitSeqClause(const OpenACCSeqClause & Clause)2608 void OpenACCClauseProfiler::VisitSeqClause(const OpenACCSeqClause &Clause) {}
2609
VisitReductionClause(const OpenACCReductionClause & Clause)2610 void OpenACCClauseProfiler::VisitReductionClause(
2611 const OpenACCReductionClause &Clause) {
2612 for (auto *E : Clause.getVarList())
2613 Profiler.VisitStmt(E);
2614 }
2615 } // namespace
2616
VisitOpenACCComputeConstruct(const OpenACCComputeConstruct * S)2617 void StmtProfiler::VisitOpenACCComputeConstruct(
2618 const OpenACCComputeConstruct *S) {
2619 // VisitStmt handles children, so the AssociatedStmt is handled.
2620 VisitStmt(S);
2621
2622 OpenACCClauseProfiler P{*this};
2623 P.VisitOpenACCClauseList(S->clauses());
2624 }
2625
VisitOpenACCLoopConstruct(const OpenACCLoopConstruct * S)2626 void StmtProfiler::VisitOpenACCLoopConstruct(const OpenACCLoopConstruct *S) {
2627 // VisitStmt handles children, so the Loop is handled.
2628 VisitStmt(S);
2629
2630 OpenACCClauseProfiler P{*this};
2631 P.VisitOpenACCClauseList(S->clauses());
2632 }
2633
Profile(llvm::FoldingSetNodeID & ID,const ASTContext & Context,bool Canonical,bool ProfileLambdaExpr) const2634 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2635 bool Canonical, bool ProfileLambdaExpr) const {
2636 StmtProfilerWithPointers Profiler(ID, Context, Canonical, ProfileLambdaExpr);
2637 Profiler.Visit(this);
2638 }
2639
ProcessODRHash(llvm::FoldingSetNodeID & ID,class ODRHash & Hash) const2640 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2641 class ODRHash &Hash) const {
2642 StmtProfilerWithoutPointers Profiler(ID, Hash);
2643 Profiler.Visit(this);
2644 }
2645