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