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