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