1 //===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the Stmt::Profile method, which builds a unique bit
10 // representation that identifies a statement/expression.
12 //===----------------------------------------------------------------------===//
13 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/DeclCXX.h"
15 #include "clang/AST/DeclObjC.h"
16 #include "clang/AST/DeclTemplate.h"
17 #include "clang/AST/Expr.h"
18 #include "clang/AST/ExprCXX.h"
19 #include "clang/AST/ExprObjC.h"
20 #include "clang/AST/ExprOpenMP.h"
21 #include "clang/AST/ODRHash.h"
22 #include "clang/AST/StmtVisitor.h"
23 #include "llvm/ADT/FoldingSet.h"
24 using namespace clang;
27 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> {
29 llvm::FoldingSetNodeID &ID;
33 StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical)
34 : ID(ID), Canonical(Canonical) {}
36 virtual ~StmtProfiler() {}
38 void VisitStmt(const Stmt *S);
40 virtual void HandleStmtClass(Stmt::StmtClass SC) = 0;
42 #define STMT(Node, Base) void Visit##Node(const Node *S);
43 #include "clang/AST/StmtNodes.inc"
45 /// Visit a declaration that is referenced within an expression
47 virtual void VisitDecl(const Decl *D) = 0;
49 /// Visit a type that is referenced within an expression or
51 virtual void VisitType(QualType T) = 0;
53 /// Visit a name that occurs within an expression or statement.
54 virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0;
56 /// Visit identifiers that are not in Decl's or Type's.
57 virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0;
59 /// Visit a nested-name-specifier that occurs within an expression
61 virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0;
63 /// Visit a template name that occurs within an expression or
65 virtual void VisitTemplateName(TemplateName Name) = 0;
67 /// Visit template arguments that occur within an expression or
69 void VisitTemplateArguments(const TemplateArgumentLoc *Args,
72 /// Visit a single template argument.
73 void VisitTemplateArgument(const TemplateArgument &Arg);
76 class StmtProfilerWithPointers : public StmtProfiler {
77 const ASTContext &Context;
80 StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID,
81 const ASTContext &Context, bool Canonical)
82 : StmtProfiler(ID, Canonical), Context(Context) {}
84 void HandleStmtClass(Stmt::StmtClass SC) override {
88 void VisitDecl(const Decl *D) override {
89 ID.AddInteger(D ? D->getKind() : 0);
92 if (const NonTypeTemplateParmDecl *NTTP =
93 dyn_cast<NonTypeTemplateParmDecl>(D)) {
94 ID.AddInteger(NTTP->getDepth());
95 ID.AddInteger(NTTP->getIndex());
96 ID.AddBoolean(NTTP->isParameterPack());
97 VisitType(NTTP->getType());
101 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) {
102 // The Itanium C++ ABI uses the type, scope depth, and scope
103 // index of a parameter when mangling expressions that involve
104 // function parameters, so we will use the parameter's type for
105 // establishing function parameter identity. That way, our
106 // definition of "equivalent" (per C++ [temp.over.link]) is at
107 // least as strong as the definition of "equivalent" used for
109 VisitType(Parm->getType());
110 ID.AddInteger(Parm->getFunctionScopeDepth());
111 ID.AddInteger(Parm->getFunctionScopeIndex());
115 if (const TemplateTypeParmDecl *TTP =
116 dyn_cast<TemplateTypeParmDecl>(D)) {
117 ID.AddInteger(TTP->getDepth());
118 ID.AddInteger(TTP->getIndex());
119 ID.AddBoolean(TTP->isParameterPack());
123 if (const TemplateTemplateParmDecl *TTP =
124 dyn_cast<TemplateTemplateParmDecl>(D)) {
125 ID.AddInteger(TTP->getDepth());
126 ID.AddInteger(TTP->getIndex());
127 ID.AddBoolean(TTP->isParameterPack());
132 ID.AddPointer(D ? D->getCanonicalDecl() : nullptr);
135 void VisitType(QualType T) override {
136 if (Canonical && !T.isNull())
137 T = Context.getCanonicalType(T);
139 ID.AddPointer(T.getAsOpaquePtr());
142 void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override {
143 ID.AddPointer(Name.getAsOpaquePtr());
146 void VisitIdentifierInfo(IdentifierInfo *II) override {
150 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
152 NNS = Context.getCanonicalNestedNameSpecifier(NNS);
156 void VisitTemplateName(TemplateName Name) override {
158 Name = Context.getCanonicalTemplateName(Name);
164 class StmtProfilerWithoutPointers : public StmtProfiler {
167 StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash)
168 : StmtProfiler(ID, false), Hash(Hash) {}
171 void HandleStmtClass(Stmt::StmtClass SC) override {
172 if (SC == Stmt::UnresolvedLookupExprClass) {
173 // Pretend that the name looked up is a Decl due to how templates
174 // handle some Decl lookups.
175 ID.AddInteger(Stmt::DeclRefExprClass);
181 void VisitType(QualType T) override {
185 void VisitName(DeclarationName Name, bool TreatAsDecl) override {
187 // A Decl can be null, so each Decl is preceded by a boolean to
188 // store its nullness. Add a boolean here to match.
191 Hash.AddDeclarationName(Name, TreatAsDecl);
193 void VisitIdentifierInfo(IdentifierInfo *II) override {
196 Hash.AddIdentifierInfo(II);
199 void VisitDecl(const Decl *D) override {
205 void VisitTemplateName(TemplateName Name) override {
206 Hash.AddTemplateName(Name);
208 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override {
211 Hash.AddNestedNameSpecifier(NNS);
217 void StmtProfiler::VisitStmt(const Stmt *S) {
218 assert(S && "Requires non-null Stmt pointer");
220 HandleStmtClass(S->getStmtClass());
222 for (const Stmt *SubStmt : S->children()) {
230 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) {
232 for (const auto *D : S->decls())
236 void StmtProfiler::VisitNullStmt(const NullStmt *S) {
240 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) {
244 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) {
248 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) {
252 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) {
254 VisitDecl(S->getDecl());
257 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) {
259 // TODO: maybe visit attributes?
262 void StmtProfiler::VisitIfStmt(const IfStmt *S) {
264 VisitDecl(S->getConditionVariable());
267 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) {
269 VisitDecl(S->getConditionVariable());
272 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) {
274 VisitDecl(S->getConditionVariable());
277 void StmtProfiler::VisitDoStmt(const DoStmt *S) {
281 void StmtProfiler::VisitForStmt(const ForStmt *S) {
285 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) {
287 VisitDecl(S->getLabel());
290 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) {
294 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) {
298 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) {
302 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) {
306 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) {
308 ID.AddBoolean(S->isVolatile());
309 ID.AddBoolean(S->isSimple());
310 VisitStringLiteral(S->getAsmString());
311 ID.AddInteger(S->getNumOutputs());
312 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) {
313 ID.AddString(S->getOutputName(I));
314 VisitStringLiteral(S->getOutputConstraintLiteral(I));
316 ID.AddInteger(S->getNumInputs());
317 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) {
318 ID.AddString(S->getInputName(I));
319 VisitStringLiteral(S->getInputConstraintLiteral(I));
321 ID.AddInteger(S->getNumClobbers());
322 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I)
323 VisitStringLiteral(S->getClobberStringLiteral(I));
324 ID.AddInteger(S->getNumLabels());
325 for (auto *L : S->labels())
326 VisitDecl(L->getLabel());
329 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) {
330 // FIXME: Implement MS style inline asm statement profiler.
334 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) {
336 VisitType(S->getCaughtType());
339 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) {
343 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) {
347 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) {
349 ID.AddBoolean(S->isIfExists());
350 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier());
351 VisitName(S->getNameInfo().getName());
354 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) {
358 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) {
362 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) {
366 void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) {
370 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) {
374 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) {
378 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) {
380 ID.AddBoolean(S->hasEllipsis());
381 if (S->getCatchParamDecl())
382 VisitType(S->getCatchParamDecl()->getType());
385 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) {
389 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) {
394 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) {
398 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) {
403 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) {
408 class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> {
409 StmtProfiler *Profiler;
410 /// Process clauses with list of variables.
411 template <typename T>
412 void VisitOMPClauseList(T *Node);
415 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { }
416 #define OPENMP_CLAUSE(Name, Class) \
417 void Visit##Class(const Class *C);
418 #include "clang/Basic/OpenMPKinds.def"
419 void VistOMPClauseWithPreInit(const OMPClauseWithPreInit *C);
420 void VistOMPClauseWithPostUpdate(const OMPClauseWithPostUpdate *C);
423 void OMPClauseProfiler::VistOMPClauseWithPreInit(
424 const OMPClauseWithPreInit *C) {
425 if (auto *S = C->getPreInitStmt())
426 Profiler->VisitStmt(S);
429 void OMPClauseProfiler::VistOMPClauseWithPostUpdate(
430 const OMPClauseWithPostUpdate *C) {
431 VistOMPClauseWithPreInit(C);
432 if (auto *E = C->getPostUpdateExpr())
433 Profiler->VisitStmt(E);
436 void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) {
437 VistOMPClauseWithPreInit(C);
438 if (C->getCondition())
439 Profiler->VisitStmt(C->getCondition());
442 void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) {
443 if (C->getCondition())
444 Profiler->VisitStmt(C->getCondition());
447 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
448 VistOMPClauseWithPreInit(C);
449 if (C->getNumThreads())
450 Profiler->VisitStmt(C->getNumThreads());
453 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
455 Profiler->VisitStmt(C->getSafelen());
458 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
460 Profiler->VisitStmt(C->getSimdlen());
463 void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
464 if (C->getAllocator())
465 Profiler->VisitStmt(C->getAllocator());
468 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
469 if (C->getNumForLoops())
470 Profiler->VisitStmt(C->getNumForLoops());
473 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
475 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
477 void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
478 const OMPUnifiedAddressClause *C) {}
480 void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
481 const OMPUnifiedSharedMemoryClause *C) {}
483 void OMPClauseProfiler::VisitOMPReverseOffloadClause(
484 const OMPReverseOffloadClause *C) {}
486 void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
487 const OMPDynamicAllocatorsClause *C) {}
489 void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
490 const OMPAtomicDefaultMemOrderClause *C) {}
492 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
493 VistOMPClauseWithPreInit(C);
494 if (auto *S = C->getChunkSize())
495 Profiler->VisitStmt(S);
498 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
499 if (auto *Num = C->getNumForLoops())
500 Profiler->VisitStmt(Num);
503 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
505 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
507 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
509 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
511 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
513 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
515 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
517 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
519 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
521 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
523 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
526 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
527 for (auto *E : Node->varlists()) {
529 Profiler->VisitStmt(E);
533 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
534 VisitOMPClauseList(C);
535 for (auto *E : C->private_copies()) {
537 Profiler->VisitStmt(E);
541 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
542 VisitOMPClauseList(C);
543 VistOMPClauseWithPreInit(C);
544 for (auto *E : C->private_copies()) {
546 Profiler->VisitStmt(E);
548 for (auto *E : C->inits()) {
550 Profiler->VisitStmt(E);
554 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
555 VisitOMPClauseList(C);
556 VistOMPClauseWithPostUpdate(C);
557 for (auto *E : C->source_exprs()) {
559 Profiler->VisitStmt(E);
561 for (auto *E : C->destination_exprs()) {
563 Profiler->VisitStmt(E);
565 for (auto *E : C->assignment_ops()) {
567 Profiler->VisitStmt(E);
570 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
571 VisitOMPClauseList(C);
573 void OMPClauseProfiler::VisitOMPReductionClause(
574 const OMPReductionClause *C) {
575 Profiler->VisitNestedNameSpecifier(
576 C->getQualifierLoc().getNestedNameSpecifier());
577 Profiler->VisitName(C->getNameInfo().getName());
578 VisitOMPClauseList(C);
579 VistOMPClauseWithPostUpdate(C);
580 for (auto *E : C->privates()) {
582 Profiler->VisitStmt(E);
584 for (auto *E : C->lhs_exprs()) {
586 Profiler->VisitStmt(E);
588 for (auto *E : C->rhs_exprs()) {
590 Profiler->VisitStmt(E);
592 for (auto *E : C->reduction_ops()) {
594 Profiler->VisitStmt(E);
597 void OMPClauseProfiler::VisitOMPTaskReductionClause(
598 const OMPTaskReductionClause *C) {
599 Profiler->VisitNestedNameSpecifier(
600 C->getQualifierLoc().getNestedNameSpecifier());
601 Profiler->VisitName(C->getNameInfo().getName());
602 VisitOMPClauseList(C);
603 VistOMPClauseWithPostUpdate(C);
604 for (auto *E : C->privates()) {
606 Profiler->VisitStmt(E);
608 for (auto *E : C->lhs_exprs()) {
610 Profiler->VisitStmt(E);
612 for (auto *E : C->rhs_exprs()) {
614 Profiler->VisitStmt(E);
616 for (auto *E : C->reduction_ops()) {
618 Profiler->VisitStmt(E);
621 void OMPClauseProfiler::VisitOMPInReductionClause(
622 const OMPInReductionClause *C) {
623 Profiler->VisitNestedNameSpecifier(
624 C->getQualifierLoc().getNestedNameSpecifier());
625 Profiler->VisitName(C->getNameInfo().getName());
626 VisitOMPClauseList(C);
627 VistOMPClauseWithPostUpdate(C);
628 for (auto *E : C->privates()) {
630 Profiler->VisitStmt(E);
632 for (auto *E : C->lhs_exprs()) {
634 Profiler->VisitStmt(E);
636 for (auto *E : C->rhs_exprs()) {
638 Profiler->VisitStmt(E);
640 for (auto *E : C->reduction_ops()) {
642 Profiler->VisitStmt(E);
644 for (auto *E : C->taskgroup_descriptors()) {
646 Profiler->VisitStmt(E);
649 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
650 VisitOMPClauseList(C);
651 VistOMPClauseWithPostUpdate(C);
652 for (auto *E : C->privates()) {
654 Profiler->VisitStmt(E);
656 for (auto *E : C->inits()) {
658 Profiler->VisitStmt(E);
660 for (auto *E : C->updates()) {
662 Profiler->VisitStmt(E);
664 for (auto *E : C->finals()) {
666 Profiler->VisitStmt(E);
669 Profiler->VisitStmt(C->getStep());
670 if (C->getCalcStep())
671 Profiler->VisitStmt(C->getCalcStep());
673 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
674 VisitOMPClauseList(C);
675 if (C->getAlignment())
676 Profiler->VisitStmt(C->getAlignment());
678 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
679 VisitOMPClauseList(C);
680 for (auto *E : C->source_exprs()) {
682 Profiler->VisitStmt(E);
684 for (auto *E : C->destination_exprs()) {
686 Profiler->VisitStmt(E);
688 for (auto *E : C->assignment_ops()) {
690 Profiler->VisitStmt(E);
694 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
695 VisitOMPClauseList(C);
696 for (auto *E : C->source_exprs()) {
698 Profiler->VisitStmt(E);
700 for (auto *E : C->destination_exprs()) {
702 Profiler->VisitStmt(E);
704 for (auto *E : C->assignment_ops()) {
706 Profiler->VisitStmt(E);
709 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
710 VisitOMPClauseList(C);
712 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
713 VisitOMPClauseList(C);
715 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
717 Profiler->VisitStmt(C->getDevice());
719 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
720 VisitOMPClauseList(C);
722 void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
723 if (Expr *Allocator = C->getAllocator())
724 Profiler->VisitStmt(Allocator);
725 VisitOMPClauseList(C);
727 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
728 VistOMPClauseWithPreInit(C);
729 if (C->getNumTeams())
730 Profiler->VisitStmt(C->getNumTeams());
732 void OMPClauseProfiler::VisitOMPThreadLimitClause(
733 const OMPThreadLimitClause *C) {
734 VistOMPClauseWithPreInit(C);
735 if (C->getThreadLimit())
736 Profiler->VisitStmt(C->getThreadLimit());
738 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
739 if (C->getPriority())
740 Profiler->VisitStmt(C->getPriority());
742 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
743 if (C->getGrainsize())
744 Profiler->VisitStmt(C->getGrainsize());
746 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
747 if (C->getNumTasks())
748 Profiler->VisitStmt(C->getNumTasks());
750 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
752 Profiler->VisitStmt(C->getHint());
754 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
755 VisitOMPClauseList(C);
757 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
758 VisitOMPClauseList(C);
760 void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
761 const OMPUseDevicePtrClause *C) {
762 VisitOMPClauseList(C);
764 void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
765 const OMPIsDevicePtrClause *C) {
766 VisitOMPClauseList(C);
771 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
773 OMPClauseProfiler P(this);
774 ArrayRef<OMPClause *> Clauses = S->clauses();
775 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
781 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
782 VisitOMPExecutableDirective(S);
785 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
786 VisitOMPExecutableDirective(S);
789 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
790 VisitOMPLoopDirective(S);
793 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
794 VisitOMPLoopDirective(S);
797 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
798 VisitOMPLoopDirective(S);
801 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
802 VisitOMPExecutableDirective(S);
805 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
806 VisitOMPExecutableDirective(S);
809 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
810 VisitOMPExecutableDirective(S);
813 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
814 VisitOMPExecutableDirective(S);
817 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
818 VisitOMPExecutableDirective(S);
819 VisitName(S->getDirectiveName().getName());
823 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
824 VisitOMPLoopDirective(S);
827 void StmtProfiler::VisitOMPParallelForSimdDirective(
828 const OMPParallelForSimdDirective *S) {
829 VisitOMPLoopDirective(S);
832 void StmtProfiler::VisitOMPParallelSectionsDirective(
833 const OMPParallelSectionsDirective *S) {
834 VisitOMPExecutableDirective(S);
837 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
838 VisitOMPExecutableDirective(S);
841 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
842 VisitOMPExecutableDirective(S);
845 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
846 VisitOMPExecutableDirective(S);
849 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
850 VisitOMPExecutableDirective(S);
853 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
854 VisitOMPExecutableDirective(S);
855 if (const Expr *E = S->getReductionRef())
859 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
860 VisitOMPExecutableDirective(S);
863 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
864 VisitOMPExecutableDirective(S);
867 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
868 VisitOMPExecutableDirective(S);
871 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
872 VisitOMPExecutableDirective(S);
875 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
876 VisitOMPExecutableDirective(S);
879 void StmtProfiler::VisitOMPTargetEnterDataDirective(
880 const OMPTargetEnterDataDirective *S) {
881 VisitOMPExecutableDirective(S);
884 void StmtProfiler::VisitOMPTargetExitDataDirective(
885 const OMPTargetExitDataDirective *S) {
886 VisitOMPExecutableDirective(S);
889 void StmtProfiler::VisitOMPTargetParallelDirective(
890 const OMPTargetParallelDirective *S) {
891 VisitOMPExecutableDirective(S);
894 void StmtProfiler::VisitOMPTargetParallelForDirective(
895 const OMPTargetParallelForDirective *S) {
896 VisitOMPExecutableDirective(S);
899 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
900 VisitOMPExecutableDirective(S);
903 void StmtProfiler::VisitOMPCancellationPointDirective(
904 const OMPCancellationPointDirective *S) {
905 VisitOMPExecutableDirective(S);
908 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
909 VisitOMPExecutableDirective(S);
912 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
913 VisitOMPLoopDirective(S);
916 void StmtProfiler::VisitOMPTaskLoopSimdDirective(
917 const OMPTaskLoopSimdDirective *S) {
918 VisitOMPLoopDirective(S);
921 void StmtProfiler::VisitOMPDistributeDirective(
922 const OMPDistributeDirective *S) {
923 VisitOMPLoopDirective(S);
926 void OMPClauseProfiler::VisitOMPDistScheduleClause(
927 const OMPDistScheduleClause *C) {
928 VistOMPClauseWithPreInit(C);
929 if (auto *S = C->getChunkSize())
930 Profiler->VisitStmt(S);
933 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
935 void StmtProfiler::VisitOMPTargetUpdateDirective(
936 const OMPTargetUpdateDirective *S) {
937 VisitOMPExecutableDirective(S);
940 void StmtProfiler::VisitOMPDistributeParallelForDirective(
941 const OMPDistributeParallelForDirective *S) {
942 VisitOMPLoopDirective(S);
945 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
946 const OMPDistributeParallelForSimdDirective *S) {
947 VisitOMPLoopDirective(S);
950 void StmtProfiler::VisitOMPDistributeSimdDirective(
951 const OMPDistributeSimdDirective *S) {
952 VisitOMPLoopDirective(S);
955 void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
956 const OMPTargetParallelForSimdDirective *S) {
957 VisitOMPLoopDirective(S);
960 void StmtProfiler::VisitOMPTargetSimdDirective(
961 const OMPTargetSimdDirective *S) {
962 VisitOMPLoopDirective(S);
965 void StmtProfiler::VisitOMPTeamsDistributeDirective(
966 const OMPTeamsDistributeDirective *S) {
967 VisitOMPLoopDirective(S);
970 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
971 const OMPTeamsDistributeSimdDirective *S) {
972 VisitOMPLoopDirective(S);
975 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
976 const OMPTeamsDistributeParallelForSimdDirective *S) {
977 VisitOMPLoopDirective(S);
980 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
981 const OMPTeamsDistributeParallelForDirective *S) {
982 VisitOMPLoopDirective(S);
985 void StmtProfiler::VisitOMPTargetTeamsDirective(
986 const OMPTargetTeamsDirective *S) {
987 VisitOMPExecutableDirective(S);
990 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
991 const OMPTargetTeamsDistributeDirective *S) {
992 VisitOMPLoopDirective(S);
995 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
996 const OMPTargetTeamsDistributeParallelForDirective *S) {
997 VisitOMPLoopDirective(S);
1000 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1001 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
1002 VisitOMPLoopDirective(S);
1005 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
1006 const OMPTargetTeamsDistributeSimdDirective *S) {
1007 VisitOMPLoopDirective(S);
1010 void StmtProfiler::VisitExpr(const Expr *S) {
1014 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1018 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
1021 VisitNestedNameSpecifier(S->getQualifier());
1022 VisitDecl(S->getDecl());
1024 ID.AddBoolean(S->hasExplicitTemplateArgs());
1025 if (S->hasExplicitTemplateArgs())
1026 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1030 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
1032 ID.AddInteger(S->getIdentKind());
1035 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
1037 S->getValue().Profile(ID);
1038 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1041 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1043 S->getValue().Profile(ID);
1044 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1047 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
1049 ID.AddInteger(S->getKind());
1050 ID.AddInteger(S->getValue());
1053 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
1055 S->getValue().Profile(ID);
1056 ID.AddBoolean(S->isExact());
1057 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1060 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
1064 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
1066 ID.AddString(S->getBytes());
1067 ID.AddInteger(S->getKind());
1070 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
1074 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
1078 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
1080 ID.AddInteger(S->getOpcode());
1083 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
1084 VisitType(S->getTypeSourceInfo()->getType());
1085 unsigned n = S->getNumComponents();
1086 for (unsigned i = 0; i < n; ++i) {
1087 const OffsetOfNode &ON = S->getComponent(i);
1088 ID.AddInteger(ON.getKind());
1089 switch (ON.getKind()) {
1090 case OffsetOfNode::Array:
1091 // Expressions handled below.
1094 case OffsetOfNode::Field:
1095 VisitDecl(ON.getField());
1098 case OffsetOfNode::Identifier:
1099 VisitIdentifierInfo(ON.getFieldName());
1102 case OffsetOfNode::Base:
1103 // These nodes are implicit, and therefore don't need profiling.
1112 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
1114 ID.AddInteger(S->getKind());
1115 if (S->isArgumentType())
1116 VisitType(S->getArgumentType());
1119 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
1123 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1127 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
1131 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
1133 VisitDecl(S->getMemberDecl());
1135 VisitNestedNameSpecifier(S->getQualifier());
1136 ID.AddBoolean(S->isArrow());
1139 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
1141 ID.AddBoolean(S->isFileScope());
1144 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
1148 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
1150 ID.AddInteger(S->getValueKind());
1153 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
1155 VisitType(S->getTypeAsWritten());
1158 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
1159 VisitExplicitCastExpr(S);
1162 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
1164 ID.AddInteger(S->getOpcode());
1168 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
1169 VisitBinaryOperator(S);
1172 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
1176 void StmtProfiler::VisitBinaryConditionalOperator(
1177 const BinaryConditionalOperator *S) {
1181 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
1183 VisitDecl(S->getLabel());
1186 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
1190 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
1194 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1198 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
1202 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
1206 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
1210 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
1211 if (S->getSyntacticForm()) {
1212 VisitInitListExpr(S->getSyntacticForm());
1219 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
1221 ID.AddBoolean(S->usesGNUSyntax());
1222 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1223 if (D.isFieldDesignator()) {
1225 VisitName(D.getFieldName());
1229 if (D.isArrayDesignator()) {
1232 assert(D.isArrayRangeDesignator());
1235 ID.AddInteger(D.getFirstExprIndex());
1239 // Seems that if VisitInitListExpr() only works on the syntactic form of an
1240 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1241 void StmtProfiler::VisitDesignatedInitUpdateExpr(
1242 const DesignatedInitUpdateExpr *S) {
1243 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1247 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1251 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1255 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1256 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1259 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
1263 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
1265 VisitName(&S->getAccessor());
1268 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
1270 VisitDecl(S->getBlockDecl());
1273 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
1275 for (const GenericSelectionExpr::ConstAssociation &Assoc :
1276 S->associations()) {
1277 QualType T = Assoc.getType();
1279 ID.AddPointer(nullptr);
1282 VisitExpr(Assoc.getAssociationExpr());
1286 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1288 for (PseudoObjectExpr::const_semantics_iterator
1289 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1290 // Normally, we would not profile the source expressions of OVEs.
1291 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1292 Visit(OVE->getSourceExpr());
1295 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1297 ID.AddInteger(S->getOp());
1300 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
1301 UnaryOperatorKind &UnaryOp,
1302 BinaryOperatorKind &BinaryOp) {
1303 switch (S->getOperator()) {
1308 case OO_Array_Delete:
1311 case OO_Conditional:
1312 case NUM_OVERLOADED_OPERATORS:
1313 llvm_unreachable("Invalid operator call kind");
1316 if (S->getNumArgs() == 1) {
1318 return Stmt::UnaryOperatorClass;
1322 return Stmt::BinaryOperatorClass;
1325 if (S->getNumArgs() == 1) {
1327 return Stmt::UnaryOperatorClass;
1331 return Stmt::BinaryOperatorClass;
1334 if (S->getNumArgs() == 1) {
1336 return Stmt::UnaryOperatorClass;
1340 return Stmt::BinaryOperatorClass;
1344 return Stmt::BinaryOperatorClass;
1348 return Stmt::BinaryOperatorClass;
1352 return Stmt::BinaryOperatorClass;
1355 if (S->getNumArgs() == 1) {
1356 UnaryOp = UO_AddrOf;
1357 return Stmt::UnaryOperatorClass;
1361 return Stmt::BinaryOperatorClass;
1365 return Stmt::BinaryOperatorClass;
1369 return Stmt::UnaryOperatorClass;
1373 return Stmt::UnaryOperatorClass;
1376 BinaryOp = BO_Assign;
1377 return Stmt::BinaryOperatorClass;
1381 return Stmt::BinaryOperatorClass;
1385 return Stmt::BinaryOperatorClass;
1388 BinaryOp = BO_AddAssign;
1389 return Stmt::CompoundAssignOperatorClass;
1392 BinaryOp = BO_SubAssign;
1393 return Stmt::CompoundAssignOperatorClass;
1396 BinaryOp = BO_MulAssign;
1397 return Stmt::CompoundAssignOperatorClass;
1400 BinaryOp = BO_DivAssign;
1401 return Stmt::CompoundAssignOperatorClass;
1403 case OO_PercentEqual:
1404 BinaryOp = BO_RemAssign;
1405 return Stmt::CompoundAssignOperatorClass;
1408 BinaryOp = BO_XorAssign;
1409 return Stmt::CompoundAssignOperatorClass;
1412 BinaryOp = BO_AndAssign;
1413 return Stmt::CompoundAssignOperatorClass;
1416 BinaryOp = BO_OrAssign;
1417 return Stmt::CompoundAssignOperatorClass;
1421 return Stmt::BinaryOperatorClass;
1423 case OO_GreaterGreater:
1425 return Stmt::BinaryOperatorClass;
1427 case OO_LessLessEqual:
1428 BinaryOp = BO_ShlAssign;
1429 return Stmt::CompoundAssignOperatorClass;
1431 case OO_GreaterGreaterEqual:
1432 BinaryOp = BO_ShrAssign;
1433 return Stmt::CompoundAssignOperatorClass;
1437 return Stmt::BinaryOperatorClass;
1439 case OO_ExclaimEqual:
1441 return Stmt::BinaryOperatorClass;
1445 return Stmt::BinaryOperatorClass;
1447 case OO_GreaterEqual:
1449 return Stmt::BinaryOperatorClass;
1452 // FIXME: Update this once we support <=> expressions.
1453 llvm_unreachable("<=> expressions not supported yet");
1457 return Stmt::BinaryOperatorClass;
1461 return Stmt::BinaryOperatorClass;
1464 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1466 return Stmt::UnaryOperatorClass;
1469 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1471 return Stmt::UnaryOperatorClass;
1474 BinaryOp = BO_Comma;
1475 return Stmt::BinaryOperatorClass;
1478 BinaryOp = BO_PtrMemI;
1479 return Stmt::BinaryOperatorClass;
1482 return Stmt::ArraySubscriptExprClass;
1485 UnaryOp = UO_Coawait;
1486 return Stmt::UnaryOperatorClass;
1489 llvm_unreachable("Invalid overloaded operator expression");
1492 #if defined(_MSC_VER) && !defined(__clang__)
1493 #if _MSC_VER == 1911
1494 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1495 // MSVC 2017 update 3 miscompiles this function, and a clang built with it
1496 // will crash in stage 2 of a bootstrap build.
1497 #pragma optimize("", off)
1501 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
1502 if (S->isTypeDependent()) {
1503 // Type-dependent operator calls are profiled like their underlying
1504 // syntactic operator.
1506 // An operator call to operator-> is always implicit, so just skip it. The
1507 // enclosing MemberExpr will profile the actual member access.
1508 if (S->getOperator() == OO_Arrow)
1509 return Visit(S->getArg(0));
1511 UnaryOperatorKind UnaryOp = UO_Extension;
1512 BinaryOperatorKind BinaryOp = BO_Comma;
1513 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
1516 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1517 Visit(S->getArg(I));
1518 if (SC == Stmt::UnaryOperatorClass)
1519 ID.AddInteger(UnaryOp);
1520 else if (SC == Stmt::BinaryOperatorClass ||
1521 SC == Stmt::CompoundAssignOperatorClass)
1522 ID.AddInteger(BinaryOp);
1524 assert(SC == Stmt::ArraySubscriptExprClass);
1530 ID.AddInteger(S->getOperator());
1533 #if defined(_MSC_VER) && !defined(__clang__)
1534 #if _MSC_VER == 1911
1535 #pragma optimize("", on)
1539 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
1543 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
1547 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
1551 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
1552 VisitExplicitCastExpr(S);
1555 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
1556 VisitCXXNamedCastExpr(S);
1559 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
1560 VisitCXXNamedCastExpr(S);
1564 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
1565 VisitCXXNamedCastExpr(S);
1568 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
1569 VisitCXXNamedCastExpr(S);
1572 void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
1574 VisitType(S->getTypeInfoAsWritten()->getType());
1577 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1581 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
1583 ID.AddBoolean(S->getValue());
1586 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
1590 void StmtProfiler::VisitCXXStdInitializerListExpr(
1591 const CXXStdInitializerListExpr *S) {
1595 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
1597 if (S->isTypeOperand())
1598 VisitType(S->getTypeOperandSourceInfo()->getType());
1601 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
1603 if (S->isTypeOperand())
1604 VisitType(S->getTypeOperandSourceInfo()->getType());
1607 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1609 VisitDecl(S->getPropertyDecl());
1612 void StmtProfiler::VisitMSPropertySubscriptExpr(
1613 const MSPropertySubscriptExpr *S) {
1617 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
1619 ID.AddBoolean(S->isImplicit());
1622 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
1626 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
1628 VisitDecl(S->getParam());
1631 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1633 VisitDecl(S->getField());
1636 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
1639 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1642 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
1644 VisitDecl(S->getConstructor());
1645 ID.AddBoolean(S->isElidable());
1648 void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1649 const CXXInheritedCtorInitExpr *S) {
1651 VisitDecl(S->getConstructor());
1654 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
1655 VisitExplicitCastExpr(S);
1659 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
1660 VisitCXXConstructExpr(S);
1664 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1666 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1667 CEnd = S->explicit_capture_end();
1669 if (C->capturesVLAType())
1672 ID.AddInteger(C->getCaptureKind());
1673 switch (C->getCaptureKind()) {
1679 VisitDecl(C->getCapturedVar());
1680 ID.AddBoolean(C->isPackExpansion());
1683 llvm_unreachable("VLA type in explicit captures.");
1686 // Note: If we actually needed to be able to match lambda
1687 // expressions, we would have to consider parameters and return type
1688 // here, among other things.
1689 VisitStmt(S->getBody());
1693 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
1697 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
1699 ID.AddBoolean(S->isGlobalDelete());
1700 ID.AddBoolean(S->isArrayForm());
1701 VisitDecl(S->getOperatorDelete());
1704 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
1706 VisitType(S->getAllocatedType());
1707 VisitDecl(S->getOperatorNew());
1708 VisitDecl(S->getOperatorDelete());
1709 ID.AddBoolean(S->isArray());
1710 ID.AddInteger(S->getNumPlacementArgs());
1711 ID.AddBoolean(S->isGlobalNew());
1712 ID.AddBoolean(S->isParenTypeId());
1713 ID.AddInteger(S->getInitializationStyle());
1717 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
1719 ID.AddBoolean(S->isArrow());
1720 VisitNestedNameSpecifier(S->getQualifier());
1721 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
1722 if (S->getScopeTypeInfo())
1723 VisitType(S->getScopeTypeInfo()->getType());
1724 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
1725 if (S->getDestroyedTypeInfo())
1726 VisitType(S->getDestroyedType());
1728 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
1731 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
1733 VisitNestedNameSpecifier(S->getQualifier());
1734 VisitName(S->getName(), /*TreatAsDecl*/ true);
1735 ID.AddBoolean(S->hasExplicitTemplateArgs());
1736 if (S->hasExplicitTemplateArgs())
1737 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1741 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
1742 VisitOverloadExpr(S);
1745 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1747 ID.AddInteger(S->getTrait());
1748 ID.AddInteger(S->getNumArgs());
1749 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1750 VisitType(S->getArg(I)->getType());
1753 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
1755 ID.AddInteger(S->getTrait());
1756 VisitType(S->getQueriedType());
1759 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
1761 ID.AddInteger(S->getTrait());
1762 VisitExpr(S->getQueriedExpression());
1765 void StmtProfiler::VisitDependentScopeDeclRefExpr(
1766 const DependentScopeDeclRefExpr *S) {
1768 VisitName(S->getDeclName());
1769 VisitNestedNameSpecifier(S->getQualifier());
1770 ID.AddBoolean(S->hasExplicitTemplateArgs());
1771 if (S->hasExplicitTemplateArgs())
1772 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1775 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
1779 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1780 const CXXUnresolvedConstructExpr *S) {
1782 VisitType(S->getTypeAsWritten());
1783 ID.AddInteger(S->isListInitialization());
1786 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1787 const CXXDependentScopeMemberExpr *S) {
1788 ID.AddBoolean(S->isImplicitAccess());
1789 if (!S->isImplicitAccess()) {
1791 ID.AddBoolean(S->isArrow());
1793 VisitNestedNameSpecifier(S->getQualifier());
1794 VisitName(S->getMember());
1795 ID.AddBoolean(S->hasExplicitTemplateArgs());
1796 if (S->hasExplicitTemplateArgs())
1797 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1800 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
1801 ID.AddBoolean(S->isImplicitAccess());
1802 if (!S->isImplicitAccess()) {
1804 ID.AddBoolean(S->isArrow());
1806 VisitNestedNameSpecifier(S->getQualifier());
1807 VisitName(S->getMemberName());
1808 ID.AddBoolean(S->hasExplicitTemplateArgs());
1809 if (S->hasExplicitTemplateArgs())
1810 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1813 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
1817 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
1821 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
1823 VisitDecl(S->getPack());
1824 if (S->isPartiallySubstituted()) {
1825 auto Args = S->getPartialArguments();
1826 ID.AddInteger(Args.size());
1827 for (const auto &TA : Args)
1828 VisitTemplateArgument(TA);
1834 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
1835 const SubstNonTypeTemplateParmPackExpr *S) {
1837 VisitDecl(S->getParameterPack());
1838 VisitTemplateArgument(S->getArgumentPack());
1841 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1842 const SubstNonTypeTemplateParmExpr *E) {
1843 // Profile exactly as the replacement expression.
1844 Visit(E->getReplacement());
1847 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1849 VisitDecl(S->getParameterPack());
1850 ID.AddInteger(S->getNumExpansions());
1851 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1855 void StmtProfiler::VisitMaterializeTemporaryExpr(
1856 const MaterializeTemporaryExpr *S) {
1860 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1862 ID.AddInteger(S->getOperator());
1865 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1869 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1873 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1877 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
1881 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1885 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
1889 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1893 void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
1897 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
1901 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
1905 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
1909 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
1913 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
1915 VisitType(S->getEncodedType());
1918 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
1920 VisitName(S->getSelector());
1923 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
1925 VisitDecl(S->getProtocol());
1928 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
1930 VisitDecl(S->getDecl());
1931 ID.AddBoolean(S->isArrow());
1932 ID.AddBoolean(S->isFreeIvar());
1935 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
1937 if (S->isImplicitProperty()) {
1938 VisitDecl(S->getImplicitPropertyGetter());
1939 VisitDecl(S->getImplicitPropertySetter());
1941 VisitDecl(S->getExplicitProperty());
1943 if (S->isSuperReceiver()) {
1944 ID.AddBoolean(S->isSuperReceiver());
1945 VisitType(S->getSuperReceiverType());
1949 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
1951 VisitDecl(S->getAtIndexMethodDecl());
1952 VisitDecl(S->setAtIndexMethodDecl());
1955 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
1957 VisitName(S->getSelector());
1958 VisitDecl(S->getMethodDecl());
1961 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
1963 ID.AddBoolean(S->isArrow());
1966 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
1968 ID.AddBoolean(S->getValue());
1971 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
1972 const ObjCIndirectCopyRestoreExpr *S) {
1974 ID.AddBoolean(S->shouldCopy());
1977 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
1978 VisitExplicitCastExpr(S);
1979 ID.AddBoolean(S->getBridgeKind());
1982 void StmtProfiler::VisitObjCAvailabilityCheckExpr(
1983 const ObjCAvailabilityCheckExpr *S) {
1987 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
1989 ID.AddInteger(NumArgs);
1990 for (unsigned I = 0; I != NumArgs; ++I)
1991 VisitTemplateArgument(Args[I].getArgument());
1994 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
1995 // Mostly repetitive with TemplateArgument::Profile!
1996 ID.AddInteger(Arg.getKind());
1997 switch (Arg.getKind()) {
1998 case TemplateArgument::Null:
2001 case TemplateArgument::Type:
2002 VisitType(Arg.getAsType());
2005 case TemplateArgument::Template:
2006 case TemplateArgument::TemplateExpansion:
2007 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
2010 case TemplateArgument::Declaration:
2011 VisitDecl(Arg.getAsDecl());
2014 case TemplateArgument::NullPtr:
2015 VisitType(Arg.getNullPtrType());
2018 case TemplateArgument::Integral:
2019 Arg.getAsIntegral().Profile(ID);
2020 VisitType(Arg.getIntegralType());
2023 case TemplateArgument::Expression:
2024 Visit(Arg.getAsExpr());
2027 case TemplateArgument::Pack:
2028 for (const auto &P : Arg.pack_elements())
2029 VisitTemplateArgument(P);
2034 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2035 bool Canonical) const {
2036 StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2037 Profiler.Visit(this);
2040 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2041 class ODRHash &Hash) const {
2042 StmtProfilerWithoutPointers Profiler(ID, Hash);
2043 Profiler.Visit(this);