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