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