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