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/ODRHash.h"
23 #include "clang/AST/StmtVisitor.h"
24 #include "llvm/ADT/FoldingSet.h"
25 using namespace clang;
28 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
30 llvm::FoldingSetNodeID &ID;
34 StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical)
35 : ID(ID), Canonical(Canonical) {}
37 virtual ~StmtProfiler() {}
39 void VisitStmt(const Stmt *S);
41 virtual void HandleStmtClass(Stmt::StmtClass SC) = 0;
43 #define STMT(Node, Base) void Visit##Node(const Node *S);
44 #include "clang/AST/StmtNodes.inc"
46 /// Visit a declaration that is referenced within an expression
48 virtual void VisitDecl(const Decl *D) = 0;
50 /// Visit a type that is referenced within an expression or
52 virtual void VisitType(QualType T) = 0;
54 /// Visit a name that occurs within an expression or statement.
55 virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0;
57 /// Visit identifiers that are not in Decl's or Type's.
58 virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0;
60 /// Visit a nested-name-specifier that occurs within an expression
62 virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0;
64 /// Visit a template name that occurs within an expression or
66 virtual void VisitTemplateName(TemplateName Name) = 0;
68 /// Visit template arguments that occur within an expression or
70 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
73 /// Visit a single template argument.
74 void VisitTemplateArgument(const TemplateArgument &Arg);
77 class StmtProfilerWithPointers : public StmtProfiler {
78 const ASTContext &Context;
81 StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID,
82 const ASTContext &Context, bool Canonical)
83 : StmtProfiler(ID, Canonical), Context(Context) {}
85 void HandleStmtClass(Stmt::StmtClass SC) override {
89 void VisitDecl(const Decl *D) override {
90 ID.AddInteger(D ? D->getKind() : 0);
93 if (const NonTypeTemplateParmDecl *NTTP =
94 dyn_cast<NonTypeTemplateParmDecl>(D)) {
95 ID.AddInteger(NTTP->getDepth());
96 ID.AddInteger(NTTP->getIndex());
97 ID.AddBoolean(NTTP->isParameterPack());
98 VisitType(NTTP->getType());
102 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
103 // The Itanium C++ ABI uses the type, scope depth, and scope
104 // index of a parameter when mangling expressions that involve
105 // function parameters, so we will use the parameter's type for
106 // establishing function parameter identity. That way, our
107 // definition of "equivalent" (per C++ [temp.over.link]) is at
108 // least as strong as the definition of "equivalent" used for
110 VisitType(Parm->getType());
111 ID.AddInteger(Parm->getFunctionScopeDepth());
112 ID.AddInteger(Parm->getFunctionScopeIndex());
116 if (const TemplateTypeParmDecl *TTP =
117 dyn_cast<TemplateTypeParmDecl>(D)) {
118 ID.AddInteger(TTP->getDepth());
119 ID.AddInteger(TTP->getIndex());
120 ID.AddBoolean(TTP->isParameterPack());
124 if (const TemplateTemplateParmDecl *TTP =
125 dyn_cast<TemplateTemplateParmDecl>(D)) {
126 ID.AddInteger(TTP->getDepth());
127 ID.AddInteger(TTP->getIndex());
128 ID.AddBoolean(TTP->isParameterPack());
133 ID.AddPointer(D ? D->getCanonicalDecl() : nullptr);
136 void VisitType(QualType T) override {
137 if (Canonical && !T.isNull())
138 T = Context.getCanonicalType(T);
140 ID.AddPointer(T.getAsOpaquePtr());
143 void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override {
144 ID.AddPointer(Name.getAsOpaquePtr());
147 void VisitIdentifierInfo(IdentifierInfo *II) override {
151 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
153 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
157 void VisitTemplateName(TemplateName Name) override {
159 Name = Context.getCanonicalTemplateName(Name);
165 class StmtProfilerWithoutPointers : public StmtProfiler {
168 StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
169 : StmtProfiler(ID, false), Hash(Hash) {}
172 void HandleStmtClass(Stmt::StmtClass SC) override {
173 if (SC == Stmt::UnresolvedLookupExprClass) {
174 // Pretend that the name looked up is a Decl due to how templates
175 // handle some Decl lookups.
176 ID.AddInteger(Stmt::DeclRefExprClass);
182 void VisitType(QualType T) override {
186 void VisitName(DeclarationName Name, bool TreatAsDecl) override {
188 // A Decl can be null, so each Decl is preceded by a boolean to
189 // store its nullness. Add a boolean here to match.
192 Hash.AddDeclarationName(Name, TreatAsDecl);
194 void VisitIdentifierInfo(IdentifierInfo *II) override {
197 Hash.AddIdentifierInfo(II);
200 void VisitDecl(const Decl *D) override {
206 void VisitTemplateName(TemplateName Name) override {
207 Hash.AddTemplateName(Name);
209 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
212 Hash.AddNestedNameSpecifier(NNS);
218 void StmtProfiler::VisitStmt(const Stmt *S) {
219 assert(S && "Requires non-null Stmt pointer");
221 HandleStmtClass(S->getStmtClass());
223 for (const Stmt *SubStmt : S->children()) {
231 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
233 for (const auto *D : S->decls())
237 void StmtProfiler::VisitNullStmt(const NullStmt *S) {
241 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
245 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
249 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
253 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
255 VisitDecl(S->getDecl());
258 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
260 // TODO: maybe visit attributes?
263 void StmtProfiler::VisitIfStmt(const IfStmt *S) {
265 VisitDecl(S->getConditionVariable());
268 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
270 VisitDecl(S->getConditionVariable());
273 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
275 VisitDecl(S->getConditionVariable());
278 void StmtProfiler::VisitDoStmt(const DoStmt *S) {
282 void StmtProfiler::VisitForStmt(const ForStmt *S) {
286 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
288 VisitDecl(S->getLabel());
291 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
295 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
299 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
303 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
307 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
309 ID.AddBoolean(S->isVolatile());
310 ID.AddBoolean(S->isSimple());
311 VisitStringLiteral(S->getAsmString());
312 ID.AddInteger(S->getNumOutputs());
313 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
314 ID.AddString(S->getOutputName(I));
315 VisitStringLiteral(S->getOutputConstraintLiteral(I));
317 ID.AddInteger(S->getNumInputs());
318 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
319 ID.AddString(S->getInputName(I));
320 VisitStringLiteral(S->getInputConstraintLiteral(I));
322 ID.AddInteger(S->getNumClobbers());
323 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
324 VisitStringLiteral(S->getClobberStringLiteral(I));
327 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
328 // FIXME: Implement MS style inline asm statement profiler.
332 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
334 VisitType(S->getCaughtType());
337 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
341 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
345 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
347 ID.AddBoolean(S->isIfExists());
348 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
349 VisitName(S->getNameInfo().getName());
352 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
356 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
360 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
364 void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
368 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
372 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
376 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
378 ID.AddBoolean(S->hasEllipsis());
379 if (S->getCatchParamDecl())
380 VisitType(S->getCatchParamDecl()->getType());
383 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
387 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
392 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
396 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
401 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
406 class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
407 StmtProfiler *Profiler;
408 /// Process clauses with list of variables.
409 template <typename T>
410 void VisitOMPClauseList(T *Node);
413 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
414 #define OPENMP_CLAUSE(Name, Class) \
415 void Visit##Class(const Class *C);
416 #include "clang/Basic/OpenMPKinds.def"
417 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
418 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
421 void OMPClauseProfiler::VistOMPClauseWithPreInit(
422 const OMPClauseWithPreInit *C) {
423 if (auto *S = C->getPreInitStmt())
424 Profiler->VisitStmt(S);
427 void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
428 const OMPClauseWithPostUpdate *C) {
429 VistOMPClauseWithPreInit(C);
430 if (auto *E = C->getPostUpdateExpr())
431 Profiler->VisitStmt(E);
434 void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
435 VistOMPClauseWithPreInit(C);
436 if (C->getCondition())
437 Profiler->VisitStmt(C->getCondition());
440 void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
441 if (C->getCondition())
442 Profiler->VisitStmt(C->getCondition());
445 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
446 VistOMPClauseWithPreInit(C);
447 if (C->getNumThreads())
448 Profiler->VisitStmt(C->getNumThreads());
451 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
453 Profiler->VisitStmt(C->getSafelen());
456 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
458 Profiler->VisitStmt(C->getSimdlen());
461 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
462 if (C->getNumForLoops())
463 Profiler->VisitStmt(C->getNumForLoops());
466 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
468 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
470 void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
471 const OMPUnifiedAddressClause *C) {}
473 void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
474 const OMPUnifiedSharedMemoryClause *C) {}
476 void OMPClauseProfiler::VisitOMPReverseOffloadClause(
477 const OMPReverseOffloadClause *C) {}
479 void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
480 const OMPDynamicAllocatorsClause *C) {}
482 void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
483 const OMPAtomicDefaultMemOrderClause *C) {}
485 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
486 VistOMPClauseWithPreInit(C);
487 if (auto *S = C->getChunkSize())
488 Profiler->VisitStmt(S);
491 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
492 if (auto *Num = C->getNumForLoops())
493 Profiler->VisitStmt(Num);
496 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
498 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
500 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
502 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
504 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
506 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
508 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
510 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
512 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
514 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
516 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
519 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
520 for (auto *E : Node->varlists()) {
522 Profiler->VisitStmt(E);
526 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
527 VisitOMPClauseList(C);
528 for (auto *E : C->private_copies()) {
530 Profiler->VisitStmt(E);
534 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
535 VisitOMPClauseList(C);
536 VistOMPClauseWithPreInit(C);
537 for (auto *E : C->private_copies()) {
539 Profiler->VisitStmt(E);
541 for (auto *E : C->inits()) {
543 Profiler->VisitStmt(E);
547 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
548 VisitOMPClauseList(C);
549 VistOMPClauseWithPostUpdate(C);
550 for (auto *E : C->source_exprs()) {
552 Profiler->VisitStmt(E);
554 for (auto *E : C->destination_exprs()) {
556 Profiler->VisitStmt(E);
558 for (auto *E : C->assignment_ops()) {
560 Profiler->VisitStmt(E);
563 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
564 VisitOMPClauseList(C);
566 void OMPClauseProfiler::VisitOMPReductionClause(
567 const OMPReductionClause *C) {
568 Profiler->VisitNestedNameSpecifier(
569 C->getQualifierLoc().getNestedNameSpecifier());
570 Profiler->VisitName(C->getNameInfo().getName());
571 VisitOMPClauseList(C);
572 VistOMPClauseWithPostUpdate(C);
573 for (auto *E : C->privates()) {
575 Profiler->VisitStmt(E);
577 for (auto *E : C->lhs_exprs()) {
579 Profiler->VisitStmt(E);
581 for (auto *E : C->rhs_exprs()) {
583 Profiler->VisitStmt(E);
585 for (auto *E : C->reduction_ops()) {
587 Profiler->VisitStmt(E);
590 void OMPClauseProfiler::VisitOMPTaskReductionClause(
591 const OMPTaskReductionClause *C) {
592 Profiler->VisitNestedNameSpecifier(
593 C->getQualifierLoc().getNestedNameSpecifier());
594 Profiler->VisitName(C->getNameInfo().getName());
595 VisitOMPClauseList(C);
596 VistOMPClauseWithPostUpdate(C);
597 for (auto *E : C->privates()) {
599 Profiler->VisitStmt(E);
601 for (auto *E : C->lhs_exprs()) {
603 Profiler->VisitStmt(E);
605 for (auto *E : C->rhs_exprs()) {
607 Profiler->VisitStmt(E);
609 for (auto *E : C->reduction_ops()) {
611 Profiler->VisitStmt(E);
614 void OMPClauseProfiler::VisitOMPInReductionClause(
615 const OMPInReductionClause *C) {
616 Profiler->VisitNestedNameSpecifier(
617 C->getQualifierLoc().getNestedNameSpecifier());
618 Profiler->VisitName(C->getNameInfo().getName());
619 VisitOMPClauseList(C);
620 VistOMPClauseWithPostUpdate(C);
621 for (auto *E : C->privates()) {
623 Profiler->VisitStmt(E);
625 for (auto *E : C->lhs_exprs()) {
627 Profiler->VisitStmt(E);
629 for (auto *E : C->rhs_exprs()) {
631 Profiler->VisitStmt(E);
633 for (auto *E : C->reduction_ops()) {
635 Profiler->VisitStmt(E);
637 for (auto *E : C->taskgroup_descriptors()) {
639 Profiler->VisitStmt(E);
642 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
643 VisitOMPClauseList(C);
644 VistOMPClauseWithPostUpdate(C);
645 for (auto *E : C->privates()) {
647 Profiler->VisitStmt(E);
649 for (auto *E : C->inits()) {
651 Profiler->VisitStmt(E);
653 for (auto *E : C->updates()) {
655 Profiler->VisitStmt(E);
657 for (auto *E : C->finals()) {
659 Profiler->VisitStmt(E);
662 Profiler->VisitStmt(C->getStep());
663 if (C->getCalcStep())
664 Profiler->VisitStmt(C->getCalcStep());
666 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
667 VisitOMPClauseList(C);
668 if (C->getAlignment())
669 Profiler->VisitStmt(C->getAlignment());
671 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
672 VisitOMPClauseList(C);
673 for (auto *E : C->source_exprs()) {
675 Profiler->VisitStmt(E);
677 for (auto *E : C->destination_exprs()) {
679 Profiler->VisitStmt(E);
681 for (auto *E : C->assignment_ops()) {
683 Profiler->VisitStmt(E);
687 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
688 VisitOMPClauseList(C);
689 for (auto *E : C->source_exprs()) {
691 Profiler->VisitStmt(E);
693 for (auto *E : C->destination_exprs()) {
695 Profiler->VisitStmt(E);
697 for (auto *E : C->assignment_ops()) {
699 Profiler->VisitStmt(E);
702 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
703 VisitOMPClauseList(C);
705 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
706 VisitOMPClauseList(C);
708 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
710 Profiler->VisitStmt(C->getDevice());
712 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
713 VisitOMPClauseList(C);
715 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
716 VistOMPClauseWithPreInit(C);
717 if (C->getNumTeams())
718 Profiler->VisitStmt(C->getNumTeams());
720 void OMPClauseProfiler::VisitOMPThreadLimitClause(
721 const OMPThreadLimitClause *C) {
722 VistOMPClauseWithPreInit(C);
723 if (C->getThreadLimit())
724 Profiler->VisitStmt(C->getThreadLimit());
726 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
727 if (C->getPriority())
728 Profiler->VisitStmt(C->getPriority());
730 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
731 if (C->getGrainsize())
732 Profiler->VisitStmt(C->getGrainsize());
734 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
735 if (C->getNumTasks())
736 Profiler->VisitStmt(C->getNumTasks());
738 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
740 Profiler->VisitStmt(C->getHint());
742 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
743 VisitOMPClauseList(C);
745 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
746 VisitOMPClauseList(C);
748 void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
749 const OMPUseDevicePtrClause *C) {
750 VisitOMPClauseList(C);
752 void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
753 const OMPIsDevicePtrClause *C) {
754 VisitOMPClauseList(C);
759 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
761 OMPClauseProfiler P(this);
762 ArrayRef<OMPClause *> Clauses = S->clauses();
763 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
769 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
770 VisitOMPExecutableDirective(S);
773 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
774 VisitOMPExecutableDirective(S);
777 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
778 VisitOMPLoopDirective(S);
781 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
782 VisitOMPLoopDirective(S);
785 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
786 VisitOMPLoopDirective(S);
789 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
790 VisitOMPExecutableDirective(S);
793 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
794 VisitOMPExecutableDirective(S);
797 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
798 VisitOMPExecutableDirective(S);
801 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
802 VisitOMPExecutableDirective(S);
805 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
806 VisitOMPExecutableDirective(S);
807 VisitName(S->getDirectiveName().getName());
811 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
812 VisitOMPLoopDirective(S);
815 void StmtProfiler::VisitOMPParallelForSimdDirective(
816 const OMPParallelForSimdDirective *S) {
817 VisitOMPLoopDirective(S);
820 void StmtProfiler::VisitOMPParallelSectionsDirective(
821 const OMPParallelSectionsDirective *S) {
822 VisitOMPExecutableDirective(S);
825 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
826 VisitOMPExecutableDirective(S);
829 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
830 VisitOMPExecutableDirective(S);
833 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
834 VisitOMPExecutableDirective(S);
837 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
838 VisitOMPExecutableDirective(S);
841 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
842 VisitOMPExecutableDirective(S);
843 if (const Expr *E = S->getReductionRef())
847 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
848 VisitOMPExecutableDirective(S);
851 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
852 VisitOMPExecutableDirective(S);
855 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
856 VisitOMPExecutableDirective(S);
859 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
860 VisitOMPExecutableDirective(S);
863 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
864 VisitOMPExecutableDirective(S);
867 void StmtProfiler::VisitOMPTargetEnterDataDirective(
868 const OMPTargetEnterDataDirective *S) {
869 VisitOMPExecutableDirective(S);
872 void StmtProfiler::VisitOMPTargetExitDataDirective(
873 const OMPTargetExitDataDirective *S) {
874 VisitOMPExecutableDirective(S);
877 void StmtProfiler::VisitOMPTargetParallelDirective(
878 const OMPTargetParallelDirective *S) {
879 VisitOMPExecutableDirective(S);
882 void StmtProfiler::VisitOMPTargetParallelForDirective(
883 const OMPTargetParallelForDirective *S) {
884 VisitOMPExecutableDirective(S);
887 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
888 VisitOMPExecutableDirective(S);
891 void StmtProfiler::VisitOMPCancellationPointDirective(
892 const OMPCancellationPointDirective *S) {
893 VisitOMPExecutableDirective(S);
896 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
897 VisitOMPExecutableDirective(S);
900 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
901 VisitOMPLoopDirective(S);
904 void StmtProfiler::VisitOMPTaskLoopSimdDirective(
905 const OMPTaskLoopSimdDirective *S) {
906 VisitOMPLoopDirective(S);
909 void StmtProfiler::VisitOMPDistributeDirective(
910 const OMPDistributeDirective *S) {
911 VisitOMPLoopDirective(S);
914 void OMPClauseProfiler::VisitOMPDistScheduleClause(
915 const OMPDistScheduleClause *C) {
916 VistOMPClauseWithPreInit(C);
917 if (auto *S = C->getChunkSize())
918 Profiler->VisitStmt(S);
921 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
923 void StmtProfiler::VisitOMPTargetUpdateDirective(
924 const OMPTargetUpdateDirective *S) {
925 VisitOMPExecutableDirective(S);
928 void StmtProfiler::VisitOMPDistributeParallelForDirective(
929 const OMPDistributeParallelForDirective *S) {
930 VisitOMPLoopDirective(S);
933 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
934 const OMPDistributeParallelForSimdDirective *S) {
935 VisitOMPLoopDirective(S);
938 void StmtProfiler::VisitOMPDistributeSimdDirective(
939 const OMPDistributeSimdDirective *S) {
940 VisitOMPLoopDirective(S);
943 void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
944 const OMPTargetParallelForSimdDirective *S) {
945 VisitOMPLoopDirective(S);
948 void StmtProfiler::VisitOMPTargetSimdDirective(
949 const OMPTargetSimdDirective *S) {
950 VisitOMPLoopDirective(S);
953 void StmtProfiler::VisitOMPTeamsDistributeDirective(
954 const OMPTeamsDistributeDirective *S) {
955 VisitOMPLoopDirective(S);
958 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
959 const OMPTeamsDistributeSimdDirective *S) {
960 VisitOMPLoopDirective(S);
963 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
964 const OMPTeamsDistributeParallelForSimdDirective *S) {
965 VisitOMPLoopDirective(S);
968 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
969 const OMPTeamsDistributeParallelForDirective *S) {
970 VisitOMPLoopDirective(S);
973 void StmtProfiler::VisitOMPTargetTeamsDirective(
974 const OMPTargetTeamsDirective *S) {
975 VisitOMPExecutableDirective(S);
978 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
979 const OMPTargetTeamsDistributeDirective *S) {
980 VisitOMPLoopDirective(S);
983 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
984 const OMPTargetTeamsDistributeParallelForDirective *S) {
985 VisitOMPLoopDirective(S);
988 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
989 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
990 VisitOMPLoopDirective(S);
993 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
994 const OMPTargetTeamsDistributeSimdDirective *S) {
995 VisitOMPLoopDirective(S);
998 void StmtProfiler::VisitExpr(const Expr *S) {
1002 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1006 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
1009 VisitNestedNameSpecifier(S->getQualifier());
1010 VisitDecl(S->getDecl());
1012 ID.AddBoolean(S->hasExplicitTemplateArgs());
1013 if (S->hasExplicitTemplateArgs())
1014 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1018 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
1020 ID.AddInteger(S->getIdentKind());
1023 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
1025 S->getValue().Profile(ID);
1026 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1029 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1031 S->getValue().Profile(ID);
1032 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1035 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
1037 ID.AddInteger(S->getKind());
1038 ID.AddInteger(S->getValue());
1041 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
1043 S->getValue().Profile(ID);
1044 ID.AddBoolean(S->isExact());
1045 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1048 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
1052 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
1054 ID.AddString(S->getBytes());
1055 ID.AddInteger(S->getKind());
1058 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
1062 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
1066 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
1068 ID.AddInteger(S->getOpcode());
1071 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
1072 VisitType(S->getTypeSourceInfo()->getType());
1073 unsigned n = S->getNumComponents();
1074 for (unsigned i = 0; i < n; ++i) {
1075 const OffsetOfNode &ON = S->getComponent(i);
1076 ID.AddInteger(ON.getKind());
1077 switch (ON.getKind()) {
1078 case OffsetOfNode::Array:
1079 // Expressions handled below.
1082 case OffsetOfNode::Field:
1083 VisitDecl(ON.getField());
1086 case OffsetOfNode::Identifier:
1087 VisitIdentifierInfo(ON.getFieldName());
1090 case OffsetOfNode::Base:
1091 // These nodes are implicit, and therefore don't need profiling.
1100 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
1102 ID.AddInteger(S->getKind());
1103 if (S->isArgumentType())
1104 VisitType(S->getArgumentType());
1107 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
1111 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1115 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
1119 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
1121 VisitDecl(S->getMemberDecl());
1123 VisitNestedNameSpecifier(S->getQualifier());
1124 ID.AddBoolean(S->isArrow());
1127 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
1129 ID.AddBoolean(S->isFileScope());
1132 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
1136 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
1138 ID.AddInteger(S->getValueKind());
1141 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
1143 VisitType(S->getTypeAsWritten());
1146 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
1147 VisitExplicitCastExpr(S);
1150 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
1152 ID.AddInteger(S->getOpcode());
1156 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
1157 VisitBinaryOperator(S);
1160 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
1164 void StmtProfiler::VisitBinaryConditionalOperator(
1165 const BinaryConditionalOperator *S) {
1169 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
1171 VisitDecl(S->getLabel());
1174 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
1178 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
1182 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1186 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
1190 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
1194 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
1198 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
1199 if (S->getSyntacticForm()) {
1200 VisitInitListExpr(S->getSyntacticForm());
1207 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
1209 ID.AddBoolean(S->usesGNUSyntax());
1210 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1211 if (D.isFieldDesignator()) {
1213 VisitName(D.getFieldName());
1217 if (D.isArrayDesignator()) {
1220 assert(D.isArrayRangeDesignator());
1223 ID.AddInteger(D.getFirstExprIndex());
1227 // Seems that if VisitInitListExpr() only works on the syntactic form of an
1228 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1229 void StmtProfiler::VisitDesignatedInitUpdateExpr(
1230 const DesignatedInitUpdateExpr *S) {
1231 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1235 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1239 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1243 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1244 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1247 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
1251 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
1253 VisitName(&S->getAccessor());
1256 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
1258 VisitDecl(S->getBlockDecl());
1261 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
1263 for (unsigned i = 0; i != S->getNumAssocs(); ++i) {
1264 QualType T = S->getAssocType(i);
1266 ID.AddPointer(nullptr);
1269 VisitExpr(S->getAssocExpr(i));
1273 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1275 for (PseudoObjectExpr::const_semantics_iterator
1276 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1277 // Normally, we would not profile the source expressions of OVEs.
1278 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1279 Visit(OVE->getSourceExpr());
1282 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1284 ID.AddInteger(S->getOp());
1287 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
1288 UnaryOperatorKind &UnaryOp,
1289 BinaryOperatorKind &BinaryOp) {
1290 switch (S->getOperator()) {
1295 case OO_Array_Delete:
1298 case OO_Conditional:
1299 case NUM_OVERLOADED_OPERATORS:
1300 llvm_unreachable("Invalid operator call kind");
1303 if (S->getNumArgs() == 1) {
1305 return Stmt::UnaryOperatorClass;
1309 return Stmt::BinaryOperatorClass;
1312 if (S->getNumArgs() == 1) {
1314 return Stmt::UnaryOperatorClass;
1318 return Stmt::BinaryOperatorClass;
1321 if (S->getNumArgs() == 1) {
1323 return Stmt::UnaryOperatorClass;
1327 return Stmt::BinaryOperatorClass;
1331 return Stmt::BinaryOperatorClass;
1335 return Stmt::BinaryOperatorClass;
1339 return Stmt::BinaryOperatorClass;
1342 if (S->getNumArgs() == 1) {
1343 UnaryOp = UO_AddrOf;
1344 return Stmt::UnaryOperatorClass;
1348 return Stmt::BinaryOperatorClass;
1352 return Stmt::BinaryOperatorClass;
1356 return Stmt::UnaryOperatorClass;
1360 return Stmt::UnaryOperatorClass;
1363 BinaryOp = BO_Assign;
1364 return Stmt::BinaryOperatorClass;
1368 return Stmt::BinaryOperatorClass;
1372 return Stmt::BinaryOperatorClass;
1375 BinaryOp = BO_AddAssign;
1376 return Stmt::CompoundAssignOperatorClass;
1379 BinaryOp = BO_SubAssign;
1380 return Stmt::CompoundAssignOperatorClass;
1383 BinaryOp = BO_MulAssign;
1384 return Stmt::CompoundAssignOperatorClass;
1387 BinaryOp = BO_DivAssign;
1388 return Stmt::CompoundAssignOperatorClass;
1390 case OO_PercentEqual:
1391 BinaryOp = BO_RemAssign;
1392 return Stmt::CompoundAssignOperatorClass;
1395 BinaryOp = BO_XorAssign;
1396 return Stmt::CompoundAssignOperatorClass;
1399 BinaryOp = BO_AndAssign;
1400 return Stmt::CompoundAssignOperatorClass;
1403 BinaryOp = BO_OrAssign;
1404 return Stmt::CompoundAssignOperatorClass;
1408 return Stmt::BinaryOperatorClass;
1410 case OO_GreaterGreater:
1412 return Stmt::BinaryOperatorClass;
1414 case OO_LessLessEqual:
1415 BinaryOp = BO_ShlAssign;
1416 return Stmt::CompoundAssignOperatorClass;
1418 case OO_GreaterGreaterEqual:
1419 BinaryOp = BO_ShrAssign;
1420 return Stmt::CompoundAssignOperatorClass;
1424 return Stmt::BinaryOperatorClass;
1426 case OO_ExclaimEqual:
1428 return Stmt::BinaryOperatorClass;
1432 return Stmt::BinaryOperatorClass;
1434 case OO_GreaterEqual:
1436 return Stmt::BinaryOperatorClass;
1439 // FIXME: Update this once we support <=> expressions.
1440 llvm_unreachable("<=> expressions not supported yet");
1444 return Stmt::BinaryOperatorClass;
1448 return Stmt::BinaryOperatorClass;
1451 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1453 return Stmt::UnaryOperatorClass;
1456 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1458 return Stmt::UnaryOperatorClass;
1461 BinaryOp = BO_Comma;
1462 return Stmt::BinaryOperatorClass;
1465 BinaryOp = BO_PtrMemI;
1466 return Stmt::BinaryOperatorClass;
1469 return Stmt::ArraySubscriptExprClass;
1472 UnaryOp = UO_Coawait;
1473 return Stmt::UnaryOperatorClass;
1476 llvm_unreachable("Invalid overloaded operator expression");
1479 #if defined(_MSC_VER) && !defined(__clang__)
1480 #if _MSC_VER == 1911
1481 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1482 // MSVC 2017 update 3 miscompiles this function, and a clang built with it
1483 // will crash in stage 2 of a bootstrap build.
1484 #pragma optimize("", off)
1488 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
1489 if (S->isTypeDependent()) {
1490 // Type-dependent operator calls are profiled like their underlying
1491 // syntactic operator.
1493 // An operator call to operator-> is always implicit, so just skip it. The
1494 // enclosing MemberExpr will profile the actual member access.
1495 if (S->getOperator() == OO_Arrow)
1496 return Visit(S->getArg(0));
1498 UnaryOperatorKind UnaryOp = UO_Extension;
1499 BinaryOperatorKind BinaryOp = BO_Comma;
1500 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
1503 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1504 Visit(S->getArg(I));
1505 if (SC == Stmt::UnaryOperatorClass)
1506 ID.AddInteger(UnaryOp);
1507 else if (SC == Stmt::BinaryOperatorClass ||
1508 SC == Stmt::CompoundAssignOperatorClass)
1509 ID.AddInteger(BinaryOp);
1511 assert(SC == Stmt::ArraySubscriptExprClass);
1517 ID.AddInteger(S->getOperator());
1520 #if defined(_MSC_VER) && !defined(__clang__)
1521 #if _MSC_VER == 1911
1522 #pragma optimize("", on)
1526 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
1530 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
1534 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
1538 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
1539 VisitExplicitCastExpr(S);
1542 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
1543 VisitCXXNamedCastExpr(S);
1546 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
1547 VisitCXXNamedCastExpr(S);
1551 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
1552 VisitCXXNamedCastExpr(S);
1555 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
1556 VisitCXXNamedCastExpr(S);
1559 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1563 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
1565 ID.AddBoolean(S->getValue());
1568 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
1572 void StmtProfiler::VisitCXXStdInitializerListExpr(
1573 const CXXStdInitializerListExpr *S) {
1577 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
1579 if (S->isTypeOperand())
1580 VisitType(S->getTypeOperandSourceInfo()->getType());
1583 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
1585 if (S->isTypeOperand())
1586 VisitType(S->getTypeOperandSourceInfo()->getType());
1589 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1591 VisitDecl(S->getPropertyDecl());
1594 void StmtProfiler::VisitMSPropertySubscriptExpr(
1595 const MSPropertySubscriptExpr *S) {
1599 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
1601 ID.AddBoolean(S->isImplicit());
1604 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
1608 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
1610 VisitDecl(S->getParam());
1613 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1615 VisitDecl(S->getField());
1618 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
1621 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1624 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
1626 VisitDecl(S->getConstructor());
1627 ID.AddBoolean(S->isElidable());
1630 void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1631 const CXXInheritedCtorInitExpr *S) {
1633 VisitDecl(S->getConstructor());
1636 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
1637 VisitExplicitCastExpr(S);
1641 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
1642 VisitCXXConstructExpr(S);
1646 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1648 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1649 CEnd = S->explicit_capture_end();
1651 if (C->capturesVLAType())
1654 ID.AddInteger(C->getCaptureKind());
1655 switch (C->getCaptureKind()) {
1661 VisitDecl(C->getCapturedVar());
1662 ID.AddBoolean(C->isPackExpansion());
1665 llvm_unreachable("VLA type in explicit captures.");
1668 // Note: If we actually needed to be able to match lambda
1669 // expressions, we would have to consider parameters and return type
1670 // here, among other things.
1671 VisitStmt(S->getBody());
1675 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
1679 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
1681 ID.AddBoolean(S->isGlobalDelete());
1682 ID.AddBoolean(S->isArrayForm());
1683 VisitDecl(S->getOperatorDelete());
1686 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
1688 VisitType(S->getAllocatedType());
1689 VisitDecl(S->getOperatorNew());
1690 VisitDecl(S->getOperatorDelete());
1691 ID.AddBoolean(S->isArray());
1692 ID.AddInteger(S->getNumPlacementArgs());
1693 ID.AddBoolean(S->isGlobalNew());
1694 ID.AddBoolean(S->isParenTypeId());
1695 ID.AddInteger(S->getInitializationStyle());
1699 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
1701 ID.AddBoolean(S->isArrow());
1702 VisitNestedNameSpecifier(S->getQualifier());
1703 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
1704 if (S->getScopeTypeInfo())
1705 VisitType(S->getScopeTypeInfo()->getType());
1706 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
1707 if (S->getDestroyedTypeInfo())
1708 VisitType(S->getDestroyedType());
1710 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
1713 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
1715 VisitNestedNameSpecifier(S->getQualifier());
1716 VisitName(S->getName(), /*TreatAsDecl*/ true);
1717 ID.AddBoolean(S->hasExplicitTemplateArgs());
1718 if (S->hasExplicitTemplateArgs())
1719 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1723 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
1724 VisitOverloadExpr(S);
1727 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1729 ID.AddInteger(S->getTrait());
1730 ID.AddInteger(S->getNumArgs());
1731 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1732 VisitType(S->getArg(I)->getType());
1735 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
1737 ID.AddInteger(S->getTrait());
1738 VisitType(S->getQueriedType());
1741 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
1743 ID.AddInteger(S->getTrait());
1744 VisitExpr(S->getQueriedExpression());
1747 void StmtProfiler::VisitDependentScopeDeclRefExpr(
1748 const DependentScopeDeclRefExpr *S) {
1750 VisitName(S->getDeclName());
1751 VisitNestedNameSpecifier(S->getQualifier());
1752 ID.AddBoolean(S->hasExplicitTemplateArgs());
1753 if (S->hasExplicitTemplateArgs())
1754 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1757 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
1761 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1762 const CXXUnresolvedConstructExpr *S) {
1764 VisitType(S->getTypeAsWritten());
1765 ID.AddInteger(S->isListInitialization());
1768 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1769 const CXXDependentScopeMemberExpr *S) {
1770 ID.AddBoolean(S->isImplicitAccess());
1771 if (!S->isImplicitAccess()) {
1773 ID.AddBoolean(S->isArrow());
1775 VisitNestedNameSpecifier(S->getQualifier());
1776 VisitName(S->getMember());
1777 ID.AddBoolean(S->hasExplicitTemplateArgs());
1778 if (S->hasExplicitTemplateArgs())
1779 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1782 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
1783 ID.AddBoolean(S->isImplicitAccess());
1784 if (!S->isImplicitAccess()) {
1786 ID.AddBoolean(S->isArrow());
1788 VisitNestedNameSpecifier(S->getQualifier());
1789 VisitName(S->getMemberName());
1790 ID.AddBoolean(S->hasExplicitTemplateArgs());
1791 if (S->hasExplicitTemplateArgs())
1792 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1795 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
1799 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
1803 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
1805 VisitDecl(S->getPack());
1806 if (S->isPartiallySubstituted()) {
1807 auto Args = S->getPartialArguments();
1808 ID.AddInteger(Args.size());
1809 for (const auto &TA : Args)
1810 VisitTemplateArgument(TA);
1816 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
1817 const SubstNonTypeTemplateParmPackExpr *S) {
1819 VisitDecl(S->getParameterPack());
1820 VisitTemplateArgument(S->getArgumentPack());
1823 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1824 const SubstNonTypeTemplateParmExpr *E) {
1825 // Profile exactly as the replacement expression.
1826 Visit(E->getReplacement());
1829 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1831 VisitDecl(S->getParameterPack());
1832 ID.AddInteger(S->getNumExpansions());
1833 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1837 void StmtProfiler::VisitMaterializeTemporaryExpr(
1838 const MaterializeTemporaryExpr *S) {
1842 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1844 ID.AddInteger(S->getOperator());
1847 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1851 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1855 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1859 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
1863 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1867 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
1871 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1875 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
1879 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
1883 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1887 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1891 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
1893 VisitType(S->getEncodedType());
1896 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
1898 VisitName(S->getSelector());
1901 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
1903 VisitDecl(S->getProtocol());
1906 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
1908 VisitDecl(S->getDecl());
1909 ID.AddBoolean(S->isArrow());
1910 ID.AddBoolean(S->isFreeIvar());
1913 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
1915 if (S->isImplicitProperty()) {
1916 VisitDecl(S->getImplicitPropertyGetter());
1917 VisitDecl(S->getImplicitPropertySetter());
1919 VisitDecl(S->getExplicitProperty());
1921 if (S->isSuperReceiver()) {
1922 ID.AddBoolean(S->isSuperReceiver());
1923 VisitType(S->getSuperReceiverType());
1927 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1929 VisitDecl(S->getAtIndexMethodDecl());
1930 VisitDecl(S->setAtIndexMethodDecl());
1933 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
1935 VisitName(S->getSelector());
1936 VisitDecl(S->getMethodDecl());
1939 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
1941 ID.AddBoolean(S->isArrow());
1944 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1946 ID.AddBoolean(S->getValue());
1949 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1950 const ObjCIndirectCopyRestoreExpr *S) {
1952 ID.AddBoolean(S->shouldCopy());
1955 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
1956 VisitExplicitCastExpr(S);
1957 ID.AddBoolean(S->getBridgeKind());
1960 void StmtProfiler::VisitObjCAvailabilityCheckExpr(
1961 const ObjCAvailabilityCheckExpr *S) {
1965 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
1967 ID.AddInteger(NumArgs);
1968 for (unsigned I = 0; I != NumArgs; ++I)
1969 VisitTemplateArgument(Args[I].getArgument());
1972 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1973 // Mostly repetitive with TemplateArgument::Profile!
1974 ID.AddInteger(Arg.getKind());
1975 switch (Arg.getKind()) {
1976 case TemplateArgument::Null:
1979 case TemplateArgument::Type:
1980 VisitType(Arg.getAsType());
1983 case TemplateArgument::Template:
1984 case TemplateArgument::TemplateExpansion:
1985 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
1988 case TemplateArgument::Declaration:
1989 VisitDecl(Arg.getAsDecl());
1992 case TemplateArgument::NullPtr:
1993 VisitType(Arg.getNullPtrType());
1996 case TemplateArgument::Integral:
1997 Arg.getAsIntegral().Profile(ID);
1998 VisitType(Arg.getIntegralType());
2001 case TemplateArgument::Expression:
2002 Visit(Arg.getAsExpr());
2005 case TemplateArgument::Pack:
2006 for (const auto &P : Arg.pack_elements())
2007 VisitTemplateArgument(P);
2012 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2013 bool Canonical) const {
2014 StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2015 Profiler.Visit(this);
2018 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2019 class ODRHash &Hash) const {
2020 StmtProfilerWithoutPointers Profiler(ID, Hash);
2021 Profiler.Visit(this);