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