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