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