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