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/StmtVisitor.h" 23 #include "llvm/ADT/FoldingSet.h" 24 using namespace clang; 25 26 namespace { 27 class StmtProfiler : public ConstStmtVisitor<StmtProfiler> { 28 llvm::FoldingSetNodeID &ID; 29 const ASTContext &Context; 30 bool Canonical; 31 32 public: 33 StmtProfiler(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 34 bool Canonical) 35 : ID(ID), Context(Context), Canonical(Canonical) { } 36 37 void VisitStmt(const Stmt *S); 38 39 #define STMT(Node, Base) void Visit##Node(const Node *S); 40 #include "clang/AST/StmtNodes.inc" 41 42 /// \brief Visit a declaration that is referenced within an expression 43 /// or statement. 44 void VisitDecl(const Decl *D); 45 46 /// \brief Visit a type that is referenced within an expression or 47 /// statement. 48 void VisitType(QualType T); 49 50 /// \brief Visit a name that occurs within an expression or statement. 51 void VisitName(DeclarationName Name); 52 53 /// \brief Visit a nested-name-specifier that occurs within an expression 54 /// or statement. 55 void VisitNestedNameSpecifier(NestedNameSpecifier *NNS); 56 57 /// \brief Visit a template name that occurs within an expression or 58 /// statement. 59 void VisitTemplateName(TemplateName Name); 60 61 /// \brief Visit template arguments that occur within an expression or 62 /// statement. 63 void VisitTemplateArguments(const TemplateArgumentLoc *Args, 64 unsigned NumArgs); 65 66 /// \brief Visit a single template argument. 67 void VisitTemplateArgument(const TemplateArgument &Arg); 68 }; 69 } 70 71 void StmtProfiler::VisitStmt(const Stmt *S) { 72 ID.AddInteger(S->getStmtClass()); 73 for (const Stmt *SubStmt : S->children()) { 74 if (SubStmt) 75 Visit(SubStmt); 76 else 77 ID.AddInteger(0); 78 } 79 } 80 81 void StmtProfiler::VisitDeclStmt(const DeclStmt *S) { 82 VisitStmt(S); 83 for (const auto *D : S->decls()) 84 VisitDecl(D); 85 } 86 87 void StmtProfiler::VisitNullStmt(const NullStmt *S) { 88 VisitStmt(S); 89 } 90 91 void StmtProfiler::VisitCompoundStmt(const CompoundStmt *S) { 92 VisitStmt(S); 93 } 94 95 void StmtProfiler::VisitSwitchCase(const SwitchCase *S) { 96 VisitStmt(S); 97 } 98 99 void StmtProfiler::VisitCaseStmt(const CaseStmt *S) { 100 VisitStmt(S); 101 } 102 103 void StmtProfiler::VisitDefaultStmt(const DefaultStmt *S) { 104 VisitStmt(S); 105 } 106 107 void StmtProfiler::VisitLabelStmt(const LabelStmt *S) { 108 VisitStmt(S); 109 VisitDecl(S->getDecl()); 110 } 111 112 void StmtProfiler::VisitAttributedStmt(const AttributedStmt *S) { 113 VisitStmt(S); 114 // TODO: maybe visit attributes? 115 } 116 117 void StmtProfiler::VisitIfStmt(const IfStmt *S) { 118 VisitStmt(S); 119 VisitDecl(S->getConditionVariable()); 120 } 121 122 void StmtProfiler::VisitSwitchStmt(const SwitchStmt *S) { 123 VisitStmt(S); 124 VisitDecl(S->getConditionVariable()); 125 } 126 127 void StmtProfiler::VisitWhileStmt(const WhileStmt *S) { 128 VisitStmt(S); 129 VisitDecl(S->getConditionVariable()); 130 } 131 132 void StmtProfiler::VisitDoStmt(const DoStmt *S) { 133 VisitStmt(S); 134 } 135 136 void StmtProfiler::VisitForStmt(const ForStmt *S) { 137 VisitStmt(S); 138 } 139 140 void StmtProfiler::VisitGotoStmt(const GotoStmt *S) { 141 VisitStmt(S); 142 VisitDecl(S->getLabel()); 143 } 144 145 void StmtProfiler::VisitIndirectGotoStmt(const IndirectGotoStmt *S) { 146 VisitStmt(S); 147 } 148 149 void StmtProfiler::VisitContinueStmt(const ContinueStmt *S) { 150 VisitStmt(S); 151 } 152 153 void StmtProfiler::VisitBreakStmt(const BreakStmt *S) { 154 VisitStmt(S); 155 } 156 157 void StmtProfiler::VisitReturnStmt(const ReturnStmt *S) { 158 VisitStmt(S); 159 } 160 161 void StmtProfiler::VisitGCCAsmStmt(const GCCAsmStmt *S) { 162 VisitStmt(S); 163 ID.AddBoolean(S->isVolatile()); 164 ID.AddBoolean(S->isSimple()); 165 VisitStringLiteral(S->getAsmString()); 166 ID.AddInteger(S->getNumOutputs()); 167 for (unsigned I = 0, N = S->getNumOutputs(); I != N; ++I) { 168 ID.AddString(S->getOutputName(I)); 169 VisitStringLiteral(S->getOutputConstraintLiteral(I)); 170 } 171 ID.AddInteger(S->getNumInputs()); 172 for (unsigned I = 0, N = S->getNumInputs(); I != N; ++I) { 173 ID.AddString(S->getInputName(I)); 174 VisitStringLiteral(S->getInputConstraintLiteral(I)); 175 } 176 ID.AddInteger(S->getNumClobbers()); 177 for (unsigned I = 0, N = S->getNumClobbers(); I != N; ++I) 178 VisitStringLiteral(S->getClobberStringLiteral(I)); 179 } 180 181 void StmtProfiler::VisitMSAsmStmt(const MSAsmStmt *S) { 182 // FIXME: Implement MS style inline asm statement profiler. 183 VisitStmt(S); 184 } 185 186 void StmtProfiler::VisitCXXCatchStmt(const CXXCatchStmt *S) { 187 VisitStmt(S); 188 VisitType(S->getCaughtType()); 189 } 190 191 void StmtProfiler::VisitCXXTryStmt(const CXXTryStmt *S) { 192 VisitStmt(S); 193 } 194 195 void StmtProfiler::VisitCXXForRangeStmt(const CXXForRangeStmt *S) { 196 VisitStmt(S); 197 } 198 199 void StmtProfiler::VisitMSDependentExistsStmt(const MSDependentExistsStmt *S) { 200 VisitStmt(S); 201 ID.AddBoolean(S->isIfExists()); 202 VisitNestedNameSpecifier(S->getQualifierLoc().getNestedNameSpecifier()); 203 VisitName(S->getNameInfo().getName()); 204 } 205 206 void StmtProfiler::VisitSEHTryStmt(const SEHTryStmt *S) { 207 VisitStmt(S); 208 } 209 210 void StmtProfiler::VisitSEHFinallyStmt(const SEHFinallyStmt *S) { 211 VisitStmt(S); 212 } 213 214 void StmtProfiler::VisitSEHExceptStmt(const SEHExceptStmt *S) { 215 VisitStmt(S); 216 } 217 218 void StmtProfiler::VisitSEHLeaveStmt(const SEHLeaveStmt *S) { 219 VisitStmt(S); 220 } 221 222 void StmtProfiler::VisitCapturedStmt(const CapturedStmt *S) { 223 VisitStmt(S); 224 } 225 226 void StmtProfiler::VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) { 227 VisitStmt(S); 228 } 229 230 void StmtProfiler::VisitObjCAtCatchStmt(const ObjCAtCatchStmt *S) { 231 VisitStmt(S); 232 ID.AddBoolean(S->hasEllipsis()); 233 if (S->getCatchParamDecl()) 234 VisitType(S->getCatchParamDecl()->getType()); 235 } 236 237 void StmtProfiler::VisitObjCAtFinallyStmt(const ObjCAtFinallyStmt *S) { 238 VisitStmt(S); 239 } 240 241 void StmtProfiler::VisitObjCAtTryStmt(const ObjCAtTryStmt *S) { 242 VisitStmt(S); 243 } 244 245 void 246 StmtProfiler::VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S) { 247 VisitStmt(S); 248 } 249 250 void StmtProfiler::VisitObjCAtThrowStmt(const ObjCAtThrowStmt *S) { 251 VisitStmt(S); 252 } 253 254 void 255 StmtProfiler::VisitObjCAutoreleasePoolStmt(const ObjCAutoreleasePoolStmt *S) { 256 VisitStmt(S); 257 } 258 259 namespace { 260 class OMPClauseProfiler : public ConstOMPClauseVisitor<OMPClauseProfiler> { 261 StmtProfiler *Profiler; 262 /// \brief Process clauses with list of variables. 263 template <typename T> 264 void VisitOMPClauseList(T *Node); 265 public: 266 OMPClauseProfiler(StmtProfiler *P) : Profiler(P) { } 267 #define OPENMP_CLAUSE(Name, Class) \ 268 void Visit##Class(const Class *C); 269 #include "clang/Basic/OpenMPKinds.def" 270 }; 271 272 void OMPClauseProfiler::VisitOMPIfClause(const OMPIfClause *C) { 273 if (C->getCondition()) 274 Profiler->VisitStmt(C->getCondition()); 275 } 276 277 void OMPClauseProfiler::VisitOMPFinalClause(const OMPFinalClause *C) { 278 if (C->getCondition()) 279 Profiler->VisitStmt(C->getCondition()); 280 } 281 282 void OMPClauseProfiler::VisitOMPNumThreadsClause(const OMPNumThreadsClause *C) { 283 if (C->getNumThreads()) 284 Profiler->VisitStmt(C->getNumThreads()); 285 } 286 287 void OMPClauseProfiler::VisitOMPSafelenClause(const OMPSafelenClause *C) { 288 if (C->getSafelen()) 289 Profiler->VisitStmt(C->getSafelen()); 290 } 291 292 void OMPClauseProfiler::VisitOMPSimdlenClause(const OMPSimdlenClause *C) { 293 if (C->getSimdlen()) 294 Profiler->VisitStmt(C->getSimdlen()); 295 } 296 297 void OMPClauseProfiler::VisitOMPCollapseClause(const OMPCollapseClause *C) { 298 if (C->getNumForLoops()) 299 Profiler->VisitStmt(C->getNumForLoops()); 300 } 301 302 void OMPClauseProfiler::VisitOMPDefaultClause(const OMPDefaultClause *C) { } 303 304 void OMPClauseProfiler::VisitOMPProcBindClause(const OMPProcBindClause *C) { } 305 306 void OMPClauseProfiler::VisitOMPScheduleClause(const OMPScheduleClause *C) { 307 if (C->getChunkSize()) { 308 Profiler->VisitStmt(C->getChunkSize()); 309 if (C->getHelperChunkSize()) { 310 Profiler->VisitStmt(C->getChunkSize()); 311 } 312 } 313 } 314 315 void OMPClauseProfiler::VisitOMPOrderedClause(const OMPOrderedClause *C) { 316 if (auto *Num = C->getNumForLoops()) 317 Profiler->VisitStmt(Num); 318 } 319 320 void OMPClauseProfiler::VisitOMPNowaitClause(const OMPNowaitClause *) {} 321 322 void OMPClauseProfiler::VisitOMPUntiedClause(const OMPUntiedClause *) {} 323 324 void OMPClauseProfiler::VisitOMPMergeableClause(const OMPMergeableClause *) {} 325 326 void OMPClauseProfiler::VisitOMPReadClause(const OMPReadClause *) {} 327 328 void OMPClauseProfiler::VisitOMPWriteClause(const OMPWriteClause *) {} 329 330 void OMPClauseProfiler::VisitOMPUpdateClause(const OMPUpdateClause *) {} 331 332 void OMPClauseProfiler::VisitOMPCaptureClause(const OMPCaptureClause *) {} 333 334 void OMPClauseProfiler::VisitOMPSeqCstClause(const OMPSeqCstClause *) {} 335 336 void OMPClauseProfiler::VisitOMPThreadsClause(const OMPThreadsClause *) {} 337 338 void OMPClauseProfiler::VisitOMPSIMDClause(const OMPSIMDClause *) {} 339 340 template<typename T> 341 void OMPClauseProfiler::VisitOMPClauseList(T *Node) { 342 for (auto *E : Node->varlists()) { 343 Profiler->VisitStmt(E); 344 } 345 } 346 347 void OMPClauseProfiler::VisitOMPPrivateClause(const OMPPrivateClause *C) { 348 VisitOMPClauseList(C); 349 for (auto *E : C->private_copies()) { 350 Profiler->VisitStmt(E); 351 } 352 } 353 void 354 OMPClauseProfiler::VisitOMPFirstprivateClause(const OMPFirstprivateClause *C) { 355 VisitOMPClauseList(C); 356 for (auto *E : C->private_copies()) { 357 Profiler->VisitStmt(E); 358 } 359 for (auto *E : C->inits()) { 360 Profiler->VisitStmt(E); 361 } 362 } 363 void 364 OMPClauseProfiler::VisitOMPLastprivateClause(const OMPLastprivateClause *C) { 365 VisitOMPClauseList(C); 366 for (auto *E : C->source_exprs()) { 367 Profiler->VisitStmt(E); 368 } 369 for (auto *E : C->destination_exprs()) { 370 Profiler->VisitStmt(E); 371 } 372 for (auto *E : C->assignment_ops()) { 373 Profiler->VisitStmt(E); 374 } 375 } 376 void OMPClauseProfiler::VisitOMPSharedClause(const OMPSharedClause *C) { 377 VisitOMPClauseList(C); 378 } 379 void OMPClauseProfiler::VisitOMPReductionClause( 380 const OMPReductionClause *C) { 381 Profiler->VisitNestedNameSpecifier( 382 C->getQualifierLoc().getNestedNameSpecifier()); 383 Profiler->VisitName(C->getNameInfo().getName()); 384 VisitOMPClauseList(C); 385 for (auto *E : C->privates()) { 386 Profiler->VisitStmt(E); 387 } 388 for (auto *E : C->lhs_exprs()) { 389 Profiler->VisitStmt(E); 390 } 391 for (auto *E : C->rhs_exprs()) { 392 Profiler->VisitStmt(E); 393 } 394 for (auto *E : C->reduction_ops()) { 395 Profiler->VisitStmt(E); 396 } 397 } 398 void OMPClauseProfiler::VisitOMPLinearClause(const OMPLinearClause *C) { 399 VisitOMPClauseList(C); 400 for (auto *E : C->privates()) { 401 Profiler->VisitStmt(E); 402 } 403 for (auto *E : C->inits()) { 404 Profiler->VisitStmt(E); 405 } 406 for (auto *E : C->updates()) { 407 Profiler->VisitStmt(E); 408 } 409 for (auto *E : C->finals()) { 410 Profiler->VisitStmt(E); 411 } 412 Profiler->VisitStmt(C->getStep()); 413 Profiler->VisitStmt(C->getCalcStep()); 414 } 415 void OMPClauseProfiler::VisitOMPAlignedClause(const OMPAlignedClause *C) { 416 VisitOMPClauseList(C); 417 Profiler->VisitStmt(C->getAlignment()); 418 } 419 void OMPClauseProfiler::VisitOMPCopyinClause(const OMPCopyinClause *C) { 420 VisitOMPClauseList(C); 421 for (auto *E : C->source_exprs()) { 422 Profiler->VisitStmt(E); 423 } 424 for (auto *E : C->destination_exprs()) { 425 Profiler->VisitStmt(E); 426 } 427 for (auto *E : C->assignment_ops()) { 428 Profiler->VisitStmt(E); 429 } 430 } 431 void 432 OMPClauseProfiler::VisitOMPCopyprivateClause(const OMPCopyprivateClause *C) { 433 VisitOMPClauseList(C); 434 for (auto *E : C->source_exprs()) { 435 Profiler->VisitStmt(E); 436 } 437 for (auto *E : C->destination_exprs()) { 438 Profiler->VisitStmt(E); 439 } 440 for (auto *E : C->assignment_ops()) { 441 Profiler->VisitStmt(E); 442 } 443 } 444 void OMPClauseProfiler::VisitOMPFlushClause(const OMPFlushClause *C) { 445 VisitOMPClauseList(C); 446 } 447 void OMPClauseProfiler::VisitOMPDependClause(const OMPDependClause *C) { 448 VisitOMPClauseList(C); 449 } 450 void OMPClauseProfiler::VisitOMPDeviceClause(const OMPDeviceClause *C) { 451 Profiler->VisitStmt(C->getDevice()); 452 } 453 void OMPClauseProfiler::VisitOMPMapClause(const OMPMapClause *C) { 454 VisitOMPClauseList(C); 455 } 456 void OMPClauseProfiler::VisitOMPNumTeamsClause(const OMPNumTeamsClause *C) { 457 Profiler->VisitStmt(C->getNumTeams()); 458 } 459 void OMPClauseProfiler::VisitOMPThreadLimitClause( 460 const OMPThreadLimitClause *C) { 461 Profiler->VisitStmt(C->getThreadLimit()); 462 } 463 void OMPClauseProfiler::VisitOMPPriorityClause(const OMPPriorityClause *C) { 464 Profiler->VisitStmt(C->getPriority()); 465 } 466 } 467 468 void 469 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) { 470 VisitStmt(S); 471 OMPClauseProfiler P(this); 472 ArrayRef<OMPClause *> Clauses = S->clauses(); 473 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); 474 I != E; ++I) 475 if (*I) 476 P.Visit(*I); 477 } 478 479 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) { 480 VisitOMPExecutableDirective(S); 481 } 482 483 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { 484 VisitOMPExecutableDirective(S); 485 } 486 487 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) { 488 VisitOMPLoopDirective(S); 489 } 490 491 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) { 492 VisitOMPLoopDirective(S); 493 } 494 495 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) { 496 VisitOMPLoopDirective(S); 497 } 498 499 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) { 500 VisitOMPExecutableDirective(S); 501 } 502 503 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) { 504 VisitOMPExecutableDirective(S); 505 } 506 507 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) { 508 VisitOMPExecutableDirective(S); 509 } 510 511 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) { 512 VisitOMPExecutableDirective(S); 513 } 514 515 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) { 516 VisitOMPExecutableDirective(S); 517 VisitName(S->getDirectiveName().getName()); 518 } 519 520 void 521 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) { 522 VisitOMPLoopDirective(S); 523 } 524 525 void StmtProfiler::VisitOMPParallelForSimdDirective( 526 const OMPParallelForSimdDirective *S) { 527 VisitOMPLoopDirective(S); 528 } 529 530 void StmtProfiler::VisitOMPParallelSectionsDirective( 531 const OMPParallelSectionsDirective *S) { 532 VisitOMPExecutableDirective(S); 533 } 534 535 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) { 536 VisitOMPExecutableDirective(S); 537 } 538 539 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) { 540 VisitOMPExecutableDirective(S); 541 } 542 543 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) { 544 VisitOMPExecutableDirective(S); 545 } 546 547 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) { 548 VisitOMPExecutableDirective(S); 549 } 550 551 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) { 552 VisitOMPExecutableDirective(S); 553 } 554 555 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) { 556 VisitOMPExecutableDirective(S); 557 } 558 559 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) { 560 VisitOMPExecutableDirective(S); 561 } 562 563 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) { 564 VisitOMPExecutableDirective(S); 565 } 566 567 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) { 568 VisitOMPExecutableDirective(S); 569 } 570 571 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) { 572 VisitOMPExecutableDirective(S); 573 } 574 575 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) { 576 VisitOMPExecutableDirective(S); 577 } 578 579 void StmtProfiler::VisitOMPCancellationPointDirective( 580 const OMPCancellationPointDirective *S) { 581 VisitOMPExecutableDirective(S); 582 } 583 584 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) { 585 VisitOMPExecutableDirective(S); 586 } 587 588 void StmtProfiler::VisitOMPTaskLoopDirective(const OMPTaskLoopDirective *S) { 589 VisitOMPLoopDirective(S); 590 } 591 592 void StmtProfiler::VisitOMPTaskLoopSimdDirective( 593 const OMPTaskLoopSimdDirective *S) { 594 VisitOMPLoopDirective(S); 595 } 596 597 void StmtProfiler::VisitExpr(const Expr *S) { 598 VisitStmt(S); 599 } 600 601 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) { 602 VisitExpr(S); 603 if (!Canonical) 604 VisitNestedNameSpecifier(S->getQualifier()); 605 VisitDecl(S->getDecl()); 606 if (!Canonical) 607 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 608 } 609 610 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) { 611 VisitExpr(S); 612 ID.AddInteger(S->getIdentType()); 613 } 614 615 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) { 616 VisitExpr(S); 617 S->getValue().Profile(ID); 618 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 619 } 620 621 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) { 622 VisitExpr(S); 623 ID.AddInteger(S->getKind()); 624 ID.AddInteger(S->getValue()); 625 } 626 627 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) { 628 VisitExpr(S); 629 S->getValue().Profile(ID); 630 ID.AddBoolean(S->isExact()); 631 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 632 } 633 634 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) { 635 VisitExpr(S); 636 } 637 638 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) { 639 VisitExpr(S); 640 ID.AddString(S->getBytes()); 641 ID.AddInteger(S->getKind()); 642 } 643 644 void StmtProfiler::VisitParenExpr(const ParenExpr *S) { 645 VisitExpr(S); 646 } 647 648 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) { 649 VisitExpr(S); 650 } 651 652 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) { 653 VisitExpr(S); 654 ID.AddInteger(S->getOpcode()); 655 } 656 657 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) { 658 VisitType(S->getTypeSourceInfo()->getType()); 659 unsigned n = S->getNumComponents(); 660 for (unsigned i = 0; i < n; ++i) { 661 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i); 662 ID.AddInteger(ON.getKind()); 663 switch (ON.getKind()) { 664 case OffsetOfExpr::OffsetOfNode::Array: 665 // Expressions handled below. 666 break; 667 668 case OffsetOfExpr::OffsetOfNode::Field: 669 VisitDecl(ON.getField()); 670 break; 671 672 case OffsetOfExpr::OffsetOfNode::Identifier: 673 ID.AddPointer(ON.getFieldName()); 674 break; 675 676 case OffsetOfExpr::OffsetOfNode::Base: 677 // These nodes are implicit, and therefore don't need profiling. 678 break; 679 } 680 } 681 682 VisitExpr(S); 683 } 684 685 void 686 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) { 687 VisitExpr(S); 688 ID.AddInteger(S->getKind()); 689 if (S->isArgumentType()) 690 VisitType(S->getArgumentType()); 691 } 692 693 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) { 694 VisitExpr(S); 695 } 696 697 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) { 698 VisitExpr(S); 699 } 700 701 void StmtProfiler::VisitCallExpr(const CallExpr *S) { 702 VisitExpr(S); 703 } 704 705 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) { 706 VisitExpr(S); 707 VisitDecl(S->getMemberDecl()); 708 if (!Canonical) 709 VisitNestedNameSpecifier(S->getQualifier()); 710 ID.AddBoolean(S->isArrow()); 711 } 712 713 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) { 714 VisitExpr(S); 715 ID.AddBoolean(S->isFileScope()); 716 } 717 718 void StmtProfiler::VisitCastExpr(const CastExpr *S) { 719 VisitExpr(S); 720 } 721 722 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) { 723 VisitCastExpr(S); 724 ID.AddInteger(S->getValueKind()); 725 } 726 727 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) { 728 VisitCastExpr(S); 729 VisitType(S->getTypeAsWritten()); 730 } 731 732 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) { 733 VisitExplicitCastExpr(S); 734 } 735 736 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) { 737 VisitExpr(S); 738 ID.AddInteger(S->getOpcode()); 739 } 740 741 void 742 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) { 743 VisitBinaryOperator(S); 744 } 745 746 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) { 747 VisitExpr(S); 748 } 749 750 void StmtProfiler::VisitBinaryConditionalOperator( 751 const BinaryConditionalOperator *S) { 752 VisitExpr(S); 753 } 754 755 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) { 756 VisitExpr(S); 757 VisitDecl(S->getLabel()); 758 } 759 760 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) { 761 VisitExpr(S); 762 } 763 764 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) { 765 VisitExpr(S); 766 } 767 768 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) { 769 VisitExpr(S); 770 } 771 772 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) { 773 VisitExpr(S); 774 } 775 776 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) { 777 VisitExpr(S); 778 } 779 780 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) { 781 VisitExpr(S); 782 } 783 784 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) { 785 if (S->getSyntacticForm()) { 786 VisitInitListExpr(S->getSyntacticForm()); 787 return; 788 } 789 790 VisitExpr(S); 791 } 792 793 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) { 794 VisitExpr(S); 795 ID.AddBoolean(S->usesGNUSyntax()); 796 for (DesignatedInitExpr::const_designators_iterator D = 797 S->designators_begin(), DEnd = S->designators_end(); 798 D != DEnd; ++D) { 799 if (D->isFieldDesignator()) { 800 ID.AddInteger(0); 801 VisitName(D->getFieldName()); 802 continue; 803 } 804 805 if (D->isArrayDesignator()) { 806 ID.AddInteger(1); 807 } else { 808 assert(D->isArrayRangeDesignator()); 809 ID.AddInteger(2); 810 } 811 ID.AddInteger(D->getFirstExprIndex()); 812 } 813 } 814 815 // Seems that if VisitInitListExpr() only works on the syntactic form of an 816 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. 817 void StmtProfiler::VisitDesignatedInitUpdateExpr( 818 const DesignatedInitUpdateExpr *S) { 819 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " 820 "initializer"); 821 } 822 823 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) { 824 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); 825 } 826 827 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) { 828 VisitExpr(S); 829 } 830 831 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) { 832 VisitExpr(S); 833 VisitName(&S->getAccessor()); 834 } 835 836 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) { 837 VisitExpr(S); 838 VisitDecl(S->getBlockDecl()); 839 } 840 841 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) { 842 VisitExpr(S); 843 for (unsigned i = 0; i != S->getNumAssocs(); ++i) { 844 QualType T = S->getAssocType(i); 845 if (T.isNull()) 846 ID.AddPointer(nullptr); 847 else 848 VisitType(T); 849 VisitExpr(S->getAssocExpr(i)); 850 } 851 } 852 853 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) { 854 VisitExpr(S); 855 for (PseudoObjectExpr::const_semantics_iterator 856 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) 857 // Normally, we would not profile the source expressions of OVEs. 858 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i)) 859 Visit(OVE->getSourceExpr()); 860 } 861 862 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) { 863 VisitExpr(S); 864 ID.AddInteger(S->getOp()); 865 } 866 867 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S, 868 UnaryOperatorKind &UnaryOp, 869 BinaryOperatorKind &BinaryOp) { 870 switch (S->getOperator()) { 871 case OO_None: 872 case OO_New: 873 case OO_Delete: 874 case OO_Array_New: 875 case OO_Array_Delete: 876 case OO_Arrow: 877 case OO_Call: 878 case OO_Conditional: 879 case OO_Coawait: 880 case NUM_OVERLOADED_OPERATORS: 881 llvm_unreachable("Invalid operator call kind"); 882 883 case OO_Plus: 884 if (S->getNumArgs() == 1) { 885 UnaryOp = UO_Plus; 886 return Stmt::UnaryOperatorClass; 887 } 888 889 BinaryOp = BO_Add; 890 return Stmt::BinaryOperatorClass; 891 892 case OO_Minus: 893 if (S->getNumArgs() == 1) { 894 UnaryOp = UO_Minus; 895 return Stmt::UnaryOperatorClass; 896 } 897 898 BinaryOp = BO_Sub; 899 return Stmt::BinaryOperatorClass; 900 901 case OO_Star: 902 if (S->getNumArgs() == 1) { 903 UnaryOp = UO_Deref; 904 return Stmt::UnaryOperatorClass; 905 } 906 907 BinaryOp = BO_Mul; 908 return Stmt::BinaryOperatorClass; 909 910 case OO_Slash: 911 BinaryOp = BO_Div; 912 return Stmt::BinaryOperatorClass; 913 914 case OO_Percent: 915 BinaryOp = BO_Rem; 916 return Stmt::BinaryOperatorClass; 917 918 case OO_Caret: 919 BinaryOp = BO_Xor; 920 return Stmt::BinaryOperatorClass; 921 922 case OO_Amp: 923 if (S->getNumArgs() == 1) { 924 UnaryOp = UO_AddrOf; 925 return Stmt::UnaryOperatorClass; 926 } 927 928 BinaryOp = BO_And; 929 return Stmt::BinaryOperatorClass; 930 931 case OO_Pipe: 932 BinaryOp = BO_Or; 933 return Stmt::BinaryOperatorClass; 934 935 case OO_Tilde: 936 UnaryOp = UO_Not; 937 return Stmt::UnaryOperatorClass; 938 939 case OO_Exclaim: 940 UnaryOp = UO_LNot; 941 return Stmt::UnaryOperatorClass; 942 943 case OO_Equal: 944 BinaryOp = BO_Assign; 945 return Stmt::BinaryOperatorClass; 946 947 case OO_Less: 948 BinaryOp = BO_LT; 949 return Stmt::BinaryOperatorClass; 950 951 case OO_Greater: 952 BinaryOp = BO_GT; 953 return Stmt::BinaryOperatorClass; 954 955 case OO_PlusEqual: 956 BinaryOp = BO_AddAssign; 957 return Stmt::CompoundAssignOperatorClass; 958 959 case OO_MinusEqual: 960 BinaryOp = BO_SubAssign; 961 return Stmt::CompoundAssignOperatorClass; 962 963 case OO_StarEqual: 964 BinaryOp = BO_MulAssign; 965 return Stmt::CompoundAssignOperatorClass; 966 967 case OO_SlashEqual: 968 BinaryOp = BO_DivAssign; 969 return Stmt::CompoundAssignOperatorClass; 970 971 case OO_PercentEqual: 972 BinaryOp = BO_RemAssign; 973 return Stmt::CompoundAssignOperatorClass; 974 975 case OO_CaretEqual: 976 BinaryOp = BO_XorAssign; 977 return Stmt::CompoundAssignOperatorClass; 978 979 case OO_AmpEqual: 980 BinaryOp = BO_AndAssign; 981 return Stmt::CompoundAssignOperatorClass; 982 983 case OO_PipeEqual: 984 BinaryOp = BO_OrAssign; 985 return Stmt::CompoundAssignOperatorClass; 986 987 case OO_LessLess: 988 BinaryOp = BO_Shl; 989 return Stmt::BinaryOperatorClass; 990 991 case OO_GreaterGreater: 992 BinaryOp = BO_Shr; 993 return Stmt::BinaryOperatorClass; 994 995 case OO_LessLessEqual: 996 BinaryOp = BO_ShlAssign; 997 return Stmt::CompoundAssignOperatorClass; 998 999 case OO_GreaterGreaterEqual: 1000 BinaryOp = BO_ShrAssign; 1001 return Stmt::CompoundAssignOperatorClass; 1002 1003 case OO_EqualEqual: 1004 BinaryOp = BO_EQ; 1005 return Stmt::BinaryOperatorClass; 1006 1007 case OO_ExclaimEqual: 1008 BinaryOp = BO_NE; 1009 return Stmt::BinaryOperatorClass; 1010 1011 case OO_LessEqual: 1012 BinaryOp = BO_LE; 1013 return Stmt::BinaryOperatorClass; 1014 1015 case OO_GreaterEqual: 1016 BinaryOp = BO_GE; 1017 return Stmt::BinaryOperatorClass; 1018 1019 case OO_AmpAmp: 1020 BinaryOp = BO_LAnd; 1021 return Stmt::BinaryOperatorClass; 1022 1023 case OO_PipePipe: 1024 BinaryOp = BO_LOr; 1025 return Stmt::BinaryOperatorClass; 1026 1027 case OO_PlusPlus: 1028 UnaryOp = S->getNumArgs() == 1? UO_PreInc 1029 : UO_PostInc; 1030 return Stmt::UnaryOperatorClass; 1031 1032 case OO_MinusMinus: 1033 UnaryOp = S->getNumArgs() == 1? UO_PreDec 1034 : UO_PostDec; 1035 return Stmt::UnaryOperatorClass; 1036 1037 case OO_Comma: 1038 BinaryOp = BO_Comma; 1039 return Stmt::BinaryOperatorClass; 1040 1041 1042 case OO_ArrowStar: 1043 BinaryOp = BO_PtrMemI; 1044 return Stmt::BinaryOperatorClass; 1045 1046 case OO_Subscript: 1047 return Stmt::ArraySubscriptExprClass; 1048 } 1049 1050 llvm_unreachable("Invalid overloaded operator expression"); 1051 } 1052 1053 1054 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) { 1055 if (S->isTypeDependent()) { 1056 // Type-dependent operator calls are profiled like their underlying 1057 // syntactic operator. 1058 UnaryOperatorKind UnaryOp = UO_Extension; 1059 BinaryOperatorKind BinaryOp = BO_Comma; 1060 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp); 1061 1062 ID.AddInteger(SC); 1063 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 1064 Visit(S->getArg(I)); 1065 if (SC == Stmt::UnaryOperatorClass) 1066 ID.AddInteger(UnaryOp); 1067 else if (SC == Stmt::BinaryOperatorClass || 1068 SC == Stmt::CompoundAssignOperatorClass) 1069 ID.AddInteger(BinaryOp); 1070 else 1071 assert(SC == Stmt::ArraySubscriptExprClass); 1072 1073 return; 1074 } 1075 1076 VisitCallExpr(S); 1077 ID.AddInteger(S->getOperator()); 1078 } 1079 1080 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) { 1081 VisitCallExpr(S); 1082 } 1083 1084 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) { 1085 VisitCallExpr(S); 1086 } 1087 1088 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) { 1089 VisitExpr(S); 1090 } 1091 1092 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) { 1093 VisitExplicitCastExpr(S); 1094 } 1095 1096 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) { 1097 VisitCXXNamedCastExpr(S); 1098 } 1099 1100 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) { 1101 VisitCXXNamedCastExpr(S); 1102 } 1103 1104 void 1105 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) { 1106 VisitCXXNamedCastExpr(S); 1107 } 1108 1109 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) { 1110 VisitCXXNamedCastExpr(S); 1111 } 1112 1113 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) { 1114 VisitCallExpr(S); 1115 } 1116 1117 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) { 1118 VisitExpr(S); 1119 ID.AddBoolean(S->getValue()); 1120 } 1121 1122 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) { 1123 VisitExpr(S); 1124 } 1125 1126 void StmtProfiler::VisitCXXStdInitializerListExpr( 1127 const CXXStdInitializerListExpr *S) { 1128 VisitExpr(S); 1129 } 1130 1131 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) { 1132 VisitExpr(S); 1133 if (S->isTypeOperand()) 1134 VisitType(S->getTypeOperandSourceInfo()->getType()); 1135 } 1136 1137 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) { 1138 VisitExpr(S); 1139 if (S->isTypeOperand()) 1140 VisitType(S->getTypeOperandSourceInfo()->getType()); 1141 } 1142 1143 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) { 1144 VisitExpr(S); 1145 VisitDecl(S->getPropertyDecl()); 1146 } 1147 1148 void StmtProfiler::VisitMSPropertySubscriptExpr( 1149 const MSPropertySubscriptExpr *S) { 1150 VisitExpr(S); 1151 } 1152 1153 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) { 1154 VisitExpr(S); 1155 ID.AddBoolean(S->isImplicit()); 1156 } 1157 1158 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) { 1159 VisitExpr(S); 1160 } 1161 1162 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) { 1163 VisitExpr(S); 1164 VisitDecl(S->getParam()); 1165 } 1166 1167 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) { 1168 VisitExpr(S); 1169 VisitDecl(S->getField()); 1170 } 1171 1172 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) { 1173 VisitExpr(S); 1174 VisitDecl( 1175 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor())); 1176 } 1177 1178 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) { 1179 VisitExpr(S); 1180 VisitDecl(S->getConstructor()); 1181 ID.AddBoolean(S->isElidable()); 1182 } 1183 1184 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) { 1185 VisitExplicitCastExpr(S); 1186 } 1187 1188 void 1189 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) { 1190 VisitCXXConstructExpr(S); 1191 } 1192 1193 void 1194 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) { 1195 VisitExpr(S); 1196 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), 1197 CEnd = S->explicit_capture_end(); 1198 C != CEnd; ++C) { 1199 ID.AddInteger(C->getCaptureKind()); 1200 switch (C->getCaptureKind()) { 1201 case LCK_This: 1202 break; 1203 case LCK_ByRef: 1204 case LCK_ByCopy: 1205 VisitDecl(C->getCapturedVar()); 1206 ID.AddBoolean(C->isPackExpansion()); 1207 break; 1208 case LCK_VLAType: 1209 llvm_unreachable("VLA type in explicit captures."); 1210 } 1211 } 1212 // Note: If we actually needed to be able to match lambda 1213 // expressions, we would have to consider parameters and return type 1214 // here, among other things. 1215 VisitStmt(S->getBody()); 1216 } 1217 1218 void 1219 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) { 1220 VisitExpr(S); 1221 } 1222 1223 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) { 1224 VisitExpr(S); 1225 ID.AddBoolean(S->isGlobalDelete()); 1226 ID.AddBoolean(S->isArrayForm()); 1227 VisitDecl(S->getOperatorDelete()); 1228 } 1229 1230 1231 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) { 1232 VisitExpr(S); 1233 VisitType(S->getAllocatedType()); 1234 VisitDecl(S->getOperatorNew()); 1235 VisitDecl(S->getOperatorDelete()); 1236 ID.AddBoolean(S->isArray()); 1237 ID.AddInteger(S->getNumPlacementArgs()); 1238 ID.AddBoolean(S->isGlobalNew()); 1239 ID.AddBoolean(S->isParenTypeId()); 1240 ID.AddInteger(S->getInitializationStyle()); 1241 } 1242 1243 void 1244 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) { 1245 VisitExpr(S); 1246 ID.AddBoolean(S->isArrow()); 1247 VisitNestedNameSpecifier(S->getQualifier()); 1248 ID.AddBoolean(S->getScopeTypeInfo() != nullptr); 1249 if (S->getScopeTypeInfo()) 1250 VisitType(S->getScopeTypeInfo()->getType()); 1251 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr); 1252 if (S->getDestroyedTypeInfo()) 1253 VisitType(S->getDestroyedType()); 1254 else 1255 ID.AddPointer(S->getDestroyedTypeIdentifier()); 1256 } 1257 1258 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) { 1259 VisitExpr(S); 1260 VisitNestedNameSpecifier(S->getQualifier()); 1261 VisitName(S->getName()); 1262 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1263 if (S->hasExplicitTemplateArgs()) 1264 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(), 1265 S->getExplicitTemplateArgs().NumTemplateArgs); 1266 } 1267 1268 void 1269 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) { 1270 VisitOverloadExpr(S); 1271 } 1272 1273 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) { 1274 VisitExpr(S); 1275 ID.AddInteger(S->getTrait()); 1276 ID.AddInteger(S->getNumArgs()); 1277 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 1278 VisitType(S->getArg(I)->getType()); 1279 } 1280 1281 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) { 1282 VisitExpr(S); 1283 ID.AddInteger(S->getTrait()); 1284 VisitType(S->getQueriedType()); 1285 } 1286 1287 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) { 1288 VisitExpr(S); 1289 ID.AddInteger(S->getTrait()); 1290 VisitExpr(S->getQueriedExpression()); 1291 } 1292 1293 void StmtProfiler::VisitDependentScopeDeclRefExpr( 1294 const DependentScopeDeclRefExpr *S) { 1295 VisitExpr(S); 1296 VisitName(S->getDeclName()); 1297 VisitNestedNameSpecifier(S->getQualifier()); 1298 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1299 if (S->hasExplicitTemplateArgs()) 1300 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1301 } 1302 1303 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) { 1304 VisitExpr(S); 1305 } 1306 1307 void StmtProfiler::VisitCXXUnresolvedConstructExpr( 1308 const CXXUnresolvedConstructExpr *S) { 1309 VisitExpr(S); 1310 VisitType(S->getTypeAsWritten()); 1311 } 1312 1313 void StmtProfiler::VisitCXXDependentScopeMemberExpr( 1314 const CXXDependentScopeMemberExpr *S) { 1315 ID.AddBoolean(S->isImplicitAccess()); 1316 if (!S->isImplicitAccess()) { 1317 VisitExpr(S); 1318 ID.AddBoolean(S->isArrow()); 1319 } 1320 VisitNestedNameSpecifier(S->getQualifier()); 1321 VisitName(S->getMember()); 1322 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1323 if (S->hasExplicitTemplateArgs()) 1324 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1325 } 1326 1327 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) { 1328 ID.AddBoolean(S->isImplicitAccess()); 1329 if (!S->isImplicitAccess()) { 1330 VisitExpr(S); 1331 ID.AddBoolean(S->isArrow()); 1332 } 1333 VisitNestedNameSpecifier(S->getQualifier()); 1334 VisitName(S->getMemberName()); 1335 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1336 if (S->hasExplicitTemplateArgs()) 1337 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1338 } 1339 1340 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) { 1341 VisitExpr(S); 1342 } 1343 1344 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) { 1345 VisitExpr(S); 1346 } 1347 1348 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) { 1349 VisitExpr(S); 1350 VisitDecl(S->getPack()); 1351 if (S->isPartiallySubstituted()) { 1352 auto Args = S->getPartialArguments(); 1353 ID.AddInteger(Args.size()); 1354 for (const auto &TA : Args) 1355 VisitTemplateArgument(TA); 1356 } else { 1357 ID.AddInteger(0); 1358 } 1359 } 1360 1361 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr( 1362 const SubstNonTypeTemplateParmPackExpr *S) { 1363 VisitExpr(S); 1364 VisitDecl(S->getParameterPack()); 1365 VisitTemplateArgument(S->getArgumentPack()); 1366 } 1367 1368 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr( 1369 const SubstNonTypeTemplateParmExpr *E) { 1370 // Profile exactly as the replacement expression. 1371 Visit(E->getReplacement()); 1372 } 1373 1374 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) { 1375 VisitExpr(S); 1376 VisitDecl(S->getParameterPack()); 1377 ID.AddInteger(S->getNumExpansions()); 1378 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I) 1379 VisitDecl(*I); 1380 } 1381 1382 void StmtProfiler::VisitMaterializeTemporaryExpr( 1383 const MaterializeTemporaryExpr *S) { 1384 VisitExpr(S); 1385 } 1386 1387 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) { 1388 VisitExpr(S); 1389 ID.AddInteger(S->getOperator()); 1390 } 1391 1392 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) { 1393 VisitStmt(S); 1394 } 1395 1396 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) { 1397 VisitStmt(S); 1398 } 1399 1400 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) { 1401 VisitExpr(S); 1402 } 1403 1404 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) { 1405 VisitExpr(S); 1406 } 1407 1408 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { 1409 VisitExpr(E); 1410 } 1411 1412 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) { 1413 VisitExpr(E); 1414 } 1415 1416 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) { 1417 VisitExpr(S); 1418 } 1419 1420 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) { 1421 VisitExpr(E); 1422 } 1423 1424 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) { 1425 VisitExpr(E); 1426 } 1427 1428 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) { 1429 VisitExpr(E); 1430 } 1431 1432 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) { 1433 VisitExpr(S); 1434 VisitType(S->getEncodedType()); 1435 } 1436 1437 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) { 1438 VisitExpr(S); 1439 VisitName(S->getSelector()); 1440 } 1441 1442 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) { 1443 VisitExpr(S); 1444 VisitDecl(S->getProtocol()); 1445 } 1446 1447 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) { 1448 VisitExpr(S); 1449 VisitDecl(S->getDecl()); 1450 ID.AddBoolean(S->isArrow()); 1451 ID.AddBoolean(S->isFreeIvar()); 1452 } 1453 1454 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) { 1455 VisitExpr(S); 1456 if (S->isImplicitProperty()) { 1457 VisitDecl(S->getImplicitPropertyGetter()); 1458 VisitDecl(S->getImplicitPropertySetter()); 1459 } else { 1460 VisitDecl(S->getExplicitProperty()); 1461 } 1462 if (S->isSuperReceiver()) { 1463 ID.AddBoolean(S->isSuperReceiver()); 1464 VisitType(S->getSuperReceiverType()); 1465 } 1466 } 1467 1468 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) { 1469 VisitExpr(S); 1470 VisitDecl(S->getAtIndexMethodDecl()); 1471 VisitDecl(S->setAtIndexMethodDecl()); 1472 } 1473 1474 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) { 1475 VisitExpr(S); 1476 VisitName(S->getSelector()); 1477 VisitDecl(S->getMethodDecl()); 1478 } 1479 1480 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) { 1481 VisitExpr(S); 1482 ID.AddBoolean(S->isArrow()); 1483 } 1484 1485 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) { 1486 VisitExpr(S); 1487 ID.AddBoolean(S->getValue()); 1488 } 1489 1490 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr( 1491 const ObjCIndirectCopyRestoreExpr *S) { 1492 VisitExpr(S); 1493 ID.AddBoolean(S->shouldCopy()); 1494 } 1495 1496 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) { 1497 VisitExplicitCastExpr(S); 1498 ID.AddBoolean(S->getBridgeKind()); 1499 } 1500 1501 void StmtProfiler::VisitDecl(const Decl *D) { 1502 ID.AddInteger(D? D->getKind() : 0); 1503 1504 if (Canonical && D) { 1505 if (const NonTypeTemplateParmDecl *NTTP = 1506 dyn_cast<NonTypeTemplateParmDecl>(D)) { 1507 ID.AddInteger(NTTP->getDepth()); 1508 ID.AddInteger(NTTP->getIndex()); 1509 ID.AddBoolean(NTTP->isParameterPack()); 1510 VisitType(NTTP->getType()); 1511 return; 1512 } 1513 1514 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { 1515 // The Itanium C++ ABI uses the type, scope depth, and scope 1516 // index of a parameter when mangling expressions that involve 1517 // function parameters, so we will use the parameter's type for 1518 // establishing function parameter identity. That way, our 1519 // definition of "equivalent" (per C++ [temp.over.link]) is at 1520 // least as strong as the definition of "equivalent" used for 1521 // name mangling. 1522 VisitType(Parm->getType()); 1523 ID.AddInteger(Parm->getFunctionScopeDepth()); 1524 ID.AddInteger(Parm->getFunctionScopeIndex()); 1525 return; 1526 } 1527 1528 if (const TemplateTypeParmDecl *TTP = 1529 dyn_cast<TemplateTypeParmDecl>(D)) { 1530 ID.AddInteger(TTP->getDepth()); 1531 ID.AddInteger(TTP->getIndex()); 1532 ID.AddBoolean(TTP->isParameterPack()); 1533 return; 1534 } 1535 1536 if (const TemplateTemplateParmDecl *TTP = 1537 dyn_cast<TemplateTemplateParmDecl>(D)) { 1538 ID.AddInteger(TTP->getDepth()); 1539 ID.AddInteger(TTP->getIndex()); 1540 ID.AddBoolean(TTP->isParameterPack()); 1541 return; 1542 } 1543 } 1544 1545 ID.AddPointer(D? D->getCanonicalDecl() : nullptr); 1546 } 1547 1548 void StmtProfiler::VisitType(QualType T) { 1549 if (Canonical) 1550 T = Context.getCanonicalType(T); 1551 1552 ID.AddPointer(T.getAsOpaquePtr()); 1553 } 1554 1555 void StmtProfiler::VisitName(DeclarationName Name) { 1556 ID.AddPointer(Name.getAsOpaquePtr()); 1557 } 1558 1559 void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) { 1560 if (Canonical) 1561 NNS = Context.getCanonicalNestedNameSpecifier(NNS); 1562 ID.AddPointer(NNS); 1563 } 1564 1565 void StmtProfiler::VisitTemplateName(TemplateName Name) { 1566 if (Canonical) 1567 Name = Context.getCanonicalTemplateName(Name); 1568 1569 Name.Profile(ID); 1570 } 1571 1572 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args, 1573 unsigned NumArgs) { 1574 ID.AddInteger(NumArgs); 1575 for (unsigned I = 0; I != NumArgs; ++I) 1576 VisitTemplateArgument(Args[I].getArgument()); 1577 } 1578 1579 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) { 1580 // Mostly repetitive with TemplateArgument::Profile! 1581 ID.AddInteger(Arg.getKind()); 1582 switch (Arg.getKind()) { 1583 case TemplateArgument::Null: 1584 break; 1585 1586 case TemplateArgument::Type: 1587 VisitType(Arg.getAsType()); 1588 break; 1589 1590 case TemplateArgument::Template: 1591 case TemplateArgument::TemplateExpansion: 1592 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern()); 1593 break; 1594 1595 case TemplateArgument::Declaration: 1596 VisitDecl(Arg.getAsDecl()); 1597 break; 1598 1599 case TemplateArgument::NullPtr: 1600 VisitType(Arg.getNullPtrType()); 1601 break; 1602 1603 case TemplateArgument::Integral: 1604 Arg.getAsIntegral().Profile(ID); 1605 VisitType(Arg.getIntegralType()); 1606 break; 1607 1608 case TemplateArgument::Expression: 1609 Visit(Arg.getAsExpr()); 1610 break; 1611 1612 case TemplateArgument::Pack: 1613 for (const auto &P : Arg.pack_elements()) 1614 VisitTemplateArgument(P); 1615 break; 1616 } 1617 } 1618 1619 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 1620 bool Canonical) const { 1621 StmtProfiler Profiler(ID, Context, Canonical); 1622 Profiler.Visit(this); 1623 } 1624