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