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 } 464 465 void 466 StmtProfiler::VisitOMPExecutableDirective(const OMPExecutableDirective *S) { 467 VisitStmt(S); 468 OMPClauseProfiler P(this); 469 ArrayRef<OMPClause *> Clauses = S->clauses(); 470 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); 471 I != E; ++I) 472 if (*I) 473 P.Visit(*I); 474 } 475 476 void StmtProfiler::VisitOMPLoopDirective(const OMPLoopDirective *S) { 477 VisitOMPExecutableDirective(S); 478 } 479 480 void StmtProfiler::VisitOMPParallelDirective(const OMPParallelDirective *S) { 481 VisitOMPExecutableDirective(S); 482 } 483 484 void StmtProfiler::VisitOMPSimdDirective(const OMPSimdDirective *S) { 485 VisitOMPLoopDirective(S); 486 } 487 488 void StmtProfiler::VisitOMPForDirective(const OMPForDirective *S) { 489 VisitOMPLoopDirective(S); 490 } 491 492 void StmtProfiler::VisitOMPForSimdDirective(const OMPForSimdDirective *S) { 493 VisitOMPLoopDirective(S); 494 } 495 496 void StmtProfiler::VisitOMPSectionsDirective(const OMPSectionsDirective *S) { 497 VisitOMPExecutableDirective(S); 498 } 499 500 void StmtProfiler::VisitOMPSectionDirective(const OMPSectionDirective *S) { 501 VisitOMPExecutableDirective(S); 502 } 503 504 void StmtProfiler::VisitOMPSingleDirective(const OMPSingleDirective *S) { 505 VisitOMPExecutableDirective(S); 506 } 507 508 void StmtProfiler::VisitOMPMasterDirective(const OMPMasterDirective *S) { 509 VisitOMPExecutableDirective(S); 510 } 511 512 void StmtProfiler::VisitOMPCriticalDirective(const OMPCriticalDirective *S) { 513 VisitOMPExecutableDirective(S); 514 VisitName(S->getDirectiveName().getName()); 515 } 516 517 void 518 StmtProfiler::VisitOMPParallelForDirective(const OMPParallelForDirective *S) { 519 VisitOMPLoopDirective(S); 520 } 521 522 void StmtProfiler::VisitOMPParallelForSimdDirective( 523 const OMPParallelForSimdDirective *S) { 524 VisitOMPLoopDirective(S); 525 } 526 527 void StmtProfiler::VisitOMPParallelSectionsDirective( 528 const OMPParallelSectionsDirective *S) { 529 VisitOMPExecutableDirective(S); 530 } 531 532 void StmtProfiler::VisitOMPTaskDirective(const OMPTaskDirective *S) { 533 VisitOMPExecutableDirective(S); 534 } 535 536 void StmtProfiler::VisitOMPTaskyieldDirective(const OMPTaskyieldDirective *S) { 537 VisitOMPExecutableDirective(S); 538 } 539 540 void StmtProfiler::VisitOMPBarrierDirective(const OMPBarrierDirective *S) { 541 VisitOMPExecutableDirective(S); 542 } 543 544 void StmtProfiler::VisitOMPTaskwaitDirective(const OMPTaskwaitDirective *S) { 545 VisitOMPExecutableDirective(S); 546 } 547 548 void StmtProfiler::VisitOMPTaskgroupDirective(const OMPTaskgroupDirective *S) { 549 VisitOMPExecutableDirective(S); 550 } 551 552 void StmtProfiler::VisitOMPFlushDirective(const OMPFlushDirective *S) { 553 VisitOMPExecutableDirective(S); 554 } 555 556 void StmtProfiler::VisitOMPOrderedDirective(const OMPOrderedDirective *S) { 557 VisitOMPExecutableDirective(S); 558 } 559 560 void StmtProfiler::VisitOMPAtomicDirective(const OMPAtomicDirective *S) { 561 VisitOMPExecutableDirective(S); 562 } 563 564 void StmtProfiler::VisitOMPTargetDirective(const OMPTargetDirective *S) { 565 VisitOMPExecutableDirective(S); 566 } 567 568 void StmtProfiler::VisitOMPTargetDataDirective(const OMPTargetDataDirective *S) { 569 VisitOMPExecutableDirective(S); 570 } 571 572 void StmtProfiler::VisitOMPTeamsDirective(const OMPTeamsDirective *S) { 573 VisitOMPExecutableDirective(S); 574 } 575 576 void StmtProfiler::VisitOMPCancellationPointDirective( 577 const OMPCancellationPointDirective *S) { 578 VisitOMPExecutableDirective(S); 579 } 580 581 void StmtProfiler::VisitOMPCancelDirective(const OMPCancelDirective *S) { 582 VisitOMPExecutableDirective(S); 583 } 584 585 void StmtProfiler::VisitExpr(const Expr *S) { 586 VisitStmt(S); 587 } 588 589 void StmtProfiler::VisitDeclRefExpr(const DeclRefExpr *S) { 590 VisitExpr(S); 591 if (!Canonical) 592 VisitNestedNameSpecifier(S->getQualifier()); 593 VisitDecl(S->getDecl()); 594 if (!Canonical) 595 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 596 } 597 598 void StmtProfiler::VisitPredefinedExpr(const PredefinedExpr *S) { 599 VisitExpr(S); 600 ID.AddInteger(S->getIdentType()); 601 } 602 603 void StmtProfiler::VisitIntegerLiteral(const IntegerLiteral *S) { 604 VisitExpr(S); 605 S->getValue().Profile(ID); 606 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 607 } 608 609 void StmtProfiler::VisitCharacterLiteral(const CharacterLiteral *S) { 610 VisitExpr(S); 611 ID.AddInteger(S->getKind()); 612 ID.AddInteger(S->getValue()); 613 } 614 615 void StmtProfiler::VisitFloatingLiteral(const FloatingLiteral *S) { 616 VisitExpr(S); 617 S->getValue().Profile(ID); 618 ID.AddBoolean(S->isExact()); 619 ID.AddInteger(S->getType()->castAs<BuiltinType>()->getKind()); 620 } 621 622 void StmtProfiler::VisitImaginaryLiteral(const ImaginaryLiteral *S) { 623 VisitExpr(S); 624 } 625 626 void StmtProfiler::VisitStringLiteral(const StringLiteral *S) { 627 VisitExpr(S); 628 ID.AddString(S->getBytes()); 629 ID.AddInteger(S->getKind()); 630 } 631 632 void StmtProfiler::VisitParenExpr(const ParenExpr *S) { 633 VisitExpr(S); 634 } 635 636 void StmtProfiler::VisitParenListExpr(const ParenListExpr *S) { 637 VisitExpr(S); 638 } 639 640 void StmtProfiler::VisitUnaryOperator(const UnaryOperator *S) { 641 VisitExpr(S); 642 ID.AddInteger(S->getOpcode()); 643 } 644 645 void StmtProfiler::VisitOffsetOfExpr(const OffsetOfExpr *S) { 646 VisitType(S->getTypeSourceInfo()->getType()); 647 unsigned n = S->getNumComponents(); 648 for (unsigned i = 0; i < n; ++i) { 649 const OffsetOfExpr::OffsetOfNode& ON = S->getComponent(i); 650 ID.AddInteger(ON.getKind()); 651 switch (ON.getKind()) { 652 case OffsetOfExpr::OffsetOfNode::Array: 653 // Expressions handled below. 654 break; 655 656 case OffsetOfExpr::OffsetOfNode::Field: 657 VisitDecl(ON.getField()); 658 break; 659 660 case OffsetOfExpr::OffsetOfNode::Identifier: 661 ID.AddPointer(ON.getFieldName()); 662 break; 663 664 case OffsetOfExpr::OffsetOfNode::Base: 665 // These nodes are implicit, and therefore don't need profiling. 666 break; 667 } 668 } 669 670 VisitExpr(S); 671 } 672 673 void 674 StmtProfiler::VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *S) { 675 VisitExpr(S); 676 ID.AddInteger(S->getKind()); 677 if (S->isArgumentType()) 678 VisitType(S->getArgumentType()); 679 } 680 681 void StmtProfiler::VisitArraySubscriptExpr(const ArraySubscriptExpr *S) { 682 VisitExpr(S); 683 } 684 685 void StmtProfiler::VisitOMPArraySectionExpr(const OMPArraySectionExpr *S) { 686 VisitExpr(S); 687 } 688 689 void StmtProfiler::VisitCallExpr(const CallExpr *S) { 690 VisitExpr(S); 691 } 692 693 void StmtProfiler::VisitMemberExpr(const MemberExpr *S) { 694 VisitExpr(S); 695 VisitDecl(S->getMemberDecl()); 696 if (!Canonical) 697 VisitNestedNameSpecifier(S->getQualifier()); 698 ID.AddBoolean(S->isArrow()); 699 } 700 701 void StmtProfiler::VisitCompoundLiteralExpr(const CompoundLiteralExpr *S) { 702 VisitExpr(S); 703 ID.AddBoolean(S->isFileScope()); 704 } 705 706 void StmtProfiler::VisitCastExpr(const CastExpr *S) { 707 VisitExpr(S); 708 } 709 710 void StmtProfiler::VisitImplicitCastExpr(const ImplicitCastExpr *S) { 711 VisitCastExpr(S); 712 ID.AddInteger(S->getValueKind()); 713 } 714 715 void StmtProfiler::VisitExplicitCastExpr(const ExplicitCastExpr *S) { 716 VisitCastExpr(S); 717 VisitType(S->getTypeAsWritten()); 718 } 719 720 void StmtProfiler::VisitCStyleCastExpr(const CStyleCastExpr *S) { 721 VisitExplicitCastExpr(S); 722 } 723 724 void StmtProfiler::VisitBinaryOperator(const BinaryOperator *S) { 725 VisitExpr(S); 726 ID.AddInteger(S->getOpcode()); 727 } 728 729 void 730 StmtProfiler::VisitCompoundAssignOperator(const CompoundAssignOperator *S) { 731 VisitBinaryOperator(S); 732 } 733 734 void StmtProfiler::VisitConditionalOperator(const ConditionalOperator *S) { 735 VisitExpr(S); 736 } 737 738 void StmtProfiler::VisitBinaryConditionalOperator( 739 const BinaryConditionalOperator *S) { 740 VisitExpr(S); 741 } 742 743 void StmtProfiler::VisitAddrLabelExpr(const AddrLabelExpr *S) { 744 VisitExpr(S); 745 VisitDecl(S->getLabel()); 746 } 747 748 void StmtProfiler::VisitStmtExpr(const StmtExpr *S) { 749 VisitExpr(S); 750 } 751 752 void StmtProfiler::VisitShuffleVectorExpr(const ShuffleVectorExpr *S) { 753 VisitExpr(S); 754 } 755 756 void StmtProfiler::VisitConvertVectorExpr(const ConvertVectorExpr *S) { 757 VisitExpr(S); 758 } 759 760 void StmtProfiler::VisitChooseExpr(const ChooseExpr *S) { 761 VisitExpr(S); 762 } 763 764 void StmtProfiler::VisitGNUNullExpr(const GNUNullExpr *S) { 765 VisitExpr(S); 766 } 767 768 void StmtProfiler::VisitVAArgExpr(const VAArgExpr *S) { 769 VisitExpr(S); 770 } 771 772 void StmtProfiler::VisitInitListExpr(const InitListExpr *S) { 773 if (S->getSyntacticForm()) { 774 VisitInitListExpr(S->getSyntacticForm()); 775 return; 776 } 777 778 VisitExpr(S); 779 } 780 781 void StmtProfiler::VisitDesignatedInitExpr(const DesignatedInitExpr *S) { 782 VisitExpr(S); 783 ID.AddBoolean(S->usesGNUSyntax()); 784 for (DesignatedInitExpr::const_designators_iterator D = 785 S->designators_begin(), DEnd = S->designators_end(); 786 D != DEnd; ++D) { 787 if (D->isFieldDesignator()) { 788 ID.AddInteger(0); 789 VisitName(D->getFieldName()); 790 continue; 791 } 792 793 if (D->isArrayDesignator()) { 794 ID.AddInteger(1); 795 } else { 796 assert(D->isArrayRangeDesignator()); 797 ID.AddInteger(2); 798 } 799 ID.AddInteger(D->getFirstExprIndex()); 800 } 801 } 802 803 // Seems that if VisitInitListExpr() only works on the syntactic form of an 804 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. 805 void StmtProfiler::VisitDesignatedInitUpdateExpr( 806 const DesignatedInitUpdateExpr *S) { 807 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " 808 "initializer"); 809 } 810 811 void StmtProfiler::VisitNoInitExpr(const NoInitExpr *S) { 812 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); 813 } 814 815 void StmtProfiler::VisitImplicitValueInitExpr(const ImplicitValueInitExpr *S) { 816 VisitExpr(S); 817 } 818 819 void StmtProfiler::VisitExtVectorElementExpr(const ExtVectorElementExpr *S) { 820 VisitExpr(S); 821 VisitName(&S->getAccessor()); 822 } 823 824 void StmtProfiler::VisitBlockExpr(const BlockExpr *S) { 825 VisitExpr(S); 826 VisitDecl(S->getBlockDecl()); 827 } 828 829 void StmtProfiler::VisitGenericSelectionExpr(const GenericSelectionExpr *S) { 830 VisitExpr(S); 831 for (unsigned i = 0; i != S->getNumAssocs(); ++i) { 832 QualType T = S->getAssocType(i); 833 if (T.isNull()) 834 ID.AddPointer(nullptr); 835 else 836 VisitType(T); 837 VisitExpr(S->getAssocExpr(i)); 838 } 839 } 840 841 void StmtProfiler::VisitPseudoObjectExpr(const PseudoObjectExpr *S) { 842 VisitExpr(S); 843 for (PseudoObjectExpr::const_semantics_iterator 844 i = S->semantics_begin(), e = S->semantics_end(); i != e; ++i) 845 // Normally, we would not profile the source expressions of OVEs. 846 if (const OpaqueValueExpr *OVE = dyn_cast<OpaqueValueExpr>(*i)) 847 Visit(OVE->getSourceExpr()); 848 } 849 850 void StmtProfiler::VisitAtomicExpr(const AtomicExpr *S) { 851 VisitExpr(S); 852 ID.AddInteger(S->getOp()); 853 } 854 855 static Stmt::StmtClass DecodeOperatorCall(const CXXOperatorCallExpr *S, 856 UnaryOperatorKind &UnaryOp, 857 BinaryOperatorKind &BinaryOp) { 858 switch (S->getOperator()) { 859 case OO_None: 860 case OO_New: 861 case OO_Delete: 862 case OO_Array_New: 863 case OO_Array_Delete: 864 case OO_Arrow: 865 case OO_Call: 866 case OO_Conditional: 867 case OO_Coawait: 868 case NUM_OVERLOADED_OPERATORS: 869 llvm_unreachable("Invalid operator call kind"); 870 871 case OO_Plus: 872 if (S->getNumArgs() == 1) { 873 UnaryOp = UO_Plus; 874 return Stmt::UnaryOperatorClass; 875 } 876 877 BinaryOp = BO_Add; 878 return Stmt::BinaryOperatorClass; 879 880 case OO_Minus: 881 if (S->getNumArgs() == 1) { 882 UnaryOp = UO_Minus; 883 return Stmt::UnaryOperatorClass; 884 } 885 886 BinaryOp = BO_Sub; 887 return Stmt::BinaryOperatorClass; 888 889 case OO_Star: 890 if (S->getNumArgs() == 1) { 891 UnaryOp = UO_Deref; 892 return Stmt::UnaryOperatorClass; 893 } 894 895 BinaryOp = BO_Mul; 896 return Stmt::BinaryOperatorClass; 897 898 case OO_Slash: 899 BinaryOp = BO_Div; 900 return Stmt::BinaryOperatorClass; 901 902 case OO_Percent: 903 BinaryOp = BO_Rem; 904 return Stmt::BinaryOperatorClass; 905 906 case OO_Caret: 907 BinaryOp = BO_Xor; 908 return Stmt::BinaryOperatorClass; 909 910 case OO_Amp: 911 if (S->getNumArgs() == 1) { 912 UnaryOp = UO_AddrOf; 913 return Stmt::UnaryOperatorClass; 914 } 915 916 BinaryOp = BO_And; 917 return Stmt::BinaryOperatorClass; 918 919 case OO_Pipe: 920 BinaryOp = BO_Or; 921 return Stmt::BinaryOperatorClass; 922 923 case OO_Tilde: 924 UnaryOp = UO_Not; 925 return Stmt::UnaryOperatorClass; 926 927 case OO_Exclaim: 928 UnaryOp = UO_LNot; 929 return Stmt::UnaryOperatorClass; 930 931 case OO_Equal: 932 BinaryOp = BO_Assign; 933 return Stmt::BinaryOperatorClass; 934 935 case OO_Less: 936 BinaryOp = BO_LT; 937 return Stmt::BinaryOperatorClass; 938 939 case OO_Greater: 940 BinaryOp = BO_GT; 941 return Stmt::BinaryOperatorClass; 942 943 case OO_PlusEqual: 944 BinaryOp = BO_AddAssign; 945 return Stmt::CompoundAssignOperatorClass; 946 947 case OO_MinusEqual: 948 BinaryOp = BO_SubAssign; 949 return Stmt::CompoundAssignOperatorClass; 950 951 case OO_StarEqual: 952 BinaryOp = BO_MulAssign; 953 return Stmt::CompoundAssignOperatorClass; 954 955 case OO_SlashEqual: 956 BinaryOp = BO_DivAssign; 957 return Stmt::CompoundAssignOperatorClass; 958 959 case OO_PercentEqual: 960 BinaryOp = BO_RemAssign; 961 return Stmt::CompoundAssignOperatorClass; 962 963 case OO_CaretEqual: 964 BinaryOp = BO_XorAssign; 965 return Stmt::CompoundAssignOperatorClass; 966 967 case OO_AmpEqual: 968 BinaryOp = BO_AndAssign; 969 return Stmt::CompoundAssignOperatorClass; 970 971 case OO_PipeEqual: 972 BinaryOp = BO_OrAssign; 973 return Stmt::CompoundAssignOperatorClass; 974 975 case OO_LessLess: 976 BinaryOp = BO_Shl; 977 return Stmt::BinaryOperatorClass; 978 979 case OO_GreaterGreater: 980 BinaryOp = BO_Shr; 981 return Stmt::BinaryOperatorClass; 982 983 case OO_LessLessEqual: 984 BinaryOp = BO_ShlAssign; 985 return Stmt::CompoundAssignOperatorClass; 986 987 case OO_GreaterGreaterEqual: 988 BinaryOp = BO_ShrAssign; 989 return Stmt::CompoundAssignOperatorClass; 990 991 case OO_EqualEqual: 992 BinaryOp = BO_EQ; 993 return Stmt::BinaryOperatorClass; 994 995 case OO_ExclaimEqual: 996 BinaryOp = BO_NE; 997 return Stmt::BinaryOperatorClass; 998 999 case OO_LessEqual: 1000 BinaryOp = BO_LE; 1001 return Stmt::BinaryOperatorClass; 1002 1003 case OO_GreaterEqual: 1004 BinaryOp = BO_GE; 1005 return Stmt::BinaryOperatorClass; 1006 1007 case OO_AmpAmp: 1008 BinaryOp = BO_LAnd; 1009 return Stmt::BinaryOperatorClass; 1010 1011 case OO_PipePipe: 1012 BinaryOp = BO_LOr; 1013 return Stmt::BinaryOperatorClass; 1014 1015 case OO_PlusPlus: 1016 UnaryOp = S->getNumArgs() == 1? UO_PreInc 1017 : UO_PostInc; 1018 return Stmt::UnaryOperatorClass; 1019 1020 case OO_MinusMinus: 1021 UnaryOp = S->getNumArgs() == 1? UO_PreDec 1022 : UO_PostDec; 1023 return Stmt::UnaryOperatorClass; 1024 1025 case OO_Comma: 1026 BinaryOp = BO_Comma; 1027 return Stmt::BinaryOperatorClass; 1028 1029 1030 case OO_ArrowStar: 1031 BinaryOp = BO_PtrMemI; 1032 return Stmt::BinaryOperatorClass; 1033 1034 case OO_Subscript: 1035 return Stmt::ArraySubscriptExprClass; 1036 } 1037 1038 llvm_unreachable("Invalid overloaded operator expression"); 1039 } 1040 1041 1042 void StmtProfiler::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *S) { 1043 if (S->isTypeDependent()) { 1044 // Type-dependent operator calls are profiled like their underlying 1045 // syntactic operator. 1046 UnaryOperatorKind UnaryOp = UO_Extension; 1047 BinaryOperatorKind BinaryOp = BO_Comma; 1048 Stmt::StmtClass SC = DecodeOperatorCall(S, UnaryOp, BinaryOp); 1049 1050 ID.AddInteger(SC); 1051 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 1052 Visit(S->getArg(I)); 1053 if (SC == Stmt::UnaryOperatorClass) 1054 ID.AddInteger(UnaryOp); 1055 else if (SC == Stmt::BinaryOperatorClass || 1056 SC == Stmt::CompoundAssignOperatorClass) 1057 ID.AddInteger(BinaryOp); 1058 else 1059 assert(SC == Stmt::ArraySubscriptExprClass); 1060 1061 return; 1062 } 1063 1064 VisitCallExpr(S); 1065 ID.AddInteger(S->getOperator()); 1066 } 1067 1068 void StmtProfiler::VisitCXXMemberCallExpr(const CXXMemberCallExpr *S) { 1069 VisitCallExpr(S); 1070 } 1071 1072 void StmtProfiler::VisitCUDAKernelCallExpr(const CUDAKernelCallExpr *S) { 1073 VisitCallExpr(S); 1074 } 1075 1076 void StmtProfiler::VisitAsTypeExpr(const AsTypeExpr *S) { 1077 VisitExpr(S); 1078 } 1079 1080 void StmtProfiler::VisitCXXNamedCastExpr(const CXXNamedCastExpr *S) { 1081 VisitExplicitCastExpr(S); 1082 } 1083 1084 void StmtProfiler::VisitCXXStaticCastExpr(const CXXStaticCastExpr *S) { 1085 VisitCXXNamedCastExpr(S); 1086 } 1087 1088 void StmtProfiler::VisitCXXDynamicCastExpr(const CXXDynamicCastExpr *S) { 1089 VisitCXXNamedCastExpr(S); 1090 } 1091 1092 void 1093 StmtProfiler::VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *S) { 1094 VisitCXXNamedCastExpr(S); 1095 } 1096 1097 void StmtProfiler::VisitCXXConstCastExpr(const CXXConstCastExpr *S) { 1098 VisitCXXNamedCastExpr(S); 1099 } 1100 1101 void StmtProfiler::VisitUserDefinedLiteral(const UserDefinedLiteral *S) { 1102 VisitCallExpr(S); 1103 } 1104 1105 void StmtProfiler::VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *S) { 1106 VisitExpr(S); 1107 ID.AddBoolean(S->getValue()); 1108 } 1109 1110 void StmtProfiler::VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *S) { 1111 VisitExpr(S); 1112 } 1113 1114 void StmtProfiler::VisitCXXStdInitializerListExpr( 1115 const CXXStdInitializerListExpr *S) { 1116 VisitExpr(S); 1117 } 1118 1119 void StmtProfiler::VisitCXXTypeidExpr(const CXXTypeidExpr *S) { 1120 VisitExpr(S); 1121 if (S->isTypeOperand()) 1122 VisitType(S->getTypeOperandSourceInfo()->getType()); 1123 } 1124 1125 void StmtProfiler::VisitCXXUuidofExpr(const CXXUuidofExpr *S) { 1126 VisitExpr(S); 1127 if (S->isTypeOperand()) 1128 VisitType(S->getTypeOperandSourceInfo()->getType()); 1129 } 1130 1131 void StmtProfiler::VisitMSPropertyRefExpr(const MSPropertyRefExpr *S) { 1132 VisitExpr(S); 1133 VisitDecl(S->getPropertyDecl()); 1134 } 1135 1136 void StmtProfiler::VisitMSPropertySubscriptExpr( 1137 const MSPropertySubscriptExpr *S) { 1138 VisitExpr(S); 1139 } 1140 1141 void StmtProfiler::VisitCXXThisExpr(const CXXThisExpr *S) { 1142 VisitExpr(S); 1143 ID.AddBoolean(S->isImplicit()); 1144 } 1145 1146 void StmtProfiler::VisitCXXThrowExpr(const CXXThrowExpr *S) { 1147 VisitExpr(S); 1148 } 1149 1150 void StmtProfiler::VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *S) { 1151 VisitExpr(S); 1152 VisitDecl(S->getParam()); 1153 } 1154 1155 void StmtProfiler::VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) { 1156 VisitExpr(S); 1157 VisitDecl(S->getField()); 1158 } 1159 1160 void StmtProfiler::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *S) { 1161 VisitExpr(S); 1162 VisitDecl( 1163 const_cast<CXXDestructorDecl *>(S->getTemporary()->getDestructor())); 1164 } 1165 1166 void StmtProfiler::VisitCXXConstructExpr(const CXXConstructExpr *S) { 1167 VisitExpr(S); 1168 VisitDecl(S->getConstructor()); 1169 ID.AddBoolean(S->isElidable()); 1170 } 1171 1172 void StmtProfiler::VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) { 1173 VisitExplicitCastExpr(S); 1174 } 1175 1176 void 1177 StmtProfiler::VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *S) { 1178 VisitCXXConstructExpr(S); 1179 } 1180 1181 void 1182 StmtProfiler::VisitLambdaExpr(const LambdaExpr *S) { 1183 VisitExpr(S); 1184 for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(), 1185 CEnd = S->explicit_capture_end(); 1186 C != CEnd; ++C) { 1187 ID.AddInteger(C->getCaptureKind()); 1188 switch (C->getCaptureKind()) { 1189 case LCK_This: 1190 break; 1191 case LCK_ByRef: 1192 case LCK_ByCopy: 1193 VisitDecl(C->getCapturedVar()); 1194 ID.AddBoolean(C->isPackExpansion()); 1195 break; 1196 case LCK_VLAType: 1197 llvm_unreachable("VLA type in explicit captures."); 1198 } 1199 } 1200 // Note: If we actually needed to be able to match lambda 1201 // expressions, we would have to consider parameters and return type 1202 // here, among other things. 1203 VisitStmt(S->getBody()); 1204 } 1205 1206 void 1207 StmtProfiler::VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *S) { 1208 VisitExpr(S); 1209 } 1210 1211 void StmtProfiler::VisitCXXDeleteExpr(const CXXDeleteExpr *S) { 1212 VisitExpr(S); 1213 ID.AddBoolean(S->isGlobalDelete()); 1214 ID.AddBoolean(S->isArrayForm()); 1215 VisitDecl(S->getOperatorDelete()); 1216 } 1217 1218 1219 void StmtProfiler::VisitCXXNewExpr(const CXXNewExpr *S) { 1220 VisitExpr(S); 1221 VisitType(S->getAllocatedType()); 1222 VisitDecl(S->getOperatorNew()); 1223 VisitDecl(S->getOperatorDelete()); 1224 ID.AddBoolean(S->isArray()); 1225 ID.AddInteger(S->getNumPlacementArgs()); 1226 ID.AddBoolean(S->isGlobalNew()); 1227 ID.AddBoolean(S->isParenTypeId()); 1228 ID.AddInteger(S->getInitializationStyle()); 1229 } 1230 1231 void 1232 StmtProfiler::VisitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *S) { 1233 VisitExpr(S); 1234 ID.AddBoolean(S->isArrow()); 1235 VisitNestedNameSpecifier(S->getQualifier()); 1236 ID.AddBoolean(S->getScopeTypeInfo() != nullptr); 1237 if (S->getScopeTypeInfo()) 1238 VisitType(S->getScopeTypeInfo()->getType()); 1239 ID.AddBoolean(S->getDestroyedTypeInfo() != nullptr); 1240 if (S->getDestroyedTypeInfo()) 1241 VisitType(S->getDestroyedType()); 1242 else 1243 ID.AddPointer(S->getDestroyedTypeIdentifier()); 1244 } 1245 1246 void StmtProfiler::VisitOverloadExpr(const OverloadExpr *S) { 1247 VisitExpr(S); 1248 VisitNestedNameSpecifier(S->getQualifier()); 1249 VisitName(S->getName()); 1250 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1251 if (S->hasExplicitTemplateArgs()) 1252 VisitTemplateArguments(S->getExplicitTemplateArgs().getTemplateArgs(), 1253 S->getExplicitTemplateArgs().NumTemplateArgs); 1254 } 1255 1256 void 1257 StmtProfiler::VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *S) { 1258 VisitOverloadExpr(S); 1259 } 1260 1261 void StmtProfiler::VisitTypeTraitExpr(const TypeTraitExpr *S) { 1262 VisitExpr(S); 1263 ID.AddInteger(S->getTrait()); 1264 ID.AddInteger(S->getNumArgs()); 1265 for (unsigned I = 0, N = S->getNumArgs(); I != N; ++I) 1266 VisitType(S->getArg(I)->getType()); 1267 } 1268 1269 void StmtProfiler::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *S) { 1270 VisitExpr(S); 1271 ID.AddInteger(S->getTrait()); 1272 VisitType(S->getQueriedType()); 1273 } 1274 1275 void StmtProfiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *S) { 1276 VisitExpr(S); 1277 ID.AddInteger(S->getTrait()); 1278 VisitExpr(S->getQueriedExpression()); 1279 } 1280 1281 void StmtProfiler::VisitDependentScopeDeclRefExpr( 1282 const DependentScopeDeclRefExpr *S) { 1283 VisitExpr(S); 1284 VisitName(S->getDeclName()); 1285 VisitNestedNameSpecifier(S->getQualifier()); 1286 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1287 if (S->hasExplicitTemplateArgs()) 1288 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1289 } 1290 1291 void StmtProfiler::VisitExprWithCleanups(const ExprWithCleanups *S) { 1292 VisitExpr(S); 1293 } 1294 1295 void StmtProfiler::VisitCXXUnresolvedConstructExpr( 1296 const CXXUnresolvedConstructExpr *S) { 1297 VisitExpr(S); 1298 VisitType(S->getTypeAsWritten()); 1299 } 1300 1301 void StmtProfiler::VisitCXXDependentScopeMemberExpr( 1302 const CXXDependentScopeMemberExpr *S) { 1303 ID.AddBoolean(S->isImplicitAccess()); 1304 if (!S->isImplicitAccess()) { 1305 VisitExpr(S); 1306 ID.AddBoolean(S->isArrow()); 1307 } 1308 VisitNestedNameSpecifier(S->getQualifier()); 1309 VisitName(S->getMember()); 1310 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1311 if (S->hasExplicitTemplateArgs()) 1312 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1313 } 1314 1315 void StmtProfiler::VisitUnresolvedMemberExpr(const UnresolvedMemberExpr *S) { 1316 ID.AddBoolean(S->isImplicitAccess()); 1317 if (!S->isImplicitAccess()) { 1318 VisitExpr(S); 1319 ID.AddBoolean(S->isArrow()); 1320 } 1321 VisitNestedNameSpecifier(S->getQualifier()); 1322 VisitName(S->getMemberName()); 1323 ID.AddBoolean(S->hasExplicitTemplateArgs()); 1324 if (S->hasExplicitTemplateArgs()) 1325 VisitTemplateArguments(S->getTemplateArgs(), S->getNumTemplateArgs()); 1326 } 1327 1328 void StmtProfiler::VisitCXXNoexceptExpr(const CXXNoexceptExpr *S) { 1329 VisitExpr(S); 1330 } 1331 1332 void StmtProfiler::VisitPackExpansionExpr(const PackExpansionExpr *S) { 1333 VisitExpr(S); 1334 } 1335 1336 void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) { 1337 VisitExpr(S); 1338 VisitDecl(S->getPack()); 1339 if (S->isPartiallySubstituted()) { 1340 auto Args = S->getPartialArguments(); 1341 ID.AddInteger(Args.size()); 1342 for (const auto &TA : Args) 1343 VisitTemplateArgument(TA); 1344 } else { 1345 ID.AddInteger(0); 1346 } 1347 } 1348 1349 void StmtProfiler::VisitSubstNonTypeTemplateParmPackExpr( 1350 const SubstNonTypeTemplateParmPackExpr *S) { 1351 VisitExpr(S); 1352 VisitDecl(S->getParameterPack()); 1353 VisitTemplateArgument(S->getArgumentPack()); 1354 } 1355 1356 void StmtProfiler::VisitSubstNonTypeTemplateParmExpr( 1357 const SubstNonTypeTemplateParmExpr *E) { 1358 // Profile exactly as the replacement expression. 1359 Visit(E->getReplacement()); 1360 } 1361 1362 void StmtProfiler::VisitFunctionParmPackExpr(const FunctionParmPackExpr *S) { 1363 VisitExpr(S); 1364 VisitDecl(S->getParameterPack()); 1365 ID.AddInteger(S->getNumExpansions()); 1366 for (FunctionParmPackExpr::iterator I = S->begin(), E = S->end(); I != E; ++I) 1367 VisitDecl(*I); 1368 } 1369 1370 void StmtProfiler::VisitMaterializeTemporaryExpr( 1371 const MaterializeTemporaryExpr *S) { 1372 VisitExpr(S); 1373 } 1374 1375 void StmtProfiler::VisitCXXFoldExpr(const CXXFoldExpr *S) { 1376 VisitExpr(S); 1377 ID.AddInteger(S->getOperator()); 1378 } 1379 1380 void StmtProfiler::VisitCoroutineBodyStmt(const CoroutineBodyStmt *S) { 1381 VisitStmt(S); 1382 } 1383 1384 void StmtProfiler::VisitCoreturnStmt(const CoreturnStmt *S) { 1385 VisitStmt(S); 1386 } 1387 1388 void StmtProfiler::VisitCoawaitExpr(const CoawaitExpr *S) { 1389 VisitExpr(S); 1390 } 1391 1392 void StmtProfiler::VisitCoyieldExpr(const CoyieldExpr *S) { 1393 VisitExpr(S); 1394 } 1395 1396 void StmtProfiler::VisitOpaqueValueExpr(const OpaqueValueExpr *E) { 1397 VisitExpr(E); 1398 } 1399 1400 void StmtProfiler::VisitTypoExpr(const TypoExpr *E) { 1401 VisitExpr(E); 1402 } 1403 1404 void StmtProfiler::VisitObjCStringLiteral(const ObjCStringLiteral *S) { 1405 VisitExpr(S); 1406 } 1407 1408 void StmtProfiler::VisitObjCBoxedExpr(const ObjCBoxedExpr *E) { 1409 VisitExpr(E); 1410 } 1411 1412 void StmtProfiler::VisitObjCArrayLiteral(const ObjCArrayLiteral *E) { 1413 VisitExpr(E); 1414 } 1415 1416 void StmtProfiler::VisitObjCDictionaryLiteral(const ObjCDictionaryLiteral *E) { 1417 VisitExpr(E); 1418 } 1419 1420 void StmtProfiler::VisitObjCEncodeExpr(const ObjCEncodeExpr *S) { 1421 VisitExpr(S); 1422 VisitType(S->getEncodedType()); 1423 } 1424 1425 void StmtProfiler::VisitObjCSelectorExpr(const ObjCSelectorExpr *S) { 1426 VisitExpr(S); 1427 VisitName(S->getSelector()); 1428 } 1429 1430 void StmtProfiler::VisitObjCProtocolExpr(const ObjCProtocolExpr *S) { 1431 VisitExpr(S); 1432 VisitDecl(S->getProtocol()); 1433 } 1434 1435 void StmtProfiler::VisitObjCIvarRefExpr(const ObjCIvarRefExpr *S) { 1436 VisitExpr(S); 1437 VisitDecl(S->getDecl()); 1438 ID.AddBoolean(S->isArrow()); 1439 ID.AddBoolean(S->isFreeIvar()); 1440 } 1441 1442 void StmtProfiler::VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *S) { 1443 VisitExpr(S); 1444 if (S->isImplicitProperty()) { 1445 VisitDecl(S->getImplicitPropertyGetter()); 1446 VisitDecl(S->getImplicitPropertySetter()); 1447 } else { 1448 VisitDecl(S->getExplicitProperty()); 1449 } 1450 if (S->isSuperReceiver()) { 1451 ID.AddBoolean(S->isSuperReceiver()); 1452 VisitType(S->getSuperReceiverType()); 1453 } 1454 } 1455 1456 void StmtProfiler::VisitObjCSubscriptRefExpr(const ObjCSubscriptRefExpr *S) { 1457 VisitExpr(S); 1458 VisitDecl(S->getAtIndexMethodDecl()); 1459 VisitDecl(S->setAtIndexMethodDecl()); 1460 } 1461 1462 void StmtProfiler::VisitObjCMessageExpr(const ObjCMessageExpr *S) { 1463 VisitExpr(S); 1464 VisitName(S->getSelector()); 1465 VisitDecl(S->getMethodDecl()); 1466 } 1467 1468 void StmtProfiler::VisitObjCIsaExpr(const ObjCIsaExpr *S) { 1469 VisitExpr(S); 1470 ID.AddBoolean(S->isArrow()); 1471 } 1472 1473 void StmtProfiler::VisitObjCBoolLiteralExpr(const ObjCBoolLiteralExpr *S) { 1474 VisitExpr(S); 1475 ID.AddBoolean(S->getValue()); 1476 } 1477 1478 void StmtProfiler::VisitObjCIndirectCopyRestoreExpr( 1479 const ObjCIndirectCopyRestoreExpr *S) { 1480 VisitExpr(S); 1481 ID.AddBoolean(S->shouldCopy()); 1482 } 1483 1484 void StmtProfiler::VisitObjCBridgedCastExpr(const ObjCBridgedCastExpr *S) { 1485 VisitExplicitCastExpr(S); 1486 ID.AddBoolean(S->getBridgeKind()); 1487 } 1488 1489 void StmtProfiler::VisitDecl(const Decl *D) { 1490 ID.AddInteger(D? D->getKind() : 0); 1491 1492 if (Canonical && D) { 1493 if (const NonTypeTemplateParmDecl *NTTP = 1494 dyn_cast<NonTypeTemplateParmDecl>(D)) { 1495 ID.AddInteger(NTTP->getDepth()); 1496 ID.AddInteger(NTTP->getIndex()); 1497 ID.AddBoolean(NTTP->isParameterPack()); 1498 VisitType(NTTP->getType()); 1499 return; 1500 } 1501 1502 if (const ParmVarDecl *Parm = dyn_cast<ParmVarDecl>(D)) { 1503 // The Itanium C++ ABI uses the type, scope depth, and scope 1504 // index of a parameter when mangling expressions that involve 1505 // function parameters, so we will use the parameter's type for 1506 // establishing function parameter identity. That way, our 1507 // definition of "equivalent" (per C++ [temp.over.link]) is at 1508 // least as strong as the definition of "equivalent" used for 1509 // name mangling. 1510 VisitType(Parm->getType()); 1511 ID.AddInteger(Parm->getFunctionScopeDepth()); 1512 ID.AddInteger(Parm->getFunctionScopeIndex()); 1513 return; 1514 } 1515 1516 if (const TemplateTypeParmDecl *TTP = 1517 dyn_cast<TemplateTypeParmDecl>(D)) { 1518 ID.AddInteger(TTP->getDepth()); 1519 ID.AddInteger(TTP->getIndex()); 1520 ID.AddBoolean(TTP->isParameterPack()); 1521 return; 1522 } 1523 1524 if (const TemplateTemplateParmDecl *TTP = 1525 dyn_cast<TemplateTemplateParmDecl>(D)) { 1526 ID.AddInteger(TTP->getDepth()); 1527 ID.AddInteger(TTP->getIndex()); 1528 ID.AddBoolean(TTP->isParameterPack()); 1529 return; 1530 } 1531 } 1532 1533 ID.AddPointer(D? D->getCanonicalDecl() : nullptr); 1534 } 1535 1536 void StmtProfiler::VisitType(QualType T) { 1537 if (Canonical) 1538 T = Context.getCanonicalType(T); 1539 1540 ID.AddPointer(T.getAsOpaquePtr()); 1541 } 1542 1543 void StmtProfiler::VisitName(DeclarationName Name) { 1544 ID.AddPointer(Name.getAsOpaquePtr()); 1545 } 1546 1547 void StmtProfiler::VisitNestedNameSpecifier(NestedNameSpecifier *NNS) { 1548 if (Canonical) 1549 NNS = Context.getCanonicalNestedNameSpecifier(NNS); 1550 ID.AddPointer(NNS); 1551 } 1552 1553 void StmtProfiler::VisitTemplateName(TemplateName Name) { 1554 if (Canonical) 1555 Name = Context.getCanonicalTemplateName(Name); 1556 1557 Name.Profile(ID); 1558 } 1559 1560 void StmtProfiler::VisitTemplateArguments(const TemplateArgumentLoc *Args, 1561 unsigned NumArgs) { 1562 ID.AddInteger(NumArgs); 1563 for (unsigned I = 0; I != NumArgs; ++I) 1564 VisitTemplateArgument(Args[I].getArgument()); 1565 } 1566 1567 void StmtProfiler::VisitTemplateArgument(const TemplateArgument &Arg) { 1568 // Mostly repetitive with TemplateArgument::Profile! 1569 ID.AddInteger(Arg.getKind()); 1570 switch (Arg.getKind()) { 1571 case TemplateArgument::Null: 1572 break; 1573 1574 case TemplateArgument::Type: 1575 VisitType(Arg.getAsType()); 1576 break; 1577 1578 case TemplateArgument::Template: 1579 case TemplateArgument::TemplateExpansion: 1580 VisitTemplateName(Arg.getAsTemplateOrTemplatePattern()); 1581 break; 1582 1583 case TemplateArgument::Declaration: 1584 VisitDecl(Arg.getAsDecl()); 1585 break; 1586 1587 case TemplateArgument::NullPtr: 1588 VisitType(Arg.getNullPtrType()); 1589 break; 1590 1591 case TemplateArgument::Integral: 1592 Arg.getAsIntegral().Profile(ID); 1593 VisitType(Arg.getIntegralType()); 1594 break; 1595 1596 case TemplateArgument::Expression: 1597 Visit(Arg.getAsExpr()); 1598 break; 1599 1600 case TemplateArgument::Pack: 1601 for (const auto &P : Arg.pack_elements()) 1602 VisitTemplateArgument(P); 1603 break; 1604 } 1605 } 1606 1607 void Stmt::Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 1608 bool Canonical) const { 1609 StmtProfiler Profiler(ID, Context, Canonical); 1610 Profiler.Visit(this); 1611 } 1612