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