1 //===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Stmt::Profile method, which builds a unique bit
11 // representation that identifies a statement/expression.
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;
27 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
28 llvm::FoldingSetNodeID &ID;
29 const ASTContext &Context;
33 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
35 : ID(ID), Context(Context), Canonical(Canonical) { }
37 void VisitStmt(const Stmt *S);
39 #define STMT(Node, Base) void Visit##Node(const Node *S);
40 #include "clang/AST/StmtNodes.inc"
42 /// \brief Visit a declaration that is referenced within an expression
44 void VisitDecl(const Decl *D);
46 /// \brief Visit a type that is referenced within an expression or
48 void VisitType(QualType T);
50 /// \brief Visit a name that occurs within an expression or statement.
51 void VisitName(DeclarationName Name);
53 /// \brief Visit a nested-name-specifier that occurs within an expression
55 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS);
57 /// \brief Visit a template name that occurs within an expression or
59 void VisitTemplateName(TemplateName Name);
61 /// \brief Visit template arguments that occur within an expression or
63 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
66 /// \brief Visit a single template argument.
67 void VisitTemplateArgument(const TemplateArgument &Arg);
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()) {
82 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
84 for (const auto *D : S->decls())
88 void StmtProfiler::VisitNullStmt(const NullStmt *S) {
92 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
96 void StmtProfiler::VisitSwitchCase(const SwitchCase *S) {
100 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
104 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
108 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
110 VisitDecl(S->getDecl());
113 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
115 // TODO: maybe visit attributes?
118 void StmtProfiler::VisitIfStmt(const IfStmt *S) {
120 VisitDecl(S->getConditionVariable());
123 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
125 VisitDecl(S->getConditionVariable());
128 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
130 VisitDecl(S->getConditionVariable());
133 void StmtProfiler::VisitDoStmt(const DoStmt *S) {
137 void StmtProfiler::VisitForStmt(const ForStmt *S) {
141 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
143 VisitDecl(S->getLabel());
146 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
150 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
154 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
158 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
162 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *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));
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));
177 ID.AddInteger(S->getNumClobbers());
178 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
179 VisitStringLiteral(S->getClobberStringLiteral(I));
182 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
183 // FIXME: Implement MS style inline asm statement profiler.
187 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
189 VisitType(S->getCaughtType());
192 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
196 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
200 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
202 ID.AddBoolean(S->isIfExists());
203 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
204 VisitName(S->getNameInfo().getName());
207 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
211 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
215 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
219 void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
223 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
227 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
231 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
233 ID.AddBoolean(S->hasEllipsis());
234 if (S->getCatchParamDecl())
235 VisitType(S->getCatchParamDecl()->getType());
238 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
242 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
247 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
251 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
256 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
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);
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);
276 void OMPClauseProfiler::VistOMPClauseWithPreInit(
277 const OMPClauseWithPreInit *C) {
278 if (auto *S = C->getPreInitStmt())
279 Profiler->VisitStmt(S);
282 void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
283 const OMPClauseWithPostUpdate *C) {
284 VistOMPClauseWithPreInit(C);
285 if (auto *E = C->getPostUpdateExpr())
286 Profiler->VisitStmt(E);
289 void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
290 if (C->getCondition())
291 Profiler->VisitStmt(C->getCondition());
294 void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
295 if (C->getCondition())
296 Profiler->VisitStmt(C->getCondition());
299 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
300 if (C->getNumThreads())
301 Profiler->VisitStmt(C->getNumThreads());
304 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
306 Profiler->VisitStmt(C->getSafelen());
309 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
311 Profiler->VisitStmt(C->getSimdlen());
314 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
315 if (C->getNumForLoops())
316 Profiler->VisitStmt(C->getNumForLoops());
319 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
321 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
323 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
324 VistOMPClauseWithPreInit(C);
325 if (auto *S = C->getChunkSize())
326 Profiler->VisitStmt(S);
329 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
330 if (auto *Num = C->getNumForLoops())
331 Profiler->VisitStmt(Num);
334 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
336 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
338 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
340 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
342 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
344 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
346 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
348 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
350 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
352 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
354 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
357 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
358 for (auto *E : Node->varlists()) {
360 Profiler->VisitStmt(E);
364 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
365 VisitOMPClauseList(C);
366 for (auto *E : C->private_copies()) {
368 Profiler->VisitStmt(E);
372 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
373 VisitOMPClauseList(C);
374 VistOMPClauseWithPreInit(C);
375 for (auto *E : C->private_copies()) {
377 Profiler->VisitStmt(E);
379 for (auto *E : C->inits()) {
381 Profiler->VisitStmt(E);
385 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
386 VisitOMPClauseList(C);
387 VistOMPClauseWithPostUpdate(C);
388 for (auto *E : C->source_exprs()) {
390 Profiler->VisitStmt(E);
392 for (auto *E : C->destination_exprs()) {
394 Profiler->VisitStmt(E);
396 for (auto *E : C->assignment_ops()) {
398 Profiler->VisitStmt(E);
401 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
402 VisitOMPClauseList(C);
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()) {
413 Profiler->VisitStmt(E);
415 for (auto *E : C->lhs_exprs()) {
417 Profiler->VisitStmt(E);
419 for (auto *E : C->rhs_exprs()) {
421 Profiler->VisitStmt(E);
423 for (auto *E : C->reduction_ops()) {
425 Profiler->VisitStmt(E);
428 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
429 VisitOMPClauseList(C);
430 VistOMPClauseWithPostUpdate(C);
431 for (auto *E : C->privates()) {
433 Profiler->VisitStmt(E);
435 for (auto *E : C->inits()) {
437 Profiler->VisitStmt(E);
439 for (auto *E : C->updates()) {
441 Profiler->VisitStmt(E);
443 for (auto *E : C->finals()) {
445 Profiler->VisitStmt(E);
448 Profiler->VisitStmt(C->getStep());
449 if (C->getCalcStep())
450 Profiler->VisitStmt(C->getCalcStep());
452 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
453 VisitOMPClauseList(C);
454 if (C->getAlignment())
455 Profiler->VisitStmt(C->getAlignment());
457 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
458 VisitOMPClauseList(C);
459 for (auto *E : C->source_exprs()) {
461 Profiler->VisitStmt(E);
463 for (auto *E : C->destination_exprs()) {
465 Profiler->VisitStmt(E);
467 for (auto *E : C->assignment_ops()) {
469 Profiler->VisitStmt(E);
473 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
474 VisitOMPClauseList(C);
475 for (auto *E : C->source_exprs()) {
477 Profiler->VisitStmt(E);
479 for (auto *E : C->destination_exprs()) {
481 Profiler->VisitStmt(E);
483 for (auto *E : C->assignment_ops()) {
485 Profiler->VisitStmt(E);
488 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
489 VisitOMPClauseList(C);
491 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
492 VisitOMPClauseList(C);
494 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
496 Profiler->VisitStmt(C->getDevice());
498 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
499 VisitOMPClauseList(C);
501 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
502 if (C->getNumTeams())
503 Profiler->VisitStmt(C->getNumTeams());
505 void OMPClauseProfiler::VisitOMPThreadLimitClause(
506 const OMPThreadLimitClause *C) {
507 if (C->getThreadLimit())
508 Profiler->VisitStmt(C->getThreadLimit());
510 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
511 if (C->getPriority())
512 Profiler->VisitStmt(C->getPriority());
514 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
515 if (C->getGrainsize())
516 Profiler->VisitStmt(C->getGrainsize());
518 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
519 if (C->getNumTasks())
520 Profiler->VisitStmt(C->getNumTasks());
522 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
524 Profiler->VisitStmt(C->getHint());
526 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
527 VisitOMPClauseList(C);
529 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
530 VisitOMPClauseList(C);
532 void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
533 const OMPUseDevicePtrClause *C) {
534 VisitOMPClauseList(C);
536 void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
537 const OMPIsDevicePtrClause *C) {
538 VisitOMPClauseList(C);
543 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
545 OMPClauseProfiler P(this);
546 ArrayRef<OMPClause *> Clauses = S->clauses();
547 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
553 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
554 VisitOMPExecutableDirective(S);
557 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
558 VisitOMPExecutableDirective(S);
561 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
562 VisitOMPLoopDirective(S);
565 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
566 VisitOMPLoopDirective(S);
569 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
570 VisitOMPLoopDirective(S);
573 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
574 VisitOMPExecutableDirective(S);
577 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
578 VisitOMPExecutableDirective(S);
581 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
582 VisitOMPExecutableDirective(S);
585 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
586 VisitOMPExecutableDirective(S);
589 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
590 VisitOMPExecutableDirective(S);
591 VisitName(S->getDirectiveName().getName());
595 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
596 VisitOMPLoopDirective(S);
599 void StmtProfiler::VisitOMPParallelForSimdDirective(
600 const OMPParallelForSimdDirective *S) {
601 VisitOMPLoopDirective(S);
604 void StmtProfiler::VisitOMPParallelSectionsDirective(
605 const OMPParallelSectionsDirective *S) {
606 VisitOMPExecutableDirective(S);
609 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
610 VisitOMPExecutableDirective(S);
613 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
614 VisitOMPExecutableDirective(S);
617 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
618 VisitOMPExecutableDirective(S);
621 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
622 VisitOMPExecutableDirective(S);
625 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
626 VisitOMPExecutableDirective(S);
629 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
630 VisitOMPExecutableDirective(S);
633 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
634 VisitOMPExecutableDirective(S);
637 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
638 VisitOMPExecutableDirective(S);
641 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
642 VisitOMPExecutableDirective(S);
645 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
646 VisitOMPExecutableDirective(S);
649 void StmtProfiler::VisitOMPTargetEnterDataDirective(
650 const OMPTargetEnterDataDirective *S) {
651 VisitOMPExecutableDirective(S);
654 void StmtProfiler::VisitOMPTargetExitDataDirective(
655 const OMPTargetExitDataDirective *S) {
656 VisitOMPExecutableDirective(S);
659 void StmtProfiler::VisitOMPTargetParallelDirective(
660 const OMPTargetParallelDirective *S) {
661 VisitOMPExecutableDirective(S);
664 void StmtProfiler::VisitOMPTargetParallelForDirective(
665 const OMPTargetParallelForDirective *S) {
666 VisitOMPExecutableDirective(S);
669 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
670 VisitOMPExecutableDirective(S);
673 void StmtProfiler::VisitOMPCancellationPointDirective(
674 const OMPCancellationPointDirective *S) {
675 VisitOMPExecutableDirective(S);
678 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
679 VisitOMPExecutableDirective(S);
682 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
683 VisitOMPLoopDirective(S);
686 void StmtProfiler::VisitOMPTaskLoopSimdDirective(
687 const OMPTaskLoopSimdDirective *S) {
688 VisitOMPLoopDirective(S);
691 void StmtProfiler::VisitOMPDistributeDirective(
692 const OMPDistributeDirective *S) {
693 VisitOMPLoopDirective(S);
696 void OMPClauseProfiler::VisitOMPDistScheduleClause(
697 const OMPDistScheduleClause *C) {
698 VistOMPClauseWithPreInit(C);
699 if (auto *S = C->getChunkSize())
700 Profiler->VisitStmt(S);
703 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
705 void StmtProfiler::VisitOMPTargetUpdateDirective(
706 const OMPTargetUpdateDirective *S) {
707 VisitOMPExecutableDirective(S);
710 void StmtProfiler::VisitOMPDistributeParallelForDirective(
711 const OMPDistributeParallelForDirective *S) {
712 VisitOMPLoopDirective(S);
715 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
716 const OMPDistributeParallelForSimdDirective *S) {
717 VisitOMPLoopDirective(S);
720 void StmtProfiler::VisitOMPDistributeSimdDirective(
721 const OMPDistributeSimdDirective *S) {
722 VisitOMPLoopDirective(S);
725 void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
726 const OMPTargetParallelForSimdDirective *S) {
727 VisitOMPLoopDirective(S);
730 void StmtProfiler::VisitExpr(const Expr *S) {
734 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
737 VisitNestedNameSpecifier(S->getQualifier());
738 VisitDecl(S->getDecl());
740 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
743 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
745 ID.AddInteger(S->getIdentType());
748 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
750 S->getValue().Profile(ID);
751 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
754 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
756 ID.AddInteger(S->getKind());
757 ID.AddInteger(S->getValue());
760 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
762 S->getValue().Profile(ID);
763 ID.AddBoolean(S->isExact());
764 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
767 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
771 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
773 ID.AddString(S->getBytes());
774 ID.AddInteger(S->getKind());
777 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
781 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
785 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
787 ID.AddInteger(S->getOpcode());
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.
801 case OffsetOfNode::Field:
802 VisitDecl(ON.getField());
805 case OffsetOfNode::Identifier:
806 ID.AddPointer(ON.getFieldName());
809 case OffsetOfNode::Base:
810 // These nodes are implicit, and therefore don't need profiling.
819 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
821 ID.AddInteger(S->getKind());
822 if (S->isArgumentType())
823 VisitType(S->getArgumentType());
826 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
830 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
834 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
838 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
840 VisitDecl(S->getMemberDecl());
842 VisitNestedNameSpecifier(S->getQualifier());
843 ID.AddBoolean(S->isArrow());
846 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
848 ID.AddBoolean(S->isFileScope());
851 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
855 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
857 ID.AddInteger(S->getValueKind());
860 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
862 VisitType(S->getTypeAsWritten());
865 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
866 VisitExplicitCastExpr(S);
869 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
871 ID.AddInteger(S->getOpcode());
875 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
876 VisitBinaryOperator(S);
879 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
883 void StmtProfiler::VisitBinaryConditionalOperator(
884 const BinaryConditionalOperator *S) {
888 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
890 VisitDecl(S->getLabel());
893 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
897 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
901 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
905 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
909 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
913 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
917 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
918 if (S->getSyntacticForm()) {
919 VisitInitListExpr(S->getSyntacticForm());
926 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
928 ID.AddBoolean(S->usesGNUSyntax());
929 for (const DesignatedInitExpr::Designator &D : S->designators()) {
930 if (D.isFieldDesignator()) {
932 VisitName(D.getFieldName());
936 if (D.isArrayDesignator()) {
939 assert(D.isArrayRangeDesignator());
942 ID.AddInteger(D.getFirstExprIndex());
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 "
954 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
955 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
958 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
962 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
964 VisitName(&S->getAccessor());
967 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
969 VisitDecl(S->getBlockDecl());
972 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
974 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
975 QualType T = S->getAssocType(i);
977 ID.AddPointer(nullptr);
980 VisitExpr(S->getAssocExpr(i));
984 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *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());
993 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
995 ID.AddInteger(S->getOp());
998 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
999 UnaryOperatorKind &UnaryOp,
1000 BinaryOperatorKind &BinaryOp) {
1001 switch (S->getOperator()) {
1006 case OO_Array_Delete:
1009 case OO_Conditional:
1011 case NUM_OVERLOADED_OPERATORS:
1012 llvm_unreachable("Invalid operator call kind");
1015 if (S->getNumArgs() == 1) {
1017 return Stmt::UnaryOperatorClass;
1021 return Stmt::BinaryOperatorClass;
1024 if (S->getNumArgs() == 1) {
1026 return Stmt::UnaryOperatorClass;
1030 return Stmt::BinaryOperatorClass;
1033 if (S->getNumArgs() == 1) {
1035 return Stmt::UnaryOperatorClass;
1039 return Stmt::BinaryOperatorClass;
1043 return Stmt::BinaryOperatorClass;
1047 return Stmt::BinaryOperatorClass;
1051 return Stmt::BinaryOperatorClass;
1054 if (S->getNumArgs() == 1) {
1055 UnaryOp = UO_AddrOf;
1056 return Stmt::UnaryOperatorClass;
1060 return Stmt::BinaryOperatorClass;
1064 return Stmt::BinaryOperatorClass;
1068 return Stmt::UnaryOperatorClass;
1072 return Stmt::UnaryOperatorClass;
1075 BinaryOp = BO_Assign;
1076 return Stmt::BinaryOperatorClass;
1080 return Stmt::BinaryOperatorClass;
1084 return Stmt::BinaryOperatorClass;
1087 BinaryOp = BO_AddAssign;
1088 return Stmt::CompoundAssignOperatorClass;
1091 BinaryOp = BO_SubAssign;
1092 return Stmt::CompoundAssignOperatorClass;
1095 BinaryOp = BO_MulAssign;
1096 return Stmt::CompoundAssignOperatorClass;
1099 BinaryOp = BO_DivAssign;
1100 return Stmt::CompoundAssignOperatorClass;
1102 case OO_PercentEqual:
1103 BinaryOp = BO_RemAssign;
1104 return Stmt::CompoundAssignOperatorClass;
1107 BinaryOp = BO_XorAssign;
1108 return Stmt::CompoundAssignOperatorClass;
1111 BinaryOp = BO_AndAssign;
1112 return Stmt::CompoundAssignOperatorClass;
1115 BinaryOp = BO_OrAssign;
1116 return Stmt::CompoundAssignOperatorClass;
1120 return Stmt::BinaryOperatorClass;
1122 case OO_GreaterGreater:
1124 return Stmt::BinaryOperatorClass;
1126 case OO_LessLessEqual:
1127 BinaryOp = BO_ShlAssign;
1128 return Stmt::CompoundAssignOperatorClass;
1130 case OO_GreaterGreaterEqual:
1131 BinaryOp = BO_ShrAssign;
1132 return Stmt::CompoundAssignOperatorClass;
1136 return Stmt::BinaryOperatorClass;
1138 case OO_ExclaimEqual:
1140 return Stmt::BinaryOperatorClass;
1144 return Stmt::BinaryOperatorClass;
1146 case OO_GreaterEqual:
1148 return Stmt::BinaryOperatorClass;
1152 return Stmt::BinaryOperatorClass;
1156 return Stmt::BinaryOperatorClass;
1159 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1161 return Stmt::UnaryOperatorClass;
1164 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1166 return Stmt::UnaryOperatorClass;
1169 BinaryOp = BO_Comma;
1170 return Stmt::BinaryOperatorClass;
1173 BinaryOp = BO_PtrMemI;
1174 return Stmt::BinaryOperatorClass;
1177 return Stmt::ArraySubscriptExprClass;
1180 llvm_unreachable("Invalid overloaded operator expression");
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);
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);
1200 assert(SC == Stmt::ArraySubscriptExprClass);
1206 ID.AddInteger(S->getOperator());
1209 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
1213 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
1217 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
1221 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
1222 VisitExplicitCastExpr(S);
1225 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
1226 VisitCXXNamedCastExpr(S);
1229 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
1230 VisitCXXNamedCastExpr(S);
1234 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
1235 VisitCXXNamedCastExpr(S);
1238 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
1239 VisitCXXNamedCastExpr(S);
1242 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1246 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
1248 ID.AddBoolean(S->getValue());
1251 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
1255 void StmtProfiler::VisitCXXStdInitializerListExpr(
1256 const CXXStdInitializerListExpr *S) {
1260 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
1262 if (S->isTypeOperand())
1263 VisitType(S->getTypeOperandSourceInfo()->getType());
1266 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
1268 if (S->isTypeOperand())
1269 VisitType(S->getTypeOperandSourceInfo()->getType());
1272 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1274 VisitDecl(S->getPropertyDecl());
1277 void StmtProfiler::VisitMSPropertySubscriptExpr(
1278 const MSPropertySubscriptExpr *S) {
1282 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
1284 ID.AddBoolean(S->isImplicit());
1287 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
1291 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
1293 VisitDecl(S->getParam());
1296 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1298 VisitDecl(S->getField());
1301 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
1304 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1307 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
1309 VisitDecl(S->getConstructor());
1310 ID.AddBoolean(S->isElidable());
1313 void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1314 const CXXInheritedCtorInitExpr *S) {
1316 VisitDecl(S->getConstructor());
1319 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
1320 VisitExplicitCastExpr(S);
1324 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
1325 VisitCXXConstructExpr(S);
1329 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1331 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1332 CEnd = S->explicit_capture_end();
1334 ID.AddInteger(C->getCaptureKind());
1335 switch (C->getCaptureKind()) {
1341 VisitDecl(C->getCapturedVar());
1342 ID.AddBoolean(C->isPackExpansion());
1345 llvm_unreachable("VLA type in explicit captures.");
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());
1355 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
1359 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
1361 ID.AddBoolean(S->isGlobalDelete());
1362 ID.AddBoolean(S->isArrayForm());
1363 VisitDecl(S->getOperatorDelete());
1366 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *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());
1379 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *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());
1390 ID.AddPointer(S->getDestroyedTypeIdentifier());
1393 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
1395 VisitNestedNameSpecifier(S->getQualifier());
1396 VisitName(S->getName());
1397 ID.AddBoolean(S->hasExplicitTemplateArgs());
1398 if (S->hasExplicitTemplateArgs())
1399 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1403 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
1404 VisitOverloadExpr(S);
1407 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *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());
1415 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
1417 ID.AddInteger(S->getTrait());
1418 VisitType(S->getQueriedType());
1421 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
1423 ID.AddInteger(S->getTrait());
1424 VisitExpr(S->getQueriedExpression());
1427 void StmtProfiler::VisitDependentScopeDeclRefExpr(
1428 const DependentScopeDeclRefExpr *S) {
1430 VisitName(S->getDeclName());
1431 VisitNestedNameSpecifier(S->getQualifier());
1432 ID.AddBoolean(S->hasExplicitTemplateArgs());
1433 if (S->hasExplicitTemplateArgs())
1434 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1437 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
1441 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1442 const CXXUnresolvedConstructExpr *S) {
1444 VisitType(S->getTypeAsWritten());
1447 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1448 const CXXDependentScopeMemberExpr *S) {
1449 ID.AddBoolean(S->isImplicitAccess());
1450 if (!S->isImplicitAccess()) {
1452 ID.AddBoolean(S->isArrow());
1454 VisitNestedNameSpecifier(S->getQualifier());
1455 VisitName(S->getMember());
1456 ID.AddBoolean(S->hasExplicitTemplateArgs());
1457 if (S->hasExplicitTemplateArgs())
1458 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1461 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
1462 ID.AddBoolean(S->isImplicitAccess());
1463 if (!S->isImplicitAccess()) {
1465 ID.AddBoolean(S->isArrow());
1467 VisitNestedNameSpecifier(S->getQualifier());
1468 VisitName(S->getMemberName());
1469 ID.AddBoolean(S->hasExplicitTemplateArgs());
1470 if (S->hasExplicitTemplateArgs())
1471 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1474 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
1478 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
1482 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *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);
1495 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
1496 const SubstNonTypeTemplateParmPackExpr *S) {
1498 VisitDecl(S->getParameterPack());
1499 VisitTemplateArgument(S->getArgumentPack());
1502 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1503 const SubstNonTypeTemplateParmExpr *E) {
1504 // Profile exactly as the replacement expression.
1505 Visit(E->getReplacement());
1508 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1510 VisitDecl(S->getParameterPack());
1511 ID.AddInteger(S->getNumExpansions());
1512 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1516 void StmtProfiler::VisitMaterializeTemporaryExpr(
1517 const MaterializeTemporaryExpr *S) {
1521 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1523 ID.AddInteger(S->getOperator());
1526 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1530 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1534 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1538 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1542 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
1546 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1550 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
1554 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
1558 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1562 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1566 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
1568 VisitType(S->getEncodedType());
1571 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
1573 VisitName(S->getSelector());
1576 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
1578 VisitDecl(S->getProtocol());
1581 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
1583 VisitDecl(S->getDecl());
1584 ID.AddBoolean(S->isArrow());
1585 ID.AddBoolean(S->isFreeIvar());
1588 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
1590 if (S->isImplicitProperty()) {
1591 VisitDecl(S->getImplicitPropertyGetter());
1592 VisitDecl(S->getImplicitPropertySetter());
1594 VisitDecl(S->getExplicitProperty());
1596 if (S->isSuperReceiver()) {
1597 ID.AddBoolean(S->isSuperReceiver());
1598 VisitType(S->getSuperReceiverType());
1602 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1604 VisitDecl(S->getAtIndexMethodDecl());
1605 VisitDecl(S->setAtIndexMethodDecl());
1608 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
1610 VisitName(S->getSelector());
1611 VisitDecl(S->getMethodDecl());
1614 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
1616 ID.AddBoolean(S->isArrow());
1619 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1621 ID.AddBoolean(S->getValue());
1624 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1625 const ObjCIndirectCopyRestoreExpr *S) {
1627 ID.AddBoolean(S->shouldCopy());
1630 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
1631 VisitExplicitCastExpr(S);
1632 ID.AddBoolean(S->getBridgeKind());
1635 void StmtProfiler::VisitObjCAvailabilityCheckExpr(
1636 const ObjCAvailabilityCheckExpr *S) {
1640 void StmtProfiler::VisitDecl(const Decl *D) {
1641 ID.AddInteger(D? D->getKind() : 0);
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());
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
1661 VisitType(Parm->getType());
1662 ID.AddInteger(Parm->getFunctionScopeDepth());
1663 ID.AddInteger(Parm->getFunctionScopeIndex());
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());
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());
1684 ID.AddPointer(D? D->getCanonicalDecl() : nullptr);
1687 void StmtProfiler::VisitType(QualType T) {
1689 T = Context.getCanonicalType(T);
1691 ID.AddPointer(T.getAsOpaquePtr());
1694 void StmtProfiler::VisitName(DeclarationName Name) {
1695 ID.AddPointer(Name.getAsOpaquePtr());
1698 void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) {
1700 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
1704 void StmtProfiler::VisitTemplateName(TemplateName Name) {
1706 Name = Context.getCanonicalTemplateName(Name);
1711 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
1713 ID.AddInteger(NumArgs);
1714 for (unsigned I = 0; I != NumArgs; ++I)
1715 VisitTemplateArgument(Args[I].getArgument());
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:
1725 case TemplateArgument::Type:
1726 VisitType(Arg.getAsType());
1729 case TemplateArgument::Template:
1730 case TemplateArgument::TemplateExpansion:
1731 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1734 case TemplateArgument::Declaration:
1735 VisitDecl(Arg.getAsDecl());
1738 case TemplateArgument::NullPtr:
1739 VisitType(Arg.getNullPtrType());
1742 case TemplateArgument::Integral:
1743 Arg.getAsIntegral().Profile(ID);
1744 VisitType(Arg.getIntegralType());
1747 case TemplateArgument::Expression:
1748 Visit(Arg.getAsExpr());
1751 case TemplateArgument::Pack:
1752 for (const auto &P : Arg.pack_elements())
1753 VisitTemplateArgument(P);
1758 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
1759 bool Canonical) const {
1760 StmtProfiler Profiler(ID, Context, Canonical);
1761 Profiler.Visit(this);