xref: /freebsd/contrib/llvm-project/clang/lib/AST/StmtProfile.cpp (revision 77013d11e6483b970af25e13c9b892075742f7e5)
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::VisitOMPSafelenClause(const OMPSafelenClause *C) {
456   if (C->getSafelen())
457     Profiler->VisitStmt(C->getSafelen());
458 }
459 
460 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
461   if (C->getSimdlen())
462     Profiler->VisitStmt(C->getSimdlen());
463 }
464 
465 void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
466   if (C->getAllocator())
467     Profiler->VisitStmt(C->getAllocator());
468 }
469 
470 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
471   if (C->getNumForLoops())
472     Profiler->VisitStmt(C->getNumForLoops());
473 }
474 
475 void OMPClauseProfiler::VisitOMPDetachClause(const OMPDetachClause *C) {
476   if (Expr *Evt = C->getEventHandler())
477     Profiler->VisitStmt(Evt);
478 }
479 
480 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
481 
482 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
483 
484 void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
485     const OMPUnifiedAddressClause *C) {}
486 
487 void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
488     const OMPUnifiedSharedMemoryClause *C) {}
489 
490 void OMPClauseProfiler::VisitOMPReverseOffloadClause(
491     const OMPReverseOffloadClause *C) {}
492 
493 void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
494     const OMPDynamicAllocatorsClause *C) {}
495 
496 void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
497     const OMPAtomicDefaultMemOrderClause *C) {}
498 
499 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
500   VistOMPClauseWithPreInit(C);
501   if (auto *S = C->getChunkSize())
502     Profiler->VisitStmt(S);
503 }
504 
505 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
506   if (auto *Num = C->getNumForLoops())
507     Profiler->VisitStmt(Num);
508 }
509 
510 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
511 
512 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
513 
514 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
515 
516 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
517 
518 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
519 
520 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
521 
522 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
523 
524 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
525 
526 void OMPClauseProfiler::VisitOMPAcqRelClause(const OMPAcqRelClause *) {}
527 
528 void OMPClauseProfiler::VisitOMPAcquireClause(const OMPAcquireClause *) {}
529 
530 void OMPClauseProfiler::VisitOMPReleaseClause(const OMPReleaseClause *) {}
531 
532 void OMPClauseProfiler::VisitOMPRelaxedClause(const OMPRelaxedClause *) {}
533 
534 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
535 
536 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
537 
538 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
539 
540 void OMPClauseProfiler::VisitOMPDestroyClause(const OMPDestroyClause *) {}
541 
542 template<typename T>
543 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
544   for (auto *E : Node->varlists()) {
545     if (E)
546       Profiler->VisitStmt(E);
547   }
548 }
549 
550 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
551   VisitOMPClauseList(C);
552   for (auto *E : C->private_copies()) {
553     if (E)
554       Profiler->VisitStmt(E);
555   }
556 }
557 void
558 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
559   VisitOMPClauseList(C);
560   VistOMPClauseWithPreInit(C);
561   for (auto *E : C->private_copies()) {
562     if (E)
563       Profiler->VisitStmt(E);
564   }
565   for (auto *E : C->inits()) {
566     if (E)
567       Profiler->VisitStmt(E);
568   }
569 }
570 void
571 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
572   VisitOMPClauseList(C);
573   VistOMPClauseWithPostUpdate(C);
574   for (auto *E : C->source_exprs()) {
575     if (E)
576       Profiler->VisitStmt(E);
577   }
578   for (auto *E : C->destination_exprs()) {
579     if (E)
580       Profiler->VisitStmt(E);
581   }
582   for (auto *E : C->assignment_ops()) {
583     if (E)
584       Profiler->VisitStmt(E);
585   }
586 }
587 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
588   VisitOMPClauseList(C);
589 }
590 void OMPClauseProfiler::VisitOMPReductionClause(
591                                          const OMPReductionClause *C) {
592   Profiler->VisitNestedNameSpecifier(
593       C->getQualifierLoc().getNestedNameSpecifier());
594   Profiler->VisitName(C->getNameInfo().getName());
595   VisitOMPClauseList(C);
596   VistOMPClauseWithPostUpdate(C);
597   for (auto *E : C->privates()) {
598     if (E)
599       Profiler->VisitStmt(E);
600   }
601   for (auto *E : C->lhs_exprs()) {
602     if (E)
603       Profiler->VisitStmt(E);
604   }
605   for (auto *E : C->rhs_exprs()) {
606     if (E)
607       Profiler->VisitStmt(E);
608   }
609   for (auto *E : C->reduction_ops()) {
610     if (E)
611       Profiler->VisitStmt(E);
612   }
613   if (C->getModifier() == clang::OMPC_REDUCTION_inscan) {
614     for (auto *E : C->copy_ops()) {
615       if (E)
616         Profiler->VisitStmt(E);
617     }
618     for (auto *E : C->copy_array_temps()) {
619       if (E)
620         Profiler->VisitStmt(E);
621     }
622     for (auto *E : C->copy_array_elems()) {
623       if (E)
624         Profiler->VisitStmt(E);
625     }
626   }
627 }
628 void OMPClauseProfiler::VisitOMPTaskReductionClause(
629     const OMPTaskReductionClause *C) {
630   Profiler->VisitNestedNameSpecifier(
631       C->getQualifierLoc().getNestedNameSpecifier());
632   Profiler->VisitName(C->getNameInfo().getName());
633   VisitOMPClauseList(C);
634   VistOMPClauseWithPostUpdate(C);
635   for (auto *E : C->privates()) {
636     if (E)
637       Profiler->VisitStmt(E);
638   }
639   for (auto *E : C->lhs_exprs()) {
640     if (E)
641       Profiler->VisitStmt(E);
642   }
643   for (auto *E : C->rhs_exprs()) {
644     if (E)
645       Profiler->VisitStmt(E);
646   }
647   for (auto *E : C->reduction_ops()) {
648     if (E)
649       Profiler->VisitStmt(E);
650   }
651 }
652 void OMPClauseProfiler::VisitOMPInReductionClause(
653     const OMPInReductionClause *C) {
654   Profiler->VisitNestedNameSpecifier(
655       C->getQualifierLoc().getNestedNameSpecifier());
656   Profiler->VisitName(C->getNameInfo().getName());
657   VisitOMPClauseList(C);
658   VistOMPClauseWithPostUpdate(C);
659   for (auto *E : C->privates()) {
660     if (E)
661       Profiler->VisitStmt(E);
662   }
663   for (auto *E : C->lhs_exprs()) {
664     if (E)
665       Profiler->VisitStmt(E);
666   }
667   for (auto *E : C->rhs_exprs()) {
668     if (E)
669       Profiler->VisitStmt(E);
670   }
671   for (auto *E : C->reduction_ops()) {
672     if (E)
673       Profiler->VisitStmt(E);
674   }
675   for (auto *E : C->taskgroup_descriptors()) {
676     if (E)
677       Profiler->VisitStmt(E);
678   }
679 }
680 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
681   VisitOMPClauseList(C);
682   VistOMPClauseWithPostUpdate(C);
683   for (auto *E : C->privates()) {
684     if (E)
685       Profiler->VisitStmt(E);
686   }
687   for (auto *E : C->inits()) {
688     if (E)
689       Profiler->VisitStmt(E);
690   }
691   for (auto *E : C->updates()) {
692     if (E)
693       Profiler->VisitStmt(E);
694   }
695   for (auto *E : C->finals()) {
696     if (E)
697       Profiler->VisitStmt(E);
698   }
699   if (C->getStep())
700     Profiler->VisitStmt(C->getStep());
701   if (C->getCalcStep())
702     Profiler->VisitStmt(C->getCalcStep());
703 }
704 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
705   VisitOMPClauseList(C);
706   if (C->getAlignment())
707     Profiler->VisitStmt(C->getAlignment());
708 }
709 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
710   VisitOMPClauseList(C);
711   for (auto *E : C->source_exprs()) {
712     if (E)
713       Profiler->VisitStmt(E);
714   }
715   for (auto *E : C->destination_exprs()) {
716     if (E)
717       Profiler->VisitStmt(E);
718   }
719   for (auto *E : C->assignment_ops()) {
720     if (E)
721       Profiler->VisitStmt(E);
722   }
723 }
724 void
725 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
726   VisitOMPClauseList(C);
727   for (auto *E : C->source_exprs()) {
728     if (E)
729       Profiler->VisitStmt(E);
730   }
731   for (auto *E : C->destination_exprs()) {
732     if (E)
733       Profiler->VisitStmt(E);
734   }
735   for (auto *E : C->assignment_ops()) {
736     if (E)
737       Profiler->VisitStmt(E);
738   }
739 }
740 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
741   VisitOMPClauseList(C);
742 }
743 void OMPClauseProfiler::VisitOMPDepobjClause(const OMPDepobjClause *C) {
744   if (const Expr *Depobj = C->getDepobj())
745     Profiler->VisitStmt(Depobj);
746 }
747 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
748   VisitOMPClauseList(C);
749 }
750 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
751   if (C->getDevice())
752     Profiler->VisitStmt(C->getDevice());
753 }
754 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
755   VisitOMPClauseList(C);
756 }
757 void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
758   if (Expr *Allocator = C->getAllocator())
759     Profiler->VisitStmt(Allocator);
760   VisitOMPClauseList(C);
761 }
762 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
763   VistOMPClauseWithPreInit(C);
764   if (C->getNumTeams())
765     Profiler->VisitStmt(C->getNumTeams());
766 }
767 void OMPClauseProfiler::VisitOMPThreadLimitClause(
768     const OMPThreadLimitClause *C) {
769   VistOMPClauseWithPreInit(C);
770   if (C->getThreadLimit())
771     Profiler->VisitStmt(C->getThreadLimit());
772 }
773 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
774   VistOMPClauseWithPreInit(C);
775   if (C->getPriority())
776     Profiler->VisitStmt(C->getPriority());
777 }
778 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
779   VistOMPClauseWithPreInit(C);
780   if (C->getGrainsize())
781     Profiler->VisitStmt(C->getGrainsize());
782 }
783 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
784   VistOMPClauseWithPreInit(C);
785   if (C->getNumTasks())
786     Profiler->VisitStmt(C->getNumTasks());
787 }
788 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
789   if (C->getHint())
790     Profiler->VisitStmt(C->getHint());
791 }
792 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
793   VisitOMPClauseList(C);
794 }
795 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
796   VisitOMPClauseList(C);
797 }
798 void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
799     const OMPUseDevicePtrClause *C) {
800   VisitOMPClauseList(C);
801 }
802 void OMPClauseProfiler::VisitOMPUseDeviceAddrClause(
803     const OMPUseDeviceAddrClause *C) {
804   VisitOMPClauseList(C);
805 }
806 void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
807     const OMPIsDevicePtrClause *C) {
808   VisitOMPClauseList(C);
809 }
810 void OMPClauseProfiler::VisitOMPNontemporalClause(
811     const OMPNontemporalClause *C) {
812   VisitOMPClauseList(C);
813   for (auto *E : C->private_refs())
814     Profiler->VisitStmt(E);
815 }
816 void OMPClauseProfiler::VisitOMPInclusiveClause(const OMPInclusiveClause *C) {
817   VisitOMPClauseList(C);
818 }
819 void OMPClauseProfiler::VisitOMPExclusiveClause(const OMPExclusiveClause *C) {
820   VisitOMPClauseList(C);
821 }
822 void OMPClauseProfiler::VisitOMPUsesAllocatorsClause(
823     const OMPUsesAllocatorsClause *C) {
824   for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
825     OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
826     Profiler->VisitStmt(D.Allocator);
827     if (D.AllocatorTraits)
828       Profiler->VisitStmt(D.AllocatorTraits);
829   }
830 }
831 void OMPClauseProfiler::VisitOMPAffinityClause(const OMPAffinityClause *C) {
832   if (const Expr *Modifier = C->getModifier())
833     Profiler->VisitStmt(Modifier);
834   for (const Expr *E : C->varlists())
835     Profiler->VisitStmt(E);
836 }
837 void OMPClauseProfiler::VisitOMPOrderClause(const OMPOrderClause *C) {}
838 } // namespace
839 
840 void
841 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
842   VisitStmt(S);
843   OMPClauseProfiler P(this);
844   ArrayRef<OMPClause *> Clauses = S->clauses();
845   for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
846        I != E; ++I)
847     if (*I)
848       P.Visit(*I);
849 }
850 
851 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
852   VisitOMPExecutableDirective(S);
853 }
854 
855 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
856   VisitOMPExecutableDirective(S);
857 }
858 
859 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
860   VisitOMPLoopDirective(S);
861 }
862 
863 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
864   VisitOMPLoopDirective(S);
865 }
866 
867 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
868   VisitOMPLoopDirective(S);
869 }
870 
871 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
872   VisitOMPExecutableDirective(S);
873 }
874 
875 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
876   VisitOMPExecutableDirective(S);
877 }
878 
879 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
880   VisitOMPExecutableDirective(S);
881 }
882 
883 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
884   VisitOMPExecutableDirective(S);
885 }
886 
887 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
888   VisitOMPExecutableDirective(S);
889   VisitName(S->getDirectiveName().getName());
890 }
891 
892 void
893 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
894   VisitOMPLoopDirective(S);
895 }
896 
897 void StmtProfiler::VisitOMPParallelForSimdDirective(
898     const OMPParallelForSimdDirective *S) {
899   VisitOMPLoopDirective(S);
900 }
901 
902 void StmtProfiler::VisitOMPParallelMasterDirective(
903     const OMPParallelMasterDirective *S) {
904   VisitOMPExecutableDirective(S);
905 }
906 
907 void StmtProfiler::VisitOMPParallelSectionsDirective(
908     const OMPParallelSectionsDirective *S) {
909   VisitOMPExecutableDirective(S);
910 }
911 
912 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
913   VisitOMPExecutableDirective(S);
914 }
915 
916 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
917   VisitOMPExecutableDirective(S);
918 }
919 
920 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
921   VisitOMPExecutableDirective(S);
922 }
923 
924 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
925   VisitOMPExecutableDirective(S);
926 }
927 
928 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
929   VisitOMPExecutableDirective(S);
930   if (const Expr *E = S->getReductionRef())
931     VisitStmt(E);
932 }
933 
934 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
935   VisitOMPExecutableDirective(S);
936 }
937 
938 void StmtProfiler::VisitOMPDepobjDirective(const OMPDepobjDirective *S) {
939   VisitOMPExecutableDirective(S);
940 }
941 
942 void StmtProfiler::VisitOMPScanDirective(const OMPScanDirective *S) {
943   VisitOMPExecutableDirective(S);
944 }
945 
946 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
947   VisitOMPExecutableDirective(S);
948 }
949 
950 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
951   VisitOMPExecutableDirective(S);
952 }
953 
954 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
955   VisitOMPExecutableDirective(S);
956 }
957 
958 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
959   VisitOMPExecutableDirective(S);
960 }
961 
962 void StmtProfiler::VisitOMPTargetEnterDataDirective(
963     const OMPTargetEnterDataDirective *S) {
964   VisitOMPExecutableDirective(S);
965 }
966 
967 void StmtProfiler::VisitOMPTargetExitDataDirective(
968     const OMPTargetExitDataDirective *S) {
969   VisitOMPExecutableDirective(S);
970 }
971 
972 void StmtProfiler::VisitOMPTargetParallelDirective(
973     const OMPTargetParallelDirective *S) {
974   VisitOMPExecutableDirective(S);
975 }
976 
977 void StmtProfiler::VisitOMPTargetParallelForDirective(
978     const OMPTargetParallelForDirective *S) {
979   VisitOMPExecutableDirective(S);
980 }
981 
982 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
983   VisitOMPExecutableDirective(S);
984 }
985 
986 void StmtProfiler::VisitOMPCancellationPointDirective(
987     const OMPCancellationPointDirective *S) {
988   VisitOMPExecutableDirective(S);
989 }
990 
991 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
992   VisitOMPExecutableDirective(S);
993 }
994 
995 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
996   VisitOMPLoopDirective(S);
997 }
998 
999 void StmtProfiler::VisitOMPTaskLoopSimdDirective(
1000     const OMPTaskLoopSimdDirective *S) {
1001   VisitOMPLoopDirective(S);
1002 }
1003 
1004 void StmtProfiler::VisitOMPMasterTaskLoopDirective(
1005     const OMPMasterTaskLoopDirective *S) {
1006   VisitOMPLoopDirective(S);
1007 }
1008 
1009 void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective(
1010     const OMPMasterTaskLoopSimdDirective *S) {
1011   VisitOMPLoopDirective(S);
1012 }
1013 
1014 void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective(
1015     const OMPParallelMasterTaskLoopDirective *S) {
1016   VisitOMPLoopDirective(S);
1017 }
1018 
1019 void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective(
1020     const OMPParallelMasterTaskLoopSimdDirective *S) {
1021   VisitOMPLoopDirective(S);
1022 }
1023 
1024 void StmtProfiler::VisitOMPDistributeDirective(
1025     const OMPDistributeDirective *S) {
1026   VisitOMPLoopDirective(S);
1027 }
1028 
1029 void OMPClauseProfiler::VisitOMPDistScheduleClause(
1030     const OMPDistScheduleClause *C) {
1031   VistOMPClauseWithPreInit(C);
1032   if (auto *S = C->getChunkSize())
1033     Profiler->VisitStmt(S);
1034 }
1035 
1036 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
1037 
1038 void StmtProfiler::VisitOMPTargetUpdateDirective(
1039     const OMPTargetUpdateDirective *S) {
1040   VisitOMPExecutableDirective(S);
1041 }
1042 
1043 void StmtProfiler::VisitOMPDistributeParallelForDirective(
1044     const OMPDistributeParallelForDirective *S) {
1045   VisitOMPLoopDirective(S);
1046 }
1047 
1048 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
1049     const OMPDistributeParallelForSimdDirective *S) {
1050   VisitOMPLoopDirective(S);
1051 }
1052 
1053 void StmtProfiler::VisitOMPDistributeSimdDirective(
1054     const OMPDistributeSimdDirective *S) {
1055   VisitOMPLoopDirective(S);
1056 }
1057 
1058 void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
1059     const OMPTargetParallelForSimdDirective *S) {
1060   VisitOMPLoopDirective(S);
1061 }
1062 
1063 void StmtProfiler::VisitOMPTargetSimdDirective(
1064     const OMPTargetSimdDirective *S) {
1065   VisitOMPLoopDirective(S);
1066 }
1067 
1068 void StmtProfiler::VisitOMPTeamsDistributeDirective(
1069     const OMPTeamsDistributeDirective *S) {
1070   VisitOMPLoopDirective(S);
1071 }
1072 
1073 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
1074     const OMPTeamsDistributeSimdDirective *S) {
1075   VisitOMPLoopDirective(S);
1076 }
1077 
1078 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
1079     const OMPTeamsDistributeParallelForSimdDirective *S) {
1080   VisitOMPLoopDirective(S);
1081 }
1082 
1083 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
1084     const OMPTeamsDistributeParallelForDirective *S) {
1085   VisitOMPLoopDirective(S);
1086 }
1087 
1088 void StmtProfiler::VisitOMPTargetTeamsDirective(
1089     const OMPTargetTeamsDirective *S) {
1090   VisitOMPExecutableDirective(S);
1091 }
1092 
1093 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
1094     const OMPTargetTeamsDistributeDirective *S) {
1095   VisitOMPLoopDirective(S);
1096 }
1097 
1098 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
1099     const OMPTargetTeamsDistributeParallelForDirective *S) {
1100   VisitOMPLoopDirective(S);
1101 }
1102 
1103 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1104     const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
1105   VisitOMPLoopDirective(S);
1106 }
1107 
1108 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
1109     const OMPTargetTeamsDistributeSimdDirective *S) {
1110   VisitOMPLoopDirective(S);
1111 }
1112 
1113 void StmtProfiler::VisitExpr(const Expr *S) {
1114   VisitStmt(S);
1115 }
1116 
1117 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1118   VisitExpr(S);
1119 }
1120 
1121 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
1122   VisitExpr(S);
1123   if (!Canonical)
1124     VisitNestedNameSpecifier(S->getQualifier());
1125   VisitDecl(S->getDecl());
1126   if (!Canonical) {
1127     ID.AddBoolean(S->hasExplicitTemplateArgs());
1128     if (S->hasExplicitTemplateArgs())
1129       VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1130   }
1131 }
1132 
1133 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
1134   VisitExpr(S);
1135   ID.AddInteger(S->getIdentKind());
1136 }
1137 
1138 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
1139   VisitExpr(S);
1140   S->getValue().Profile(ID);
1141   ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1142 }
1143 
1144 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1145   VisitExpr(S);
1146   S->getValue().Profile(ID);
1147   ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1148 }
1149 
1150 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
1151   VisitExpr(S);
1152   ID.AddInteger(S->getKind());
1153   ID.AddInteger(S->getValue());
1154 }
1155 
1156 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
1157   VisitExpr(S);
1158   S->getValue().Profile(ID);
1159   ID.AddBoolean(S->isExact());
1160   ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1161 }
1162 
1163 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
1164   VisitExpr(S);
1165 }
1166 
1167 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
1168   VisitExpr(S);
1169   ID.AddString(S->getBytes());
1170   ID.AddInteger(S->getKind());
1171 }
1172 
1173 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
1174   VisitExpr(S);
1175 }
1176 
1177 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
1178   VisitExpr(S);
1179 }
1180 
1181 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
1182   VisitExpr(S);
1183   ID.AddInteger(S->getOpcode());
1184 }
1185 
1186 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
1187   VisitType(S->getTypeSourceInfo()->getType());
1188   unsigned n = S->getNumComponents();
1189   for (unsigned i = 0; i < n; ++i) {
1190     const OffsetOfNode &ON = S->getComponent(i);
1191     ID.AddInteger(ON.getKind());
1192     switch (ON.getKind()) {
1193     case OffsetOfNode::Array:
1194       // Expressions handled below.
1195       break;
1196 
1197     case OffsetOfNode::Field:
1198       VisitDecl(ON.getField());
1199       break;
1200 
1201     case OffsetOfNode::Identifier:
1202       VisitIdentifierInfo(ON.getFieldName());
1203       break;
1204 
1205     case OffsetOfNode::Base:
1206       // These nodes are implicit, and therefore don't need profiling.
1207       break;
1208     }
1209   }
1210 
1211   VisitExpr(S);
1212 }
1213 
1214 void
1215 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
1216   VisitExpr(S);
1217   ID.AddInteger(S->getKind());
1218   if (S->isArgumentType())
1219     VisitType(S->getArgumentType());
1220 }
1221 
1222 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
1223   VisitExpr(S);
1224 }
1225 
1226 void StmtProfiler::VisitMatrixSubscriptExpr(const MatrixSubscriptExpr *S) {
1227   VisitExpr(S);
1228 }
1229 
1230 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1231   VisitExpr(S);
1232 }
1233 
1234 void StmtProfiler::VisitOMPArrayShapingExpr(const OMPArrayShapingExpr *S) {
1235   VisitExpr(S);
1236 }
1237 
1238 void StmtProfiler::VisitOMPIteratorExpr(const OMPIteratorExpr *S) {
1239   VisitExpr(S);
1240   for (unsigned I = 0, E = S->numOfIterators(); I < E; ++I)
1241     VisitDecl(S->getIteratorDecl(I));
1242 }
1243 
1244 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
1245   VisitExpr(S);
1246 }
1247 
1248 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
1249   VisitExpr(S);
1250   VisitDecl(S->getMemberDecl());
1251   if (!Canonical)
1252     VisitNestedNameSpecifier(S->getQualifier());
1253   ID.AddBoolean(S->isArrow());
1254 }
1255 
1256 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
1257   VisitExpr(S);
1258   ID.AddBoolean(S->isFileScope());
1259 }
1260 
1261 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
1262   VisitExpr(S);
1263 }
1264 
1265 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
1266   VisitCastExpr(S);
1267   ID.AddInteger(S->getValueKind());
1268 }
1269 
1270 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
1271   VisitCastExpr(S);
1272   VisitType(S->getTypeAsWritten());
1273 }
1274 
1275 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
1276   VisitExplicitCastExpr(S);
1277 }
1278 
1279 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
1280   VisitExpr(S);
1281   ID.AddInteger(S->getOpcode());
1282 }
1283 
1284 void
1285 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
1286   VisitBinaryOperator(S);
1287 }
1288 
1289 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
1290   VisitExpr(S);
1291 }
1292 
1293 void StmtProfiler::VisitBinaryConditionalOperator(
1294     const BinaryConditionalOperator *S) {
1295   VisitExpr(S);
1296 }
1297 
1298 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
1299   VisitExpr(S);
1300   VisitDecl(S->getLabel());
1301 }
1302 
1303 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
1304   VisitExpr(S);
1305 }
1306 
1307 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
1308   VisitExpr(S);
1309 }
1310 
1311 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1312   VisitExpr(S);
1313 }
1314 
1315 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
1316   VisitExpr(S);
1317 }
1318 
1319 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
1320   VisitExpr(S);
1321 }
1322 
1323 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
1324   VisitExpr(S);
1325 }
1326 
1327 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
1328   if (S->getSyntacticForm()) {
1329     VisitInitListExpr(S->getSyntacticForm());
1330     return;
1331   }
1332 
1333   VisitExpr(S);
1334 }
1335 
1336 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
1337   VisitExpr(S);
1338   ID.AddBoolean(S->usesGNUSyntax());
1339   for (const DesignatedInitExpr::Designator &D : S->designators()) {
1340     if (D.isFieldDesignator()) {
1341       ID.AddInteger(0);
1342       VisitName(D.getFieldName());
1343       continue;
1344     }
1345 
1346     if (D.isArrayDesignator()) {
1347       ID.AddInteger(1);
1348     } else {
1349       assert(D.isArrayRangeDesignator());
1350       ID.AddInteger(2);
1351     }
1352     ID.AddInteger(D.getFirstExprIndex());
1353   }
1354 }
1355 
1356 // Seems that if VisitInitListExpr() only works on the syntactic form of an
1357 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1358 void StmtProfiler::VisitDesignatedInitUpdateExpr(
1359     const DesignatedInitUpdateExpr *S) {
1360   llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1361                    "initializer");
1362 }
1363 
1364 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1365   VisitExpr(S);
1366 }
1367 
1368 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1369   VisitExpr(S);
1370 }
1371 
1372 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1373   llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1374 }
1375 
1376 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
1377   VisitExpr(S);
1378 }
1379 
1380 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
1381   VisitExpr(S);
1382   VisitName(&S->getAccessor());
1383 }
1384 
1385 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
1386   VisitExpr(S);
1387   VisitDecl(S->getBlockDecl());
1388 }
1389 
1390 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
1391   VisitExpr(S);
1392   for (const GenericSelectionExpr::ConstAssociation Assoc :
1393        S->associations()) {
1394     QualType T = Assoc.getType();
1395     if (T.isNull())
1396       ID.AddPointer(nullptr);
1397     else
1398       VisitType(T);
1399     VisitExpr(Assoc.getAssociationExpr());
1400   }
1401 }
1402 
1403 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1404   VisitExpr(S);
1405   for (PseudoObjectExpr::const_semantics_iterator
1406          i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1407     // Normally, we would not profile the source expressions of OVEs.
1408     if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1409       Visit(OVE->getSourceExpr());
1410 }
1411 
1412 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1413   VisitExpr(S);
1414   ID.AddInteger(S->getOp());
1415 }
1416 
1417 void StmtProfiler::VisitConceptSpecializationExpr(
1418                                            const ConceptSpecializationExpr *S) {
1419   VisitExpr(S);
1420   VisitDecl(S->getNamedConcept());
1421   for (const TemplateArgument &Arg : S->getTemplateArguments())
1422     VisitTemplateArgument(Arg);
1423 }
1424 
1425 void StmtProfiler::VisitRequiresExpr(const RequiresExpr *S) {
1426   VisitExpr(S);
1427   ID.AddInteger(S->getLocalParameters().size());
1428   for (ParmVarDecl *LocalParam : S->getLocalParameters())
1429     VisitDecl(LocalParam);
1430   ID.AddInteger(S->getRequirements().size());
1431   for (concepts::Requirement *Req : S->getRequirements()) {
1432     if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
1433       ID.AddInteger(concepts::Requirement::RK_Type);
1434       ID.AddBoolean(TypeReq->isSubstitutionFailure());
1435       if (!TypeReq->isSubstitutionFailure())
1436         VisitType(TypeReq->getType()->getType());
1437     } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
1438       ID.AddInteger(concepts::Requirement::RK_Compound);
1439       ID.AddBoolean(ExprReq->isExprSubstitutionFailure());
1440       if (!ExprReq->isExprSubstitutionFailure())
1441         Visit(ExprReq->getExpr());
1442       // C++2a [expr.prim.req.compound]p1 Example:
1443       //    [...] The compound-requirement in C1 requires that x++ is a valid
1444       //    expression. It is equivalent to the simple-requirement x++; [...]
1445       // We therefore do not profile isSimple() here.
1446       ID.AddBoolean(ExprReq->getNoexceptLoc().isValid());
1447       const concepts::ExprRequirement::ReturnTypeRequirement &RetReq =
1448           ExprReq->getReturnTypeRequirement();
1449       if (RetReq.isEmpty()) {
1450         ID.AddInteger(0);
1451       } else if (RetReq.isTypeConstraint()) {
1452         ID.AddInteger(1);
1453         Visit(RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint());
1454       } else {
1455         assert(RetReq.isSubstitutionFailure());
1456         ID.AddInteger(2);
1457       }
1458     } else {
1459       ID.AddInteger(concepts::Requirement::RK_Nested);
1460       auto *NestedReq = cast<concepts::NestedRequirement>(Req);
1461       ID.AddBoolean(NestedReq->isSubstitutionFailure());
1462       if (!NestedReq->isSubstitutionFailure())
1463         Visit(NestedReq->getConstraintExpr());
1464     }
1465   }
1466 }
1467 
1468 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
1469                                           UnaryOperatorKind &UnaryOp,
1470                                           BinaryOperatorKind &BinaryOp) {
1471   switch (S->getOperator()) {
1472   case OO_None:
1473   case OO_New:
1474   case OO_Delete:
1475   case OO_Array_New:
1476   case OO_Array_Delete:
1477   case OO_Arrow:
1478   case OO_Conditional:
1479   case NUM_OVERLOADED_OPERATORS:
1480     llvm_unreachable("Invalid operator call kind");
1481 
1482   case OO_Plus:
1483     if (S->getNumArgs() == 1) {
1484       UnaryOp = UO_Plus;
1485       return Stmt::UnaryOperatorClass;
1486     }
1487 
1488     BinaryOp = BO_Add;
1489     return Stmt::BinaryOperatorClass;
1490 
1491   case OO_Minus:
1492     if (S->getNumArgs() == 1) {
1493       UnaryOp = UO_Minus;
1494       return Stmt::UnaryOperatorClass;
1495     }
1496 
1497     BinaryOp = BO_Sub;
1498     return Stmt::BinaryOperatorClass;
1499 
1500   case OO_Star:
1501     if (S->getNumArgs() == 1) {
1502       UnaryOp = UO_Deref;
1503       return Stmt::UnaryOperatorClass;
1504     }
1505 
1506     BinaryOp = BO_Mul;
1507     return Stmt::BinaryOperatorClass;
1508 
1509   case OO_Slash:
1510     BinaryOp = BO_Div;
1511     return Stmt::BinaryOperatorClass;
1512 
1513   case OO_Percent:
1514     BinaryOp = BO_Rem;
1515     return Stmt::BinaryOperatorClass;
1516 
1517   case OO_Caret:
1518     BinaryOp = BO_Xor;
1519     return Stmt::BinaryOperatorClass;
1520 
1521   case OO_Amp:
1522     if (S->getNumArgs() == 1) {
1523       UnaryOp = UO_AddrOf;
1524       return Stmt::UnaryOperatorClass;
1525     }
1526 
1527     BinaryOp = BO_And;
1528     return Stmt::BinaryOperatorClass;
1529 
1530   case OO_Pipe:
1531     BinaryOp = BO_Or;
1532     return Stmt::BinaryOperatorClass;
1533 
1534   case OO_Tilde:
1535     UnaryOp = UO_Not;
1536     return Stmt::UnaryOperatorClass;
1537 
1538   case OO_Exclaim:
1539     UnaryOp = UO_LNot;
1540     return Stmt::UnaryOperatorClass;
1541 
1542   case OO_Equal:
1543     BinaryOp = BO_Assign;
1544     return Stmt::BinaryOperatorClass;
1545 
1546   case OO_Less:
1547     BinaryOp = BO_LT;
1548     return Stmt::BinaryOperatorClass;
1549 
1550   case OO_Greater:
1551     BinaryOp = BO_GT;
1552     return Stmt::BinaryOperatorClass;
1553 
1554   case OO_PlusEqual:
1555     BinaryOp = BO_AddAssign;
1556     return Stmt::CompoundAssignOperatorClass;
1557 
1558   case OO_MinusEqual:
1559     BinaryOp = BO_SubAssign;
1560     return Stmt::CompoundAssignOperatorClass;
1561 
1562   case OO_StarEqual:
1563     BinaryOp = BO_MulAssign;
1564     return Stmt::CompoundAssignOperatorClass;
1565 
1566   case OO_SlashEqual:
1567     BinaryOp = BO_DivAssign;
1568     return Stmt::CompoundAssignOperatorClass;
1569 
1570   case OO_PercentEqual:
1571     BinaryOp = BO_RemAssign;
1572     return Stmt::CompoundAssignOperatorClass;
1573 
1574   case OO_CaretEqual:
1575     BinaryOp = BO_XorAssign;
1576     return Stmt::CompoundAssignOperatorClass;
1577 
1578   case OO_AmpEqual:
1579     BinaryOp = BO_AndAssign;
1580     return Stmt::CompoundAssignOperatorClass;
1581 
1582   case OO_PipeEqual:
1583     BinaryOp = BO_OrAssign;
1584     return Stmt::CompoundAssignOperatorClass;
1585 
1586   case OO_LessLess:
1587     BinaryOp = BO_Shl;
1588     return Stmt::BinaryOperatorClass;
1589 
1590   case OO_GreaterGreater:
1591     BinaryOp = BO_Shr;
1592     return Stmt::BinaryOperatorClass;
1593 
1594   case OO_LessLessEqual:
1595     BinaryOp = BO_ShlAssign;
1596     return Stmt::CompoundAssignOperatorClass;
1597 
1598   case OO_GreaterGreaterEqual:
1599     BinaryOp = BO_ShrAssign;
1600     return Stmt::CompoundAssignOperatorClass;
1601 
1602   case OO_EqualEqual:
1603     BinaryOp = BO_EQ;
1604     return Stmt::BinaryOperatorClass;
1605 
1606   case OO_ExclaimEqual:
1607     BinaryOp = BO_NE;
1608     return Stmt::BinaryOperatorClass;
1609 
1610   case OO_LessEqual:
1611     BinaryOp = BO_LE;
1612     return Stmt::BinaryOperatorClass;
1613 
1614   case OO_GreaterEqual:
1615     BinaryOp = BO_GE;
1616     return Stmt::BinaryOperatorClass;
1617 
1618   case OO_Spaceship:
1619     BinaryOp = BO_Cmp;
1620     return Stmt::BinaryOperatorClass;
1621 
1622   case OO_AmpAmp:
1623     BinaryOp = BO_LAnd;
1624     return Stmt::BinaryOperatorClass;
1625 
1626   case OO_PipePipe:
1627     BinaryOp = BO_LOr;
1628     return Stmt::BinaryOperatorClass;
1629 
1630   case OO_PlusPlus:
1631     UnaryOp = S->getNumArgs() == 1? UO_PreInc
1632                                   : UO_PostInc;
1633     return Stmt::UnaryOperatorClass;
1634 
1635   case OO_MinusMinus:
1636     UnaryOp = S->getNumArgs() == 1? UO_PreDec
1637                                   : UO_PostDec;
1638     return Stmt::UnaryOperatorClass;
1639 
1640   case OO_Comma:
1641     BinaryOp = BO_Comma;
1642     return Stmt::BinaryOperatorClass;
1643 
1644   case OO_ArrowStar:
1645     BinaryOp = BO_PtrMemI;
1646     return Stmt::BinaryOperatorClass;
1647 
1648   case OO_Subscript:
1649     return Stmt::ArraySubscriptExprClass;
1650 
1651   case OO_Call:
1652     return Stmt::CallExprClass;
1653 
1654   case OO_Coawait:
1655     UnaryOp = UO_Coawait;
1656     return Stmt::UnaryOperatorClass;
1657   }
1658 
1659   llvm_unreachable("Invalid overloaded operator expression");
1660 }
1661 
1662 #if defined(_MSC_VER) && !defined(__clang__)
1663 #if _MSC_VER == 1911
1664 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1665 // MSVC 2017 update 3 miscompiles this function, and a clang built with it
1666 // will crash in stage 2 of a bootstrap build.
1667 #pragma optimize("", off)
1668 #endif
1669 #endif
1670 
1671 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
1672   if (S->isTypeDependent()) {
1673     // Type-dependent operator calls are profiled like their underlying
1674     // syntactic operator.
1675     //
1676     // An operator call to operator-> is always implicit, so just skip it. The
1677     // enclosing MemberExpr will profile the actual member access.
1678     if (S->getOperator() == OO_Arrow)
1679       return Visit(S->getArg(0));
1680 
1681     UnaryOperatorKind UnaryOp = UO_Extension;
1682     BinaryOperatorKind BinaryOp = BO_Comma;
1683     Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
1684 
1685     ID.AddInteger(SC);
1686     for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1687       Visit(S->getArg(I));
1688     if (SC == Stmt::UnaryOperatorClass)
1689       ID.AddInteger(UnaryOp);
1690     else if (SC == Stmt::BinaryOperatorClass ||
1691              SC == Stmt::CompoundAssignOperatorClass)
1692       ID.AddInteger(BinaryOp);
1693     else
1694       assert(SC == Stmt::ArraySubscriptExprClass || SC == Stmt::CallExprClass);
1695 
1696     return;
1697   }
1698 
1699   VisitCallExpr(S);
1700   ID.AddInteger(S->getOperator());
1701 }
1702 
1703 void StmtProfiler::VisitCXXRewrittenBinaryOperator(
1704     const CXXRewrittenBinaryOperator *S) {
1705   // If a rewritten operator were ever to be type-dependent, we should profile
1706   // it following its syntactic operator.
1707   assert(!S->isTypeDependent() &&
1708          "resolved rewritten operator should never be type-dependent");
1709   ID.AddBoolean(S->isReversed());
1710   VisitExpr(S->getSemanticForm());
1711 }
1712 
1713 #if defined(_MSC_VER) && !defined(__clang__)
1714 #if _MSC_VER == 1911
1715 #pragma optimize("", on)
1716 #endif
1717 #endif
1718 
1719 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
1720   VisitCallExpr(S);
1721 }
1722 
1723 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
1724   VisitCallExpr(S);
1725 }
1726 
1727 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
1728   VisitExpr(S);
1729 }
1730 
1731 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
1732   VisitExplicitCastExpr(S);
1733 }
1734 
1735 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
1736   VisitCXXNamedCastExpr(S);
1737 }
1738 
1739 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
1740   VisitCXXNamedCastExpr(S);
1741 }
1742 
1743 void
1744 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
1745   VisitCXXNamedCastExpr(S);
1746 }
1747 
1748 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
1749   VisitCXXNamedCastExpr(S);
1750 }
1751 
1752 void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
1753   VisitExpr(S);
1754   VisitType(S->getTypeInfoAsWritten()->getType());
1755 }
1756 
1757 void StmtProfiler::VisitCXXAddrspaceCastExpr(const CXXAddrspaceCastExpr *S) {
1758   VisitCXXNamedCastExpr(S);
1759 }
1760 
1761 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1762   VisitCallExpr(S);
1763 }
1764 
1765 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
1766   VisitExpr(S);
1767   ID.AddBoolean(S->getValue());
1768 }
1769 
1770 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
1771   VisitExpr(S);
1772 }
1773 
1774 void StmtProfiler::VisitCXXStdInitializerListExpr(
1775     const CXXStdInitializerListExpr *S) {
1776   VisitExpr(S);
1777 }
1778 
1779 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
1780   VisitExpr(S);
1781   if (S->isTypeOperand())
1782     VisitType(S->getTypeOperandSourceInfo()->getType());
1783 }
1784 
1785 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
1786   VisitExpr(S);
1787   if (S->isTypeOperand())
1788     VisitType(S->getTypeOperandSourceInfo()->getType());
1789 }
1790 
1791 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1792   VisitExpr(S);
1793   VisitDecl(S->getPropertyDecl());
1794 }
1795 
1796 void StmtProfiler::VisitMSPropertySubscriptExpr(
1797     const MSPropertySubscriptExpr *S) {
1798   VisitExpr(S);
1799 }
1800 
1801 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
1802   VisitExpr(S);
1803   ID.AddBoolean(S->isImplicit());
1804 }
1805 
1806 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
1807   VisitExpr(S);
1808 }
1809 
1810 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
1811   VisitExpr(S);
1812   VisitDecl(S->getParam());
1813 }
1814 
1815 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1816   VisitExpr(S);
1817   VisitDecl(S->getField());
1818 }
1819 
1820 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
1821   VisitExpr(S);
1822   VisitDecl(
1823          const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1824 }
1825 
1826 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
1827   VisitExpr(S);
1828   VisitDecl(S->getConstructor());
1829   ID.AddBoolean(S->isElidable());
1830 }
1831 
1832 void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1833     const CXXInheritedCtorInitExpr *S) {
1834   VisitExpr(S);
1835   VisitDecl(S->getConstructor());
1836 }
1837 
1838 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
1839   VisitExplicitCastExpr(S);
1840 }
1841 
1842 void
1843 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
1844   VisitCXXConstructExpr(S);
1845 }
1846 
1847 void
1848 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1849   VisitExpr(S);
1850   for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1851                                  CEnd = S->explicit_capture_end();
1852        C != CEnd; ++C) {
1853     if (C->capturesVLAType())
1854       continue;
1855 
1856     ID.AddInteger(C->getCaptureKind());
1857     switch (C->getCaptureKind()) {
1858     case LCK_StarThis:
1859     case LCK_This:
1860       break;
1861     case LCK_ByRef:
1862     case LCK_ByCopy:
1863       VisitDecl(C->getCapturedVar());
1864       ID.AddBoolean(C->isPackExpansion());
1865       break;
1866     case LCK_VLAType:
1867       llvm_unreachable("VLA type in explicit captures.");
1868     }
1869   }
1870   // Note: If we actually needed to be able to match lambda
1871   // expressions, we would have to consider parameters and return type
1872   // here, among other things.
1873   VisitStmt(S->getBody());
1874 }
1875 
1876 void
1877 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
1878   VisitExpr(S);
1879 }
1880 
1881 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
1882   VisitExpr(S);
1883   ID.AddBoolean(S->isGlobalDelete());
1884   ID.AddBoolean(S->isArrayForm());
1885   VisitDecl(S->getOperatorDelete());
1886 }
1887 
1888 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
1889   VisitExpr(S);
1890   VisitType(S->getAllocatedType());
1891   VisitDecl(S->getOperatorNew());
1892   VisitDecl(S->getOperatorDelete());
1893   ID.AddBoolean(S->isArray());
1894   ID.AddInteger(S->getNumPlacementArgs());
1895   ID.AddBoolean(S->isGlobalNew());
1896   ID.AddBoolean(S->isParenTypeId());
1897   ID.AddInteger(S->getInitializationStyle());
1898 }
1899 
1900 void
1901 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
1902   VisitExpr(S);
1903   ID.AddBoolean(S->isArrow());
1904   VisitNestedNameSpecifier(S->getQualifier());
1905   ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
1906   if (S->getScopeTypeInfo())
1907     VisitType(S->getScopeTypeInfo()->getType());
1908   ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
1909   if (S->getDestroyedTypeInfo())
1910     VisitType(S->getDestroyedType());
1911   else
1912     VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
1913 }
1914 
1915 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
1916   VisitExpr(S);
1917   VisitNestedNameSpecifier(S->getQualifier());
1918   VisitName(S->getName(), /*TreatAsDecl*/ true);
1919   ID.AddBoolean(S->hasExplicitTemplateArgs());
1920   if (S->hasExplicitTemplateArgs())
1921     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1922 }
1923 
1924 void
1925 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
1926   VisitOverloadExpr(S);
1927 }
1928 
1929 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1930   VisitExpr(S);
1931   ID.AddInteger(S->getTrait());
1932   ID.AddInteger(S->getNumArgs());
1933   for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1934     VisitType(S->getArg(I)->getType());
1935 }
1936 
1937 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
1938   VisitExpr(S);
1939   ID.AddInteger(S->getTrait());
1940   VisitType(S->getQueriedType());
1941 }
1942 
1943 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
1944   VisitExpr(S);
1945   ID.AddInteger(S->getTrait());
1946   VisitExpr(S->getQueriedExpression());
1947 }
1948 
1949 void StmtProfiler::VisitDependentScopeDeclRefExpr(
1950     const DependentScopeDeclRefExpr *S) {
1951   VisitExpr(S);
1952   VisitName(S->getDeclName());
1953   VisitNestedNameSpecifier(S->getQualifier());
1954   ID.AddBoolean(S->hasExplicitTemplateArgs());
1955   if (S->hasExplicitTemplateArgs())
1956     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1957 }
1958 
1959 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
1960   VisitExpr(S);
1961 }
1962 
1963 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1964     const CXXUnresolvedConstructExpr *S) {
1965   VisitExpr(S);
1966   VisitType(S->getTypeAsWritten());
1967   ID.AddInteger(S->isListInitialization());
1968 }
1969 
1970 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1971     const CXXDependentScopeMemberExpr *S) {
1972   ID.AddBoolean(S->isImplicitAccess());
1973   if (!S->isImplicitAccess()) {
1974     VisitExpr(S);
1975     ID.AddBoolean(S->isArrow());
1976   }
1977   VisitNestedNameSpecifier(S->getQualifier());
1978   VisitName(S->getMember());
1979   ID.AddBoolean(S->hasExplicitTemplateArgs());
1980   if (S->hasExplicitTemplateArgs())
1981     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1982 }
1983 
1984 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
1985   ID.AddBoolean(S->isImplicitAccess());
1986   if (!S->isImplicitAccess()) {
1987     VisitExpr(S);
1988     ID.AddBoolean(S->isArrow());
1989   }
1990   VisitNestedNameSpecifier(S->getQualifier());
1991   VisitName(S->getMemberName());
1992   ID.AddBoolean(S->hasExplicitTemplateArgs());
1993   if (S->hasExplicitTemplateArgs())
1994     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1995 }
1996 
1997 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
1998   VisitExpr(S);
1999 }
2000 
2001 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
2002   VisitExpr(S);
2003 }
2004 
2005 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
2006   VisitExpr(S);
2007   VisitDecl(S->getPack());
2008   if (S->isPartiallySubstituted()) {
2009     auto Args = S->getPartialArguments();
2010     ID.AddInteger(Args.size());
2011     for (const auto &TA : Args)
2012       VisitTemplateArgument(TA);
2013   } else {
2014     ID.AddInteger(0);
2015   }
2016 }
2017 
2018 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
2019     const SubstNonTypeTemplateParmPackExpr *S) {
2020   VisitExpr(S);
2021   VisitDecl(S->getParameterPack());
2022   VisitTemplateArgument(S->getArgumentPack());
2023 }
2024 
2025 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
2026     const SubstNonTypeTemplateParmExpr *E) {
2027   // Profile exactly as the replacement expression.
2028   Visit(E->getReplacement());
2029 }
2030 
2031 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
2032   VisitExpr(S);
2033   VisitDecl(S->getParameterPack());
2034   ID.AddInteger(S->getNumExpansions());
2035   for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
2036     VisitDecl(*I);
2037 }
2038 
2039 void StmtProfiler::VisitMaterializeTemporaryExpr(
2040                                            const MaterializeTemporaryExpr *S) {
2041   VisitExpr(S);
2042 }
2043 
2044 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
2045   VisitExpr(S);
2046   ID.AddInteger(S->getOperator());
2047 }
2048 
2049 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
2050   VisitStmt(S);
2051 }
2052 
2053 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
2054   VisitStmt(S);
2055 }
2056 
2057 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
2058   VisitExpr(S);
2059 }
2060 
2061 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
2062   VisitExpr(S);
2063 }
2064 
2065 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
2066   VisitExpr(S);
2067 }
2068 
2069 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
2070   VisitExpr(E);
2071 }
2072 
2073 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
2074   VisitExpr(E);
2075 }
2076 
2077 void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
2078   VisitExpr(E);
2079 }
2080 
2081 void StmtProfiler::VisitRecoveryExpr(const RecoveryExpr *E) { VisitExpr(E); }
2082 
2083 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
2084   VisitExpr(S);
2085 }
2086 
2087 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
2088   VisitExpr(E);
2089 }
2090 
2091 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
2092   VisitExpr(E);
2093 }
2094 
2095 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
2096   VisitExpr(E);
2097 }
2098 
2099 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
2100   VisitExpr(S);
2101   VisitType(S->getEncodedType());
2102 }
2103 
2104 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
2105   VisitExpr(S);
2106   VisitName(S->getSelector());
2107 }
2108 
2109 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
2110   VisitExpr(S);
2111   VisitDecl(S->getProtocol());
2112 }
2113 
2114 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
2115   VisitExpr(S);
2116   VisitDecl(S->getDecl());
2117   ID.AddBoolean(S->isArrow());
2118   ID.AddBoolean(S->isFreeIvar());
2119 }
2120 
2121 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
2122   VisitExpr(S);
2123   if (S->isImplicitProperty()) {
2124     VisitDecl(S->getImplicitPropertyGetter());
2125     VisitDecl(S->getImplicitPropertySetter());
2126   } else {
2127     VisitDecl(S->getExplicitProperty());
2128   }
2129   if (S->isSuperReceiver()) {
2130     ID.AddBoolean(S->isSuperReceiver());
2131     VisitType(S->getSuperReceiverType());
2132   }
2133 }
2134 
2135 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
2136   VisitExpr(S);
2137   VisitDecl(S->getAtIndexMethodDecl());
2138   VisitDecl(S->setAtIndexMethodDecl());
2139 }
2140 
2141 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
2142   VisitExpr(S);
2143   VisitName(S->getSelector());
2144   VisitDecl(S->getMethodDecl());
2145 }
2146 
2147 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
2148   VisitExpr(S);
2149   ID.AddBoolean(S->isArrow());
2150 }
2151 
2152 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
2153   VisitExpr(S);
2154   ID.AddBoolean(S->getValue());
2155 }
2156 
2157 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
2158     const ObjCIndirectCopyRestoreExpr *S) {
2159   VisitExpr(S);
2160   ID.AddBoolean(S->shouldCopy());
2161 }
2162 
2163 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
2164   VisitExplicitCastExpr(S);
2165   ID.AddBoolean(S->getBridgeKind());
2166 }
2167 
2168 void StmtProfiler::VisitObjCAvailabilityCheckExpr(
2169     const ObjCAvailabilityCheckExpr *S) {
2170   VisitExpr(S);
2171 }
2172 
2173 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
2174                                           unsigned NumArgs) {
2175   ID.AddInteger(NumArgs);
2176   for (unsigned I = 0; I != NumArgs; ++I)
2177     VisitTemplateArgument(Args[I].getArgument());
2178 }
2179 
2180 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
2181   // Mostly repetitive with TemplateArgument::Profile!
2182   ID.AddInteger(Arg.getKind());
2183   switch (Arg.getKind()) {
2184   case TemplateArgument::Null:
2185     break;
2186 
2187   case TemplateArgument::Type:
2188     VisitType(Arg.getAsType());
2189     break;
2190 
2191   case TemplateArgument::Template:
2192   case TemplateArgument::TemplateExpansion:
2193     VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
2194     break;
2195 
2196   case TemplateArgument::Declaration:
2197     VisitType(Arg.getParamTypeForDecl());
2198     // FIXME: Do we need to recursively decompose template parameter objects?
2199     VisitDecl(Arg.getAsDecl());
2200     break;
2201 
2202   case TemplateArgument::NullPtr:
2203     VisitType(Arg.getNullPtrType());
2204     break;
2205 
2206   case TemplateArgument::Integral:
2207     VisitType(Arg.getIntegralType());
2208     Arg.getAsIntegral().Profile(ID);
2209     break;
2210 
2211   case TemplateArgument::Expression:
2212     Visit(Arg.getAsExpr());
2213     break;
2214 
2215   case TemplateArgument::Pack:
2216     for (const auto &P : Arg.pack_elements())
2217       VisitTemplateArgument(P);
2218     break;
2219   }
2220 }
2221 
2222 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2223                    bool Canonical) const {
2224   StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2225   Profiler.Visit(this);
2226 }
2227 
2228 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2229                           class ODRHash &Hash) const {
2230   StmtProfilerWithoutPointers Profiler(ID, Hash);
2231   Profiler.Visit(this);
2232 }
2233