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