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