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