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