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