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