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