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