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 VistOMPClauseWithPreInit(C);
444 if (C->getCondition())
445 Profiler->VisitStmt(C->getCondition());
448 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) {
449 VistOMPClauseWithPreInit(C);
450 if (C->getNumThreads())
451 Profiler->VisitStmt(C->getNumThreads());
454 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) {
456 Profiler->VisitStmt(C->getSafelen());
459 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) {
461 Profiler->VisitStmt(C->getSimdlen());
464 void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) {
465 if (C->getAllocator())
466 Profiler->VisitStmt(C->getAllocator());
469 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) {
470 if (C->getNumForLoops())
471 Profiler->VisitStmt(C->getNumForLoops());
474 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { }
476 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { }
478 void OMPClauseProfiler::VisitOMPUnifiedAddressClause(
479 const OMPUnifiedAddressClause *C) {}
481 void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause(
482 const OMPUnifiedSharedMemoryClause *C) {}
484 void OMPClauseProfiler::VisitOMPReverseOffloadClause(
485 const OMPReverseOffloadClause *C) {}
487 void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause(
488 const OMPDynamicAllocatorsClause *C) {}
490 void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause(
491 const OMPAtomicDefaultMemOrderClause *C) {}
493 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) {
494 VistOMPClauseWithPreInit(C);
495 if (auto *S = C->getChunkSize())
496 Profiler->VisitStmt(S);
499 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) {
500 if (auto *Num = C->getNumForLoops())
501 Profiler->VisitStmt(Num);
504 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {}
506 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {}
508 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {}
510 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {}
512 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {}
514 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {}
516 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {}
518 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {}
520 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {}
522 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {}
524 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {}
527 void OMPClauseProfiler::VisitOMPClauseList(T *Node) {
528 for (auto *E : Node->varlists()) {
530 Profiler->VisitStmt(E);
534 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) {
535 VisitOMPClauseList(C);
536 for (auto *E : C->private_copies()) {
538 Profiler->VisitStmt(E);
542 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) {
543 VisitOMPClauseList(C);
544 VistOMPClauseWithPreInit(C);
545 for (auto *E : C->private_copies()) {
547 Profiler->VisitStmt(E);
549 for (auto *E : C->inits()) {
551 Profiler->VisitStmt(E);
555 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) {
556 VisitOMPClauseList(C);
557 VistOMPClauseWithPostUpdate(C);
558 for (auto *E : C->source_exprs()) {
560 Profiler->VisitStmt(E);
562 for (auto *E : C->destination_exprs()) {
564 Profiler->VisitStmt(E);
566 for (auto *E : C->assignment_ops()) {
568 Profiler->VisitStmt(E);
571 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) {
572 VisitOMPClauseList(C);
574 void OMPClauseProfiler::VisitOMPReductionClause(
575 const OMPReductionClause *C) {
576 Profiler->VisitNestedNameSpecifier(
577 C->getQualifierLoc().getNestedNameSpecifier());
578 Profiler->VisitName(C->getNameInfo().getName());
579 VisitOMPClauseList(C);
580 VistOMPClauseWithPostUpdate(C);
581 for (auto *E : C->privates()) {
583 Profiler->VisitStmt(E);
585 for (auto *E : C->lhs_exprs()) {
587 Profiler->VisitStmt(E);
589 for (auto *E : C->rhs_exprs()) {
591 Profiler->VisitStmt(E);
593 for (auto *E : C->reduction_ops()) {
595 Profiler->VisitStmt(E);
598 void OMPClauseProfiler::VisitOMPTaskReductionClause(
599 const OMPTaskReductionClause *C) {
600 Profiler->VisitNestedNameSpecifier(
601 C->getQualifierLoc().getNestedNameSpecifier());
602 Profiler->VisitName(C->getNameInfo().getName());
603 VisitOMPClauseList(C);
604 VistOMPClauseWithPostUpdate(C);
605 for (auto *E : C->privates()) {
607 Profiler->VisitStmt(E);
609 for (auto *E : C->lhs_exprs()) {
611 Profiler->VisitStmt(E);
613 for (auto *E : C->rhs_exprs()) {
615 Profiler->VisitStmt(E);
617 for (auto *E : C->reduction_ops()) {
619 Profiler->VisitStmt(E);
622 void OMPClauseProfiler::VisitOMPInReductionClause(
623 const OMPInReductionClause *C) {
624 Profiler->VisitNestedNameSpecifier(
625 C->getQualifierLoc().getNestedNameSpecifier());
626 Profiler->VisitName(C->getNameInfo().getName());
627 VisitOMPClauseList(C);
628 VistOMPClauseWithPostUpdate(C);
629 for (auto *E : C->privates()) {
631 Profiler->VisitStmt(E);
633 for (auto *E : C->lhs_exprs()) {
635 Profiler->VisitStmt(E);
637 for (auto *E : C->rhs_exprs()) {
639 Profiler->VisitStmt(E);
641 for (auto *E : C->reduction_ops()) {
643 Profiler->VisitStmt(E);
645 for (auto *E : C->taskgroup_descriptors()) {
647 Profiler->VisitStmt(E);
650 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) {
651 VisitOMPClauseList(C);
652 VistOMPClauseWithPostUpdate(C);
653 for (auto *E : C->privates()) {
655 Profiler->VisitStmt(E);
657 for (auto *E : C->inits()) {
659 Profiler->VisitStmt(E);
661 for (auto *E : C->updates()) {
663 Profiler->VisitStmt(E);
665 for (auto *E : C->finals()) {
667 Profiler->VisitStmt(E);
670 Profiler->VisitStmt(C->getStep());
671 if (C->getCalcStep())
672 Profiler->VisitStmt(C->getCalcStep());
674 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) {
675 VisitOMPClauseList(C);
676 if (C->getAlignment())
677 Profiler->VisitStmt(C->getAlignment());
679 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) {
680 VisitOMPClauseList(C);
681 for (auto *E : C->source_exprs()) {
683 Profiler->VisitStmt(E);
685 for (auto *E : C->destination_exprs()) {
687 Profiler->VisitStmt(E);
689 for (auto *E : C->assignment_ops()) {
691 Profiler->VisitStmt(E);
695 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) {
696 VisitOMPClauseList(C);
697 for (auto *E : C->source_exprs()) {
699 Profiler->VisitStmt(E);
701 for (auto *E : C->destination_exprs()) {
703 Profiler->VisitStmt(E);
705 for (auto *E : C->assignment_ops()) {
707 Profiler->VisitStmt(E);
710 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) {
711 VisitOMPClauseList(C);
713 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) {
714 VisitOMPClauseList(C);
716 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) {
718 Profiler->VisitStmt(C->getDevice());
720 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) {
721 VisitOMPClauseList(C);
723 void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) {
724 if (Expr *Allocator = C->getAllocator())
725 Profiler->VisitStmt(Allocator);
726 VisitOMPClauseList(C);
728 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) {
729 VistOMPClauseWithPreInit(C);
730 if (C->getNumTeams())
731 Profiler->VisitStmt(C->getNumTeams());
733 void OMPClauseProfiler::VisitOMPThreadLimitClause(
734 const OMPThreadLimitClause *C) {
735 VistOMPClauseWithPreInit(C);
736 if (C->getThreadLimit())
737 Profiler->VisitStmt(C->getThreadLimit());
739 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) {
740 VistOMPClauseWithPreInit(C);
741 if (C->getPriority())
742 Profiler->VisitStmt(C->getPriority());
744 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) {
745 VistOMPClauseWithPreInit(C);
746 if (C->getGrainsize())
747 Profiler->VisitStmt(C->getGrainsize());
749 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) {
750 VistOMPClauseWithPreInit(C);
751 if (C->getNumTasks())
752 Profiler->VisitStmt(C->getNumTasks());
754 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) {
756 Profiler->VisitStmt(C->getHint());
758 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) {
759 VisitOMPClauseList(C);
761 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) {
762 VisitOMPClauseList(C);
764 void OMPClauseProfiler::VisitOMPUseDevicePtrClause(
765 const OMPUseDevicePtrClause *C) {
766 VisitOMPClauseList(C);
768 void OMPClauseProfiler::VisitOMPIsDevicePtrClause(
769 const OMPIsDevicePtrClause *C) {
770 VisitOMPClauseList(C);
772 void OMPClauseProfiler::VisitOMPNontemporalClause(
773 const OMPNontemporalClause *C) {
774 VisitOMPClauseList(C);
775 for (auto *E : C->private_refs())
776 Profiler->VisitStmt(E);
781 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) {
783 OMPClauseProfiler P(this);
784 ArrayRef<OMPClause *> Clauses = S->clauses();
785 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
791 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) {
792 VisitOMPExecutableDirective(S);
795 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) {
796 VisitOMPExecutableDirective(S);
799 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) {
800 VisitOMPLoopDirective(S);
803 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) {
804 VisitOMPLoopDirective(S);
807 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) {
808 VisitOMPLoopDirective(S);
811 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) {
812 VisitOMPExecutableDirective(S);
815 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) {
816 VisitOMPExecutableDirective(S);
819 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) {
820 VisitOMPExecutableDirective(S);
823 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) {
824 VisitOMPExecutableDirective(S);
827 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) {
828 VisitOMPExecutableDirective(S);
829 VisitName(S->getDirectiveName().getName());
833 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) {
834 VisitOMPLoopDirective(S);
837 void StmtProfiler::VisitOMPParallelForSimdDirective(
838 const OMPParallelForSimdDirective *S) {
839 VisitOMPLoopDirective(S);
842 void StmtProfiler::VisitOMPParallelMasterDirective(
843 const OMPParallelMasterDirective *S) {
844 VisitOMPExecutableDirective(S);
847 void StmtProfiler::VisitOMPParallelSectionsDirective(
848 const OMPParallelSectionsDirective *S) {
849 VisitOMPExecutableDirective(S);
852 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) {
853 VisitOMPExecutableDirective(S);
856 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) {
857 VisitOMPExecutableDirective(S);
860 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) {
861 VisitOMPExecutableDirective(S);
864 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) {
865 VisitOMPExecutableDirective(S);
868 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) {
869 VisitOMPExecutableDirective(S);
870 if (const Expr *E = S->getReductionRef())
874 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) {
875 VisitOMPExecutableDirective(S);
878 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) {
879 VisitOMPExecutableDirective(S);
882 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) {
883 VisitOMPExecutableDirective(S);
886 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) {
887 VisitOMPExecutableDirective(S);
890 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) {
891 VisitOMPExecutableDirective(S);
894 void StmtProfiler::VisitOMPTargetEnterDataDirective(
895 const OMPTargetEnterDataDirective *S) {
896 VisitOMPExecutableDirective(S);
899 void StmtProfiler::VisitOMPTargetExitDataDirective(
900 const OMPTargetExitDataDirective *S) {
901 VisitOMPExecutableDirective(S);
904 void StmtProfiler::VisitOMPTargetParallelDirective(
905 const OMPTargetParallelDirective *S) {
906 VisitOMPExecutableDirective(S);
909 void StmtProfiler::VisitOMPTargetParallelForDirective(
910 const OMPTargetParallelForDirective *S) {
911 VisitOMPExecutableDirective(S);
914 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) {
915 VisitOMPExecutableDirective(S);
918 void StmtProfiler::VisitOMPCancellationPointDirective(
919 const OMPCancellationPointDirective *S) {
920 VisitOMPExecutableDirective(S);
923 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) {
924 VisitOMPExecutableDirective(S);
927 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) {
928 VisitOMPLoopDirective(S);
931 void StmtProfiler::VisitOMPTaskLoopSimdDirective(
932 const OMPTaskLoopSimdDirective *S) {
933 VisitOMPLoopDirective(S);
936 void StmtProfiler::VisitOMPMasterTaskLoopDirective(
937 const OMPMasterTaskLoopDirective *S) {
938 VisitOMPLoopDirective(S);
941 void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective(
942 const OMPMasterTaskLoopSimdDirective *S) {
943 VisitOMPLoopDirective(S);
946 void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective(
947 const OMPParallelMasterTaskLoopDirective *S) {
948 VisitOMPLoopDirective(S);
951 void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective(
952 const OMPParallelMasterTaskLoopSimdDirective *S) {
953 VisitOMPLoopDirective(S);
956 void StmtProfiler::VisitOMPDistributeDirective(
957 const OMPDistributeDirective *S) {
958 VisitOMPLoopDirective(S);
961 void OMPClauseProfiler::VisitOMPDistScheduleClause(
962 const OMPDistScheduleClause *C) {
963 VistOMPClauseWithPreInit(C);
964 if (auto *S = C->getChunkSize())
965 Profiler->VisitStmt(S);
968 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {}
970 void StmtProfiler::VisitOMPTargetUpdateDirective(
971 const OMPTargetUpdateDirective *S) {
972 VisitOMPExecutableDirective(S);
975 void StmtProfiler::VisitOMPDistributeParallelForDirective(
976 const OMPDistributeParallelForDirective *S) {
977 VisitOMPLoopDirective(S);
980 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective(
981 const OMPDistributeParallelForSimdDirective *S) {
982 VisitOMPLoopDirective(S);
985 void StmtProfiler::VisitOMPDistributeSimdDirective(
986 const OMPDistributeSimdDirective *S) {
987 VisitOMPLoopDirective(S);
990 void StmtProfiler::VisitOMPTargetParallelForSimdDirective(
991 const OMPTargetParallelForSimdDirective *S) {
992 VisitOMPLoopDirective(S);
995 void StmtProfiler::VisitOMPTargetSimdDirective(
996 const OMPTargetSimdDirective *S) {
997 VisitOMPLoopDirective(S);
1000 void StmtProfiler::VisitOMPTeamsDistributeDirective(
1001 const OMPTeamsDistributeDirective *S) {
1002 VisitOMPLoopDirective(S);
1005 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective(
1006 const OMPTeamsDistributeSimdDirective *S) {
1007 VisitOMPLoopDirective(S);
1010 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective(
1011 const OMPTeamsDistributeParallelForSimdDirective *S) {
1012 VisitOMPLoopDirective(S);
1015 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective(
1016 const OMPTeamsDistributeParallelForDirective *S) {
1017 VisitOMPLoopDirective(S);
1020 void StmtProfiler::VisitOMPTargetTeamsDirective(
1021 const OMPTargetTeamsDirective *S) {
1022 VisitOMPExecutableDirective(S);
1025 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective(
1026 const OMPTargetTeamsDistributeDirective *S) {
1027 VisitOMPLoopDirective(S);
1030 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective(
1031 const OMPTargetTeamsDistributeParallelForDirective *S) {
1032 VisitOMPLoopDirective(S);
1035 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective(
1036 const OMPTargetTeamsDistributeParallelForSimdDirective *S) {
1037 VisitOMPLoopDirective(S);
1040 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective(
1041 const OMPTargetTeamsDistributeSimdDirective *S) {
1042 VisitOMPLoopDirective(S);
1045 void StmtProfiler::VisitExpr(const Expr *S) {
1049 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) {
1053 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) {
1056 VisitNestedNameSpecifier(S->getQualifier());
1057 VisitDecl(S->getDecl());
1059 ID.AddBoolean(S->hasExplicitTemplateArgs());
1060 if (S->hasExplicitTemplateArgs())
1061 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1065 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) {
1067 ID.AddInteger(S->getIdentKind());
1070 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) {
1072 S->getValue().Profile(ID);
1073 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1076 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) {
1078 S->getValue().Profile(ID);
1079 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1082 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) {
1084 ID.AddInteger(S->getKind());
1085 ID.AddInteger(S->getValue());
1088 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) {
1090 S->getValue().Profile(ID);
1091 ID.AddBoolean(S->isExact());
1092 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind());
1095 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) {
1099 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) {
1101 ID.AddString(S->getBytes());
1102 ID.AddInteger(S->getKind());
1105 void StmtProfiler::VisitParenExpr(const ParenExpr *S) {
1109 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) {
1113 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) {
1115 ID.AddInteger(S->getOpcode());
1118 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) {
1119 VisitType(S->getTypeSourceInfo()->getType());
1120 unsigned n = S->getNumComponents();
1121 for (unsigned i = 0; i < n; ++i) {
1122 const OffsetOfNode &ON = S->getComponent(i);
1123 ID.AddInteger(ON.getKind());
1124 switch (ON.getKind()) {
1125 case OffsetOfNode::Array:
1126 // Expressions handled below.
1129 case OffsetOfNode::Field:
1130 VisitDecl(ON.getField());
1133 case OffsetOfNode::Identifier:
1134 VisitIdentifierInfo(ON.getFieldName());
1137 case OffsetOfNode::Base:
1138 // These nodes are implicit, and therefore don't need profiling.
1147 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) {
1149 ID.AddInteger(S->getKind());
1150 if (S->isArgumentType())
1151 VisitType(S->getArgumentType());
1154 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) {
1158 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) {
1162 void StmtProfiler::VisitCallExpr(const CallExpr *S) {
1166 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) {
1168 VisitDecl(S->getMemberDecl());
1170 VisitNestedNameSpecifier(S->getQualifier());
1171 ID.AddBoolean(S->isArrow());
1174 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) {
1176 ID.AddBoolean(S->isFileScope());
1179 void StmtProfiler::VisitCastExpr(const CastExpr *S) {
1183 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) {
1185 ID.AddInteger(S->getValueKind());
1188 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) {
1190 VisitType(S->getTypeAsWritten());
1193 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) {
1194 VisitExplicitCastExpr(S);
1197 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) {
1199 ID.AddInteger(S->getOpcode());
1203 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) {
1204 VisitBinaryOperator(S);
1207 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) {
1211 void StmtProfiler::VisitBinaryConditionalOperator(
1212 const BinaryConditionalOperator *S) {
1216 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) {
1218 VisitDecl(S->getLabel());
1221 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) {
1225 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) {
1229 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) {
1233 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) {
1237 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) {
1241 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) {
1245 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) {
1246 if (S->getSyntacticForm()) {
1247 VisitInitListExpr(S->getSyntacticForm());
1254 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) {
1256 ID.AddBoolean(S->usesGNUSyntax());
1257 for (const DesignatedInitExpr::Designator &D : S->designators()) {
1258 if (D.isFieldDesignator()) {
1260 VisitName(D.getFieldName());
1264 if (D.isArrayDesignator()) {
1267 assert(D.isArrayRangeDesignator());
1270 ID.AddInteger(D.getFirstExprIndex());
1274 // Seems that if VisitInitListExpr() only works on the syntactic form of an
1275 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
1276 void StmtProfiler::VisitDesignatedInitUpdateExpr(
1277 const DesignatedInitUpdateExpr *S) {
1278 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
1282 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) {
1286 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) {
1290 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) {
1291 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
1294 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) {
1298 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) {
1300 VisitName(&S->getAccessor());
1303 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) {
1305 VisitDecl(S->getBlockDecl());
1308 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) {
1310 for (const GenericSelectionExpr::ConstAssociation Assoc :
1311 S->associations()) {
1312 QualType T = Assoc.getType();
1314 ID.AddPointer(nullptr);
1317 VisitExpr(Assoc.getAssociationExpr());
1321 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) {
1323 for (PseudoObjectExpr::const_semantics_iterator
1324 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i)
1325 // Normally, we would not profile the source expressions of OVEs.
1326 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i))
1327 Visit(OVE->getSourceExpr());
1330 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) {
1332 ID.AddInteger(S->getOp());
1335 void StmtProfiler::VisitConceptSpecializationExpr(
1336 const ConceptSpecializationExpr *S) {
1338 VisitDecl(S->getNamedConcept());
1339 for (const TemplateArgument &Arg : S->getTemplateArguments())
1340 VisitTemplateArgument(Arg);
1343 void StmtProfiler::VisitRequiresExpr(const RequiresExpr *S) {
1345 ID.AddInteger(S->getLocalParameters().size());
1346 for (ParmVarDecl *LocalParam : S->getLocalParameters())
1347 VisitDecl(LocalParam);
1348 ID.AddInteger(S->getRequirements().size());
1349 for (concepts::Requirement *Req : S->getRequirements()) {
1350 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) {
1351 ID.AddInteger(concepts::Requirement::RK_Type);
1352 ID.AddBoolean(TypeReq->isSubstitutionFailure());
1353 if (!TypeReq->isSubstitutionFailure())
1354 VisitType(TypeReq->getType()->getType());
1355 } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) {
1356 ID.AddInteger(concepts::Requirement::RK_Compound);
1357 ID.AddBoolean(ExprReq->isExprSubstitutionFailure());
1358 if (!ExprReq->isExprSubstitutionFailure())
1359 Visit(ExprReq->getExpr());
1360 // C++2a [expr.prim.req.compound]p1 Example:
1361 // [...] The compound-requirement in C1 requires that x++ is a valid
1362 // expression. It is equivalent to the simple-requirement x++; [...]
1363 // We therefore do not profile isSimple() here.
1364 ID.AddBoolean(ExprReq->getNoexceptLoc().isValid());
1365 const concepts::ExprRequirement::ReturnTypeRequirement &RetReq =
1366 ExprReq->getReturnTypeRequirement();
1367 if (RetReq.isEmpty()) {
1369 } else if (RetReq.isTypeConstraint()) {
1371 Visit(RetReq.getTypeConstraint()->getImmediatelyDeclaredConstraint());
1373 assert(RetReq.isSubstitutionFailure());
1377 ID.AddInteger(concepts::Requirement::RK_Nested);
1378 auto *NestedReq = cast<concepts::NestedRequirement>(Req);
1379 ID.AddBoolean(NestedReq->isSubstitutionFailure());
1380 if (!NestedReq->isSubstitutionFailure())
1381 Visit(NestedReq->getConstraintExpr());
1386 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S,
1387 UnaryOperatorKind &UnaryOp,
1388 BinaryOperatorKind &BinaryOp) {
1389 switch (S->getOperator()) {
1394 case OO_Array_Delete:
1397 case OO_Conditional:
1398 case NUM_OVERLOADED_OPERATORS:
1399 llvm_unreachable("Invalid operator call kind");
1402 if (S->getNumArgs() == 1) {
1404 return Stmt::UnaryOperatorClass;
1408 return Stmt::BinaryOperatorClass;
1411 if (S->getNumArgs() == 1) {
1413 return Stmt::UnaryOperatorClass;
1417 return Stmt::BinaryOperatorClass;
1420 if (S->getNumArgs() == 1) {
1422 return Stmt::UnaryOperatorClass;
1426 return Stmt::BinaryOperatorClass;
1430 return Stmt::BinaryOperatorClass;
1434 return Stmt::BinaryOperatorClass;
1438 return Stmt::BinaryOperatorClass;
1441 if (S->getNumArgs() == 1) {
1442 UnaryOp = UO_AddrOf;
1443 return Stmt::UnaryOperatorClass;
1447 return Stmt::BinaryOperatorClass;
1451 return Stmt::BinaryOperatorClass;
1455 return Stmt::UnaryOperatorClass;
1459 return Stmt::UnaryOperatorClass;
1462 BinaryOp = BO_Assign;
1463 return Stmt::BinaryOperatorClass;
1467 return Stmt::BinaryOperatorClass;
1471 return Stmt::BinaryOperatorClass;
1474 BinaryOp = BO_AddAssign;
1475 return Stmt::CompoundAssignOperatorClass;
1478 BinaryOp = BO_SubAssign;
1479 return Stmt::CompoundAssignOperatorClass;
1482 BinaryOp = BO_MulAssign;
1483 return Stmt::CompoundAssignOperatorClass;
1486 BinaryOp = BO_DivAssign;
1487 return Stmt::CompoundAssignOperatorClass;
1489 case OO_PercentEqual:
1490 BinaryOp = BO_RemAssign;
1491 return Stmt::CompoundAssignOperatorClass;
1494 BinaryOp = BO_XorAssign;
1495 return Stmt::CompoundAssignOperatorClass;
1498 BinaryOp = BO_AndAssign;
1499 return Stmt::CompoundAssignOperatorClass;
1502 BinaryOp = BO_OrAssign;
1503 return Stmt::CompoundAssignOperatorClass;
1507 return Stmt::BinaryOperatorClass;
1509 case OO_GreaterGreater:
1511 return Stmt::BinaryOperatorClass;
1513 case OO_LessLessEqual:
1514 BinaryOp = BO_ShlAssign;
1515 return Stmt::CompoundAssignOperatorClass;
1517 case OO_GreaterGreaterEqual:
1518 BinaryOp = BO_ShrAssign;
1519 return Stmt::CompoundAssignOperatorClass;
1523 return Stmt::BinaryOperatorClass;
1525 case OO_ExclaimEqual:
1527 return Stmt::BinaryOperatorClass;
1531 return Stmt::BinaryOperatorClass;
1533 case OO_GreaterEqual:
1535 return Stmt::BinaryOperatorClass;
1539 return Stmt::BinaryOperatorClass;
1543 return Stmt::BinaryOperatorClass;
1547 return Stmt::BinaryOperatorClass;
1550 UnaryOp = S->getNumArgs() == 1? UO_PreInc
1552 return Stmt::UnaryOperatorClass;
1555 UnaryOp = S->getNumArgs() == 1? UO_PreDec
1557 return Stmt::UnaryOperatorClass;
1560 BinaryOp = BO_Comma;
1561 return Stmt::BinaryOperatorClass;
1564 BinaryOp = BO_PtrMemI;
1565 return Stmt::BinaryOperatorClass;
1568 return Stmt::ArraySubscriptExprClass;
1571 UnaryOp = UO_Coawait;
1572 return Stmt::UnaryOperatorClass;
1575 llvm_unreachable("Invalid overloaded operator expression");
1578 #if defined(_MSC_VER) && !defined(__clang__)
1579 #if _MSC_VER == 1911
1580 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html
1581 // MSVC 2017 update 3 miscompiles this function, and a clang built with it
1582 // will crash in stage 2 of a bootstrap build.
1583 #pragma optimize("", off)
1587 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) {
1588 if (S->isTypeDependent()) {
1589 // Type-dependent operator calls are profiled like their underlying
1590 // syntactic operator.
1592 // An operator call to operator-> is always implicit, so just skip it. The
1593 // enclosing MemberExpr will profile the actual member access.
1594 if (S->getOperator() == OO_Arrow)
1595 return Visit(S->getArg(0));
1597 UnaryOperatorKind UnaryOp = UO_Extension;
1598 BinaryOperatorKind BinaryOp = BO_Comma;
1599 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp);
1602 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1603 Visit(S->getArg(I));
1604 if (SC == Stmt::UnaryOperatorClass)
1605 ID.AddInteger(UnaryOp);
1606 else if (SC == Stmt::BinaryOperatorClass ||
1607 SC == Stmt::CompoundAssignOperatorClass)
1608 ID.AddInteger(BinaryOp);
1610 assert(SC == Stmt::ArraySubscriptExprClass);
1616 ID.AddInteger(S->getOperator());
1619 void StmtProfiler::VisitCXXRewrittenBinaryOperator(
1620 const CXXRewrittenBinaryOperator *S) {
1621 // If a rewritten operator were ever to be type-dependent, we should profile
1622 // it following its syntactic operator.
1623 assert(!S->isTypeDependent() &&
1624 "resolved rewritten operator should never be type-dependent");
1625 ID.AddBoolean(S->isReversed());
1626 VisitExpr(S->getSemanticForm());
1629 #if defined(_MSC_VER) && !defined(__clang__)
1630 #if _MSC_VER == 1911
1631 #pragma optimize("", on)
1635 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) {
1639 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) {
1643 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) {
1647 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) {
1648 VisitExplicitCastExpr(S);
1651 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) {
1652 VisitCXXNamedCastExpr(S);
1655 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) {
1656 VisitCXXNamedCastExpr(S);
1660 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) {
1661 VisitCXXNamedCastExpr(S);
1664 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) {
1665 VisitCXXNamedCastExpr(S);
1668 void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) {
1670 VisitType(S->getTypeInfoAsWritten()->getType());
1673 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) {
1677 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) {
1679 ID.AddBoolean(S->getValue());
1682 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) {
1686 void StmtProfiler::VisitCXXStdInitializerListExpr(
1687 const CXXStdInitializerListExpr *S) {
1691 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) {
1693 if (S->isTypeOperand())
1694 VisitType(S->getTypeOperandSourceInfo()->getType());
1697 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) {
1699 if (S->isTypeOperand())
1700 VisitType(S->getTypeOperandSourceInfo()->getType());
1703 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) {
1705 VisitDecl(S->getPropertyDecl());
1708 void StmtProfiler::VisitMSPropertySubscriptExpr(
1709 const MSPropertySubscriptExpr *S) {
1713 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) {
1715 ID.AddBoolean(S->isImplicit());
1718 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) {
1722 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) {
1724 VisitDecl(S->getParam());
1727 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
1729 VisitDecl(S->getField());
1732 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) {
1735 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor()));
1738 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) {
1740 VisitDecl(S->getConstructor());
1741 ID.AddBoolean(S->isElidable());
1744 void StmtProfiler::VisitCXXInheritedCtorInitExpr(
1745 const CXXInheritedCtorInitExpr *S) {
1747 VisitDecl(S->getConstructor());
1750 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) {
1751 VisitExplicitCastExpr(S);
1755 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) {
1756 VisitCXXConstructExpr(S);
1760 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) {
1762 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
1763 CEnd = S->explicit_capture_end();
1765 if (C->capturesVLAType())
1768 ID.AddInteger(C->getCaptureKind());
1769 switch (C->getCaptureKind()) {
1775 VisitDecl(C->getCapturedVar());
1776 ID.AddBoolean(C->isPackExpansion());
1779 llvm_unreachable("VLA type in explicit captures.");
1782 // Note: If we actually needed to be able to match lambda
1783 // expressions, we would have to consider parameters and return type
1784 // here, among other things.
1785 VisitStmt(S->getBody());
1789 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) {
1793 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) {
1795 ID.AddBoolean(S->isGlobalDelete());
1796 ID.AddBoolean(S->isArrayForm());
1797 VisitDecl(S->getOperatorDelete());
1800 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) {
1802 VisitType(S->getAllocatedType());
1803 VisitDecl(S->getOperatorNew());
1804 VisitDecl(S->getOperatorDelete());
1805 ID.AddBoolean(S->isArray());
1806 ID.AddInteger(S->getNumPlacementArgs());
1807 ID.AddBoolean(S->isGlobalNew());
1808 ID.AddBoolean(S->isParenTypeId());
1809 ID.AddInteger(S->getInitializationStyle());
1813 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) {
1815 ID.AddBoolean(S->isArrow());
1816 VisitNestedNameSpecifier(S->getQualifier());
1817 ID.AddBoolean(S->getScopeTypeInfo() != nullptr);
1818 if (S->getScopeTypeInfo())
1819 VisitType(S->getScopeTypeInfo()->getType());
1820 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr);
1821 if (S->getDestroyedTypeInfo())
1822 VisitType(S->getDestroyedType());
1824 VisitIdentifierInfo(S->getDestroyedTypeIdentifier());
1827 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) {
1829 VisitNestedNameSpecifier(S->getQualifier());
1830 VisitName(S->getName(), /*TreatAsDecl*/ true);
1831 ID.AddBoolean(S->hasExplicitTemplateArgs());
1832 if (S->hasExplicitTemplateArgs())
1833 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1837 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) {
1838 VisitOverloadExpr(S);
1841 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) {
1843 ID.AddInteger(S->getTrait());
1844 ID.AddInteger(S->getNumArgs());
1845 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I)
1846 VisitType(S->getArg(I)->getType());
1849 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) {
1851 ID.AddInteger(S->getTrait());
1852 VisitType(S->getQueriedType());
1855 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) {
1857 ID.AddInteger(S->getTrait());
1858 VisitExpr(S->getQueriedExpression());
1861 void StmtProfiler::VisitDependentScopeDeclRefExpr(
1862 const DependentScopeDeclRefExpr *S) {
1864 VisitName(S->getDeclName());
1865 VisitNestedNameSpecifier(S->getQualifier());
1866 ID.AddBoolean(S->hasExplicitTemplateArgs());
1867 if (S->hasExplicitTemplateArgs())
1868 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1871 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) {
1875 void StmtProfiler::VisitCXXUnresolvedConstructExpr(
1876 const CXXUnresolvedConstructExpr *S) {
1878 VisitType(S->getTypeAsWritten());
1879 ID.AddInteger(S->isListInitialization());
1882 void StmtProfiler::VisitCXXDependentScopeMemberExpr(
1883 const CXXDependentScopeMemberExpr *S) {
1884 ID.AddBoolean(S->isImplicitAccess());
1885 if (!S->isImplicitAccess()) {
1887 ID.AddBoolean(S->isArrow());
1889 VisitNestedNameSpecifier(S->getQualifier());
1890 VisitName(S->getMember());
1891 ID.AddBoolean(S->hasExplicitTemplateArgs());
1892 if (S->hasExplicitTemplateArgs())
1893 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1896 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) {
1897 ID.AddBoolean(S->isImplicitAccess());
1898 if (!S->isImplicitAccess()) {
1900 ID.AddBoolean(S->isArrow());
1902 VisitNestedNameSpecifier(S->getQualifier());
1903 VisitName(S->getMemberName());
1904 ID.AddBoolean(S->hasExplicitTemplateArgs());
1905 if (S->hasExplicitTemplateArgs())
1906 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs());
1909 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) {
1913 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) {
1917 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
1919 VisitDecl(S->getPack());
1920 if (S->isPartiallySubstituted()) {
1921 auto Args = S->getPartialArguments();
1922 ID.AddInteger(Args.size());
1923 for (const auto &TA : Args)
1924 VisitTemplateArgument(TA);
1930 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr(
1931 const SubstNonTypeTemplateParmPackExpr *S) {
1933 VisitDecl(S->getParameterPack());
1934 VisitTemplateArgument(S->getArgumentPack());
1937 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr(
1938 const SubstNonTypeTemplateParmExpr *E) {
1939 // Profile exactly as the replacement expression.
1940 Visit(E->getReplacement());
1943 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) {
1945 VisitDecl(S->getParameterPack());
1946 ID.AddInteger(S->getNumExpansions());
1947 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I)
1951 void StmtProfiler::VisitMaterializeTemporaryExpr(
1952 const MaterializeTemporaryExpr *S) {
1956 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) {
1958 ID.AddInteger(S->getOperator());
1961 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) {
1965 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) {
1969 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) {
1973 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) {
1977 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) {
1981 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
1985 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) {
1989 void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) {
1993 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) {
1997 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
2001 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) {
2005 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) {
2009 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) {
2011 VisitType(S->getEncodedType());
2014 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) {
2016 VisitName(S->getSelector());
2019 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) {
2021 VisitDecl(S->getProtocol());
2024 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) {
2026 VisitDecl(S->getDecl());
2027 ID.AddBoolean(S->isArrow());
2028 ID.AddBoolean(S->isFreeIvar());
2031 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) {
2033 if (S->isImplicitProperty()) {
2034 VisitDecl(S->getImplicitPropertyGetter());
2035 VisitDecl(S->getImplicitPropertySetter());
2037 VisitDecl(S->getExplicitProperty());
2039 if (S->isSuperReceiver()) {
2040 ID.AddBoolean(S->isSuperReceiver());
2041 VisitType(S->getSuperReceiverType());
2045 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) {
2047 VisitDecl(S->getAtIndexMethodDecl());
2048 VisitDecl(S->setAtIndexMethodDecl());
2051 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) {
2053 VisitName(S->getSelector());
2054 VisitDecl(S->getMethodDecl());
2057 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) {
2059 ID.AddBoolean(S->isArrow());
2062 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) {
2064 ID.AddBoolean(S->getValue());
2067 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr(
2068 const ObjCIndirectCopyRestoreExpr *S) {
2070 ID.AddBoolean(S->shouldCopy());
2073 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) {
2074 VisitExplicitCastExpr(S);
2075 ID.AddBoolean(S->getBridgeKind());
2078 void StmtProfiler::VisitObjCAvailabilityCheckExpr(
2079 const ObjCAvailabilityCheckExpr *S) {
2083 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args,
2085 ID.AddInteger(NumArgs);
2086 for (unsigned I = 0; I != NumArgs; ++I)
2087 VisitTemplateArgument(Args[I].getArgument());
2090 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) {
2091 // Mostly repetitive with TemplateArgument::Profile!
2092 ID.AddInteger(Arg.getKind());
2093 switch (Arg.getKind()) {
2094 case TemplateArgument::Null:
2097 case TemplateArgument::Type:
2098 VisitType(Arg.getAsType());
2101 case TemplateArgument::Template:
2102 case TemplateArgument::TemplateExpansion:
2103 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
2106 case TemplateArgument::Declaration:
2107 VisitDecl(Arg.getAsDecl());
2110 case TemplateArgument::NullPtr:
2111 VisitType(Arg.getNullPtrType());
2114 case TemplateArgument::Integral:
2115 Arg.getAsIntegral().Profile(ID);
2116 VisitType(Arg.getIntegralType());
2119 case TemplateArgument::Expression:
2120 Visit(Arg.getAsExpr());
2123 case TemplateArgument::Pack:
2124 for (const auto &P : Arg.pack_elements())
2125 VisitTemplateArgument(P);
2130 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
2131 bool Canonical) const {
2132 StmtProfilerWithPointers Profiler(ID, Context, Canonical);
2133 Profiler.Visit(this);
2136 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID,
2137 class ODRHash &Hash) const {
2138 StmtProfilerWithoutPointers Profiler(ID, Hash);
2139 Profiler.Visit(this);