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::VisitOMPCollapseClause(const OMPCollapseClause *C) {
461   if (C->getNumForLoops())
462     Profiler->VisitStmt(C->getNumForLoops());
463 }
464 
465 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
466 
467 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
468 
469 void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
470     const OMPUnifiedAddressClause *C) {}
471 
472 void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
473     const OMPUnifiedSharedMemoryClause *C) {}
474 
475 void OMPClauseProfiler::VisitOMPReverseOffloadClause(
476     const OMPReverseOffloadClause *C) {}
477 
478 void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
479     const OMPDynamicAllocatorsClause *C) {}
480 
481 void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
482     const OMPAtomicDefaultMemOrderClause *C) {}
483 
484 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
485   VistOMPClauseWithPreInit(C);
486   if (auto *S = C->getChunkSize())
487     Profiler->VisitStmt(S);
488 }
489 
490 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
491   if (auto *Num = C->getNumForLoops())
492     Profiler->VisitStmt(Num);
493 }
494 
495 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
496 
497 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
498 
499 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
500 
501 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
502 
503 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
504 
505 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
506 
507 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
508 
509 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
510 
511 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
512 
513 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
514 
515 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
516 
517 template<typename T>
518 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
519   for (auto *E : Node->varlists()) {
520     if (E)
521       Profiler->VisitStmt(E);
522   }
523 }
524 
525 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
526   VisitOMPClauseList(C);
527   for (auto *E : C->private_copies()) {
528     if (E)
529       Profiler->VisitStmt(E);
530   }
531 }
532 void
533 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
534   VisitOMPClauseList(C);
535   VistOMPClauseWithPreInit(C);
536   for (auto *E : C->private_copies()) {
537     if (E)
538       Profiler->VisitStmt(E);
539   }
540   for (auto *E : C->inits()) {
541     if (E)
542       Profiler->VisitStmt(E);
543   }
544 }
545 void
546 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
547   VisitOMPClauseList(C);
548   VistOMPClauseWithPostUpdate(C);
549   for (auto *E : C->source_exprs()) {
550     if (E)
551       Profiler->VisitStmt(E);
552   }
553   for (auto *E : C->destination_exprs()) {
554     if (E)
555       Profiler->VisitStmt(E);
556   }
557   for (auto *E : C->assignment_ops()) {
558     if (E)
559       Profiler->VisitStmt(E);
560   }
561 }
562 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
563   VisitOMPClauseList(C);
564 }
565 void OMPClauseProfiler::VisitOMPReductionClause(
566                                          const OMPReductionClause *C) {
567   Profiler->VisitNestedNameSpecifier(
568       C->getQualifierLoc().getNestedNameSpecifier());
569   Profiler->VisitName(C->getNameInfo().getName());
570   VisitOMPClauseList(C);
571   VistOMPClauseWithPostUpdate(C);
572   for (auto *E : C->privates()) {
573     if (E)
574       Profiler->VisitStmt(E);
575   }
576   for (auto *E : C->lhs_exprs()) {
577     if (E)
578       Profiler->VisitStmt(E);
579   }
580   for (auto *E : C->rhs_exprs()) {
581     if (E)
582       Profiler->VisitStmt(E);
583   }
584   for (auto *E : C->reduction_ops()) {
585     if (E)
586       Profiler->VisitStmt(E);
587   }
588 }
589 void OMPClauseProfiler::VisitOMPTaskReductionClause(
590     const OMPTaskReductionClause *C) {
591   Profiler->VisitNestedNameSpecifier(
592       C->getQualifierLoc().getNestedNameSpecifier());
593   Profiler->VisitName(C->getNameInfo().getName());
594   VisitOMPClauseList(C);
595   VistOMPClauseWithPostUpdate(C);
596   for (auto *E : C->privates()) {
597     if (E)
598       Profiler->VisitStmt(E);
599   }
600   for (auto *E : C->lhs_exprs()) {
601     if (E)
602       Profiler->VisitStmt(E);
603   }
604   for (auto *E : C->rhs_exprs()) {
605     if (E)
606       Profiler->VisitStmt(E);
607   }
608   for (auto *E : C->reduction_ops()) {
609     if (E)
610       Profiler->VisitStmt(E);
611   }
612 }
613 void OMPClauseProfiler::VisitOMPInReductionClause(
614     const OMPInReductionClause *C) {
615   Profiler->VisitNestedNameSpecifier(
616       C->getQualifierLoc().getNestedNameSpecifier());
617   Profiler->VisitName(C->getNameInfo().getName());
618   VisitOMPClauseList(C);
619   VistOMPClauseWithPostUpdate(C);
620   for (auto *E : C->privates()) {
621     if (E)
622       Profiler->VisitStmt(E);
623   }
624   for (auto *E : C->lhs_exprs()) {
625     if (E)
626       Profiler->VisitStmt(E);
627   }
628   for (auto *E : C->rhs_exprs()) {
629     if (E)
630       Profiler->VisitStmt(E);
631   }
632   for (auto *E : C->reduction_ops()) {
633     if (E)
634       Profiler->VisitStmt(E);
635   }
636   for (auto *E : C->taskgroup_descriptors()) {
637     if (E)
638       Profiler->VisitStmt(E);
639   }
640 }
641 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
642   VisitOMPClauseList(C);
643   VistOMPClauseWithPostUpdate(C);
644   for (auto *E : C->privates()) {
645     if (E)
646       Profiler->VisitStmt(E);
647   }
648   for (auto *E : C->inits()) {
649     if (E)
650       Profiler->VisitStmt(E);
651   }
652   for (auto *E : C->updates()) {
653     if (E)
654       Profiler->VisitStmt(E);
655   }
656   for (auto *E : C->finals()) {
657     if (E)
658       Profiler->VisitStmt(E);
659   }
660   if (C->getStep())
661     Profiler->VisitStmt(C->getStep());
662   if (C->getCalcStep())
663     Profiler->VisitStmt(C->getCalcStep());
664 }
665 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
666   VisitOMPClauseList(C);
667   if (C->getAlignment())
668     Profiler->VisitStmt(C->getAlignment());
669 }
670 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
671   VisitOMPClauseList(C);
672   for (auto *E : C->source_exprs()) {
673     if (E)
674       Profiler->VisitStmt(E);
675   }
676   for (auto *E : C->destination_exprs()) {
677     if (E)
678       Profiler->VisitStmt(E);
679   }
680   for (auto *E : C->assignment_ops()) {
681     if (E)
682       Profiler->VisitStmt(E);
683   }
684 }
685 void
686 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
687   VisitOMPClauseList(C);
688   for (auto *E : C->source_exprs()) {
689     if (E)
690       Profiler->VisitStmt(E);
691   }
692   for (auto *E : C->destination_exprs()) {
693     if (E)
694       Profiler->VisitStmt(E);
695   }
696   for (auto *E : C->assignment_ops()) {
697     if (E)
698       Profiler->VisitStmt(E);
699   }
700 }
701 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
702   VisitOMPClauseList(C);
703 }
704 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
705   VisitOMPClauseList(C);
706 }
707 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
708   if (C->getDevice())
709     Profiler->VisitStmt(C->getDevice());
710 }
711 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
712   VisitOMPClauseList(C);
713 }
714 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
715   VistOMPClauseWithPreInit(C);
716   if (C->getNumTeams())
717     Profiler->VisitStmt(C->getNumTeams());
718 }
719 void OMPClauseProfiler::VisitOMPThreadLimitClause(
720     const OMPThreadLimitClause *C) {
721   VistOMPClauseWithPreInit(C);
722   if (C->getThreadLimit())
723     Profiler->VisitStmt(C->getThreadLimit());
724 }
725 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
726   if (C->getPriority())
727     Profiler->VisitStmt(C->getPriority());
728 }
729 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
730   if (C->getGrainsize())
731     Profiler->VisitStmt(C->getGrainsize());
732 }
733 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
734   if (C->getNumTasks())
735     Profiler->VisitStmt(C->getNumTasks());
736 }
737 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
738   if (C->getHint())
739     Profiler->VisitStmt(C->getHint());
740 }
741 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
742   VisitOMPClauseList(C);
743 }
744 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
745   VisitOMPClauseList(C);
746 }
747 void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
748     const OMPUseDevicePtrClause *C) {
749   VisitOMPClauseList(C);
750 }
751 void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
752     const OMPIsDevicePtrClause *C) {
753   VisitOMPClauseList(C);
754 }
755 }
756 
757 void
758 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
759   VisitStmt(S);
760   OMPClauseProfiler P(this);
761   ArrayRef<OMPClause *> Clauses = S->clauses();
762   for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
763        I != E; ++I)
764     if (*I)
765       P.Visit(*I);
766 }
767 
768 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
769   VisitOMPExecutableDirective(S);
770 }
771 
772 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
773   VisitOMPExecutableDirective(S);
774 }
775 
776 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
777   VisitOMPLoopDirective(S);
778 }
779 
780 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
781   VisitOMPLoopDirective(S);
782 }
783 
784 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
785   VisitOMPLoopDirective(S);
786 }
787 
788 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
789   VisitOMPExecutableDirective(S);
790 }
791 
792 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
793   VisitOMPExecutableDirective(S);
794 }
795 
796 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
797   VisitOMPExecutableDirective(S);
798 }
799 
800 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
801   VisitOMPExecutableDirective(S);
802 }
803 
804 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
805   VisitOMPExecutableDirective(S);
806   VisitName(S->getDirectiveName().getName());
807 }
808 
809 void
810 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
811   VisitOMPLoopDirective(S);
812 }
813 
814 void StmtProfiler::VisitOMPParallelForSimdDirective(
815     const OMPParallelForSimdDirective *S) {
816   VisitOMPLoopDirective(S);
817 }
818 
819 void StmtProfiler::VisitOMPParallelSectionsDirective(
820     const OMPParallelSectionsDirective *S) {
821   VisitOMPExecutableDirective(S);
822 }
823 
824 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
825   VisitOMPExecutableDirective(S);
826 }
827 
828 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
829   VisitOMPExecutableDirective(S);
830 }
831 
832 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
833   VisitOMPExecutableDirective(S);
834 }
835 
836 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
837   VisitOMPExecutableDirective(S);
838 }
839 
840 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
841   VisitOMPExecutableDirective(S);
842   if (const Expr *E = S->getReductionRef())
843     VisitStmt(E);
844 }
845 
846 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
847   VisitOMPExecutableDirective(S);
848 }
849 
850 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
851   VisitOMPExecutableDirective(S);
852 }
853 
854 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
855   VisitOMPExecutableDirective(S);
856 }
857 
858 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
859   VisitOMPExecutableDirective(S);
860 }
861 
862 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
863   VisitOMPExecutableDirective(S);
864 }
865 
866 void StmtProfiler::VisitOMPTargetEnterDataDirective(
867     const OMPTargetEnterDataDirective *S) {
868   VisitOMPExecutableDirective(S);
869 }
870 
871 void StmtProfiler::VisitOMPTargetExitDataDirective(
872     const OMPTargetExitDataDirective *S) {
873   VisitOMPExecutableDirective(S);
874 }
875 
876 void StmtProfiler::VisitOMPTargetParallelDirective(
877     const OMPTargetParallelDirective *S) {
878   VisitOMPExecutableDirective(S);
879 }
880 
881 void StmtProfiler::VisitOMPTargetParallelForDirective(
882     const OMPTargetParallelForDirective *S) {
883   VisitOMPExecutableDirective(S);
884 }
885 
886 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
887   VisitOMPExecutableDirective(S);
888 }
889 
890 void StmtProfiler::VisitOMPCancellationPointDirective(
891     const OMPCancellationPointDirective *S) {
892   VisitOMPExecutableDirective(S);
893 }
894 
895 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
896   VisitOMPExecutableDirective(S);
897 }
898 
899 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
900   VisitOMPLoopDirective(S);
901 }
902 
903 void StmtProfiler::VisitOMPTaskLoopSimdDirective(
904     const OMPTaskLoopSimdDirective *S) {
905   VisitOMPLoopDirective(S);
906 }
907 
908 void StmtProfiler::VisitOMPDistributeDirective(
909     const OMPDistributeDirective *S) {
910   VisitOMPLoopDirective(S);
911 }
912 
913 void OMPClauseProfiler::VisitOMPDistScheduleClause(
914     const OMPDistScheduleClause *C) {
915   VistOMPClauseWithPreInit(C);
916   if (auto *S = C->getChunkSize())
917     Profiler->VisitStmt(S);
918 }
919 
920 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
921 
922 void StmtProfiler::VisitOMPTargetUpdateDirective(
923     const OMPTargetUpdateDirective *S) {
924   VisitOMPExecutableDirective(S);
925 }
926 
927 void StmtProfiler::VisitOMPDistributeParallelForDirective(
928     const OMPDistributeParallelForDirective *S) {
929   VisitOMPLoopDirective(S);
930 }
931 
932 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
933     const OMPDistributeParallelForSimdDirective *S) {
934   VisitOMPLoopDirective(S);
935 }
936 
937 void StmtProfiler::VisitOMPDistributeSimdDirective(
938     const OMPDistributeSimdDirective *S) {
939   VisitOMPLoopDirective(S);
940 }
941 
942 void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
943     const OMPTargetParallelForSimdDirective *S) {
944   VisitOMPLoopDirective(S);
945 }
946 
947 void StmtProfiler::VisitOMPTargetSimdDirective(
948     const OMPTargetSimdDirective *S) {
949   VisitOMPLoopDirective(S);
950 }
951 
952 void StmtProfiler::VisitOMPTeamsDistributeDirective(
953     const OMPTeamsDistributeDirective *S) {
954   VisitOMPLoopDirective(S);
955 }
956 
957 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
958     const OMPTeamsDistributeSimdDirective *S) {
959   VisitOMPLoopDirective(S);
960 }
961 
962 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
963     const OMPTeamsDistributeParallelForSimdDirective *S) {
964   VisitOMPLoopDirective(S);
965 }
966 
967 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
968     const OMPTeamsDistributeParallelForDirective *S) {
969   VisitOMPLoopDirective(S);
970 }
971 
972 void StmtProfiler::VisitOMPTargetTeamsDirective(
973     const OMPTargetTeamsDirective *S) {
974   VisitOMPExecutableDirective(S);
975 }
976 
977 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
978     const OMPTargetTeamsDistributeDirective *S) {
979   VisitOMPLoopDirective(S);
980 }
981 
982 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
983     const OMPTargetTeamsDistributeParallelForDirective *S) {
984   VisitOMPLoopDirective(S);
985 }
986 
987 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
988     const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
989   VisitOMPLoopDirective(S);
990 }
991 
992 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
993     const OMPTargetTeamsDistributeSimdDirective *S) {
994   VisitOMPLoopDirective(S);
995 }
996 
997 void StmtProfiler::VisitExpr(const Expr *S) {
998   VisitStmt(S);
999 }
1000 
1001 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1002   VisitExpr(S);
1003 }
1004 
1005 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
1006   VisitExpr(S);
1007   if (!Canonical)
1008     VisitNestedNameSpecifier(S->getQualifier());
1009   VisitDecl(S->getDecl());
1010   if (!Canonical) {
1011     ID.AddBoolean(S->hasExplicitTemplateArgs());
1012     if (S->hasExplicitTemplateArgs())
1013       VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1014   }
1015 }
1016 
1017 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
1018   VisitExpr(S);
1019   ID.AddInteger(S->getIdentKind());
1020 }
1021 
1022 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
1023   VisitExpr(S);
1024   S->getValue().Profile(ID);
1025   ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1026 }
1027 
1028 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1029   VisitExpr(S);
1030   S->getValue().Profile(ID);
1031   ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1032 }
1033 
1034 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
1035   VisitExpr(S);
1036   ID.AddInteger(S->getKind());
1037   ID.AddInteger(S->getValue());
1038 }
1039 
1040 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
1041   VisitExpr(S);
1042   S->getValue().Profile(ID);
1043   ID.AddBoolean(S->isExact());
1044   ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1045 }
1046 
1047 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
1048   VisitExpr(S);
1049 }
1050 
1051 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
1052   VisitExpr(S);
1053   ID.AddString(S->getBytes());
1054   ID.AddInteger(S->getKind());
1055 }
1056 
1057 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
1058   VisitExpr(S);
1059 }
1060 
1061 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
1062   VisitExpr(S);
1063 }
1064 
1065 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
1066   VisitExpr(S);
1067   ID.AddInteger(S->getOpcode());
1068 }
1069 
1070 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
1071   VisitType(S->getTypeSourceInfo()->getType());
1072   unsigned n = S->getNumComponents();
1073   for (unsigned i = 0; i < n; ++i) {
1074     const OffsetOfNode &ON = S->getComponent(i);
1075     ID.AddInteger(ON.getKind());
1076     switch (ON.getKind()) {
1077     case OffsetOfNode::Array:
1078       // Expressions handled below.
1079       break;
1080 
1081     case OffsetOfNode::Field:
1082       VisitDecl(ON.getField());
1083       break;
1084 
1085     case OffsetOfNode::Identifier:
1086       VisitIdentifierInfo(ON.getFieldName());
1087       break;
1088 
1089     case OffsetOfNode::Base:
1090       // These nodes are implicit, and therefore don't need profiling.
1091       break;
1092     }
1093   }
1094 
1095   VisitExpr(S);
1096 }
1097 
1098 void
1099 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
1100   VisitExpr(S);
1101   ID.AddInteger(S->getKind());
1102   if (S->isArgumentType())
1103     VisitType(S->getArgumentType());
1104 }
1105 
1106 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
1107   VisitExpr(S);
1108 }
1109 
1110 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1111   VisitExpr(S);
1112 }
1113 
1114 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
1115   VisitExpr(S);
1116 }
1117 
1118 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
1119   VisitExpr(S);
1120   VisitDecl(S->getMemberDecl());
1121   if (!Canonical)
1122     VisitNestedNameSpecifier(S->getQualifier());
1123   ID.AddBoolean(S->isArrow());
1124 }
1125 
1126 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
1127   VisitExpr(S);
1128   ID.AddBoolean(S->isFileScope());
1129 }
1130 
1131 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
1132   VisitExpr(S);
1133 }
1134 
1135 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
1136   VisitCastExpr(S);
1137   ID.AddInteger(S->getValueKind());
1138 }
1139 
1140 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
1141   VisitCastExpr(S);
1142   VisitType(S->getTypeAsWritten());
1143 }
1144 
1145 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
1146   VisitExplicitCastExpr(S);
1147 }
1148 
1149 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
1150   VisitExpr(S);
1151   ID.AddInteger(S->getOpcode());
1152 }
1153 
1154 void
1155 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
1156   VisitBinaryOperator(S);
1157 }
1158 
1159 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
1160   VisitExpr(S);
1161 }
1162 
1163 void StmtProfiler::VisitBinaryConditionalOperator(
1164     const BinaryConditionalOperator *S) {
1165   VisitExpr(S);
1166 }
1167 
1168 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
1169   VisitExpr(S);
1170   VisitDecl(S->getLabel());
1171 }
1172 
1173 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
1174   VisitExpr(S);
1175 }
1176 
1177 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
1178   VisitExpr(S);
1179 }
1180 
1181 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1182   VisitExpr(S);
1183 }
1184 
1185 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
1186   VisitExpr(S);
1187 }
1188 
1189 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
1190   VisitExpr(S);
1191 }
1192 
1193 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
1194   VisitExpr(S);
1195 }
1196 
1197 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
1198   if (S->getSyntacticForm()) {
1199     VisitInitListExpr(S->getSyntacticForm());
1200     return;
1201   }
1202 
1203   VisitExpr(S);
1204 }
1205 
1206 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
1207   VisitExpr(S);
1208   ID.AddBoolean(S->usesGNUSyntax());
1209   for (const DesignatedInitExpr::Designator &D : S->designators()) {
1210     if (D.isFieldDesignator()) {
1211       ID.AddInteger(0);
1212       VisitName(D.getFieldName());
1213       continue;
1214     }
1215 
1216     if (D.isArrayDesignator()) {
1217       ID.AddInteger(1);
1218     } else {
1219       assert(D.isArrayRangeDesignator());
1220       ID.AddInteger(2);
1221     }
1222     ID.AddInteger(D.getFirstExprIndex());
1223   }
1224 }
1225 
1226 // Seems that if VisitInitListExpr() only works on the syntactic form of an
1227 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1228 void StmtProfiler::VisitDesignatedInitUpdateExpr(
1229     const DesignatedInitUpdateExpr *S) {
1230   llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1231                    "initializer");
1232 }
1233 
1234 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1235   VisitExpr(S);
1236 }
1237 
1238 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1239   VisitExpr(S);
1240 }
1241 
1242 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1243   llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1244 }
1245 
1246 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
1247   VisitExpr(S);
1248 }
1249 
1250 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
1251   VisitExpr(S);
1252   VisitName(&S->getAccessor());
1253 }
1254 
1255 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
1256   VisitExpr(S);
1257   VisitDecl(S->getBlockDecl());
1258 }
1259 
1260 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
1261   VisitExpr(S);
1262   for (const GenericSelectionExpr::ConstAssociation &Assoc :
1263        S->associations()) {
1264     QualType T = Assoc.getType();
1265     if (T.isNull())
1266       ID.AddPointer(nullptr);
1267     else
1268       VisitType(T);
1269     VisitExpr(Assoc.getAssociationExpr());
1270   }
1271 }
1272 
1273 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1274   VisitExpr(S);
1275   for (PseudoObjectExpr::const_semantics_iterator
1276          i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1277     // Normally, we would not profile the source expressions of OVEs.
1278     if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1279       Visit(OVE->getSourceExpr());
1280 }
1281 
1282 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1283   VisitExpr(S);
1284   ID.AddInteger(S->getOp());
1285 }
1286 
1287 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
1288                                           UnaryOperatorKind &UnaryOp,
1289                                           BinaryOperatorKind &BinaryOp) {
1290   switch (S->getOperator()) {
1291   case OO_None:
1292   case OO_New:
1293   case OO_Delete:
1294   case OO_Array_New:
1295   case OO_Array_Delete:
1296   case OO_Arrow:
1297   case OO_Call:
1298   case OO_Conditional:
1299   case NUM_OVERLOADED_OPERATORS:
1300     llvm_unreachable("Invalid operator call kind");
1301 
1302   case OO_Plus:
1303     if (S->getNumArgs() == 1) {
1304       UnaryOp = UO_Plus;
1305       return Stmt::UnaryOperatorClass;
1306     }
1307 
1308     BinaryOp = BO_Add;
1309     return Stmt::BinaryOperatorClass;
1310 
1311   case OO_Minus:
1312     if (S->getNumArgs() == 1) {
1313       UnaryOp = UO_Minus;
1314       return Stmt::UnaryOperatorClass;
1315     }
1316 
1317     BinaryOp = BO_Sub;
1318     return Stmt::BinaryOperatorClass;
1319 
1320   case OO_Star:
1321     if (S->getNumArgs() == 1) {
1322       UnaryOp = UO_Deref;
1323       return Stmt::UnaryOperatorClass;
1324     }
1325 
1326     BinaryOp = BO_Mul;
1327     return Stmt::BinaryOperatorClass;
1328 
1329   case OO_Slash:
1330     BinaryOp = BO_Div;
1331     return Stmt::BinaryOperatorClass;
1332 
1333   case OO_Percent:
1334     BinaryOp = BO_Rem;
1335     return Stmt::BinaryOperatorClass;
1336 
1337   case OO_Caret:
1338     BinaryOp = BO_Xor;
1339     return Stmt::BinaryOperatorClass;
1340 
1341   case OO_Amp:
1342     if (S->getNumArgs() == 1) {
1343       UnaryOp = UO_AddrOf;
1344       return Stmt::UnaryOperatorClass;
1345     }
1346 
1347     BinaryOp = BO_And;
1348     return Stmt::BinaryOperatorClass;
1349 
1350   case OO_Pipe:
1351     BinaryOp = BO_Or;
1352     return Stmt::BinaryOperatorClass;
1353 
1354   case OO_Tilde:
1355     UnaryOp = UO_Not;
1356     return Stmt::UnaryOperatorClass;
1357 
1358   case OO_Exclaim:
1359     UnaryOp = UO_LNot;
1360     return Stmt::UnaryOperatorClass;
1361 
1362   case OO_Equal:
1363     BinaryOp = BO_Assign;
1364     return Stmt::BinaryOperatorClass;
1365 
1366   case OO_Less:
1367     BinaryOp = BO_LT;
1368     return Stmt::BinaryOperatorClass;
1369 
1370   case OO_Greater:
1371     BinaryOp = BO_GT;
1372     return Stmt::BinaryOperatorClass;
1373 
1374   case OO_PlusEqual:
1375     BinaryOp = BO_AddAssign;
1376     return Stmt::CompoundAssignOperatorClass;
1377 
1378   case OO_MinusEqual:
1379     BinaryOp = BO_SubAssign;
1380     return Stmt::CompoundAssignOperatorClass;
1381 
1382   case OO_StarEqual:
1383     BinaryOp = BO_MulAssign;
1384     return Stmt::CompoundAssignOperatorClass;
1385 
1386   case OO_SlashEqual:
1387     BinaryOp = BO_DivAssign;
1388     return Stmt::CompoundAssignOperatorClass;
1389 
1390   case OO_PercentEqual:
1391     BinaryOp = BO_RemAssign;
1392     return Stmt::CompoundAssignOperatorClass;
1393 
1394   case OO_CaretEqual:
1395     BinaryOp = BO_XorAssign;
1396     return Stmt::CompoundAssignOperatorClass;
1397 
1398   case OO_AmpEqual:
1399     BinaryOp = BO_AndAssign;
1400     return Stmt::CompoundAssignOperatorClass;
1401 
1402   case OO_PipeEqual:
1403     BinaryOp = BO_OrAssign;
1404     return Stmt::CompoundAssignOperatorClass;
1405 
1406   case OO_LessLess:
1407     BinaryOp = BO_Shl;
1408     return Stmt::BinaryOperatorClass;
1409 
1410   case OO_GreaterGreater:
1411     BinaryOp = BO_Shr;
1412     return Stmt::BinaryOperatorClass;
1413 
1414   case OO_LessLessEqual:
1415     BinaryOp = BO_ShlAssign;
1416     return Stmt::CompoundAssignOperatorClass;
1417 
1418   case OO_GreaterGreaterEqual:
1419     BinaryOp = BO_ShrAssign;
1420     return Stmt::CompoundAssignOperatorClass;
1421 
1422   case OO_EqualEqual:
1423     BinaryOp = BO_EQ;
1424     return Stmt::BinaryOperatorClass;
1425 
1426   case OO_ExclaimEqual:
1427     BinaryOp = BO_NE;
1428     return Stmt::BinaryOperatorClass;
1429 
1430   case OO_LessEqual:
1431     BinaryOp = BO_LE;
1432     return Stmt::BinaryOperatorClass;
1433 
1434   case OO_GreaterEqual:
1435     BinaryOp = BO_GE;
1436     return Stmt::BinaryOperatorClass;
1437 
1438   case OO_Spaceship:
1439     // FIXME: Update this once we support <=> expressions.
1440     llvm_unreachable("<=> expressions not supported yet");
1441 
1442   case OO_AmpAmp:
1443     BinaryOp = BO_LAnd;
1444     return Stmt::BinaryOperatorClass;
1445 
1446   case OO_PipePipe:
1447     BinaryOp = BO_LOr;
1448     return Stmt::BinaryOperatorClass;
1449 
1450   case OO_PlusPlus:
1451     UnaryOp = S->getNumArgs() == 1? UO_PreInc
1452                                   : UO_PostInc;
1453     return Stmt::UnaryOperatorClass;
1454 
1455   case OO_MinusMinus:
1456     UnaryOp = S->getNumArgs() == 1? UO_PreDec
1457                                   : UO_PostDec;
1458     return Stmt::UnaryOperatorClass;
1459 
1460   case OO_Comma:
1461     BinaryOp = BO_Comma;
1462     return Stmt::BinaryOperatorClass;
1463 
1464   case OO_ArrowStar:
1465     BinaryOp = BO_PtrMemI;
1466     return Stmt::BinaryOperatorClass;
1467 
1468   case OO_Subscript:
1469     return Stmt::ArraySubscriptExprClass;
1470 
1471   case OO_Coawait:
1472     UnaryOp = UO_Coawait;
1473     return Stmt::UnaryOperatorClass;
1474   }
1475 
1476   llvm_unreachable("Invalid overloaded operator expression");
1477 }
1478 
1479 #if defined(_MSC_VER) && !defined(__clang__)
1480 #if _MSC_VER == 1911
1481 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1482 // MSVC 2017 update 3 miscompiles this function, and a clang built with it
1483 // will crash in stage 2 of a bootstrap build.
1484 #pragma optimize("", off)
1485 #endif
1486 #endif
1487 
1488 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
1489   if (S->isTypeDependent()) {
1490     // Type-dependent operator calls are profiled like their underlying
1491     // syntactic operator.
1492     //
1493     // An operator call to operator-> is always implicit, so just skip it. The
1494     // enclosing MemberExpr will profile the actual member access.
1495     if (S->getOperator() == OO_Arrow)
1496       return Visit(S->getArg(0));
1497 
1498     UnaryOperatorKind UnaryOp = UO_Extension;
1499     BinaryOperatorKind BinaryOp = BO_Comma;
1500     Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
1501 
1502     ID.AddInteger(SC);
1503     for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1504       Visit(S->getArg(I));
1505     if (SC == Stmt::UnaryOperatorClass)
1506       ID.AddInteger(UnaryOp);
1507     else if (SC == Stmt::BinaryOperatorClass ||
1508              SC == Stmt::CompoundAssignOperatorClass)
1509       ID.AddInteger(BinaryOp);
1510     else
1511       assert(SC == Stmt::ArraySubscriptExprClass);
1512 
1513     return;
1514   }
1515 
1516   VisitCallExpr(S);
1517   ID.AddInteger(S->getOperator());
1518 }
1519 
1520 #if defined(_MSC_VER) && !defined(__clang__)
1521 #if _MSC_VER == 1911
1522 #pragma optimize("", on)
1523 #endif
1524 #endif
1525 
1526 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
1527   VisitCallExpr(S);
1528 }
1529 
1530 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
1531   VisitCallExpr(S);
1532 }
1533 
1534 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
1535   VisitExpr(S);
1536 }
1537 
1538 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
1539   VisitExplicitCastExpr(S);
1540 }
1541 
1542 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
1543   VisitCXXNamedCastExpr(S);
1544 }
1545 
1546 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
1547   VisitCXXNamedCastExpr(S);
1548 }
1549 
1550 void
1551 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
1552   VisitCXXNamedCastExpr(S);
1553 }
1554 
1555 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
1556   VisitCXXNamedCastExpr(S);
1557 }
1558 
1559 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1560   VisitCallExpr(S);
1561 }
1562 
1563 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
1564   VisitExpr(S);
1565   ID.AddBoolean(S->getValue());
1566 }
1567 
1568 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
1569   VisitExpr(S);
1570 }
1571 
1572 void StmtProfiler::VisitCXXStdInitializerListExpr(
1573     const CXXStdInitializerListExpr *S) {
1574   VisitExpr(S);
1575 }
1576 
1577 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
1578   VisitExpr(S);
1579   if (S->isTypeOperand())
1580     VisitType(S->getTypeOperandSourceInfo()->getType());
1581 }
1582 
1583 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
1584   VisitExpr(S);
1585   if (S->isTypeOperand())
1586     VisitType(S->getTypeOperandSourceInfo()->getType());
1587 }
1588 
1589 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1590   VisitExpr(S);
1591   VisitDecl(S->getPropertyDecl());
1592 }
1593 
1594 void StmtProfiler::VisitMSPropertySubscriptExpr(
1595     const MSPropertySubscriptExpr *S) {
1596   VisitExpr(S);
1597 }
1598 
1599 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
1600   VisitExpr(S);
1601   ID.AddBoolean(S->isImplicit());
1602 }
1603 
1604 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
1605   VisitExpr(S);
1606 }
1607 
1608 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
1609   VisitExpr(S);
1610   VisitDecl(S->getParam());
1611 }
1612 
1613 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1614   VisitExpr(S);
1615   VisitDecl(S->getField());
1616 }
1617 
1618 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
1619   VisitExpr(S);
1620   VisitDecl(
1621          const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1622 }
1623 
1624 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
1625   VisitExpr(S);
1626   VisitDecl(S->getConstructor());
1627   ID.AddBoolean(S->isElidable());
1628 }
1629 
1630 void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1631     const CXXInheritedCtorInitExpr *S) {
1632   VisitExpr(S);
1633   VisitDecl(S->getConstructor());
1634 }
1635 
1636 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
1637   VisitExplicitCastExpr(S);
1638 }
1639 
1640 void
1641 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
1642   VisitCXXConstructExpr(S);
1643 }
1644 
1645 void
1646 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1647   VisitExpr(S);
1648   for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1649                                  CEnd = S->explicit_capture_end();
1650        C != CEnd; ++C) {
1651     if (C->capturesVLAType())
1652       continue;
1653 
1654     ID.AddInteger(C->getCaptureKind());
1655     switch (C->getCaptureKind()) {
1656     case LCK_StarThis:
1657     case LCK_This:
1658       break;
1659     case LCK_ByRef:
1660     case LCK_ByCopy:
1661       VisitDecl(C->getCapturedVar());
1662       ID.AddBoolean(C->isPackExpansion());
1663       break;
1664     case LCK_VLAType:
1665       llvm_unreachable("VLA type in explicit captures.");
1666     }
1667   }
1668   // Note: If we actually needed to be able to match lambda
1669   // expressions, we would have to consider parameters and return type
1670   // here, among other things.
1671   VisitStmt(S->getBody());
1672 }
1673 
1674 void
1675 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
1676   VisitExpr(S);
1677 }
1678 
1679 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
1680   VisitExpr(S);
1681   ID.AddBoolean(S->isGlobalDelete());
1682   ID.AddBoolean(S->isArrayForm());
1683   VisitDecl(S->getOperatorDelete());
1684 }
1685 
1686 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
1687   VisitExpr(S);
1688   VisitType(S->getAllocatedType());
1689   VisitDecl(S->getOperatorNew());
1690   VisitDecl(S->getOperatorDelete());
1691   ID.AddBoolean(S->isArray());
1692   ID.AddInteger(S->getNumPlacementArgs());
1693   ID.AddBoolean(S->isGlobalNew());
1694   ID.AddBoolean(S->isParenTypeId());
1695   ID.AddInteger(S->getInitializationStyle());
1696 }
1697 
1698 void
1699 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
1700   VisitExpr(S);
1701   ID.AddBoolean(S->isArrow());
1702   VisitNestedNameSpecifier(S->getQualifier());
1703   ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
1704   if (S->getScopeTypeInfo())
1705     VisitType(S->getScopeTypeInfo()->getType());
1706   ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
1707   if (S->getDestroyedTypeInfo())
1708     VisitType(S->getDestroyedType());
1709   else
1710     VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
1711 }
1712 
1713 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
1714   VisitExpr(S);
1715   VisitNestedNameSpecifier(S->getQualifier());
1716   VisitName(S->getName(), /*TreatAsDecl*/ true);
1717   ID.AddBoolean(S->hasExplicitTemplateArgs());
1718   if (S->hasExplicitTemplateArgs())
1719     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1720 }
1721 
1722 void
1723 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
1724   VisitOverloadExpr(S);
1725 }
1726 
1727 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1728   VisitExpr(S);
1729   ID.AddInteger(S->getTrait());
1730   ID.AddInteger(S->getNumArgs());
1731   for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1732     VisitType(S->getArg(I)->getType());
1733 }
1734 
1735 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
1736   VisitExpr(S);
1737   ID.AddInteger(S->getTrait());
1738   VisitType(S->getQueriedType());
1739 }
1740 
1741 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
1742   VisitExpr(S);
1743   ID.AddInteger(S->getTrait());
1744   VisitExpr(S->getQueriedExpression());
1745 }
1746 
1747 void StmtProfiler::VisitDependentScopeDeclRefExpr(
1748     const DependentScopeDeclRefExpr *S) {
1749   VisitExpr(S);
1750   VisitName(S->getDeclName());
1751   VisitNestedNameSpecifier(S->getQualifier());
1752   ID.AddBoolean(S->hasExplicitTemplateArgs());
1753   if (S->hasExplicitTemplateArgs())
1754     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1755 }
1756 
1757 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
1758   VisitExpr(S);
1759 }
1760 
1761 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1762     const CXXUnresolvedConstructExpr *S) {
1763   VisitExpr(S);
1764   VisitType(S->getTypeAsWritten());
1765   ID.AddInteger(S->isListInitialization());
1766 }
1767 
1768 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1769     const CXXDependentScopeMemberExpr *S) {
1770   ID.AddBoolean(S->isImplicitAccess());
1771   if (!S->isImplicitAccess()) {
1772     VisitExpr(S);
1773     ID.AddBoolean(S->isArrow());
1774   }
1775   VisitNestedNameSpecifier(S->getQualifier());
1776   VisitName(S->getMember());
1777   ID.AddBoolean(S->hasExplicitTemplateArgs());
1778   if (S->hasExplicitTemplateArgs())
1779     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1780 }
1781 
1782 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
1783   ID.AddBoolean(S->isImplicitAccess());
1784   if (!S->isImplicitAccess()) {
1785     VisitExpr(S);
1786     ID.AddBoolean(S->isArrow());
1787   }
1788   VisitNestedNameSpecifier(S->getQualifier());
1789   VisitName(S->getMemberName());
1790   ID.AddBoolean(S->hasExplicitTemplateArgs());
1791   if (S->hasExplicitTemplateArgs())
1792     VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1793 }
1794 
1795 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
1796   VisitExpr(S);
1797 }
1798 
1799 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
1800   VisitExpr(S);
1801 }
1802 
1803 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
1804   VisitExpr(S);
1805   VisitDecl(S->getPack());
1806   if (S->isPartiallySubstituted()) {
1807     auto Args = S->getPartialArguments();
1808     ID.AddInteger(Args.size());
1809     for (const auto &TA : Args)
1810       VisitTemplateArgument(TA);
1811   } else {
1812     ID.AddInteger(0);
1813   }
1814 }
1815 
1816 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
1817     const SubstNonTypeTemplateParmPackExpr *S) {
1818   VisitExpr(S);
1819   VisitDecl(S->getParameterPack());
1820   VisitTemplateArgument(S->getArgumentPack());
1821 }
1822 
1823 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1824     const SubstNonTypeTemplateParmExpr *E) {
1825   // Profile exactly as the replacement expression.
1826   Visit(E->getReplacement());
1827 }
1828 
1829 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1830   VisitExpr(S);
1831   VisitDecl(S->getParameterPack());
1832   ID.AddInteger(S->getNumExpansions());
1833   for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1834     VisitDecl(*I);
1835 }
1836 
1837 void StmtProfiler::VisitMaterializeTemporaryExpr(
1838                                            const MaterializeTemporaryExpr *S) {
1839   VisitExpr(S);
1840 }
1841 
1842 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1843   VisitExpr(S);
1844   ID.AddInteger(S->getOperator());
1845 }
1846 
1847 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1848   VisitStmt(S);
1849 }
1850 
1851 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1852   VisitStmt(S);
1853 }
1854 
1855 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1856   VisitExpr(S);
1857 }
1858 
1859 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
1860   VisitExpr(S);
1861 }
1862 
1863 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1864   VisitExpr(S);
1865 }
1866 
1867 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
1868   VisitExpr(E);
1869 }
1870 
1871 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1872   VisitExpr(E);
1873 }
1874 
1875 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
1876   VisitExpr(S);
1877 }
1878 
1879 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
1880   VisitExpr(E);
1881 }
1882 
1883 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1884   VisitExpr(E);
1885 }
1886 
1887 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1888   VisitExpr(E);
1889 }
1890 
1891 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
1892   VisitExpr(S);
1893   VisitType(S->getEncodedType());
1894 }
1895 
1896 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
1897   VisitExpr(S);
1898   VisitName(S->getSelector());
1899 }
1900 
1901 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
1902   VisitExpr(S);
1903   VisitDecl(S->getProtocol());
1904 }
1905 
1906 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
1907   VisitExpr(S);
1908   VisitDecl(S->getDecl());
1909   ID.AddBoolean(S->isArrow());
1910   ID.AddBoolean(S->isFreeIvar());
1911 }
1912 
1913 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
1914   VisitExpr(S);
1915   if (S->isImplicitProperty()) {
1916     VisitDecl(S->getImplicitPropertyGetter());
1917     VisitDecl(S->getImplicitPropertySetter());
1918   } else {
1919     VisitDecl(S->getExplicitProperty());
1920   }
1921   if (S->isSuperReceiver()) {
1922     ID.AddBoolean(S->isSuperReceiver());
1923     VisitType(S->getSuperReceiverType());
1924   }
1925 }
1926 
1927 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1928   VisitExpr(S);
1929   VisitDecl(S->getAtIndexMethodDecl());
1930   VisitDecl(S->setAtIndexMethodDecl());
1931 }
1932 
1933 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
1934   VisitExpr(S);
1935   VisitName(S->getSelector());
1936   VisitDecl(S->getMethodDecl());
1937 }
1938 
1939 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
1940   VisitExpr(S);
1941   ID.AddBoolean(S->isArrow());
1942 }
1943 
1944 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1945   VisitExpr(S);
1946   ID.AddBoolean(S->getValue());
1947 }
1948 
1949 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1950     const ObjCIndirectCopyRestoreExpr *S) {
1951   VisitExpr(S);
1952   ID.AddBoolean(S->shouldCopy());
1953 }
1954 
1955 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
1956   VisitExplicitCastExpr(S);
1957   ID.AddBoolean(S->getBridgeKind());
1958 }
1959 
1960 void StmtProfiler::VisitObjCAvailabilityCheckExpr(
1961     const ObjCAvailabilityCheckExpr *S) {
1962   VisitExpr(S);
1963 }
1964 
1965 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
1966                                           unsigned NumArgs) {
1967   ID.AddInteger(NumArgs);
1968   for (unsigned I = 0; I != NumArgs; ++I)
1969     VisitTemplateArgument(Args[I].getArgument());
1970 }
1971 
1972 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1973   // Mostly repetitive with TemplateArgument::Profile!
1974   ID.AddInteger(Arg.getKind());
1975   switch (Arg.getKind()) {
1976   case TemplateArgument::Null:
1977     break;
1978 
1979   case TemplateArgument::Type:
1980     VisitType(Arg.getAsType());
1981     break;
1982 
1983   case TemplateArgument::Template:
1984   case TemplateArgument::TemplateExpansion:
1985     VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1986     break;
1987 
1988   case TemplateArgument::Declaration:
1989     VisitDecl(Arg.getAsDecl());
1990     break;
1991 
1992   case TemplateArgument::NullPtr:
1993     VisitType(Arg.getNullPtrType());
1994     break;
1995 
1996   case TemplateArgument::Integral:
1997     Arg.getAsIntegral().Profile(ID);
1998     VisitType(Arg.getIntegralType());
1999     break;
2000 
2001   case TemplateArgument::Expression:
2002     Visit(Arg.getAsExpr());
2003     break;
2004 
2005   case TemplateArgument::Pack:
2006     for (const auto &P : Arg.pack_elements())
2007       VisitTemplateArgument(P);
2008     break;
2009   }
2010 }
2011 
2012 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2013                    bool Canonical) const {
2014   StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2015   Profiler.Visit(this);
2016 }
2017 
2018 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2019                           class ODRHash &Hash) const {
2020   StmtProfilerWithoutPointers Profiler(ID, Hash);
2021   Profiler.Visit(this);
2022 }
2023