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