1 //===---- StmtProfile.cpp - Profile implementation for Stmt ASTs ----------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the Stmt::Profile method, which builds a unique bit 10 // representation that identifies a statement/expression. 11 // 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; 25 26 namespace { 27 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> { 28 protected: 29 llvm::FoldingSetNodeID &ID; 30 bool Canonical; 31 32 public: 33 StmtProfiler(llvm::FoldingSetNodeID &ID, bool Canonical) 34 : ID(ID), Canonical(Canonical) {} 35 36 virtual ~StmtProfiler() {} 37 38 void VisitStmt(const Stmt *S); 39 40 virtual void HandleStmtClass(Stmt::StmtClass SC) = 0; 41 42 #define STMT(Node, Base) void Visit##Node(const Node *S); 43 #include "clang/AST/StmtNodes.inc" 44 45 /// Visit a declaration that is referenced within an expression 46 /// or statement. 47 virtual void VisitDecl(const Decl *D) = 0; 48 49 /// Visit a type that is referenced within an expression or 50 /// statement. 51 virtual void VisitType(QualType T) = 0; 52 53 /// Visit a name that occurs within an expression or statement. 54 virtual void VisitName(DeclarationName Name, bool TreatAsDecl = false) = 0; 55 56 /// Visit identifiers that are not in Decl's or Type's. 57 virtual void VisitIdentifierInfo(IdentifierInfo *II) = 0; 58 59 /// Visit a nested-name-specifier that occurs within an expression 60 /// or statement. 61 virtual void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) = 0; 62 63 /// Visit a template name that occurs within an expression or 64 /// statement. 65 virtual void VisitTemplateName(TemplateName Name) = 0; 66 67 /// Visit template arguments that occur within an expression or 68 /// statement. 69 void VisitTemplateArguments(const TemplateArgumentLoc *Args, 70 unsigned NumArgs); 71 72 /// Visit a single template argument. 73 void VisitTemplateArgument(const TemplateArgument &Arg); 74 }; 75 76 class StmtProfilerWithPointers : public StmtProfiler { 77 const ASTContext &Context; 78 79 public: 80 StmtProfilerWithPointers(llvm::FoldingSetNodeID &ID, 81 const ASTContext &Context, bool Canonical) 82 : StmtProfiler(ID, Canonical), Context(Context) {} 83 private: 84 void HandleStmtClass(Stmt::StmtClass SC) override { 85 ID.AddInteger(SC); 86 } 87 88 void VisitDecl(const Decl *D) override { 89 ID.AddInteger(D ? D->getKind() : 0); 90 91 if (Canonical && D) { 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()); 98 return; 99 } 100 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 108 // name mangling. 109 VisitType(Parm->getType()); 110 ID.AddInteger(Parm->getFunctionScopeDepth()); 111 ID.AddInteger(Parm->getFunctionScopeIndex()); 112 return; 113 } 114 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()); 120 return; 121 } 122 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()); 128 return; 129 } 130 } 131 132 ID.AddPointer(D ? D->getCanonicalDecl() : nullptr); 133 } 134 135 void VisitType(QualType T) override { 136 if (Canonical && !T.isNull()) 137 T = Context.getCanonicalType(T); 138 139 ID.AddPointer(T.getAsOpaquePtr()); 140 } 141 142 void VisitName(DeclarationName Name, bool /*TreatAsDecl*/) override { 143 ID.AddPointer(Name.getAsOpaquePtr()); 144 } 145 146 void VisitIdentifierInfo(IdentifierInfo *II) override { 147 ID.AddPointer(II); 148 } 149 150 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override { 151 if (Canonical) 152 NNS = Context.getCanonicalNestedNameSpecifier(NNS); 153 ID.AddPointer(NNS); 154 } 155 156 void VisitTemplateName(TemplateName Name) override { 157 if (Canonical) 158 Name = Context.getCanonicalTemplateName(Name); 159 160 Name.Profile(ID); 161 } 162 }; 163 164 class StmtProfilerWithoutPointers : public StmtProfiler { 165 ODRHash &Hash; 166 public: 167 StmtProfilerWithoutPointers(llvm::FoldingSetNodeID &ID, ODRHash &Hash) 168 : StmtProfiler(ID, false), Hash(Hash) {} 169 170 private: 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); 176 } else { 177 ID.AddInteger(SC); 178 } 179 } 180 181 void VisitType(QualType T) override { 182 Hash.AddQualType(T); 183 } 184 185 void VisitName(DeclarationName Name, bool TreatAsDecl) override { 186 if (TreatAsDecl) { 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. 189 ID.AddBoolean(true); 190 } 191 Hash.AddDeclarationName(Name, TreatAsDecl); 192 } 193 void VisitIdentifierInfo(IdentifierInfo *II) override { 194 ID.AddBoolean(II); 195 if (II) { 196 Hash.AddIdentifierInfo(II); 197 } 198 } 199 void VisitDecl(const Decl *D) override { 200 ID.AddBoolean(D); 201 if (D) { 202 Hash.AddDecl(D); 203 } 204 } 205 void VisitTemplateName(TemplateName Name) override { 206 Hash.AddTemplateName(Name); 207 } 208 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS) override { 209 ID.AddBoolean(NNS); 210 if (NNS) { 211 Hash.AddNestedNameSpecifier(NNS); 212 } 213 } 214 }; 215 } 216 217 void StmtProfiler::VisitStmt(const Stmt *S) { 218 assert(S && "Requires non-null Stmt pointer"); 219 220 HandleStmtClass(S->getStmtClass()); 221 222 for (const Stmt *SubStmt : S->children()) { 223 if (SubStmt) 224 Visit(SubStmt); 225 else 226 ID.AddInteger(0); 227 } 228 } 229 230 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) { 231 VisitStmt(S); 232 for (const auto *D : S->decls()) 233 VisitDecl(D); 234 } 235 236 void StmtProfiler::VisitNullStmt(const NullStmt *S) { 237 VisitStmt(S); 238 } 239 240 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) { 241 VisitStmt(S); 242 } 243 244 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) { 245 VisitStmt(S); 246 } 247 248 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) { 249 VisitStmt(S); 250 } 251 252 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) { 253 VisitStmt(S); 254 VisitDecl(S->getDecl()); 255 } 256 257 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) { 258 VisitStmt(S); 259 // TODO: maybe visit attributes? 260 } 261 262 void StmtProfiler::VisitIfStmt(const IfStmt *S) { 263 VisitStmt(S); 264 VisitDecl(S->getConditionVariable()); 265 } 266 267 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) { 268 VisitStmt(S); 269 VisitDecl(S->getConditionVariable()); 270 } 271 272 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) { 273 VisitStmt(S); 274 VisitDecl(S->getConditionVariable()); 275 } 276 277 void StmtProfiler::VisitDoStmt(const DoStmt *S) { 278 VisitStmt(S); 279 } 280 281 void StmtProfiler::VisitForStmt(const ForStmt *S) { 282 VisitStmt(S); 283 } 284 285 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) { 286 VisitStmt(S); 287 VisitDecl(S->getLabel()); 288 } 289 290 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) { 291 VisitStmt(S); 292 } 293 294 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) { 295 VisitStmt(S); 296 } 297 298 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) { 299 VisitStmt(S); 300 } 301 302 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) { 303 VisitStmt(S); 304 } 305 306 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) { 307 VisitStmt(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)); 315 } 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)); 320 } 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()); 327 } 328 329 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) { 330 // FIXME: Implement MS style inline asm statement profiler. 331 VisitStmt(S); 332 } 333 334 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) { 335 VisitStmt(S); 336 VisitType(S->getCaughtType()); 337 } 338 339 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) { 340 VisitStmt(S); 341 } 342 343 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) { 344 VisitStmt(S); 345 } 346 347 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) { 348 VisitStmt(S); 349 ID.AddBoolean(S->isIfExists()); 350 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier()); 351 VisitName(S->getNameInfo().getName()); 352 } 353 354 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) { 355 VisitStmt(S); 356 } 357 358 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) { 359 VisitStmt(S); 360 } 361 362 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) { 363 VisitStmt(S); 364 } 365 366 void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) { 367 VisitStmt(S); 368 } 369 370 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) { 371 VisitStmt(S); 372 } 373 374 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) { 375 VisitStmt(S); 376 } 377 378 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) { 379 VisitStmt(S); 380 ID.AddBoolean(S->hasEllipsis()); 381 if (S->getCatchParamDecl()) 382 VisitType(S->getCatchParamDecl()->getType()); 383 } 384 385 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) { 386 VisitStmt(S); 387 } 388 389 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) { 390 VisitStmt(S); 391 } 392 393 void 394 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) { 395 VisitStmt(S); 396 } 397 398 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) { 399 VisitStmt(S); 400 } 401 402 void 403 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) { 404 VisitStmt(S); 405 } 406 407 namespace { 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); 413 414 public: 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); 421 }; 422 423 void OMPClauseProfiler::VistOMPClauseWithPreInit( 424 const OMPClauseWithPreInit *C) { 425 if (auto *S = C->getPreInitStmt()) 426 Profiler->VisitStmt(S); 427 } 428 429 void OMPClauseProfiler::VistOMPClauseWithPostUpdate( 430 const OMPClauseWithPostUpdate *C) { 431 VistOMPClauseWithPreInit(C); 432 if (auto *E = C->getPostUpdateExpr()) 433 Profiler->VisitStmt(E); 434 } 435 436 void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) { 437 VistOMPClauseWithPreInit(C); 438 if (C->getCondition()) 439 Profiler->VisitStmt(C->getCondition()); 440 } 441 442 void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) { 443 VistOMPClauseWithPreInit(C); 444 if (C->getCondition()) 445 Profiler->VisitStmt(C->getCondition()); 446 } 447 448 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) { 449 VistOMPClauseWithPreInit(C); 450 if (C->getNumThreads()) 451 Profiler->VisitStmt(C->getNumThreads()); 452 } 453 454 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) { 455 if (C->getSafelen()) 456 Profiler->VisitStmt(C->getSafelen()); 457 } 458 459 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) { 460 if (C->getSimdlen()) 461 Profiler->VisitStmt(C->getSimdlen()); 462 } 463 464 void OMPClauseProfiler::VisitOMPAllocatorClause(const OMPAllocatorClause *C) { 465 if (C->getAllocator()) 466 Profiler->VisitStmt(C->getAllocator()); 467 } 468 469 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) { 470 if (C->getNumForLoops()) 471 Profiler->VisitStmt(C->getNumForLoops()); 472 } 473 474 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { } 475 476 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { } 477 478 void OMPClauseProfiler::VisitOMPUnifiedAddressClause( 479 const OMPUnifiedAddressClause *C) {} 480 481 void OMPClauseProfiler::VisitOMPUnifiedSharedMemoryClause( 482 const OMPUnifiedSharedMemoryClause *C) {} 483 484 void OMPClauseProfiler::VisitOMPReverseOffloadClause( 485 const OMPReverseOffloadClause *C) {} 486 487 void OMPClauseProfiler::VisitOMPDynamicAllocatorsClause( 488 const OMPDynamicAllocatorsClause *C) {} 489 490 void OMPClauseProfiler::VisitOMPAtomicDefaultMemOrderClause( 491 const OMPAtomicDefaultMemOrderClause *C) {} 492 493 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) { 494 VistOMPClauseWithPreInit(C); 495 if (auto *S = C->getChunkSize()) 496 Profiler->VisitStmt(S); 497 } 498 499 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) { 500 if (auto *Num = C->getNumForLoops()) 501 Profiler->VisitStmt(Num); 502 } 503 504 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {} 505 506 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {} 507 508 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {} 509 510 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {} 511 512 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {} 513 514 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {} 515 516 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {} 517 518 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {} 519 520 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {} 521 522 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {} 523 524 void OMPClauseProfiler::VisitOMPNogroupClause(const OMPNogroupClause *) {} 525 526 template<typename T> 527 void OMPClauseProfiler::VisitOMPClauseList(T *Node) { 528 for (auto *E : Node->varlists()) { 529 if (E) 530 Profiler->VisitStmt(E); 531 } 532 } 533 534 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) { 535 VisitOMPClauseList(C); 536 for (auto *E : C->private_copies()) { 537 if (E) 538 Profiler->VisitStmt(E); 539 } 540 } 541 void 542 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) { 543 VisitOMPClauseList(C); 544 VistOMPClauseWithPreInit(C); 545 for (auto *E : C->private_copies()) { 546 if (E) 547 Profiler->VisitStmt(E); 548 } 549 for (auto *E : C->inits()) { 550 if (E) 551 Profiler->VisitStmt(E); 552 } 553 } 554 void 555 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) { 556 VisitOMPClauseList(C); 557 VistOMPClauseWithPostUpdate(C); 558 for (auto *E : C->source_exprs()) { 559 if (E) 560 Profiler->VisitStmt(E); 561 } 562 for (auto *E : C->destination_exprs()) { 563 if (E) 564 Profiler->VisitStmt(E); 565 } 566 for (auto *E : C->assignment_ops()) { 567 if (E) 568 Profiler->VisitStmt(E); 569 } 570 } 571 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) { 572 VisitOMPClauseList(C); 573 } 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()) { 582 if (E) 583 Profiler->VisitStmt(E); 584 } 585 for (auto *E : C->lhs_exprs()) { 586 if (E) 587 Profiler->VisitStmt(E); 588 } 589 for (auto *E : C->rhs_exprs()) { 590 if (E) 591 Profiler->VisitStmt(E); 592 } 593 for (auto *E : C->reduction_ops()) { 594 if (E) 595 Profiler->VisitStmt(E); 596 } 597 } 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()) { 606 if (E) 607 Profiler->VisitStmt(E); 608 } 609 for (auto *E : C->lhs_exprs()) { 610 if (E) 611 Profiler->VisitStmt(E); 612 } 613 for (auto *E : C->rhs_exprs()) { 614 if (E) 615 Profiler->VisitStmt(E); 616 } 617 for (auto *E : C->reduction_ops()) { 618 if (E) 619 Profiler->VisitStmt(E); 620 } 621 } 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()) { 630 if (E) 631 Profiler->VisitStmt(E); 632 } 633 for (auto *E : C->lhs_exprs()) { 634 if (E) 635 Profiler->VisitStmt(E); 636 } 637 for (auto *E : C->rhs_exprs()) { 638 if (E) 639 Profiler->VisitStmt(E); 640 } 641 for (auto *E : C->reduction_ops()) { 642 if (E) 643 Profiler->VisitStmt(E); 644 } 645 for (auto *E : C->taskgroup_descriptors()) { 646 if (E) 647 Profiler->VisitStmt(E); 648 } 649 } 650 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) { 651 VisitOMPClauseList(C); 652 VistOMPClauseWithPostUpdate(C); 653 for (auto *E : C->privates()) { 654 if (E) 655 Profiler->VisitStmt(E); 656 } 657 for (auto *E : C->inits()) { 658 if (E) 659 Profiler->VisitStmt(E); 660 } 661 for (auto *E : C->updates()) { 662 if (E) 663 Profiler->VisitStmt(E); 664 } 665 for (auto *E : C->finals()) { 666 if (E) 667 Profiler->VisitStmt(E); 668 } 669 if (C->getStep()) 670 Profiler->VisitStmt(C->getStep()); 671 if (C->getCalcStep()) 672 Profiler->VisitStmt(C->getCalcStep()); 673 } 674 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) { 675 VisitOMPClauseList(C); 676 if (C->getAlignment()) 677 Profiler->VisitStmt(C->getAlignment()); 678 } 679 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) { 680 VisitOMPClauseList(C); 681 for (auto *E : C->source_exprs()) { 682 if (E) 683 Profiler->VisitStmt(E); 684 } 685 for (auto *E : C->destination_exprs()) { 686 if (E) 687 Profiler->VisitStmt(E); 688 } 689 for (auto *E : C->assignment_ops()) { 690 if (E) 691 Profiler->VisitStmt(E); 692 } 693 } 694 void 695 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) { 696 VisitOMPClauseList(C); 697 for (auto *E : C->source_exprs()) { 698 if (E) 699 Profiler->VisitStmt(E); 700 } 701 for (auto *E : C->destination_exprs()) { 702 if (E) 703 Profiler->VisitStmt(E); 704 } 705 for (auto *E : C->assignment_ops()) { 706 if (E) 707 Profiler->VisitStmt(E); 708 } 709 } 710 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) { 711 VisitOMPClauseList(C); 712 } 713 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) { 714 VisitOMPClauseList(C); 715 } 716 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) { 717 if (C->getDevice()) 718 Profiler->VisitStmt(C->getDevice()); 719 } 720 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) { 721 VisitOMPClauseList(C); 722 } 723 void OMPClauseProfiler::VisitOMPAllocateClause(const OMPAllocateClause *C) { 724 if (Expr *Allocator = C->getAllocator()) 725 Profiler->VisitStmt(Allocator); 726 VisitOMPClauseList(C); 727 } 728 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) { 729 VistOMPClauseWithPreInit(C); 730 if (C->getNumTeams()) 731 Profiler->VisitStmt(C->getNumTeams()); 732 } 733 void OMPClauseProfiler::VisitOMPThreadLimitClause( 734 const OMPThreadLimitClause *C) { 735 VistOMPClauseWithPreInit(C); 736 if (C->getThreadLimit()) 737 Profiler->VisitStmt(C->getThreadLimit()); 738 } 739 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) { 740 VistOMPClauseWithPreInit(C); 741 if (C->getPriority()) 742 Profiler->VisitStmt(C->getPriority()); 743 } 744 void OMPClauseProfiler::VisitOMPGrainsizeClause(const OMPGrainsizeClause *C) { 745 VistOMPClauseWithPreInit(C); 746 if (C->getGrainsize()) 747 Profiler->VisitStmt(C->getGrainsize()); 748 } 749 void OMPClauseProfiler::VisitOMPNumTasksClause(const OMPNumTasksClause *C) { 750 VistOMPClauseWithPreInit(C); 751 if (C->getNumTasks()) 752 Profiler->VisitStmt(C->getNumTasks()); 753 } 754 void OMPClauseProfiler::VisitOMPHintClause(const OMPHintClause *C) { 755 if (C->getHint()) 756 Profiler->VisitStmt(C->getHint()); 757 } 758 void OMPClauseProfiler::VisitOMPToClause(const OMPToClause *C) { 759 VisitOMPClauseList(C); 760 } 761 void OMPClauseProfiler::VisitOMPFromClause(const OMPFromClause *C) { 762 VisitOMPClauseList(C); 763 } 764 void OMPClauseProfiler::VisitOMPUseDevicePtrClause( 765 const OMPUseDevicePtrClause *C) { 766 VisitOMPClauseList(C); 767 } 768 void OMPClauseProfiler::VisitOMPIsDevicePtrClause( 769 const OMPIsDevicePtrClause *C) { 770 VisitOMPClauseList(C); 771 } 772 void OMPClauseProfiler::VisitOMPNontemporalClause(const OMPNontemporalClause *C) { 773 VisitOMPClauseList(C); 774 } 775 } 776 777 void 778 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) { 779 VisitStmt(S); 780 OMPClauseProfiler P(this); 781 ArrayRef<OMPClause *> Clauses = S->clauses(); 782 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); 783 I != E; ++I) 784 if (*I) 785 P.Visit(*I); 786 } 787 788 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) { 789 VisitOMPExecutableDirective(S); 790 } 791 792 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { 793 VisitOMPExecutableDirective(S); 794 } 795 796 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) { 797 VisitOMPLoopDirective(S); 798 } 799 800 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) { 801 VisitOMPLoopDirective(S); 802 } 803 804 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) { 805 VisitOMPLoopDirective(S); 806 } 807 808 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) { 809 VisitOMPExecutableDirective(S); 810 } 811 812 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) { 813 VisitOMPExecutableDirective(S); 814 } 815 816 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) { 817 VisitOMPExecutableDirective(S); 818 } 819 820 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) { 821 VisitOMPExecutableDirective(S); 822 } 823 824 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) { 825 VisitOMPExecutableDirective(S); 826 VisitName(S->getDirectiveName().getName()); 827 } 828 829 void 830 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) { 831 VisitOMPLoopDirective(S); 832 } 833 834 void StmtProfiler::VisitOMPParallelForSimdDirective( 835 const OMPParallelForSimdDirective *S) { 836 VisitOMPLoopDirective(S); 837 } 838 839 void StmtProfiler::VisitOMPParallelMasterDirective( 840 const OMPParallelMasterDirective *S) { 841 VisitOMPExecutableDirective(S); 842 } 843 844 void StmtProfiler::VisitOMPParallelSectionsDirective( 845 const OMPParallelSectionsDirective *S) { 846 VisitOMPExecutableDirective(S); 847 } 848 849 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) { 850 VisitOMPExecutableDirective(S); 851 } 852 853 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) { 854 VisitOMPExecutableDirective(S); 855 } 856 857 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) { 858 VisitOMPExecutableDirective(S); 859 } 860 861 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) { 862 VisitOMPExecutableDirective(S); 863 } 864 865 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) { 866 VisitOMPExecutableDirective(S); 867 if (const Expr *E = S->getReductionRef()) 868 VisitStmt(E); 869 } 870 871 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) { 872 VisitOMPExecutableDirective(S); 873 } 874 875 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) { 876 VisitOMPExecutableDirective(S); 877 } 878 879 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) { 880 VisitOMPExecutableDirective(S); 881 } 882 883 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) { 884 VisitOMPExecutableDirective(S); 885 } 886 887 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) { 888 VisitOMPExecutableDirective(S); 889 } 890 891 void StmtProfiler::VisitOMPTargetEnterDataDirective( 892 const OMPTargetEnterDataDirective *S) { 893 VisitOMPExecutableDirective(S); 894 } 895 896 void StmtProfiler::VisitOMPTargetExitDataDirective( 897 const OMPTargetExitDataDirective *S) { 898 VisitOMPExecutableDirective(S); 899 } 900 901 void StmtProfiler::VisitOMPTargetParallelDirective( 902 const OMPTargetParallelDirective *S) { 903 VisitOMPExecutableDirective(S); 904 } 905 906 void StmtProfiler::VisitOMPTargetParallelForDirective( 907 const OMPTargetParallelForDirective *S) { 908 VisitOMPExecutableDirective(S); 909 } 910 911 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) { 912 VisitOMPExecutableDirective(S); 913 } 914 915 void StmtProfiler::VisitOMPCancellationPointDirective( 916 const OMPCancellationPointDirective *S) { 917 VisitOMPExecutableDirective(S); 918 } 919 920 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) { 921 VisitOMPExecutableDirective(S); 922 } 923 924 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) { 925 VisitOMPLoopDirective(S); 926 } 927 928 void StmtProfiler::VisitOMPTaskLoopSimdDirective( 929 const OMPTaskLoopSimdDirective *S) { 930 VisitOMPLoopDirective(S); 931 } 932 933 void StmtProfiler::VisitOMPMasterTaskLoopDirective( 934 const OMPMasterTaskLoopDirective *S) { 935 VisitOMPLoopDirective(S); 936 } 937 938 void StmtProfiler::VisitOMPMasterTaskLoopSimdDirective( 939 const OMPMasterTaskLoopSimdDirective *S) { 940 VisitOMPLoopDirective(S); 941 } 942 943 void StmtProfiler::VisitOMPParallelMasterTaskLoopDirective( 944 const OMPParallelMasterTaskLoopDirective *S) { 945 VisitOMPLoopDirective(S); 946 } 947 948 void StmtProfiler::VisitOMPParallelMasterTaskLoopSimdDirective( 949 const OMPParallelMasterTaskLoopSimdDirective *S) { 950 VisitOMPLoopDirective(S); 951 } 952 953 void StmtProfiler::VisitOMPDistributeDirective( 954 const OMPDistributeDirective *S) { 955 VisitOMPLoopDirective(S); 956 } 957 958 void OMPClauseProfiler::VisitOMPDistScheduleClause( 959 const OMPDistScheduleClause *C) { 960 VistOMPClauseWithPreInit(C); 961 if (auto *S = C->getChunkSize()) 962 Profiler->VisitStmt(S); 963 } 964 965 void OMPClauseProfiler::VisitOMPDefaultmapClause(const OMPDefaultmapClause *) {} 966 967 void StmtProfiler::VisitOMPTargetUpdateDirective( 968 const OMPTargetUpdateDirective *S) { 969 VisitOMPExecutableDirective(S); 970 } 971 972 void StmtProfiler::VisitOMPDistributeParallelForDirective( 973 const OMPDistributeParallelForDirective *S) { 974 VisitOMPLoopDirective(S); 975 } 976 977 void StmtProfiler::VisitOMPDistributeParallelForSimdDirective( 978 const OMPDistributeParallelForSimdDirective *S) { 979 VisitOMPLoopDirective(S); 980 } 981 982 void StmtProfiler::VisitOMPDistributeSimdDirective( 983 const OMPDistributeSimdDirective *S) { 984 VisitOMPLoopDirective(S); 985 } 986 987 void StmtProfiler::VisitOMPTargetParallelForSimdDirective( 988 const OMPTargetParallelForSimdDirective *S) { 989 VisitOMPLoopDirective(S); 990 } 991 992 void StmtProfiler::VisitOMPTargetSimdDirective( 993 const OMPTargetSimdDirective *S) { 994 VisitOMPLoopDirective(S); 995 } 996 997 void StmtProfiler::VisitOMPTeamsDistributeDirective( 998 const OMPTeamsDistributeDirective *S) { 999 VisitOMPLoopDirective(S); 1000 } 1001 1002 void StmtProfiler::VisitOMPTeamsDistributeSimdDirective( 1003 const OMPTeamsDistributeSimdDirective *S) { 1004 VisitOMPLoopDirective(S); 1005 } 1006 1007 void StmtProfiler::VisitOMPTeamsDistributeParallelForSimdDirective( 1008 const OMPTeamsDistributeParallelForSimdDirective *S) { 1009 VisitOMPLoopDirective(S); 1010 } 1011 1012 void StmtProfiler::VisitOMPTeamsDistributeParallelForDirective( 1013 const OMPTeamsDistributeParallelForDirective *S) { 1014 VisitOMPLoopDirective(S); 1015 } 1016 1017 void StmtProfiler::VisitOMPTargetTeamsDirective( 1018 const OMPTargetTeamsDirective *S) { 1019 VisitOMPExecutableDirective(S); 1020 } 1021 1022 void StmtProfiler::VisitOMPTargetTeamsDistributeDirective( 1023 const OMPTargetTeamsDistributeDirective *S) { 1024 VisitOMPLoopDirective(S); 1025 } 1026 1027 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForDirective( 1028 const OMPTargetTeamsDistributeParallelForDirective *S) { 1029 VisitOMPLoopDirective(S); 1030 } 1031 1032 void StmtProfiler::VisitOMPTargetTeamsDistributeParallelForSimdDirective( 1033 const OMPTargetTeamsDistributeParallelForSimdDirective *S) { 1034 VisitOMPLoopDirective(S); 1035 } 1036 1037 void StmtProfiler::VisitOMPTargetTeamsDistributeSimdDirective( 1038 const OMPTargetTeamsDistributeSimdDirective *S) { 1039 VisitOMPLoopDirective(S); 1040 } 1041 1042 void StmtProfiler::VisitExpr(const Expr *S) { 1043 VisitStmt(S); 1044 } 1045 1046 void StmtProfiler::VisitConstantExpr(const ConstantExpr *S) { 1047 VisitExpr(S); 1048 } 1049 1050 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) { 1051 VisitExpr(S); 1052 if (!Canonical) 1053 VisitNestedNameSpecifier(S->getQualifier()); 1054 VisitDecl(S->getDecl()); 1055 if (!Canonical) { 1056 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1057 if (S->hasExplicitTemplateArgs()) 1058 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1059 } 1060 } 1061 1062 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) { 1063 VisitExpr(S); 1064 ID.AddInteger(S->getIdentKind()); 1065 } 1066 1067 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) { 1068 VisitExpr(S); 1069 S->getValue().Profile(ID); 1070 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1071 } 1072 1073 void StmtProfiler::VisitFixedPointLiteral(const FixedPointLiteral *S) { 1074 VisitExpr(S); 1075 S->getValue().Profile(ID); 1076 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1077 } 1078 1079 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) { 1080 VisitExpr(S); 1081 ID.AddInteger(S->getKind()); 1082 ID.AddInteger(S->getValue()); 1083 } 1084 1085 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) { 1086 VisitExpr(S); 1087 S->getValue().Profile(ID); 1088 ID.AddBoolean(S->isExact()); 1089 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 1090 } 1091 1092 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) { 1093 VisitExpr(S); 1094 } 1095 1096 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) { 1097 VisitExpr(S); 1098 ID.AddString(S->getBytes()); 1099 ID.AddInteger(S->getKind()); 1100 } 1101 1102 void StmtProfiler::VisitParenExpr(const ParenExpr *S) { 1103 VisitExpr(S); 1104 } 1105 1106 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) { 1107 VisitExpr(S); 1108 } 1109 1110 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) { 1111 VisitExpr(S); 1112 ID.AddInteger(S->getOpcode()); 1113 } 1114 1115 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) { 1116 VisitType(S->getTypeSourceInfo()->getType()); 1117 unsigned n = S->getNumComponents(); 1118 for (unsigned i = 0; i < n; ++i) { 1119 const OffsetOfNode &ON = S->getComponent(i); 1120 ID.AddInteger(ON.getKind()); 1121 switch (ON.getKind()) { 1122 case OffsetOfNode::Array: 1123 // Expressions handled below. 1124 break; 1125 1126 case OffsetOfNode::Field: 1127 VisitDecl(ON.getField()); 1128 break; 1129 1130 case OffsetOfNode::Identifier: 1131 VisitIdentifierInfo(ON.getFieldName()); 1132 break; 1133 1134 case OffsetOfNode::Base: 1135 // These nodes are implicit, and therefore don't need profiling. 1136 break; 1137 } 1138 } 1139 1140 VisitExpr(S); 1141 } 1142 1143 void 1144 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) { 1145 VisitExpr(S); 1146 ID.AddInteger(S->getKind()); 1147 if (S->isArgumentType()) 1148 VisitType(S->getArgumentType()); 1149 } 1150 1151 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) { 1152 VisitExpr(S); 1153 } 1154 1155 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) { 1156 VisitExpr(S); 1157 } 1158 1159 void StmtProfiler::VisitCallExpr(const CallExpr *S) { 1160 VisitExpr(S); 1161 } 1162 1163 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) { 1164 VisitExpr(S); 1165 VisitDecl(S->getMemberDecl()); 1166 if (!Canonical) 1167 VisitNestedNameSpecifier(S->getQualifier()); 1168 ID.AddBoolean(S->isArrow()); 1169 } 1170 1171 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) { 1172 VisitExpr(S); 1173 ID.AddBoolean(S->isFileScope()); 1174 } 1175 1176 void StmtProfiler::VisitCastExpr(const CastExpr *S) { 1177 VisitExpr(S); 1178 } 1179 1180 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) { 1181 VisitCastExpr(S); 1182 ID.AddInteger(S->getValueKind()); 1183 } 1184 1185 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) { 1186 VisitCastExpr(S); 1187 VisitType(S->getTypeAsWritten()); 1188 } 1189 1190 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) { 1191 VisitExplicitCastExpr(S); 1192 } 1193 1194 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) { 1195 VisitExpr(S); 1196 ID.AddInteger(S->getOpcode()); 1197 } 1198 1199 void 1200 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) { 1201 VisitBinaryOperator(S); 1202 } 1203 1204 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) { 1205 VisitExpr(S); 1206 } 1207 1208 void StmtProfiler::VisitBinaryConditionalOperator( 1209 const BinaryConditionalOperator *S) { 1210 VisitExpr(S); 1211 } 1212 1213 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) { 1214 VisitExpr(S); 1215 VisitDecl(S->getLabel()); 1216 } 1217 1218 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) { 1219 VisitExpr(S); 1220 } 1221 1222 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) { 1223 VisitExpr(S); 1224 } 1225 1226 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) { 1227 VisitExpr(S); 1228 } 1229 1230 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) { 1231 VisitExpr(S); 1232 } 1233 1234 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) { 1235 VisitExpr(S); 1236 } 1237 1238 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) { 1239 VisitExpr(S); 1240 } 1241 1242 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) { 1243 if (S->getSyntacticForm()) { 1244 VisitInitListExpr(S->getSyntacticForm()); 1245 return; 1246 } 1247 1248 VisitExpr(S); 1249 } 1250 1251 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) { 1252 VisitExpr(S); 1253 ID.AddBoolean(S->usesGNUSyntax()); 1254 for (const DesignatedInitExpr::Designator &D : S->designators()) { 1255 if (D.isFieldDesignator()) { 1256 ID.AddInteger(0); 1257 VisitName(D.getFieldName()); 1258 continue; 1259 } 1260 1261 if (D.isArrayDesignator()) { 1262 ID.AddInteger(1); 1263 } else { 1264 assert(D.isArrayRangeDesignator()); 1265 ID.AddInteger(2); 1266 } 1267 ID.AddInteger(D.getFirstExprIndex()); 1268 } 1269 } 1270 1271 // Seems that if VisitInitListExpr() only works on the syntactic form of an 1272 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. 1273 void StmtProfiler::VisitDesignatedInitUpdateExpr( 1274 const DesignatedInitUpdateExpr *S) { 1275 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " 1276 "initializer"); 1277 } 1278 1279 void StmtProfiler::VisitArrayInitLoopExpr(const ArrayInitLoopExpr *S) { 1280 VisitExpr(S); 1281 } 1282 1283 void StmtProfiler::VisitArrayInitIndexExpr(const ArrayInitIndexExpr *S) { 1284 VisitExpr(S); 1285 } 1286 1287 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) { 1288 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); 1289 } 1290 1291 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) { 1292 VisitExpr(S); 1293 } 1294 1295 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) { 1296 VisitExpr(S); 1297 VisitName(&S->getAccessor()); 1298 } 1299 1300 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) { 1301 VisitExpr(S); 1302 VisitDecl(S->getBlockDecl()); 1303 } 1304 1305 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) { 1306 VisitExpr(S); 1307 for (const GenericSelectionExpr::ConstAssociation Assoc : 1308 S->associations()) { 1309 QualType T = Assoc.getType(); 1310 if (T.isNull()) 1311 ID.AddPointer(nullptr); 1312 else 1313 VisitType(T); 1314 VisitExpr(Assoc.getAssociationExpr()); 1315 } 1316 } 1317 1318 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) { 1319 VisitExpr(S); 1320 for (PseudoObjectExpr::const_semantics_iterator 1321 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) 1322 // Normally, we would not profile the source expressions of OVEs. 1323 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i)) 1324 Visit(OVE->getSourceExpr()); 1325 } 1326 1327 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) { 1328 VisitExpr(S); 1329 ID.AddInteger(S->getOp()); 1330 } 1331 1332 void StmtProfiler::VisitConceptSpecializationExpr( 1333 const ConceptSpecializationExpr *S) { 1334 VisitExpr(S); 1335 VisitDecl(S->getFoundDecl()); 1336 VisitTemplateArguments(S->getTemplateArgsAsWritten()->getTemplateArgs(), 1337 S->getTemplateArgsAsWritten()->NumTemplateArgs); 1338 } 1339 1340 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S, 1341 UnaryOperatorKind &UnaryOp, 1342 BinaryOperatorKind &BinaryOp) { 1343 switch (S->getOperator()) { 1344 case OO_None: 1345 case OO_New: 1346 case OO_Delete: 1347 case OO_Array_New: 1348 case OO_Array_Delete: 1349 case OO_Arrow: 1350 case OO_Call: 1351 case OO_Conditional: 1352 case NUM_OVERLOADED_OPERATORS: 1353 llvm_unreachable("Invalid operator call kind"); 1354 1355 case OO_Plus: 1356 if (S->getNumArgs() == 1) { 1357 UnaryOp = UO_Plus; 1358 return Stmt::UnaryOperatorClass; 1359 } 1360 1361 BinaryOp = BO_Add; 1362 return Stmt::BinaryOperatorClass; 1363 1364 case OO_Minus: 1365 if (S->getNumArgs() == 1) { 1366 UnaryOp = UO_Minus; 1367 return Stmt::UnaryOperatorClass; 1368 } 1369 1370 BinaryOp = BO_Sub; 1371 return Stmt::BinaryOperatorClass; 1372 1373 case OO_Star: 1374 if (S->getNumArgs() == 1) { 1375 UnaryOp = UO_Deref; 1376 return Stmt::UnaryOperatorClass; 1377 } 1378 1379 BinaryOp = BO_Mul; 1380 return Stmt::BinaryOperatorClass; 1381 1382 case OO_Slash: 1383 BinaryOp = BO_Div; 1384 return Stmt::BinaryOperatorClass; 1385 1386 case OO_Percent: 1387 BinaryOp = BO_Rem; 1388 return Stmt::BinaryOperatorClass; 1389 1390 case OO_Caret: 1391 BinaryOp = BO_Xor; 1392 return Stmt::BinaryOperatorClass; 1393 1394 case OO_Amp: 1395 if (S->getNumArgs() == 1) { 1396 UnaryOp = UO_AddrOf; 1397 return Stmt::UnaryOperatorClass; 1398 } 1399 1400 BinaryOp = BO_And; 1401 return Stmt::BinaryOperatorClass; 1402 1403 case OO_Pipe: 1404 BinaryOp = BO_Or; 1405 return Stmt::BinaryOperatorClass; 1406 1407 case OO_Tilde: 1408 UnaryOp = UO_Not; 1409 return Stmt::UnaryOperatorClass; 1410 1411 case OO_Exclaim: 1412 UnaryOp = UO_LNot; 1413 return Stmt::UnaryOperatorClass; 1414 1415 case OO_Equal: 1416 BinaryOp = BO_Assign; 1417 return Stmt::BinaryOperatorClass; 1418 1419 case OO_Less: 1420 BinaryOp = BO_LT; 1421 return Stmt::BinaryOperatorClass; 1422 1423 case OO_Greater: 1424 BinaryOp = BO_GT; 1425 return Stmt::BinaryOperatorClass; 1426 1427 case OO_PlusEqual: 1428 BinaryOp = BO_AddAssign; 1429 return Stmt::CompoundAssignOperatorClass; 1430 1431 case OO_MinusEqual: 1432 BinaryOp = BO_SubAssign; 1433 return Stmt::CompoundAssignOperatorClass; 1434 1435 case OO_StarEqual: 1436 BinaryOp = BO_MulAssign; 1437 return Stmt::CompoundAssignOperatorClass; 1438 1439 case OO_SlashEqual: 1440 BinaryOp = BO_DivAssign; 1441 return Stmt::CompoundAssignOperatorClass; 1442 1443 case OO_PercentEqual: 1444 BinaryOp = BO_RemAssign; 1445 return Stmt::CompoundAssignOperatorClass; 1446 1447 case OO_CaretEqual: 1448 BinaryOp = BO_XorAssign; 1449 return Stmt::CompoundAssignOperatorClass; 1450 1451 case OO_AmpEqual: 1452 BinaryOp = BO_AndAssign; 1453 return Stmt::CompoundAssignOperatorClass; 1454 1455 case OO_PipeEqual: 1456 BinaryOp = BO_OrAssign; 1457 return Stmt::CompoundAssignOperatorClass; 1458 1459 case OO_LessLess: 1460 BinaryOp = BO_Shl; 1461 return Stmt::BinaryOperatorClass; 1462 1463 case OO_GreaterGreater: 1464 BinaryOp = BO_Shr; 1465 return Stmt::BinaryOperatorClass; 1466 1467 case OO_LessLessEqual: 1468 BinaryOp = BO_ShlAssign; 1469 return Stmt::CompoundAssignOperatorClass; 1470 1471 case OO_GreaterGreaterEqual: 1472 BinaryOp = BO_ShrAssign; 1473 return Stmt::CompoundAssignOperatorClass; 1474 1475 case OO_EqualEqual: 1476 BinaryOp = BO_EQ; 1477 return Stmt::BinaryOperatorClass; 1478 1479 case OO_ExclaimEqual: 1480 BinaryOp = BO_NE; 1481 return Stmt::BinaryOperatorClass; 1482 1483 case OO_LessEqual: 1484 BinaryOp = BO_LE; 1485 return Stmt::BinaryOperatorClass; 1486 1487 case OO_GreaterEqual: 1488 BinaryOp = BO_GE; 1489 return Stmt::BinaryOperatorClass; 1490 1491 case OO_Spaceship: 1492 // FIXME: Update this once we support <=> expressions. 1493 llvm_unreachable("<=> expressions not supported yet"); 1494 1495 case OO_AmpAmp: 1496 BinaryOp = BO_LAnd; 1497 return Stmt::BinaryOperatorClass; 1498 1499 case OO_PipePipe: 1500 BinaryOp = BO_LOr; 1501 return Stmt::BinaryOperatorClass; 1502 1503 case OO_PlusPlus: 1504 UnaryOp = S->getNumArgs() == 1? UO_PreInc 1505 : UO_PostInc; 1506 return Stmt::UnaryOperatorClass; 1507 1508 case OO_MinusMinus: 1509 UnaryOp = S->getNumArgs() == 1? UO_PreDec 1510 : UO_PostDec; 1511 return Stmt::UnaryOperatorClass; 1512 1513 case OO_Comma: 1514 BinaryOp = BO_Comma; 1515 return Stmt::BinaryOperatorClass; 1516 1517 case OO_ArrowStar: 1518 BinaryOp = BO_PtrMemI; 1519 return Stmt::BinaryOperatorClass; 1520 1521 case OO_Subscript: 1522 return Stmt::ArraySubscriptExprClass; 1523 1524 case OO_Coawait: 1525 UnaryOp = UO_Coawait; 1526 return Stmt::UnaryOperatorClass; 1527 } 1528 1529 llvm_unreachable("Invalid overloaded operator expression"); 1530 } 1531 1532 #if defined(_MSC_VER) && !defined(__clang__) 1533 #if _MSC_VER == 1911 1534 // Work around https://developercommunity.visualstudio.com/content/problem/84002/clang-cl-when-built-with-vc-2017-crashes-cause-vc.html 1535 // MSVC 2017 update 3 miscompiles this function, and a clang built with it 1536 // will crash in stage 2 of a bootstrap build. 1537 #pragma optimize("", off) 1538 #endif 1539 #endif 1540 1541 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) { 1542 if (S->isTypeDependent()) { 1543 // Type-dependent operator calls are profiled like their underlying 1544 // syntactic operator. 1545 // 1546 // An operator call to operator-> is always implicit, so just skip it. The 1547 // enclosing MemberExpr will profile the actual member access. 1548 if (S->getOperator() == OO_Arrow) 1549 return Visit(S->getArg(0)); 1550 1551 UnaryOperatorKind UnaryOp = UO_Extension; 1552 BinaryOperatorKind BinaryOp = BO_Comma; 1553 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp); 1554 1555 ID.AddInteger(SC); 1556 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 1557 Visit(S->getArg(I)); 1558 if (SC == Stmt::UnaryOperatorClass) 1559 ID.AddInteger(UnaryOp); 1560 else if (SC == Stmt::BinaryOperatorClass || 1561 SC == Stmt::CompoundAssignOperatorClass) 1562 ID.AddInteger(BinaryOp); 1563 else 1564 assert(SC == Stmt::ArraySubscriptExprClass); 1565 1566 return; 1567 } 1568 1569 VisitCallExpr(S); 1570 ID.AddInteger(S->getOperator()); 1571 } 1572 1573 void StmtProfiler::VisitCXXRewrittenBinaryOperator( 1574 const CXXRewrittenBinaryOperator *S) { 1575 // If a rewritten operator were ever to be type-dependent, we should profile 1576 // it following its syntactic operator. 1577 assert(!S->isTypeDependent() && 1578 "resolved rewritten operator should never be type-dependent"); 1579 ID.AddBoolean(S->isReversed()); 1580 VisitExpr(S->getSemanticForm()); 1581 } 1582 1583 #if defined(_MSC_VER) && !defined(__clang__) 1584 #if _MSC_VER == 1911 1585 #pragma optimize("", on) 1586 #endif 1587 #endif 1588 1589 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) { 1590 VisitCallExpr(S); 1591 } 1592 1593 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) { 1594 VisitCallExpr(S); 1595 } 1596 1597 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) { 1598 VisitExpr(S); 1599 } 1600 1601 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) { 1602 VisitExplicitCastExpr(S); 1603 } 1604 1605 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) { 1606 VisitCXXNamedCastExpr(S); 1607 } 1608 1609 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) { 1610 VisitCXXNamedCastExpr(S); 1611 } 1612 1613 void 1614 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) { 1615 VisitCXXNamedCastExpr(S); 1616 } 1617 1618 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) { 1619 VisitCXXNamedCastExpr(S); 1620 } 1621 1622 void StmtProfiler::VisitBuiltinBitCastExpr(const BuiltinBitCastExpr *S) { 1623 VisitExpr(S); 1624 VisitType(S->getTypeInfoAsWritten()->getType()); 1625 } 1626 1627 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) { 1628 VisitCallExpr(S); 1629 } 1630 1631 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) { 1632 VisitExpr(S); 1633 ID.AddBoolean(S->getValue()); 1634 } 1635 1636 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) { 1637 VisitExpr(S); 1638 } 1639 1640 void StmtProfiler::VisitCXXStdInitializerListExpr( 1641 const CXXStdInitializerListExpr *S) { 1642 VisitExpr(S); 1643 } 1644 1645 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) { 1646 VisitExpr(S); 1647 if (S->isTypeOperand()) 1648 VisitType(S->getTypeOperandSourceInfo()->getType()); 1649 } 1650 1651 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) { 1652 VisitExpr(S); 1653 if (S->isTypeOperand()) 1654 VisitType(S->getTypeOperandSourceInfo()->getType()); 1655 } 1656 1657 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) { 1658 VisitExpr(S); 1659 VisitDecl(S->getPropertyDecl()); 1660 } 1661 1662 void StmtProfiler::VisitMSPropertySubscriptExpr( 1663 const MSPropertySubscriptExpr *S) { 1664 VisitExpr(S); 1665 } 1666 1667 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) { 1668 VisitExpr(S); 1669 ID.AddBoolean(S->isImplicit()); 1670 } 1671 1672 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) { 1673 VisitExpr(S); 1674 } 1675 1676 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) { 1677 VisitExpr(S); 1678 VisitDecl(S->getParam()); 1679 } 1680 1681 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) { 1682 VisitExpr(S); 1683 VisitDecl(S->getField()); 1684 } 1685 1686 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) { 1687 VisitExpr(S); 1688 VisitDecl( 1689 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor())); 1690 } 1691 1692 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) { 1693 VisitExpr(S); 1694 VisitDecl(S->getConstructor()); 1695 ID.AddBoolean(S->isElidable()); 1696 } 1697 1698 void StmtProfiler::VisitCXXInheritedCtorInitExpr( 1699 const CXXInheritedCtorInitExpr *S) { 1700 VisitExpr(S); 1701 VisitDecl(S->getConstructor()); 1702 } 1703 1704 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) { 1705 VisitExplicitCastExpr(S); 1706 } 1707 1708 void 1709 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) { 1710 VisitCXXConstructExpr(S); 1711 } 1712 1713 void 1714 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) { 1715 VisitExpr(S); 1716 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), 1717 CEnd = S->explicit_capture_end(); 1718 C != CEnd; ++C) { 1719 if (C->capturesVLAType()) 1720 continue; 1721 1722 ID.AddInteger(C->getCaptureKind()); 1723 switch (C->getCaptureKind()) { 1724 case LCK_StarThis: 1725 case LCK_This: 1726 break; 1727 case LCK_ByRef: 1728 case LCK_ByCopy: 1729 VisitDecl(C->getCapturedVar()); 1730 ID.AddBoolean(C->isPackExpansion()); 1731 break; 1732 case LCK_VLAType: 1733 llvm_unreachable("VLA type in explicit captures."); 1734 } 1735 } 1736 // Note: If we actually needed to be able to match lambda 1737 // expressions, we would have to consider parameters and return type 1738 // here, among other things. 1739 VisitStmt(S->getBody()); 1740 } 1741 1742 void 1743 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) { 1744 VisitExpr(S); 1745 } 1746 1747 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) { 1748 VisitExpr(S); 1749 ID.AddBoolean(S->isGlobalDelete()); 1750 ID.AddBoolean(S->isArrayForm()); 1751 VisitDecl(S->getOperatorDelete()); 1752 } 1753 1754 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) { 1755 VisitExpr(S); 1756 VisitType(S->getAllocatedType()); 1757 VisitDecl(S->getOperatorNew()); 1758 VisitDecl(S->getOperatorDelete()); 1759 ID.AddBoolean(S->isArray()); 1760 ID.AddInteger(S->getNumPlacementArgs()); 1761 ID.AddBoolean(S->isGlobalNew()); 1762 ID.AddBoolean(S->isParenTypeId()); 1763 ID.AddInteger(S->getInitializationStyle()); 1764 } 1765 1766 void 1767 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) { 1768 VisitExpr(S); 1769 ID.AddBoolean(S->isArrow()); 1770 VisitNestedNameSpecifier(S->getQualifier()); 1771 ID.AddBoolean(S->getScopeTypeInfo() != nullptr); 1772 if (S->getScopeTypeInfo()) 1773 VisitType(S->getScopeTypeInfo()->getType()); 1774 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr); 1775 if (S->getDestroyedTypeInfo()) 1776 VisitType(S->getDestroyedType()); 1777 else 1778 VisitIdentifierInfo(S->getDestroyedTypeIdentifier()); 1779 } 1780 1781 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) { 1782 VisitExpr(S); 1783 VisitNestedNameSpecifier(S->getQualifier()); 1784 VisitName(S->getName(), /*TreatAsDecl*/ true); 1785 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1786 if (S->hasExplicitTemplateArgs()) 1787 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1788 } 1789 1790 void 1791 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) { 1792 VisitOverloadExpr(S); 1793 } 1794 1795 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) { 1796 VisitExpr(S); 1797 ID.AddInteger(S->getTrait()); 1798 ID.AddInteger(S->getNumArgs()); 1799 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 1800 VisitType(S->getArg(I)->getType()); 1801 } 1802 1803 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) { 1804 VisitExpr(S); 1805 ID.AddInteger(S->getTrait()); 1806 VisitType(S->getQueriedType()); 1807 } 1808 1809 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) { 1810 VisitExpr(S); 1811 ID.AddInteger(S->getTrait()); 1812 VisitExpr(S->getQueriedExpression()); 1813 } 1814 1815 void StmtProfiler::VisitDependentScopeDeclRefExpr( 1816 const DependentScopeDeclRefExpr *S) { 1817 VisitExpr(S); 1818 VisitName(S->getDeclName()); 1819 VisitNestedNameSpecifier(S->getQualifier()); 1820 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1821 if (S->hasExplicitTemplateArgs()) 1822 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1823 } 1824 1825 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) { 1826 VisitExpr(S); 1827 } 1828 1829 void StmtProfiler::VisitCXXUnresolvedConstructExpr( 1830 const CXXUnresolvedConstructExpr *S) { 1831 VisitExpr(S); 1832 VisitType(S->getTypeAsWritten()); 1833 ID.AddInteger(S->isListInitialization()); 1834 } 1835 1836 void StmtProfiler::VisitCXXDependentScopeMemberExpr( 1837 const CXXDependentScopeMemberExpr *S) { 1838 ID.AddBoolean(S->isImplicitAccess()); 1839 if (!S->isImplicitAccess()) { 1840 VisitExpr(S); 1841 ID.AddBoolean(S->isArrow()); 1842 } 1843 VisitNestedNameSpecifier(S->getQualifier()); 1844 VisitName(S->getMember()); 1845 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1846 if (S->hasExplicitTemplateArgs()) 1847 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1848 } 1849 1850 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) { 1851 ID.AddBoolean(S->isImplicitAccess()); 1852 if (!S->isImplicitAccess()) { 1853 VisitExpr(S); 1854 ID.AddBoolean(S->isArrow()); 1855 } 1856 VisitNestedNameSpecifier(S->getQualifier()); 1857 VisitName(S->getMemberName()); 1858 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1859 if (S->hasExplicitTemplateArgs()) 1860 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1861 } 1862 1863 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) { 1864 VisitExpr(S); 1865 } 1866 1867 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) { 1868 VisitExpr(S); 1869 } 1870 1871 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) { 1872 VisitExpr(S); 1873 VisitDecl(S->getPack()); 1874 if (S->isPartiallySubstituted()) { 1875 auto Args = S->getPartialArguments(); 1876 ID.AddInteger(Args.size()); 1877 for (const auto &TA : Args) 1878 VisitTemplateArgument(TA); 1879 } else { 1880 ID.AddInteger(0); 1881 } 1882 } 1883 1884 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr( 1885 const SubstNonTypeTemplateParmPackExpr *S) { 1886 VisitExpr(S); 1887 VisitDecl(S->getParameterPack()); 1888 VisitTemplateArgument(S->getArgumentPack()); 1889 } 1890 1891 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr( 1892 const SubstNonTypeTemplateParmExpr *E) { 1893 // Profile exactly as the replacement expression. 1894 Visit(E->getReplacement()); 1895 } 1896 1897 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) { 1898 VisitExpr(S); 1899 VisitDecl(S->getParameterPack()); 1900 ID.AddInteger(S->getNumExpansions()); 1901 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I) 1902 VisitDecl(*I); 1903 } 1904 1905 void StmtProfiler::VisitMaterializeTemporaryExpr( 1906 const MaterializeTemporaryExpr *S) { 1907 VisitExpr(S); 1908 } 1909 1910 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) { 1911 VisitExpr(S); 1912 ID.AddInteger(S->getOperator()); 1913 } 1914 1915 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) { 1916 VisitStmt(S); 1917 } 1918 1919 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) { 1920 VisitStmt(S); 1921 } 1922 1923 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) { 1924 VisitExpr(S); 1925 } 1926 1927 void StmtProfiler::VisitDependentCoawaitExpr(const DependentCoawaitExpr *S) { 1928 VisitExpr(S); 1929 } 1930 1931 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) { 1932 VisitExpr(S); 1933 } 1934 1935 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { 1936 VisitExpr(E); 1937 } 1938 1939 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) { 1940 VisitExpr(E); 1941 } 1942 1943 void StmtProfiler::VisitSourceLocExpr(const SourceLocExpr *E) { 1944 VisitExpr(E); 1945 } 1946 1947 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) { 1948 VisitExpr(S); 1949 } 1950 1951 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) { 1952 VisitExpr(E); 1953 } 1954 1955 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) { 1956 VisitExpr(E); 1957 } 1958 1959 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) { 1960 VisitExpr(E); 1961 } 1962 1963 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) { 1964 VisitExpr(S); 1965 VisitType(S->getEncodedType()); 1966 } 1967 1968 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) { 1969 VisitExpr(S); 1970 VisitName(S->getSelector()); 1971 } 1972 1973 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) { 1974 VisitExpr(S); 1975 VisitDecl(S->getProtocol()); 1976 } 1977 1978 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) { 1979 VisitExpr(S); 1980 VisitDecl(S->getDecl()); 1981 ID.AddBoolean(S->isArrow()); 1982 ID.AddBoolean(S->isFreeIvar()); 1983 } 1984 1985 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) { 1986 VisitExpr(S); 1987 if (S->isImplicitProperty()) { 1988 VisitDecl(S->getImplicitPropertyGetter()); 1989 VisitDecl(S->getImplicitPropertySetter()); 1990 } else { 1991 VisitDecl(S->getExplicitProperty()); 1992 } 1993 if (S->isSuperReceiver()) { 1994 ID.AddBoolean(S->isSuperReceiver()); 1995 VisitType(S->getSuperReceiverType()); 1996 } 1997 } 1998 1999 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) { 2000 VisitExpr(S); 2001 VisitDecl(S->getAtIndexMethodDecl()); 2002 VisitDecl(S->setAtIndexMethodDecl()); 2003 } 2004 2005 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) { 2006 VisitExpr(S); 2007 VisitName(S->getSelector()); 2008 VisitDecl(S->getMethodDecl()); 2009 } 2010 2011 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) { 2012 VisitExpr(S); 2013 ID.AddBoolean(S->isArrow()); 2014 } 2015 2016 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) { 2017 VisitExpr(S); 2018 ID.AddBoolean(S->getValue()); 2019 } 2020 2021 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr( 2022 const ObjCIndirectCopyRestoreExpr *S) { 2023 VisitExpr(S); 2024 ID.AddBoolean(S->shouldCopy()); 2025 } 2026 2027 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) { 2028 VisitExplicitCastExpr(S); 2029 ID.AddBoolean(S->getBridgeKind()); 2030 } 2031 2032 void StmtProfiler::VisitObjCAvailabilityCheckExpr( 2033 const ObjCAvailabilityCheckExpr *S) { 2034 VisitExpr(S); 2035 } 2036 2037 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args, 2038 unsigned NumArgs) { 2039 ID.AddInteger(NumArgs); 2040 for (unsigned I = 0; I != NumArgs; ++I) 2041 VisitTemplateArgument(Args[I].getArgument()); 2042 } 2043 2044 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) { 2045 // Mostly repetitive with TemplateArgument::Profile! 2046 ID.AddInteger(Arg.getKind()); 2047 switch (Arg.getKind()) { 2048 case TemplateArgument::Null: 2049 break; 2050 2051 case TemplateArgument::Type: 2052 VisitType(Arg.getAsType()); 2053 break; 2054 2055 case TemplateArgument::Template: 2056 case TemplateArgument::TemplateExpansion: 2057 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern()); 2058 break; 2059 2060 case TemplateArgument::Declaration: 2061 VisitDecl(Arg.getAsDecl()); 2062 break; 2063 2064 case TemplateArgument::NullPtr: 2065 VisitType(Arg.getNullPtrType()); 2066 break; 2067 2068 case TemplateArgument::Integral: 2069 Arg.getAsIntegral().Profile(ID); 2070 VisitType(Arg.getIntegralType()); 2071 break; 2072 2073 case TemplateArgument::Expression: 2074 Visit(Arg.getAsExpr()); 2075 break; 2076 2077 case TemplateArgument::Pack: 2078 for (const auto &P : Arg.pack_elements()) 2079 VisitTemplateArgument(P); 2080 break; 2081 } 2082 } 2083 2084 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 2085 bool Canonical) const { 2086 StmtProfilerWithPointers Profiler(ID, Context, Canonical); 2087 Profiler.Visit(this); 2088 } 2089 2090 void Stmt::ProcessODRHash(llvm::FoldingSetNodeID &ID, 2091 class ODRHash &Hash) const { 2092 StmtProfilerWithoutPointers Profiler(ID, Hash); 2093 Profiler.Visit(this); 2094 } 2095