1 //===- Attributor.cpp - Module-wide attribute deduction -------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements an interprocedural pass that deduces and/or propagates 10 // attributes. This is done in an abstract interpretation style fixpoint 11 // iteration. See the Attributor.h file comment and the class descriptions in 12 // that file for more information. 13 // 14 //===----------------------------------------------------------------------===// 15 16 #include "llvm/Transforms/IPO/Attributor.h" 17 18 #include "llvm/ADT/Statistic.h" 19 #include "llvm/Analysis/LazyValueInfo.h" 20 #include "llvm/Analysis/MustExecute.h" 21 #include "llvm/Analysis/ValueTracking.h" 22 #include "llvm/IR/IRBuilder.h" 23 #include "llvm/IR/NoFolder.h" 24 #include "llvm/IR/Verifier.h" 25 #include "llvm/InitializePasses.h" 26 #include "llvm/Support/CommandLine.h" 27 #include "llvm/Transforms/Utils/BasicBlockUtils.h" 28 #include "llvm/Transforms/Utils/Local.h" 29 30 #include <cassert> 31 32 using namespace llvm; 33 34 #define DEBUG_TYPE "attributor" 35 36 STATISTIC(NumFnDeleted, "Number of function deleted"); 37 STATISTIC(NumFnWithExactDefinition, 38 "Number of functions with exact definitions"); 39 STATISTIC(NumFnWithoutExactDefinition, 40 "Number of functions without exact definitions"); 41 STATISTIC(NumFnShallowWrapperCreated, "Number of shallow wrappers created"); 42 STATISTIC(NumAttributesTimedOut, 43 "Number of abstract attributes timed out before fixpoint"); 44 STATISTIC(NumAttributesValidFixpoint, 45 "Number of abstract attributes in a valid fixpoint state"); 46 STATISTIC(NumAttributesManifested, 47 "Number of abstract attributes manifested in IR"); 48 STATISTIC(NumAttributesFixedDueToRequiredDependences, 49 "Number of abstract attributes fixed due to required dependences"); 50 51 // TODO: Determine a good default value. 52 // 53 // In the LLVM-TS and SPEC2006, 32 seems to not induce compile time overheads 54 // (when run with the first 5 abstract attributes). The results also indicate 55 // that we never reach 32 iterations but always find a fixpoint sooner. 56 // 57 // This will become more evolved once we perform two interleaved fixpoint 58 // iterations: bottom-up and top-down. 59 static cl::opt<unsigned> 60 MaxFixpointIterations("attributor-max-iterations", cl::Hidden, 61 cl::desc("Maximal number of fixpoint iterations."), 62 cl::init(32)); 63 static cl::opt<bool> VerifyMaxFixpointIterations( 64 "attributor-max-iterations-verify", cl::Hidden, 65 cl::desc("Verify that max-iterations is a tight bound for a fixpoint"), 66 cl::init(false)); 67 68 static cl::opt<bool> AnnotateDeclarationCallSites( 69 "attributor-annotate-decl-cs", cl::Hidden, 70 cl::desc("Annotate call sites of function declarations."), cl::init(false)); 71 72 static cl::opt<bool> EnableHeapToStack("enable-heap-to-stack-conversion", 73 cl::init(true), cl::Hidden); 74 75 static cl::opt<bool> 76 AllowShallowWrappers("attributor-allow-shallow-wrappers", cl::Hidden, 77 cl::desc("Allow the Attributor to create shallow " 78 "wrappers for non-exact definitions."), 79 cl::init(false)); 80 81 static cl::list<std::string> 82 SeedAllowList("attributor-seed-allow-list", cl::Hidden, 83 cl::desc("Comma seperated list of attrbute names that are " 84 "allowed to be seeded."), 85 cl::ZeroOrMore, cl::CommaSeparated); 86 87 /// Logic operators for the change status enum class. 88 /// 89 ///{ 90 ChangeStatus llvm::operator|(ChangeStatus l, ChangeStatus r) { 91 return l == ChangeStatus::CHANGED ? l : r; 92 } 93 ChangeStatus llvm::operator&(ChangeStatus l, ChangeStatus r) { 94 return l == ChangeStatus::UNCHANGED ? l : r; 95 } 96 ///} 97 98 /// Return true if \p New is equal or worse than \p Old. 99 static bool isEqualOrWorse(const Attribute &New, const Attribute &Old) { 100 if (!Old.isIntAttribute()) 101 return true; 102 103 return Old.getValueAsInt() >= New.getValueAsInt(); 104 } 105 106 /// Return true if the information provided by \p Attr was added to the 107 /// attribute list \p Attrs. This is only the case if it was not already present 108 /// in \p Attrs at the position describe by \p PK and \p AttrIdx. 109 static bool addIfNotExistent(LLVMContext &Ctx, const Attribute &Attr, 110 AttributeList &Attrs, int AttrIdx) { 111 112 if (Attr.isEnumAttribute()) { 113 Attribute::AttrKind Kind = Attr.getKindAsEnum(); 114 if (Attrs.hasAttribute(AttrIdx, Kind)) 115 if (isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) 116 return false; 117 Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); 118 return true; 119 } 120 if (Attr.isStringAttribute()) { 121 StringRef Kind = Attr.getKindAsString(); 122 if (Attrs.hasAttribute(AttrIdx, Kind)) 123 if (isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) 124 return false; 125 Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); 126 return true; 127 } 128 if (Attr.isIntAttribute()) { 129 Attribute::AttrKind Kind = Attr.getKindAsEnum(); 130 if (Attrs.hasAttribute(AttrIdx, Kind)) 131 if (isEqualOrWorse(Attr, Attrs.getAttribute(AttrIdx, Kind))) 132 return false; 133 Attrs = Attrs.removeAttribute(Ctx, AttrIdx, Kind); 134 Attrs = Attrs.addAttribute(Ctx, AttrIdx, Attr); 135 return true; 136 } 137 138 llvm_unreachable("Expected enum or string attribute!"); 139 } 140 141 Argument *IRPosition::getAssociatedArgument() const { 142 if (getPositionKind() == IRP_ARGUMENT) 143 return cast<Argument>(&getAnchorValue()); 144 145 // Not an Argument and no argument number means this is not a call site 146 // argument, thus we cannot find a callback argument to return. 147 int ArgNo = getArgNo(); 148 if (ArgNo < 0) 149 return nullptr; 150 151 // Use abstract call sites to make the connection between the call site 152 // values and the ones in callbacks. If a callback was found that makes use 153 // of the underlying call site operand, we want the corresponding callback 154 // callee argument and not the direct callee argument. 155 Optional<Argument *> CBCandidateArg; 156 SmallVector<const Use *, 4> CallbackUses; 157 const auto &CB = cast<CallBase>(getAnchorValue()); 158 AbstractCallSite::getCallbackUses(CB, CallbackUses); 159 for (const Use *U : CallbackUses) { 160 AbstractCallSite ACS(U); 161 assert(ACS && ACS.isCallbackCall()); 162 if (!ACS.getCalledFunction()) 163 continue; 164 165 for (unsigned u = 0, e = ACS.getNumArgOperands(); u < e; u++) { 166 167 // Test if the underlying call site operand is argument number u of the 168 // callback callee. 169 if (ACS.getCallArgOperandNo(u) != ArgNo) 170 continue; 171 172 assert(ACS.getCalledFunction()->arg_size() > u && 173 "ACS mapped into var-args arguments!"); 174 if (CBCandidateArg.hasValue()) { 175 CBCandidateArg = nullptr; 176 break; 177 } 178 CBCandidateArg = ACS.getCalledFunction()->getArg(u); 179 } 180 } 181 182 // If we found a unique callback candidate argument, return it. 183 if (CBCandidateArg.hasValue() && CBCandidateArg.getValue()) 184 return CBCandidateArg.getValue(); 185 186 // If no callbacks were found, or none used the underlying call site operand 187 // exclusively, use the direct callee argument if available. 188 const Function *Callee = CB.getCalledFunction(); 189 if (Callee && Callee->arg_size() > unsigned(ArgNo)) 190 return Callee->getArg(ArgNo); 191 192 return nullptr; 193 } 194 195 ChangeStatus AbstractAttribute::update(Attributor &A) { 196 ChangeStatus HasChanged = ChangeStatus::UNCHANGED; 197 if (getState().isAtFixpoint()) 198 return HasChanged; 199 200 LLVM_DEBUG(dbgs() << "[Attributor] Update: " << *this << "\n"); 201 202 HasChanged = updateImpl(A); 203 204 LLVM_DEBUG(dbgs() << "[Attributor] Update " << HasChanged << " " << *this 205 << "\n"); 206 207 return HasChanged; 208 } 209 210 ChangeStatus 211 IRAttributeManifest::manifestAttrs(Attributor &A, const IRPosition &IRP, 212 const ArrayRef<Attribute> &DeducedAttrs) { 213 Function *ScopeFn = IRP.getAnchorScope(); 214 IRPosition::Kind PK = IRP.getPositionKind(); 215 216 // In the following some generic code that will manifest attributes in 217 // DeducedAttrs if they improve the current IR. Due to the different 218 // annotation positions we use the underlying AttributeList interface. 219 220 AttributeList Attrs; 221 switch (PK) { 222 case IRPosition::IRP_INVALID: 223 case IRPosition::IRP_FLOAT: 224 return ChangeStatus::UNCHANGED; 225 case IRPosition::IRP_ARGUMENT: 226 case IRPosition::IRP_FUNCTION: 227 case IRPosition::IRP_RETURNED: 228 Attrs = ScopeFn->getAttributes(); 229 break; 230 case IRPosition::IRP_CALL_SITE: 231 case IRPosition::IRP_CALL_SITE_RETURNED: 232 case IRPosition::IRP_CALL_SITE_ARGUMENT: 233 Attrs = cast<CallBase>(IRP.getAnchorValue()).getAttributes(); 234 break; 235 } 236 237 ChangeStatus HasChanged = ChangeStatus::UNCHANGED; 238 LLVMContext &Ctx = IRP.getAnchorValue().getContext(); 239 for (const Attribute &Attr : DeducedAttrs) { 240 if (!addIfNotExistent(Ctx, Attr, Attrs, IRP.getAttrIdx())) 241 continue; 242 243 HasChanged = ChangeStatus::CHANGED; 244 } 245 246 if (HasChanged == ChangeStatus::UNCHANGED) 247 return HasChanged; 248 249 switch (PK) { 250 case IRPosition::IRP_ARGUMENT: 251 case IRPosition::IRP_FUNCTION: 252 case IRPosition::IRP_RETURNED: 253 ScopeFn->setAttributes(Attrs); 254 break; 255 case IRPosition::IRP_CALL_SITE: 256 case IRPosition::IRP_CALL_SITE_RETURNED: 257 case IRPosition::IRP_CALL_SITE_ARGUMENT: 258 cast<CallBase>(IRP.getAnchorValue()).setAttributes(Attrs); 259 break; 260 case IRPosition::IRP_INVALID: 261 case IRPosition::IRP_FLOAT: 262 break; 263 } 264 265 return HasChanged; 266 } 267 268 const IRPosition IRPosition::EmptyKey(DenseMapInfo<void *>::getEmptyKey()); 269 const IRPosition 270 IRPosition::TombstoneKey(DenseMapInfo<void *>::getTombstoneKey()); 271 272 SubsumingPositionIterator::SubsumingPositionIterator(const IRPosition &IRP) { 273 IRPositions.emplace_back(IRP); 274 275 const auto *CB = dyn_cast<CallBase>(&IRP.getAnchorValue()); 276 switch (IRP.getPositionKind()) { 277 case IRPosition::IRP_INVALID: 278 case IRPosition::IRP_FLOAT: 279 case IRPosition::IRP_FUNCTION: 280 return; 281 case IRPosition::IRP_ARGUMENT: 282 case IRPosition::IRP_RETURNED: 283 IRPositions.emplace_back(IRPosition::function(*IRP.getAnchorScope())); 284 return; 285 case IRPosition::IRP_CALL_SITE: 286 assert(CB && "Expected call site!"); 287 // TODO: We need to look at the operand bundles similar to the redirection 288 // in CallBase. 289 if (!CB->hasOperandBundles()) 290 if (const Function *Callee = CB->getCalledFunction()) 291 IRPositions.emplace_back(IRPosition::function(*Callee)); 292 return; 293 case IRPosition::IRP_CALL_SITE_RETURNED: 294 assert(CB && "Expected call site!"); 295 // TODO: We need to look at the operand bundles similar to the redirection 296 // in CallBase. 297 if (!CB->hasOperandBundles()) { 298 if (const Function *Callee = CB->getCalledFunction()) { 299 IRPositions.emplace_back(IRPosition::returned(*Callee)); 300 IRPositions.emplace_back(IRPosition::function(*Callee)); 301 for (const Argument &Arg : Callee->args()) 302 if (Arg.hasReturnedAttr()) { 303 IRPositions.emplace_back( 304 IRPosition::callsite_argument(*CB, Arg.getArgNo())); 305 IRPositions.emplace_back( 306 IRPosition::value(*CB->getArgOperand(Arg.getArgNo()))); 307 IRPositions.emplace_back(IRPosition::argument(Arg)); 308 } 309 } 310 } 311 IRPositions.emplace_back(IRPosition::callsite_function(*CB)); 312 return; 313 case IRPosition::IRP_CALL_SITE_ARGUMENT: { 314 int ArgNo = IRP.getArgNo(); 315 assert(CB && ArgNo >= 0 && "Expected call site!"); 316 // TODO: We need to look at the operand bundles similar to the redirection 317 // in CallBase. 318 if (!CB->hasOperandBundles()) { 319 const Function *Callee = CB->getCalledFunction(); 320 if (Callee && Callee->arg_size() > unsigned(ArgNo)) 321 IRPositions.emplace_back(IRPosition::argument(*Callee->getArg(ArgNo))); 322 if (Callee) 323 IRPositions.emplace_back(IRPosition::function(*Callee)); 324 } 325 IRPositions.emplace_back(IRPosition::value(IRP.getAssociatedValue())); 326 return; 327 } 328 } 329 } 330 331 bool IRPosition::hasAttr(ArrayRef<Attribute::AttrKind> AKs, 332 bool IgnoreSubsumingPositions, Attributor *A) const { 333 SmallVector<Attribute, 4> Attrs; 334 for (const IRPosition &EquivIRP : SubsumingPositionIterator(*this)) { 335 for (Attribute::AttrKind AK : AKs) 336 if (EquivIRP.getAttrsFromIRAttr(AK, Attrs)) 337 return true; 338 // The first position returned by the SubsumingPositionIterator is 339 // always the position itself. If we ignore subsuming positions we 340 // are done after the first iteration. 341 if (IgnoreSubsumingPositions) 342 break; 343 } 344 if (A) 345 for (Attribute::AttrKind AK : AKs) 346 if (getAttrsFromAssumes(AK, Attrs, *A)) 347 return true; 348 return false; 349 } 350 351 void IRPosition::getAttrs(ArrayRef<Attribute::AttrKind> AKs, 352 SmallVectorImpl<Attribute> &Attrs, 353 bool IgnoreSubsumingPositions, Attributor *A) const { 354 for (const IRPosition &EquivIRP : SubsumingPositionIterator(*this)) { 355 for (Attribute::AttrKind AK : AKs) 356 EquivIRP.getAttrsFromIRAttr(AK, Attrs); 357 // The first position returned by the SubsumingPositionIterator is 358 // always the position itself. If we ignore subsuming positions we 359 // are done after the first iteration. 360 if (IgnoreSubsumingPositions) 361 break; 362 } 363 if (A) 364 for (Attribute::AttrKind AK : AKs) 365 getAttrsFromAssumes(AK, Attrs, *A); 366 } 367 368 bool IRPosition::getAttrsFromIRAttr(Attribute::AttrKind AK, 369 SmallVectorImpl<Attribute> &Attrs) const { 370 if (getPositionKind() == IRP_INVALID || getPositionKind() == IRP_FLOAT) 371 return false; 372 373 AttributeList AttrList; 374 if (const auto *CB = dyn_cast<CallBase>(&getAnchorValue())) 375 AttrList = CB->getAttributes(); 376 else 377 AttrList = getAssociatedFunction()->getAttributes(); 378 379 bool HasAttr = AttrList.hasAttribute(getAttrIdx(), AK); 380 if (HasAttr) 381 Attrs.push_back(AttrList.getAttribute(getAttrIdx(), AK)); 382 return HasAttr; 383 } 384 385 bool IRPosition::getAttrsFromAssumes(Attribute::AttrKind AK, 386 SmallVectorImpl<Attribute> &Attrs, 387 Attributor &A) const { 388 assert(getPositionKind() != IRP_INVALID && "Did expect a valid position!"); 389 Value &AssociatedValue = getAssociatedValue(); 390 391 const Assume2KnowledgeMap &A2K = 392 A.getInfoCache().getKnowledgeMap().lookup({&AssociatedValue, AK}); 393 394 // Check if we found any potential assume use, if not we don't need to create 395 // explorer iterators. 396 if (A2K.empty()) 397 return false; 398 399 LLVMContext &Ctx = AssociatedValue.getContext(); 400 unsigned AttrsSize = Attrs.size(); 401 MustBeExecutedContextExplorer &Explorer = 402 A.getInfoCache().getMustBeExecutedContextExplorer(); 403 auto EIt = Explorer.begin(getCtxI()), EEnd = Explorer.end(getCtxI()); 404 for (auto &It : A2K) 405 if (Explorer.findInContextOf(It.first, EIt, EEnd)) 406 Attrs.push_back(Attribute::get(Ctx, AK, It.second.Max)); 407 return AttrsSize != Attrs.size(); 408 } 409 410 void IRPosition::verify() { 411 #ifdef EXPENSIVE_CHECKS 412 switch (getPositionKind()) { 413 case IRP_INVALID: 414 assert(!Enc.getOpaqueValue() && 415 "Expected a nullptr for an invalid position!"); 416 return; 417 case IRP_FLOAT: 418 assert((!isa<CallBase>(&getAssociatedValue()) && 419 !isa<Argument>(&getAssociatedValue())) && 420 "Expected specialized kind for call base and argument values!"); 421 return; 422 case IRP_RETURNED: 423 assert(isa<Function>(getAsValuePtr()) && 424 "Expected function for a 'returned' position!"); 425 assert(getAsValuePtr() == &getAssociatedValue() && 426 "Associated value mismatch!"); 427 return; 428 case IRP_CALL_SITE_RETURNED: 429 assert((isa<CallBase>(getAsValuePtr())) && 430 "Expected call base for 'call site returned' position!"); 431 assert(getAsValuePtr() == &getAssociatedValue() && 432 "Associated value mismatch!"); 433 return; 434 case IRP_CALL_SITE: 435 assert((isa<CallBase>(getAsValuePtr())) && 436 "Expected call base for 'call site function' position!"); 437 assert(getAsValuePtr() == &getAssociatedValue() && 438 "Associated value mismatch!"); 439 return; 440 case IRP_FUNCTION: 441 assert(isa<Function>(getAsValuePtr()) && 442 "Expected function for a 'function' position!"); 443 assert(getAsValuePtr() == &getAssociatedValue() && 444 "Associated value mismatch!"); 445 return; 446 case IRP_ARGUMENT: 447 assert(isa<Argument>(getAsValuePtr()) && 448 "Expected argument for a 'argument' position!"); 449 assert(getAsValuePtr() == &getAssociatedValue() && 450 "Associated value mismatch!"); 451 return; 452 case IRP_CALL_SITE_ARGUMENT: { 453 Use *U = getAsUsePtr(); 454 assert(U && "Expected use for a 'call site argument' position!"); 455 assert(isa<CallBase>(U->getUser()) && 456 "Expected call base user for a 'call site argument' position!"); 457 assert(cast<CallBase>(U->getUser())->isArgOperand(U) && 458 "Expected call base argument operand for a 'call site argument' " 459 "position"); 460 assert(cast<CallBase>(U->getUser())->getArgOperandNo(U) == 461 unsigned(getArgNo()) && 462 "Argument number mismatch!"); 463 assert(U->get() == &getAssociatedValue() && "Associated value mismatch!"); 464 return; 465 } 466 } 467 #endif 468 } 469 470 Optional<Constant *> 471 Attributor::getAssumedConstant(const Value &V, const AbstractAttribute &AA, 472 bool &UsedAssumedInformation) { 473 const auto &ValueSimplifyAA = getAAFor<AAValueSimplify>( 474 AA, IRPosition::value(V), /* TrackDependence */ false); 475 Optional<Value *> SimplifiedV = 476 ValueSimplifyAA.getAssumedSimplifiedValue(*this); 477 bool IsKnown = ValueSimplifyAA.isKnown(); 478 UsedAssumedInformation |= !IsKnown; 479 if (!SimplifiedV.hasValue()) { 480 recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL); 481 return llvm::None; 482 } 483 if (isa_and_nonnull<UndefValue>(SimplifiedV.getValue())) { 484 recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL); 485 return llvm::None; 486 } 487 Constant *CI = dyn_cast_or_null<Constant>(SimplifiedV.getValue()); 488 if (CI && CI->getType() != V.getType()) { 489 // TODO: Check for a save conversion. 490 return nullptr; 491 } 492 if (CI) 493 recordDependence(ValueSimplifyAA, AA, DepClassTy::OPTIONAL); 494 return CI; 495 } 496 497 Attributor::~Attributor() { 498 // The abstract attributes are allocated via the BumpPtrAllocator Allocator, 499 // thus we cannot delete them. We can, and want to, destruct them though. 500 for (AbstractAttribute *AA : AllAbstractAttributes) 501 AA->~AbstractAttribute(); 502 } 503 504 bool Attributor::isAssumedDead(const AbstractAttribute &AA, 505 const AAIsDead *FnLivenessAA, 506 bool CheckBBLivenessOnly, DepClassTy DepClass) { 507 const IRPosition &IRP = AA.getIRPosition(); 508 if (!Functions.count(IRP.getAnchorScope())) 509 return false; 510 return isAssumedDead(IRP, &AA, FnLivenessAA, CheckBBLivenessOnly, DepClass); 511 } 512 513 bool Attributor::isAssumedDead(const Use &U, 514 const AbstractAttribute *QueryingAA, 515 const AAIsDead *FnLivenessAA, 516 bool CheckBBLivenessOnly, DepClassTy DepClass) { 517 Instruction *UserI = dyn_cast<Instruction>(U.getUser()); 518 if (!UserI) 519 return isAssumedDead(IRPosition::value(*U.get()), QueryingAA, FnLivenessAA, 520 CheckBBLivenessOnly, DepClass); 521 522 if (auto *CB = dyn_cast<CallBase>(UserI)) { 523 // For call site argument uses we can check if the argument is 524 // unused/dead. 525 if (CB->isArgOperand(&U)) { 526 const IRPosition &CSArgPos = 527 IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)); 528 return isAssumedDead(CSArgPos, QueryingAA, FnLivenessAA, 529 CheckBBLivenessOnly, DepClass); 530 } 531 } else if (ReturnInst *RI = dyn_cast<ReturnInst>(UserI)) { 532 const IRPosition &RetPos = IRPosition::returned(*RI->getFunction()); 533 return isAssumedDead(RetPos, QueryingAA, FnLivenessAA, CheckBBLivenessOnly, 534 DepClass); 535 } else if (PHINode *PHI = dyn_cast<PHINode>(UserI)) { 536 BasicBlock *IncomingBB = PHI->getIncomingBlock(U); 537 return isAssumedDead(*IncomingBB->getTerminator(), QueryingAA, FnLivenessAA, 538 CheckBBLivenessOnly, DepClass); 539 } 540 541 return isAssumedDead(IRPosition::value(*UserI), QueryingAA, FnLivenessAA, 542 CheckBBLivenessOnly, DepClass); 543 } 544 545 bool Attributor::isAssumedDead(const Instruction &I, 546 const AbstractAttribute *QueryingAA, 547 const AAIsDead *FnLivenessAA, 548 bool CheckBBLivenessOnly, DepClassTy DepClass) { 549 if (!FnLivenessAA) 550 FnLivenessAA = lookupAAFor<AAIsDead>(IRPosition::function(*I.getFunction()), 551 QueryingAA, 552 /* TrackDependence */ false); 553 554 // If we have a context instruction and a liveness AA we use it. 555 if (FnLivenessAA && 556 FnLivenessAA->getIRPosition().getAnchorScope() == I.getFunction() && 557 FnLivenessAA->isAssumedDead(&I)) { 558 if (QueryingAA) 559 recordDependence(*FnLivenessAA, *QueryingAA, DepClass); 560 return true; 561 } 562 563 if (CheckBBLivenessOnly) 564 return false; 565 566 const AAIsDead &IsDeadAA = getOrCreateAAFor<AAIsDead>( 567 IRPosition::value(I), QueryingAA, /* TrackDependence */ false); 568 // Don't check liveness for AAIsDead. 569 if (QueryingAA == &IsDeadAA) 570 return false; 571 572 if (IsDeadAA.isAssumedDead()) { 573 if (QueryingAA) 574 recordDependence(IsDeadAA, *QueryingAA, DepClass); 575 return true; 576 } 577 578 return false; 579 } 580 581 bool Attributor::isAssumedDead(const IRPosition &IRP, 582 const AbstractAttribute *QueryingAA, 583 const AAIsDead *FnLivenessAA, 584 bool CheckBBLivenessOnly, DepClassTy DepClass) { 585 Instruction *CtxI = IRP.getCtxI(); 586 if (CtxI && 587 isAssumedDead(*CtxI, QueryingAA, FnLivenessAA, 588 /* CheckBBLivenessOnly */ true, 589 CheckBBLivenessOnly ? DepClass : DepClassTy::OPTIONAL)) 590 return true; 591 592 if (CheckBBLivenessOnly) 593 return false; 594 595 // If we haven't succeeded we query the specific liveness info for the IRP. 596 const AAIsDead *IsDeadAA; 597 if (IRP.getPositionKind() == IRPosition::IRP_CALL_SITE) 598 IsDeadAA = &getOrCreateAAFor<AAIsDead>( 599 IRPosition::callsite_returned(cast<CallBase>(IRP.getAssociatedValue())), 600 QueryingAA, /* TrackDependence */ false); 601 else 602 IsDeadAA = &getOrCreateAAFor<AAIsDead>(IRP, QueryingAA, 603 /* TrackDependence */ false); 604 // Don't check liveness for AAIsDead. 605 if (QueryingAA == IsDeadAA) 606 return false; 607 608 if (IsDeadAA->isAssumedDead()) { 609 if (QueryingAA) 610 recordDependence(*IsDeadAA, *QueryingAA, DepClass); 611 return true; 612 } 613 614 return false; 615 } 616 617 bool Attributor::checkForAllUses(function_ref<bool(const Use &, bool &)> Pred, 618 const AbstractAttribute &QueryingAA, 619 const Value &V, DepClassTy LivenessDepClass) { 620 621 // Check the trivial case first as it catches void values. 622 if (V.use_empty()) 623 return true; 624 625 // If the value is replaced by another one, for now a constant, we do not have 626 // uses. Note that this requires users of `checkForAllUses` to not recurse but 627 // instead use the `follow` callback argument to look at transitive users, 628 // however, that should be clear from the presence of the argument. 629 bool UsedAssumedInformation = false; 630 Optional<Constant *> C = 631 getAssumedConstant(V, QueryingAA, UsedAssumedInformation); 632 if (C.hasValue() && C.getValue()) { 633 LLVM_DEBUG(dbgs() << "[Attributor] Value is simplified, uses skipped: " << V 634 << " -> " << *C.getValue() << "\n"); 635 return true; 636 } 637 638 const IRPosition &IRP = QueryingAA.getIRPosition(); 639 SmallVector<const Use *, 16> Worklist; 640 SmallPtrSet<const Use *, 16> Visited; 641 642 for (const Use &U : V.uses()) 643 Worklist.push_back(&U); 644 645 LLVM_DEBUG(dbgs() << "[Attributor] Got " << Worklist.size() 646 << " initial uses to check\n"); 647 648 const Function *ScopeFn = IRP.getAnchorScope(); 649 const auto *LivenessAA = 650 ScopeFn ? &getAAFor<AAIsDead>(QueryingAA, IRPosition::function(*ScopeFn), 651 /* TrackDependence */ false) 652 : nullptr; 653 654 while (!Worklist.empty()) { 655 const Use *U = Worklist.pop_back_val(); 656 if (!Visited.insert(U).second) 657 continue; 658 LLVM_DEBUG(dbgs() << "[Attributor] Check use: " << **U << " in " 659 << *U->getUser() << "\n"); 660 if (isAssumedDead(*U, &QueryingAA, LivenessAA, 661 /* CheckBBLivenessOnly */ false, LivenessDepClass)) { 662 LLVM_DEBUG(dbgs() << "[Attributor] Dead use, skip!\n"); 663 continue; 664 } 665 if (U->getUser()->isDroppable()) { 666 LLVM_DEBUG(dbgs() << "[Attributor] Droppable user, skip!\n"); 667 continue; 668 } 669 670 bool Follow = false; 671 if (!Pred(*U, Follow)) 672 return false; 673 if (!Follow) 674 continue; 675 for (const Use &UU : U->getUser()->uses()) 676 Worklist.push_back(&UU); 677 } 678 679 return true; 680 } 681 682 bool Attributor::checkForAllCallSites(function_ref<bool(AbstractCallSite)> Pred, 683 const AbstractAttribute &QueryingAA, 684 bool RequireAllCallSites, 685 bool &AllCallSitesKnown) { 686 // We can try to determine information from 687 // the call sites. However, this is only possible all call sites are known, 688 // hence the function has internal linkage. 689 const IRPosition &IRP = QueryingAA.getIRPosition(); 690 const Function *AssociatedFunction = IRP.getAssociatedFunction(); 691 if (!AssociatedFunction) { 692 LLVM_DEBUG(dbgs() << "[Attributor] No function associated with " << IRP 693 << "\n"); 694 AllCallSitesKnown = false; 695 return false; 696 } 697 698 return checkForAllCallSites(Pred, *AssociatedFunction, RequireAllCallSites, 699 &QueryingAA, AllCallSitesKnown); 700 } 701 702 bool Attributor::checkForAllCallSites(function_ref<bool(AbstractCallSite)> Pred, 703 const Function &Fn, 704 bool RequireAllCallSites, 705 const AbstractAttribute *QueryingAA, 706 bool &AllCallSitesKnown) { 707 if (RequireAllCallSites && !Fn.hasLocalLinkage()) { 708 LLVM_DEBUG( 709 dbgs() 710 << "[Attributor] Function " << Fn.getName() 711 << " has no internal linkage, hence not all call sites are known\n"); 712 AllCallSitesKnown = false; 713 return false; 714 } 715 716 // If we do not require all call sites we might not see all. 717 AllCallSitesKnown = RequireAllCallSites; 718 719 SmallVector<const Use *, 8> Uses(make_pointer_range(Fn.uses())); 720 for (unsigned u = 0; u < Uses.size(); ++u) { 721 const Use &U = *Uses[u]; 722 LLVM_DEBUG(dbgs() << "[Attributor] Check use: " << *U << " in " 723 << *U.getUser() << "\n"); 724 if (isAssumedDead(U, QueryingAA, nullptr, /* CheckBBLivenessOnly */ true)) { 725 LLVM_DEBUG(dbgs() << "[Attributor] Dead use, skip!\n"); 726 continue; 727 } 728 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U.getUser())) { 729 if (CE->isCast() && CE->getType()->isPointerTy() && 730 CE->getType()->getPointerElementType()->isFunctionTy()) { 731 for (const Use &CEU : CE->uses()) 732 Uses.push_back(&CEU); 733 continue; 734 } 735 } 736 737 AbstractCallSite ACS(&U); 738 if (!ACS) { 739 LLVM_DEBUG(dbgs() << "[Attributor] Function " << Fn.getName() 740 << " has non call site use " << *U.get() << " in " 741 << *U.getUser() << "\n"); 742 // BlockAddress users are allowed. 743 if (isa<BlockAddress>(U.getUser())) 744 continue; 745 return false; 746 } 747 748 const Use *EffectiveUse = 749 ACS.isCallbackCall() ? &ACS.getCalleeUseForCallback() : &U; 750 if (!ACS.isCallee(EffectiveUse)) { 751 if (!RequireAllCallSites) 752 continue; 753 LLVM_DEBUG(dbgs() << "[Attributor] User " << EffectiveUse->getUser() 754 << " is an invalid use of " << Fn.getName() << "\n"); 755 return false; 756 } 757 758 // Make sure the arguments that can be matched between the call site and the 759 // callee argee on their type. It is unlikely they do not and it doesn't 760 // make sense for all attributes to know/care about this. 761 assert(&Fn == ACS.getCalledFunction() && "Expected known callee"); 762 unsigned MinArgsParams = 763 std::min(size_t(ACS.getNumArgOperands()), Fn.arg_size()); 764 for (unsigned u = 0; u < MinArgsParams; ++u) { 765 Value *CSArgOp = ACS.getCallArgOperand(u); 766 if (CSArgOp && Fn.getArg(u)->getType() != CSArgOp->getType()) { 767 LLVM_DEBUG( 768 dbgs() << "[Attributor] Call site / callee argument type mismatch [" 769 << u << "@" << Fn.getName() << ": " 770 << *Fn.getArg(u)->getType() << " vs. " 771 << *ACS.getCallArgOperand(u)->getType() << "\n"); 772 return false; 773 } 774 } 775 776 if (Pred(ACS)) 777 continue; 778 779 LLVM_DEBUG(dbgs() << "[Attributor] Call site callback failed for " 780 << *ACS.getInstruction() << "\n"); 781 return false; 782 } 783 784 return true; 785 } 786 787 bool Attributor::checkForAllReturnedValuesAndReturnInsts( 788 function_ref<bool(Value &, const SmallSetVector<ReturnInst *, 4> &)> Pred, 789 const AbstractAttribute &QueryingAA) { 790 791 const IRPosition &IRP = QueryingAA.getIRPosition(); 792 // Since we need to provide return instructions we have to have an exact 793 // definition. 794 const Function *AssociatedFunction = IRP.getAssociatedFunction(); 795 if (!AssociatedFunction) 796 return false; 797 798 // If this is a call site query we use the call site specific return values 799 // and liveness information. 800 // TODO: use the function scope once we have call site AAReturnedValues. 801 const IRPosition &QueryIRP = IRPosition::function(*AssociatedFunction); 802 const auto &AARetVal = getAAFor<AAReturnedValues>(QueryingAA, QueryIRP); 803 if (!AARetVal.getState().isValidState()) 804 return false; 805 806 return AARetVal.checkForAllReturnedValuesAndReturnInsts(Pred); 807 } 808 809 bool Attributor::checkForAllReturnedValues( 810 function_ref<bool(Value &)> Pred, const AbstractAttribute &QueryingAA) { 811 812 const IRPosition &IRP = QueryingAA.getIRPosition(); 813 const Function *AssociatedFunction = IRP.getAssociatedFunction(); 814 if (!AssociatedFunction) 815 return false; 816 817 // TODO: use the function scope once we have call site AAReturnedValues. 818 const IRPosition &QueryIRP = IRPosition::function(*AssociatedFunction); 819 const auto &AARetVal = getAAFor<AAReturnedValues>(QueryingAA, QueryIRP); 820 if (!AARetVal.getState().isValidState()) 821 return false; 822 823 return AARetVal.checkForAllReturnedValuesAndReturnInsts( 824 [&](Value &RV, const SmallSetVector<ReturnInst *, 4> &) { 825 return Pred(RV); 826 }); 827 } 828 829 static bool checkForAllInstructionsImpl( 830 Attributor *A, InformationCache::OpcodeInstMapTy &OpcodeInstMap, 831 function_ref<bool(Instruction &)> Pred, const AbstractAttribute *QueryingAA, 832 const AAIsDead *LivenessAA, const ArrayRef<unsigned> &Opcodes, 833 bool CheckBBLivenessOnly = false) { 834 for (unsigned Opcode : Opcodes) { 835 // Check if we have instructions with this opcode at all first. 836 auto *Insts = OpcodeInstMap.lookup(Opcode); 837 if (!Insts) 838 continue; 839 840 for (Instruction *I : *Insts) { 841 // Skip dead instructions. 842 if (A && A->isAssumedDead(IRPosition::value(*I), QueryingAA, LivenessAA, 843 CheckBBLivenessOnly)) 844 continue; 845 846 if (!Pred(*I)) 847 return false; 848 } 849 } 850 return true; 851 } 852 853 bool Attributor::checkForAllInstructions(function_ref<bool(Instruction &)> Pred, 854 const AbstractAttribute &QueryingAA, 855 const ArrayRef<unsigned> &Opcodes, 856 bool CheckBBLivenessOnly) { 857 858 const IRPosition &IRP = QueryingAA.getIRPosition(); 859 // Since we need to provide instructions we have to have an exact definition. 860 const Function *AssociatedFunction = IRP.getAssociatedFunction(); 861 if (!AssociatedFunction) 862 return false; 863 864 // TODO: use the function scope once we have call site AAReturnedValues. 865 const IRPosition &QueryIRP = IRPosition::function(*AssociatedFunction); 866 const auto &LivenessAA = 867 getAAFor<AAIsDead>(QueryingAA, QueryIRP, /* TrackDependence */ false); 868 869 auto &OpcodeInstMap = 870 InfoCache.getOpcodeInstMapForFunction(*AssociatedFunction); 871 if (!checkForAllInstructionsImpl(this, OpcodeInstMap, Pred, &QueryingAA, 872 &LivenessAA, Opcodes, CheckBBLivenessOnly)) 873 return false; 874 875 return true; 876 } 877 878 bool Attributor::checkForAllReadWriteInstructions( 879 function_ref<bool(Instruction &)> Pred, AbstractAttribute &QueryingAA) { 880 881 const Function *AssociatedFunction = 882 QueryingAA.getIRPosition().getAssociatedFunction(); 883 if (!AssociatedFunction) 884 return false; 885 886 // TODO: use the function scope once we have call site AAReturnedValues. 887 const IRPosition &QueryIRP = IRPosition::function(*AssociatedFunction); 888 const auto &LivenessAA = 889 getAAFor<AAIsDead>(QueryingAA, QueryIRP, /* TrackDependence */ false); 890 891 for (Instruction *I : 892 InfoCache.getReadOrWriteInstsForFunction(*AssociatedFunction)) { 893 // Skip dead instructions. 894 if (isAssumedDead(IRPosition::value(*I), &QueryingAA, &LivenessAA)) 895 continue; 896 897 if (!Pred(*I)) 898 return false; 899 } 900 901 return true; 902 } 903 904 void Attributor::runTillFixpoint() { 905 LLVM_DEBUG(dbgs() << "[Attributor] Identified and initialized " 906 << AllAbstractAttributes.size() 907 << " abstract attributes.\n"); 908 909 // Now that all abstract attributes are collected and initialized we start 910 // the abstract analysis. 911 912 unsigned IterationCounter = 1; 913 914 SmallVector<AbstractAttribute *, 32> ChangedAAs; 915 SetVector<AbstractAttribute *> Worklist, InvalidAAs; 916 Worklist.insert(AllAbstractAttributes.begin(), AllAbstractAttributes.end()); 917 918 do { 919 // Remember the size to determine new attributes. 920 size_t NumAAs = AllAbstractAttributes.size(); 921 LLVM_DEBUG(dbgs() << "\n\n[Attributor] #Iteration: " << IterationCounter 922 << ", Worklist size: " << Worklist.size() << "\n"); 923 924 // For invalid AAs we can fix dependent AAs that have a required dependence, 925 // thereby folding long dependence chains in a single step without the need 926 // to run updates. 927 for (unsigned u = 0; u < InvalidAAs.size(); ++u) { 928 AbstractAttribute *InvalidAA = InvalidAAs[u]; 929 930 // Check the dependences to fast track invalidation. 931 LLVM_DEBUG(dbgs() << "[Attributor] InvalidAA: " << *InvalidAA << " has " 932 << InvalidAA->Deps.size() 933 << " required & optional dependences\n"); 934 while (!InvalidAA->Deps.empty()) { 935 const auto &Dep = InvalidAA->Deps.back(); 936 InvalidAA->Deps.pop_back(); 937 AbstractAttribute *DepAA = Dep.getPointer(); 938 if (Dep.getInt() == unsigned(DepClassTy::OPTIONAL)) { 939 Worklist.insert(DepAA); 940 continue; 941 } 942 DepAA->getState().indicatePessimisticFixpoint(); 943 assert(DepAA->getState().isAtFixpoint() && "Expected fixpoint state!"); 944 if (!DepAA->getState().isValidState()) 945 InvalidAAs.insert(DepAA); 946 else 947 ChangedAAs.push_back(DepAA); 948 } 949 } 950 951 // Add all abstract attributes that are potentially dependent on one that 952 // changed to the work list. 953 for (AbstractAttribute *ChangedAA : ChangedAAs) 954 while (!ChangedAA->Deps.empty()) { 955 Worklist.insert(ChangedAA->Deps.back().getPointer()); 956 ChangedAA->Deps.pop_back(); 957 } 958 959 LLVM_DEBUG(dbgs() << "[Attributor] #Iteration: " << IterationCounter 960 << ", Worklist+Dependent size: " << Worklist.size() 961 << "\n"); 962 963 // Reset the changed and invalid set. 964 ChangedAAs.clear(); 965 InvalidAAs.clear(); 966 967 // Update all abstract attribute in the work list and record the ones that 968 // changed. 969 for (AbstractAttribute *AA : Worklist) { 970 const auto &AAState = AA->getState(); 971 if (!AAState.isAtFixpoint()) 972 if (updateAA(*AA) == ChangeStatus::CHANGED) 973 ChangedAAs.push_back(AA); 974 975 // Use the InvalidAAs vector to propagate invalid states fast transitively 976 // without requiring updates. 977 if (!AAState.isValidState()) 978 InvalidAAs.insert(AA); 979 } 980 981 // Add attributes to the changed set if they have been created in the last 982 // iteration. 983 ChangedAAs.append(AllAbstractAttributes.begin() + NumAAs, 984 AllAbstractAttributes.end()); 985 986 // Reset the work list and repopulate with the changed abstract attributes. 987 // Note that dependent ones are added above. 988 Worklist.clear(); 989 Worklist.insert(ChangedAAs.begin(), ChangedAAs.end()); 990 991 } while (!Worklist.empty() && (IterationCounter++ < MaxFixpointIterations || 992 VerifyMaxFixpointIterations)); 993 994 LLVM_DEBUG(dbgs() << "\n[Attributor] Fixpoint iteration done after: " 995 << IterationCounter << "/" << MaxFixpointIterations 996 << " iterations\n"); 997 998 // Reset abstract arguments not settled in a sound fixpoint by now. This 999 // happens when we stopped the fixpoint iteration early. Note that only the 1000 // ones marked as "changed" *and* the ones transitively depending on them 1001 // need to be reverted to a pessimistic state. Others might not be in a 1002 // fixpoint state but we can use the optimistic results for them anyway. 1003 SmallPtrSet<AbstractAttribute *, 32> Visited; 1004 for (unsigned u = 0; u < ChangedAAs.size(); u++) { 1005 AbstractAttribute *ChangedAA = ChangedAAs[u]; 1006 if (!Visited.insert(ChangedAA).second) 1007 continue; 1008 1009 AbstractState &State = ChangedAA->getState(); 1010 if (!State.isAtFixpoint()) { 1011 State.indicatePessimisticFixpoint(); 1012 1013 NumAttributesTimedOut++; 1014 } 1015 1016 while (!ChangedAA->Deps.empty()) { 1017 ChangedAAs.push_back(ChangedAA->Deps.back().getPointer()); 1018 ChangedAA->Deps.pop_back(); 1019 } 1020 } 1021 1022 LLVM_DEBUG({ 1023 if (!Visited.empty()) 1024 dbgs() << "\n[Attributor] Finalized " << Visited.size() 1025 << " abstract attributes.\n"; 1026 }); 1027 1028 if (VerifyMaxFixpointIterations && 1029 IterationCounter != MaxFixpointIterations) { 1030 errs() << "\n[Attributor] Fixpoint iteration done after: " 1031 << IterationCounter << "/" << MaxFixpointIterations 1032 << " iterations\n"; 1033 llvm_unreachable("The fixpoint was not reached with exactly the number of " 1034 "specified iterations!"); 1035 } 1036 } 1037 1038 ChangeStatus Attributor::manifestAttributes() { 1039 size_t NumFinalAAs = AllAbstractAttributes.size(); 1040 1041 unsigned NumManifested = 0; 1042 unsigned NumAtFixpoint = 0; 1043 ChangeStatus ManifestChange = ChangeStatus::UNCHANGED; 1044 for (AbstractAttribute *AA : AllAbstractAttributes) { 1045 AbstractState &State = AA->getState(); 1046 1047 // If there is not already a fixpoint reached, we can now take the 1048 // optimistic state. This is correct because we enforced a pessimistic one 1049 // on abstract attributes that were transitively dependent on a changed one 1050 // already above. 1051 if (!State.isAtFixpoint()) 1052 State.indicateOptimisticFixpoint(); 1053 1054 // If the state is invalid, we do not try to manifest it. 1055 if (!State.isValidState()) 1056 continue; 1057 1058 // Skip dead code. 1059 if (isAssumedDead(*AA, nullptr, /* CheckBBLivenessOnly */ true)) 1060 continue; 1061 // Manifest the state and record if we changed the IR. 1062 ChangeStatus LocalChange = AA->manifest(*this); 1063 if (LocalChange == ChangeStatus::CHANGED && AreStatisticsEnabled()) 1064 AA->trackStatistics(); 1065 LLVM_DEBUG(dbgs() << "[Attributor] Manifest " << LocalChange << " : " << *AA 1066 << "\n"); 1067 1068 ManifestChange = ManifestChange | LocalChange; 1069 1070 NumAtFixpoint++; 1071 NumManifested += (LocalChange == ChangeStatus::CHANGED); 1072 } 1073 1074 (void)NumManifested; 1075 (void)NumAtFixpoint; 1076 LLVM_DEBUG(dbgs() << "\n[Attributor] Manifested " << NumManifested 1077 << " arguments while " << NumAtFixpoint 1078 << " were in a valid fixpoint state\n"); 1079 1080 NumAttributesManifested += NumManifested; 1081 NumAttributesValidFixpoint += NumAtFixpoint; 1082 1083 (void)NumFinalAAs; 1084 if (NumFinalAAs != AllAbstractAttributes.size()) { 1085 for (unsigned u = NumFinalAAs; u < AllAbstractAttributes.size(); ++u) 1086 errs() << "Unexpected abstract attribute: " << *AllAbstractAttributes[u] 1087 << " :: " 1088 << AllAbstractAttributes[u]->getIRPosition().getAssociatedValue() 1089 << "\n"; 1090 llvm_unreachable("Expected the final number of abstract attributes to " 1091 "remain unchanged!"); 1092 } 1093 return ManifestChange; 1094 } 1095 1096 ChangeStatus Attributor::cleanupIR() { 1097 // Delete stuff at the end to avoid invalid references and a nice order. 1098 LLVM_DEBUG(dbgs() << "\n[Attributor] Delete at least " 1099 << ToBeDeletedFunctions.size() << " functions and " 1100 << ToBeDeletedBlocks.size() << " blocks and " 1101 << ToBeDeletedInsts.size() << " instructions and " 1102 << ToBeChangedUses.size() << " uses\n"); 1103 1104 SmallVector<WeakTrackingVH, 32> DeadInsts; 1105 SmallVector<Instruction *, 32> TerminatorsToFold; 1106 1107 for (auto &It : ToBeChangedUses) { 1108 Use *U = It.first; 1109 Value *NewV = It.second; 1110 Value *OldV = U->get(); 1111 1112 // Do not replace uses in returns if the value is a must-tail call we will 1113 // not delete. 1114 if (isa<ReturnInst>(U->getUser())) 1115 if (auto *CI = dyn_cast<CallInst>(OldV->stripPointerCasts())) 1116 if (CI->isMustTailCall() && !ToBeDeletedInsts.count(CI)) 1117 continue; 1118 1119 LLVM_DEBUG(dbgs() << "Use " << *NewV << " in " << *U->getUser() 1120 << " instead of " << *OldV << "\n"); 1121 U->set(NewV); 1122 // Do not modify call instructions outside the SCC. 1123 if (auto *CB = dyn_cast<CallBase>(OldV)) 1124 if (!Functions.count(CB->getCaller())) 1125 continue; 1126 if (Instruction *I = dyn_cast<Instruction>(OldV)) { 1127 CGModifiedFunctions.insert(I->getFunction()); 1128 if (!isa<PHINode>(I) && !ToBeDeletedInsts.count(I) && 1129 isInstructionTriviallyDead(I)) 1130 DeadInsts.push_back(I); 1131 } 1132 if (isa<Constant>(NewV) && isa<BranchInst>(U->getUser())) { 1133 Instruction *UserI = cast<Instruction>(U->getUser()); 1134 if (isa<UndefValue>(NewV)) { 1135 ToBeChangedToUnreachableInsts.insert(UserI); 1136 } else { 1137 TerminatorsToFold.push_back(UserI); 1138 } 1139 } 1140 } 1141 for (auto &V : InvokeWithDeadSuccessor) 1142 if (InvokeInst *II = dyn_cast_or_null<InvokeInst>(V)) { 1143 bool UnwindBBIsDead = II->hasFnAttr(Attribute::NoUnwind); 1144 bool NormalBBIsDead = II->hasFnAttr(Attribute::NoReturn); 1145 bool Invoke2CallAllowed = 1146 !AAIsDead::mayCatchAsynchronousExceptions(*II->getFunction()); 1147 assert((UnwindBBIsDead || NormalBBIsDead) && 1148 "Invoke does not have dead successors!"); 1149 BasicBlock *BB = II->getParent(); 1150 BasicBlock *NormalDestBB = II->getNormalDest(); 1151 if (UnwindBBIsDead) { 1152 Instruction *NormalNextIP = &NormalDestBB->front(); 1153 if (Invoke2CallAllowed) { 1154 changeToCall(II); 1155 NormalNextIP = BB->getTerminator(); 1156 } 1157 if (NormalBBIsDead) 1158 ToBeChangedToUnreachableInsts.insert(NormalNextIP); 1159 } else { 1160 assert(NormalBBIsDead && "Broken invariant!"); 1161 if (!NormalDestBB->getUniquePredecessor()) 1162 NormalDestBB = SplitBlockPredecessors(NormalDestBB, {BB}, ".dead"); 1163 ToBeChangedToUnreachableInsts.insert(&NormalDestBB->front()); 1164 } 1165 } 1166 for (Instruction *I : TerminatorsToFold) { 1167 CGModifiedFunctions.insert(I->getFunction()); 1168 ConstantFoldTerminator(I->getParent()); 1169 } 1170 for (auto &V : ToBeChangedToUnreachableInsts) 1171 if (Instruction *I = dyn_cast_or_null<Instruction>(V)) { 1172 CGModifiedFunctions.insert(I->getFunction()); 1173 changeToUnreachable(I, /* UseLLVMTrap */ false); 1174 } 1175 1176 for (auto &V : ToBeDeletedInsts) { 1177 if (Instruction *I = dyn_cast_or_null<Instruction>(V)) { 1178 I->dropDroppableUses(); 1179 CGModifiedFunctions.insert(I->getFunction()); 1180 if (!I->getType()->isVoidTy()) 1181 I->replaceAllUsesWith(UndefValue::get(I->getType())); 1182 if (!isa<PHINode>(I) && isInstructionTriviallyDead(I)) 1183 DeadInsts.push_back(I); 1184 else 1185 I->eraseFromParent(); 1186 } 1187 } 1188 1189 LLVM_DEBUG(dbgs() << "[Attributor] DeadInsts size: " << DeadInsts.size() 1190 << "\n"); 1191 1192 RecursivelyDeleteTriviallyDeadInstructions(DeadInsts); 1193 1194 if (unsigned NumDeadBlocks = ToBeDeletedBlocks.size()) { 1195 SmallVector<BasicBlock *, 8> ToBeDeletedBBs; 1196 ToBeDeletedBBs.reserve(NumDeadBlocks); 1197 for (BasicBlock *BB : ToBeDeletedBlocks) { 1198 CGModifiedFunctions.insert(BB->getParent()); 1199 ToBeDeletedBBs.push_back(BB); 1200 } 1201 // Actually we do not delete the blocks but squash them into a single 1202 // unreachable but untangling branches that jump here is something we need 1203 // to do in a more generic way. 1204 DetatchDeadBlocks(ToBeDeletedBBs, nullptr); 1205 } 1206 1207 // Identify dead internal functions and delete them. This happens outside 1208 // the other fixpoint analysis as we might treat potentially dead functions 1209 // as live to lower the number of iterations. If they happen to be dead, the 1210 // below fixpoint loop will identify and eliminate them. 1211 SmallVector<Function *, 8> InternalFns; 1212 for (Function *F : Functions) 1213 if (F->hasLocalLinkage()) 1214 InternalFns.push_back(F); 1215 1216 bool FoundDeadFn = true; 1217 while (FoundDeadFn) { 1218 FoundDeadFn = false; 1219 for (unsigned u = 0, e = InternalFns.size(); u < e; ++u) { 1220 Function *F = InternalFns[u]; 1221 if (!F) 1222 continue; 1223 1224 bool AllCallSitesKnown; 1225 if (!checkForAllCallSites( 1226 [this](AbstractCallSite ACS) { 1227 return ToBeDeletedFunctions.count( 1228 ACS.getInstruction()->getFunction()); 1229 }, 1230 *F, true, nullptr, AllCallSitesKnown)) 1231 continue; 1232 1233 ToBeDeletedFunctions.insert(F); 1234 InternalFns[u] = nullptr; 1235 FoundDeadFn = true; 1236 } 1237 } 1238 1239 // Rewrite the functions as requested during manifest. 1240 ChangeStatus ManifestChange = rewriteFunctionSignatures(CGModifiedFunctions); 1241 1242 for (Function *Fn : CGModifiedFunctions) 1243 CGUpdater.reanalyzeFunction(*Fn); 1244 1245 for (Function *Fn : ToBeDeletedFunctions) 1246 CGUpdater.removeFunction(*Fn); 1247 1248 NumFnDeleted += ToBeDeletedFunctions.size(); 1249 1250 LLVM_DEBUG(dbgs() << "[Attributor] Deleted " << NumFnDeleted 1251 << " functions after manifest.\n"); 1252 1253 #ifdef EXPENSIVE_CHECKS 1254 for (Function *F : Functions) { 1255 if (ToBeDeletedFunctions.count(F)) 1256 continue; 1257 assert(!verifyFunction(*F, &errs()) && "Module verification failed!"); 1258 } 1259 #endif 1260 1261 return ManifestChange; 1262 } 1263 1264 ChangeStatus Attributor::run() { 1265 SeedingPeriod = false; 1266 runTillFixpoint(); 1267 ChangeStatus ManifestChange = manifestAttributes(); 1268 ChangeStatus CleanupChange = cleanupIR(); 1269 return ManifestChange | CleanupChange; 1270 } 1271 1272 ChangeStatus Attributor::updateAA(AbstractAttribute &AA) { 1273 // Use a new dependence vector for this update. 1274 DependenceVector DV; 1275 DependenceStack.push_back(&DV); 1276 1277 auto &AAState = AA.getState(); 1278 ChangeStatus CS = ChangeStatus::UNCHANGED; 1279 if (!isAssumedDead(AA, nullptr, /* CheckBBLivenessOnly */ true)) 1280 CS = AA.update(*this); 1281 1282 if (DV.empty()) { 1283 // If the attribute did not query any non-fix information, the state 1284 // will not change and we can indicate that right away. 1285 AAState.indicateOptimisticFixpoint(); 1286 } 1287 1288 if (!AAState.isAtFixpoint()) 1289 rememberDependences(); 1290 1291 // Verify the stack was used properly, that is we pop the dependence vector we 1292 // put there earlier. 1293 DependenceVector *PoppedDV = DependenceStack.pop_back_val(); 1294 (void)PoppedDV; 1295 assert(PoppedDV == &DV && "Inconsistent usage of the dependence stack!"); 1296 1297 return CS; 1298 } 1299 1300 /// Create a shallow wrapper for \p F such that \p F has internal linkage 1301 /// afterwards. It also sets the original \p F 's name to anonymous 1302 /// 1303 /// A wrapper is a function with the same type (and attributes) as \p F 1304 /// that will only call \p F and return the result, if any. 1305 /// 1306 /// Assuming the declaration of looks like: 1307 /// rty F(aty0 arg0, ..., atyN argN); 1308 /// 1309 /// The wrapper will then look as follows: 1310 /// rty wrapper(aty0 arg0, ..., atyN argN) { 1311 /// return F(arg0, ..., argN); 1312 /// } 1313 /// 1314 static void createShallowWrapper(Function &F) { 1315 assert(AllowShallowWrappers && 1316 "Cannot create a wrapper if it is not allowed!"); 1317 assert(!F.isDeclaration() && "Cannot create a wrapper around a declaration!"); 1318 1319 Module &M = *F.getParent(); 1320 LLVMContext &Ctx = M.getContext(); 1321 FunctionType *FnTy = F.getFunctionType(); 1322 1323 Function *Wrapper = 1324 Function::Create(FnTy, F.getLinkage(), F.getAddressSpace(), F.getName()); 1325 F.setName(""); // set the inside function anonymous 1326 M.getFunctionList().insert(F.getIterator(), Wrapper); 1327 1328 F.setLinkage(GlobalValue::InternalLinkage); 1329 1330 F.replaceAllUsesWith(Wrapper); 1331 assert(F.use_empty() && "Uses remained after wrapper was created!"); 1332 1333 // Move the COMDAT section to the wrapper. 1334 // TODO: Check if we need to keep it for F as well. 1335 Wrapper->setComdat(F.getComdat()); 1336 F.setComdat(nullptr); 1337 1338 // Copy all metadata and attributes but keep them on F as well. 1339 SmallVector<std::pair<unsigned, MDNode *>, 1> MDs; 1340 F.getAllMetadata(MDs); 1341 for (auto MDIt : MDs) 1342 Wrapper->addMetadata(MDIt.first, *MDIt.second); 1343 Wrapper->setAttributes(F.getAttributes()); 1344 1345 // Create the call in the wrapper. 1346 BasicBlock *EntryBB = BasicBlock::Create(Ctx, "entry", Wrapper); 1347 1348 SmallVector<Value *, 8> Args; 1349 auto FArgIt = F.arg_begin(); 1350 for (Argument &Arg : Wrapper->args()) { 1351 Args.push_back(&Arg); 1352 Arg.setName((FArgIt++)->getName()); 1353 } 1354 1355 CallInst *CI = CallInst::Create(&F, Args, "", EntryBB); 1356 CI->setTailCall(true); 1357 CI->addAttribute(AttributeList::FunctionIndex, Attribute::NoInline); 1358 ReturnInst::Create(Ctx, CI->getType()->isVoidTy() ? nullptr : CI, EntryBB); 1359 1360 NumFnShallowWrapperCreated++; 1361 } 1362 1363 bool Attributor::isValidFunctionSignatureRewrite( 1364 Argument &Arg, ArrayRef<Type *> ReplacementTypes) { 1365 1366 auto CallSiteCanBeChanged = [](AbstractCallSite ACS) { 1367 // Forbid the call site to cast the function return type. If we need to 1368 // rewrite these functions we need to re-create a cast for the new call site 1369 // (if the old had uses). 1370 if (!ACS.getCalledFunction() || 1371 ACS.getInstruction()->getType() != 1372 ACS.getCalledFunction()->getReturnType()) 1373 return false; 1374 // Forbid must-tail calls for now. 1375 return !ACS.isCallbackCall() && !ACS.getInstruction()->isMustTailCall(); 1376 }; 1377 1378 Function *Fn = Arg.getParent(); 1379 // Avoid var-arg functions for now. 1380 if (Fn->isVarArg()) { 1381 LLVM_DEBUG(dbgs() << "[Attributor] Cannot rewrite var-args functions\n"); 1382 return false; 1383 } 1384 1385 // Avoid functions with complicated argument passing semantics. 1386 AttributeList FnAttributeList = Fn->getAttributes(); 1387 if (FnAttributeList.hasAttrSomewhere(Attribute::Nest) || 1388 FnAttributeList.hasAttrSomewhere(Attribute::StructRet) || 1389 FnAttributeList.hasAttrSomewhere(Attribute::InAlloca) || 1390 FnAttributeList.hasAttrSomewhere(Attribute::Preallocated)) { 1391 LLVM_DEBUG( 1392 dbgs() << "[Attributor] Cannot rewrite due to complex attribute\n"); 1393 return false; 1394 } 1395 1396 // Avoid callbacks for now. 1397 bool AllCallSitesKnown; 1398 if (!checkForAllCallSites(CallSiteCanBeChanged, *Fn, true, nullptr, 1399 AllCallSitesKnown)) { 1400 LLVM_DEBUG(dbgs() << "[Attributor] Cannot rewrite all call sites\n"); 1401 return false; 1402 } 1403 1404 auto InstPred = [](Instruction &I) { 1405 if (auto *CI = dyn_cast<CallInst>(&I)) 1406 return !CI->isMustTailCall(); 1407 return true; 1408 }; 1409 1410 // Forbid must-tail calls for now. 1411 // TODO: 1412 auto &OpcodeInstMap = InfoCache.getOpcodeInstMapForFunction(*Fn); 1413 if (!checkForAllInstructionsImpl(nullptr, OpcodeInstMap, InstPred, nullptr, 1414 nullptr, {Instruction::Call})) { 1415 LLVM_DEBUG(dbgs() << "[Attributor] Cannot rewrite due to instructions\n"); 1416 return false; 1417 } 1418 1419 return true; 1420 } 1421 1422 bool Attributor::registerFunctionSignatureRewrite( 1423 Argument &Arg, ArrayRef<Type *> ReplacementTypes, 1424 ArgumentReplacementInfo::CalleeRepairCBTy &&CalleeRepairCB, 1425 ArgumentReplacementInfo::ACSRepairCBTy &&ACSRepairCB) { 1426 LLVM_DEBUG(dbgs() << "[Attributor] Register new rewrite of " << Arg << " in " 1427 << Arg.getParent()->getName() << " with " 1428 << ReplacementTypes.size() << " replacements\n"); 1429 assert(isValidFunctionSignatureRewrite(Arg, ReplacementTypes) && 1430 "Cannot register an invalid rewrite"); 1431 1432 Function *Fn = Arg.getParent(); 1433 SmallVectorImpl<std::unique_ptr<ArgumentReplacementInfo>> &ARIs = 1434 ArgumentReplacementMap[Fn]; 1435 if (ARIs.empty()) 1436 ARIs.resize(Fn->arg_size()); 1437 1438 // If we have a replacement already with less than or equal new arguments, 1439 // ignore this request. 1440 std::unique_ptr<ArgumentReplacementInfo> &ARI = ARIs[Arg.getArgNo()]; 1441 if (ARI && ARI->getNumReplacementArgs() <= ReplacementTypes.size()) { 1442 LLVM_DEBUG(dbgs() << "[Attributor] Existing rewrite is preferred\n"); 1443 return false; 1444 } 1445 1446 // If we have a replacement already but we like the new one better, delete 1447 // the old. 1448 ARI.reset(); 1449 1450 LLVM_DEBUG(dbgs() << "[Attributor] Register new rewrite of " << Arg << " in " 1451 << Arg.getParent()->getName() << " with " 1452 << ReplacementTypes.size() << " replacements\n"); 1453 1454 // Remember the replacement. 1455 ARI.reset(new ArgumentReplacementInfo(*this, Arg, ReplacementTypes, 1456 std::move(CalleeRepairCB), 1457 std::move(ACSRepairCB))); 1458 1459 return true; 1460 } 1461 1462 bool Attributor::shouldSeedAttribute(AbstractAttribute &AA) { 1463 if (SeedAllowList.size() == 0) 1464 return true; 1465 return std::count(SeedAllowList.begin(), SeedAllowList.end(), AA.getName()); 1466 } 1467 1468 ChangeStatus Attributor::rewriteFunctionSignatures( 1469 SmallPtrSetImpl<Function *> &ModifiedFns) { 1470 ChangeStatus Changed = ChangeStatus::UNCHANGED; 1471 1472 for (auto &It : ArgumentReplacementMap) { 1473 Function *OldFn = It.getFirst(); 1474 1475 // Deleted functions do not require rewrites. 1476 if (ToBeDeletedFunctions.count(OldFn)) 1477 continue; 1478 1479 const SmallVectorImpl<std::unique_ptr<ArgumentReplacementInfo>> &ARIs = 1480 It.getSecond(); 1481 assert(ARIs.size() == OldFn->arg_size() && "Inconsistent state!"); 1482 1483 SmallVector<Type *, 16> NewArgumentTypes; 1484 SmallVector<AttributeSet, 16> NewArgumentAttributes; 1485 1486 // Collect replacement argument types and copy over existing attributes. 1487 AttributeList OldFnAttributeList = OldFn->getAttributes(); 1488 for (Argument &Arg : OldFn->args()) { 1489 if (const std::unique_ptr<ArgumentReplacementInfo> &ARI = 1490 ARIs[Arg.getArgNo()]) { 1491 NewArgumentTypes.append(ARI->ReplacementTypes.begin(), 1492 ARI->ReplacementTypes.end()); 1493 NewArgumentAttributes.append(ARI->getNumReplacementArgs(), 1494 AttributeSet()); 1495 } else { 1496 NewArgumentTypes.push_back(Arg.getType()); 1497 NewArgumentAttributes.push_back( 1498 OldFnAttributeList.getParamAttributes(Arg.getArgNo())); 1499 } 1500 } 1501 1502 FunctionType *OldFnTy = OldFn->getFunctionType(); 1503 Type *RetTy = OldFnTy->getReturnType(); 1504 1505 // Construct the new function type using the new arguments types. 1506 FunctionType *NewFnTy = 1507 FunctionType::get(RetTy, NewArgumentTypes, OldFnTy->isVarArg()); 1508 1509 LLVM_DEBUG(dbgs() << "[Attributor] Function rewrite '" << OldFn->getName() 1510 << "' from " << *OldFn->getFunctionType() << " to " 1511 << *NewFnTy << "\n"); 1512 1513 // Create the new function body and insert it into the module. 1514 Function *NewFn = Function::Create(NewFnTy, OldFn->getLinkage(), 1515 OldFn->getAddressSpace(), ""); 1516 OldFn->getParent()->getFunctionList().insert(OldFn->getIterator(), NewFn); 1517 NewFn->takeName(OldFn); 1518 NewFn->copyAttributesFrom(OldFn); 1519 1520 // Patch the pointer to LLVM function in debug info descriptor. 1521 NewFn->setSubprogram(OldFn->getSubprogram()); 1522 OldFn->setSubprogram(nullptr); 1523 1524 // Recompute the parameter attributes list based on the new arguments for 1525 // the function. 1526 LLVMContext &Ctx = OldFn->getContext(); 1527 NewFn->setAttributes(AttributeList::get( 1528 Ctx, OldFnAttributeList.getFnAttributes(), 1529 OldFnAttributeList.getRetAttributes(), NewArgumentAttributes)); 1530 1531 // Since we have now created the new function, splice the body of the old 1532 // function right into the new function, leaving the old rotting hulk of the 1533 // function empty. 1534 NewFn->getBasicBlockList().splice(NewFn->begin(), 1535 OldFn->getBasicBlockList()); 1536 1537 // Fixup block addresses to reference new function. 1538 SmallVector<BlockAddress *, 8u> BlockAddresses; 1539 for (User *U : OldFn->users()) 1540 if (auto *BA = dyn_cast<BlockAddress>(U)) 1541 BlockAddresses.push_back(BA); 1542 for (auto *BA : BlockAddresses) 1543 BA->replaceAllUsesWith(BlockAddress::get(NewFn, BA->getBasicBlock())); 1544 1545 // Set of all "call-like" instructions that invoke the old function mapped 1546 // to their new replacements. 1547 SmallVector<std::pair<CallBase *, CallBase *>, 8> CallSitePairs; 1548 1549 // Callback to create a new "call-like" instruction for a given one. 1550 auto CallSiteReplacementCreator = [&](AbstractCallSite ACS) { 1551 CallBase *OldCB = cast<CallBase>(ACS.getInstruction()); 1552 const AttributeList &OldCallAttributeList = OldCB->getAttributes(); 1553 1554 // Collect the new argument operands for the replacement call site. 1555 SmallVector<Value *, 16> NewArgOperands; 1556 SmallVector<AttributeSet, 16> NewArgOperandAttributes; 1557 for (unsigned OldArgNum = 0; OldArgNum < ARIs.size(); ++OldArgNum) { 1558 unsigned NewFirstArgNum = NewArgOperands.size(); 1559 (void)NewFirstArgNum; // only used inside assert. 1560 if (const std::unique_ptr<ArgumentReplacementInfo> &ARI = 1561 ARIs[OldArgNum]) { 1562 if (ARI->ACSRepairCB) 1563 ARI->ACSRepairCB(*ARI, ACS, NewArgOperands); 1564 assert(ARI->getNumReplacementArgs() + NewFirstArgNum == 1565 NewArgOperands.size() && 1566 "ACS repair callback did not provide as many operand as new " 1567 "types were registered!"); 1568 // TODO: Exose the attribute set to the ACS repair callback 1569 NewArgOperandAttributes.append(ARI->ReplacementTypes.size(), 1570 AttributeSet()); 1571 } else { 1572 NewArgOperands.push_back(ACS.getCallArgOperand(OldArgNum)); 1573 NewArgOperandAttributes.push_back( 1574 OldCallAttributeList.getParamAttributes(OldArgNum)); 1575 } 1576 } 1577 1578 assert(NewArgOperands.size() == NewArgOperandAttributes.size() && 1579 "Mismatch # argument operands vs. # argument operand attributes!"); 1580 assert(NewArgOperands.size() == NewFn->arg_size() && 1581 "Mismatch # argument operands vs. # function arguments!"); 1582 1583 SmallVector<OperandBundleDef, 4> OperandBundleDefs; 1584 OldCB->getOperandBundlesAsDefs(OperandBundleDefs); 1585 1586 // Create a new call or invoke instruction to replace the old one. 1587 CallBase *NewCB; 1588 if (InvokeInst *II = dyn_cast<InvokeInst>(OldCB)) { 1589 NewCB = 1590 InvokeInst::Create(NewFn, II->getNormalDest(), II->getUnwindDest(), 1591 NewArgOperands, OperandBundleDefs, "", OldCB); 1592 } else { 1593 auto *NewCI = CallInst::Create(NewFn, NewArgOperands, OperandBundleDefs, 1594 "", OldCB); 1595 NewCI->setTailCallKind(cast<CallInst>(OldCB)->getTailCallKind()); 1596 NewCB = NewCI; 1597 } 1598 1599 // Copy over various properties and the new attributes. 1600 NewCB->copyMetadata(*OldCB, {LLVMContext::MD_prof, LLVMContext::MD_dbg}); 1601 NewCB->setCallingConv(OldCB->getCallingConv()); 1602 NewCB->takeName(OldCB); 1603 NewCB->setAttributes(AttributeList::get( 1604 Ctx, OldCallAttributeList.getFnAttributes(), 1605 OldCallAttributeList.getRetAttributes(), NewArgOperandAttributes)); 1606 1607 CallSitePairs.push_back({OldCB, NewCB}); 1608 return true; 1609 }; 1610 1611 // Use the CallSiteReplacementCreator to create replacement call sites. 1612 bool AllCallSitesKnown; 1613 bool Success = checkForAllCallSites(CallSiteReplacementCreator, *OldFn, 1614 true, nullptr, AllCallSitesKnown); 1615 (void)Success; 1616 assert(Success && "Assumed call site replacement to succeed!"); 1617 1618 // Rewire the arguments. 1619 auto OldFnArgIt = OldFn->arg_begin(); 1620 auto NewFnArgIt = NewFn->arg_begin(); 1621 for (unsigned OldArgNum = 0; OldArgNum < ARIs.size(); 1622 ++OldArgNum, ++OldFnArgIt) { 1623 if (const std::unique_ptr<ArgumentReplacementInfo> &ARI = 1624 ARIs[OldArgNum]) { 1625 if (ARI->CalleeRepairCB) 1626 ARI->CalleeRepairCB(*ARI, *NewFn, NewFnArgIt); 1627 NewFnArgIt += ARI->ReplacementTypes.size(); 1628 } else { 1629 NewFnArgIt->takeName(&*OldFnArgIt); 1630 OldFnArgIt->replaceAllUsesWith(&*NewFnArgIt); 1631 ++NewFnArgIt; 1632 } 1633 } 1634 1635 // Eliminate the instructions *after* we visited all of them. 1636 for (auto &CallSitePair : CallSitePairs) { 1637 CallBase &OldCB = *CallSitePair.first; 1638 CallBase &NewCB = *CallSitePair.second; 1639 assert(OldCB.getType() == NewCB.getType() && 1640 "Cannot handle call sites with different types!"); 1641 ModifiedFns.insert(OldCB.getFunction()); 1642 CGUpdater.replaceCallSite(OldCB, NewCB); 1643 OldCB.replaceAllUsesWith(&NewCB); 1644 OldCB.eraseFromParent(); 1645 } 1646 1647 // Replace the function in the call graph (if any). 1648 CGUpdater.replaceFunctionWith(*OldFn, *NewFn); 1649 1650 // If the old function was modified and needed to be reanalyzed, the new one 1651 // does now. 1652 if (ModifiedFns.erase(OldFn)) 1653 ModifiedFns.insert(NewFn); 1654 1655 Changed = ChangeStatus::CHANGED; 1656 } 1657 1658 return Changed; 1659 } 1660 1661 void InformationCache::initializeInformationCache(const Function &CF, 1662 FunctionInfo &FI) { 1663 // As we do not modify the function here we can remove the const 1664 // withouth breaking implicit assumptions. At the end of the day, we could 1665 // initialize the cache eagerly which would look the same to the users. 1666 Function &F = const_cast<Function &>(CF); 1667 1668 // Walk all instructions to find interesting instructions that might be 1669 // queried by abstract attributes during their initialization or update. 1670 // This has to happen before we create attributes. 1671 1672 for (Instruction &I : instructions(&F)) { 1673 bool IsInterestingOpcode = false; 1674 1675 // To allow easy access to all instructions in a function with a given 1676 // opcode we store them in the InfoCache. As not all opcodes are interesting 1677 // to concrete attributes we only cache the ones that are as identified in 1678 // the following switch. 1679 // Note: There are no concrete attributes now so this is initially empty. 1680 switch (I.getOpcode()) { 1681 default: 1682 assert(!isa<CallBase>(&I) && 1683 "New call base instruction type needs to be known in the " 1684 "Attributor."); 1685 break; 1686 case Instruction::Call: 1687 // Calls are interesting on their own, additionally: 1688 // For `llvm.assume` calls we also fill the KnowledgeMap as we find them. 1689 // For `must-tail` calls we remember the caller and callee. 1690 if (IntrinsicInst *Assume = dyn_cast<IntrinsicInst>(&I)) { 1691 if (Assume->getIntrinsicID() == Intrinsic::assume) 1692 fillMapFromAssume(*Assume, KnowledgeMap); 1693 } else if (cast<CallInst>(I).isMustTailCall()) { 1694 FI.ContainsMustTailCall = true; 1695 if (const Function *Callee = cast<CallInst>(I).getCalledFunction()) 1696 getFunctionInfo(*Callee).CalledViaMustTail = true; 1697 } 1698 LLVM_FALLTHROUGH; 1699 case Instruction::CallBr: 1700 case Instruction::Invoke: 1701 case Instruction::CleanupRet: 1702 case Instruction::CatchSwitch: 1703 case Instruction::AtomicRMW: 1704 case Instruction::AtomicCmpXchg: 1705 case Instruction::Br: 1706 case Instruction::Resume: 1707 case Instruction::Ret: 1708 case Instruction::Load: 1709 // The alignment of a pointer is interesting for loads. 1710 case Instruction::Store: 1711 // The alignment of a pointer is interesting for stores. 1712 IsInterestingOpcode = true; 1713 } 1714 if (IsInterestingOpcode) { 1715 auto *&Insts = FI.OpcodeInstMap[I.getOpcode()]; 1716 if (!Insts) 1717 Insts = new (Allocator) InstructionVectorTy(); 1718 Insts->push_back(&I); 1719 } 1720 if (I.mayReadOrWriteMemory()) 1721 FI.RWInsts.push_back(&I); 1722 } 1723 1724 if (F.hasFnAttribute(Attribute::AlwaysInline) && 1725 isInlineViable(F).isSuccess()) 1726 InlineableFunctions.insert(&F); 1727 } 1728 1729 InformationCache::FunctionInfo::~FunctionInfo() { 1730 // The instruction vectors are allocated using a BumpPtrAllocator, we need to 1731 // manually destroy them. 1732 for (auto &It : OpcodeInstMap) 1733 It.getSecond()->~InstructionVectorTy(); 1734 } 1735 1736 void Attributor::recordDependence(const AbstractAttribute &FromAA, 1737 const AbstractAttribute &ToAA, 1738 DepClassTy DepClass) { 1739 // If we are outside of an update, thus before the actual fixpoint iteration 1740 // started (= when we create AAs), we do not track dependences because we will 1741 // put all AAs into the initial worklist anyway. 1742 if (DependenceStack.empty()) 1743 return; 1744 if (FromAA.getState().isAtFixpoint()) 1745 return; 1746 DependenceStack.back()->push_back({&FromAA, &ToAA, DepClass}); 1747 } 1748 1749 void Attributor::rememberDependences() { 1750 assert(!DependenceStack.empty() && "No dependences to remember!"); 1751 1752 for (DepInfo &DI : *DependenceStack.back()) { 1753 auto &DepAAs = const_cast<AbstractAttribute &>(*DI.FromAA).Deps; 1754 DepAAs.push_back(AbstractAttribute::DepTy( 1755 const_cast<AbstractAttribute *>(DI.ToAA), unsigned(DI.DepClass))); 1756 } 1757 } 1758 1759 void Attributor::identifyDefaultAbstractAttributes(Function &F) { 1760 if (!VisitedFunctions.insert(&F).second) 1761 return; 1762 if (F.isDeclaration()) 1763 return; 1764 1765 // In non-module runs we need to look at the call sites of a function to 1766 // determine if it is part of a must-tail call edge. This will influence what 1767 // attributes we can derive. 1768 InformationCache::FunctionInfo &FI = InfoCache.getFunctionInfo(F); 1769 if (!isModulePass() && !FI.CalledViaMustTail) { 1770 for (const Use &U : F.uses()) 1771 if (const auto *CB = dyn_cast<CallBase>(U.getUser())) 1772 if (CB->isCallee(&U) && CB->isMustTailCall()) 1773 FI.CalledViaMustTail = true; 1774 } 1775 1776 IRPosition FPos = IRPosition::function(F); 1777 1778 // Check for dead BasicBlocks in every function. 1779 // We need dead instruction detection because we do not want to deal with 1780 // broken IR in which SSA rules do not apply. 1781 getOrCreateAAFor<AAIsDead>(FPos); 1782 1783 // Every function might be "will-return". 1784 getOrCreateAAFor<AAWillReturn>(FPos); 1785 1786 // Every function might contain instructions that cause "undefined behavior". 1787 getOrCreateAAFor<AAUndefinedBehavior>(FPos); 1788 1789 // Every function can be nounwind. 1790 getOrCreateAAFor<AANoUnwind>(FPos); 1791 1792 // Every function might be marked "nosync" 1793 getOrCreateAAFor<AANoSync>(FPos); 1794 1795 // Every function might be "no-free". 1796 getOrCreateAAFor<AANoFree>(FPos); 1797 1798 // Every function might be "no-return". 1799 getOrCreateAAFor<AANoReturn>(FPos); 1800 1801 // Every function might be "no-recurse". 1802 getOrCreateAAFor<AANoRecurse>(FPos); 1803 1804 // Every function might be "readnone/readonly/writeonly/...". 1805 getOrCreateAAFor<AAMemoryBehavior>(FPos); 1806 1807 // Every function can be "readnone/argmemonly/inaccessiblememonly/...". 1808 getOrCreateAAFor<AAMemoryLocation>(FPos); 1809 1810 // Every function might be applicable for Heap-To-Stack conversion. 1811 if (EnableHeapToStack) 1812 getOrCreateAAFor<AAHeapToStack>(FPos); 1813 1814 // Return attributes are only appropriate if the return type is non void. 1815 Type *ReturnType = F.getReturnType(); 1816 if (!ReturnType->isVoidTy()) { 1817 // Argument attribute "returned" --- Create only one per function even 1818 // though it is an argument attribute. 1819 getOrCreateAAFor<AAReturnedValues>(FPos); 1820 1821 IRPosition RetPos = IRPosition::returned(F); 1822 1823 // Every returned value might be dead. 1824 getOrCreateAAFor<AAIsDead>(RetPos); 1825 1826 // Every function might be simplified. 1827 getOrCreateAAFor<AAValueSimplify>(RetPos); 1828 1829 if (ReturnType->isPointerTy()) { 1830 1831 // Every function with pointer return type might be marked align. 1832 getOrCreateAAFor<AAAlign>(RetPos); 1833 1834 // Every function with pointer return type might be marked nonnull. 1835 getOrCreateAAFor<AANonNull>(RetPos); 1836 1837 // Every function with pointer return type might be marked noalias. 1838 getOrCreateAAFor<AANoAlias>(RetPos); 1839 1840 // Every function with pointer return type might be marked 1841 // dereferenceable. 1842 getOrCreateAAFor<AADereferenceable>(RetPos); 1843 } 1844 } 1845 1846 for (Argument &Arg : F.args()) { 1847 IRPosition ArgPos = IRPosition::argument(Arg); 1848 1849 // Every argument might be simplified. 1850 getOrCreateAAFor<AAValueSimplify>(ArgPos); 1851 1852 // Every argument might be dead. 1853 getOrCreateAAFor<AAIsDead>(ArgPos); 1854 1855 if (Arg.getType()->isPointerTy()) { 1856 // Every argument with pointer type might be marked nonnull. 1857 getOrCreateAAFor<AANonNull>(ArgPos); 1858 1859 // Every argument with pointer type might be marked noalias. 1860 getOrCreateAAFor<AANoAlias>(ArgPos); 1861 1862 // Every argument with pointer type might be marked dereferenceable. 1863 getOrCreateAAFor<AADereferenceable>(ArgPos); 1864 1865 // Every argument with pointer type might be marked align. 1866 getOrCreateAAFor<AAAlign>(ArgPos); 1867 1868 // Every argument with pointer type might be marked nocapture. 1869 getOrCreateAAFor<AANoCapture>(ArgPos); 1870 1871 // Every argument with pointer type might be marked 1872 // "readnone/readonly/writeonly/..." 1873 getOrCreateAAFor<AAMemoryBehavior>(ArgPos); 1874 1875 // Every argument with pointer type might be marked nofree. 1876 getOrCreateAAFor<AANoFree>(ArgPos); 1877 1878 // Every argument with pointer type might be privatizable (or promotable) 1879 getOrCreateAAFor<AAPrivatizablePtr>(ArgPos); 1880 } 1881 } 1882 1883 auto CallSitePred = [&](Instruction &I) -> bool { 1884 auto &CB = cast<CallBase>(I); 1885 IRPosition CBRetPos = IRPosition::callsite_returned(CB); 1886 1887 // Call sites might be dead if they do not have side effects and no live 1888 // users. The return value might be dead if there are no live users. 1889 getOrCreateAAFor<AAIsDead>(CBRetPos); 1890 1891 Function *Callee = CB.getCalledFunction(); 1892 // TODO: Even if the callee is not known now we might be able to simplify 1893 // the call/callee. 1894 if (!Callee) 1895 return true; 1896 1897 // Skip declarations except if annotations on their call sites were 1898 // explicitly requested. 1899 if (!AnnotateDeclarationCallSites && Callee->isDeclaration() && 1900 !Callee->hasMetadata(LLVMContext::MD_callback)) 1901 return true; 1902 1903 if (!Callee->getReturnType()->isVoidTy() && !CB.use_empty()) { 1904 1905 IRPosition CBRetPos = IRPosition::callsite_returned(CB); 1906 1907 // Call site return integer values might be limited by a constant range. 1908 if (Callee->getReturnType()->isIntegerTy()) 1909 getOrCreateAAFor<AAValueConstantRange>(CBRetPos); 1910 } 1911 1912 for (int I = 0, E = CB.getNumArgOperands(); I < E; ++I) { 1913 1914 IRPosition CBArgPos = IRPosition::callsite_argument(CB, I); 1915 1916 // Every call site argument might be dead. 1917 getOrCreateAAFor<AAIsDead>(CBArgPos); 1918 1919 // Call site argument might be simplified. 1920 getOrCreateAAFor<AAValueSimplify>(CBArgPos); 1921 1922 if (!CB.getArgOperand(I)->getType()->isPointerTy()) 1923 continue; 1924 1925 // Call site argument attribute "non-null". 1926 getOrCreateAAFor<AANonNull>(CBArgPos); 1927 1928 // Call site argument attribute "nocapture". 1929 getOrCreateAAFor<AANoCapture>(CBArgPos); 1930 1931 // Call site argument attribute "no-alias". 1932 getOrCreateAAFor<AANoAlias>(CBArgPos); 1933 1934 // Call site argument attribute "dereferenceable". 1935 getOrCreateAAFor<AADereferenceable>(CBArgPos); 1936 1937 // Call site argument attribute "align". 1938 getOrCreateAAFor<AAAlign>(CBArgPos); 1939 1940 // Call site argument attribute 1941 // "readnone/readonly/writeonly/..." 1942 getOrCreateAAFor<AAMemoryBehavior>(CBArgPos); 1943 1944 // Call site argument attribute "nofree". 1945 getOrCreateAAFor<AANoFree>(CBArgPos); 1946 } 1947 return true; 1948 }; 1949 1950 auto &OpcodeInstMap = InfoCache.getOpcodeInstMapForFunction(F); 1951 bool Success; 1952 Success = checkForAllInstructionsImpl( 1953 nullptr, OpcodeInstMap, CallSitePred, nullptr, nullptr, 1954 {(unsigned)Instruction::Invoke, (unsigned)Instruction::CallBr, 1955 (unsigned)Instruction::Call}); 1956 (void)Success; 1957 assert(Success && "Expected the check call to be successful!"); 1958 1959 auto LoadStorePred = [&](Instruction &I) -> bool { 1960 if (isa<LoadInst>(I)) 1961 getOrCreateAAFor<AAAlign>( 1962 IRPosition::value(*cast<LoadInst>(I).getPointerOperand())); 1963 else 1964 getOrCreateAAFor<AAAlign>( 1965 IRPosition::value(*cast<StoreInst>(I).getPointerOperand())); 1966 return true; 1967 }; 1968 Success = checkForAllInstructionsImpl( 1969 nullptr, OpcodeInstMap, LoadStorePred, nullptr, nullptr, 1970 {(unsigned)Instruction::Load, (unsigned)Instruction::Store}); 1971 (void)Success; 1972 assert(Success && "Expected the check call to be successful!"); 1973 } 1974 1975 /// Helpers to ease debugging through output streams and print calls. 1976 /// 1977 ///{ 1978 raw_ostream &llvm::operator<<(raw_ostream &OS, ChangeStatus S) { 1979 return OS << (S == ChangeStatus::CHANGED ? "changed" : "unchanged"); 1980 } 1981 1982 raw_ostream &llvm::operator<<(raw_ostream &OS, IRPosition::Kind AP) { 1983 switch (AP) { 1984 case IRPosition::IRP_INVALID: 1985 return OS << "inv"; 1986 case IRPosition::IRP_FLOAT: 1987 return OS << "flt"; 1988 case IRPosition::IRP_RETURNED: 1989 return OS << "fn_ret"; 1990 case IRPosition::IRP_CALL_SITE_RETURNED: 1991 return OS << "cs_ret"; 1992 case IRPosition::IRP_FUNCTION: 1993 return OS << "fn"; 1994 case IRPosition::IRP_CALL_SITE: 1995 return OS << "cs"; 1996 case IRPosition::IRP_ARGUMENT: 1997 return OS << "arg"; 1998 case IRPosition::IRP_CALL_SITE_ARGUMENT: 1999 return OS << "cs_arg"; 2000 } 2001 llvm_unreachable("Unknown attribute position!"); 2002 } 2003 2004 raw_ostream &llvm::operator<<(raw_ostream &OS, const IRPosition &Pos) { 2005 const Value &AV = Pos.getAssociatedValue(); 2006 return OS << "{" << Pos.getPositionKind() << ":" << AV.getName() << " [" 2007 << Pos.getAnchorValue().getName() << "@" << Pos.getArgNo() << "]}"; 2008 } 2009 2010 raw_ostream &llvm::operator<<(raw_ostream &OS, const IntegerRangeState &S) { 2011 OS << "range-state(" << S.getBitWidth() << ")<"; 2012 S.getKnown().print(OS); 2013 OS << " / "; 2014 S.getAssumed().print(OS); 2015 OS << ">"; 2016 2017 return OS << static_cast<const AbstractState &>(S); 2018 } 2019 2020 raw_ostream &llvm::operator<<(raw_ostream &OS, const AbstractState &S) { 2021 return OS << (!S.isValidState() ? "top" : (S.isAtFixpoint() ? "fix" : "")); 2022 } 2023 2024 raw_ostream &llvm::operator<<(raw_ostream &OS, const AbstractAttribute &AA) { 2025 AA.print(OS); 2026 return OS; 2027 } 2028 2029 void AbstractAttribute::print(raw_ostream &OS) const { 2030 OS << "[P: " << getIRPosition() << "][" << getAsStr() << "][S: " << getState() 2031 << "]"; 2032 } 2033 ///} 2034 2035 /// ---------------------------------------------------------------------------- 2036 /// Pass (Manager) Boilerplate 2037 /// ---------------------------------------------------------------------------- 2038 2039 static bool runAttributorOnFunctions(InformationCache &InfoCache, 2040 SetVector<Function *> &Functions, 2041 AnalysisGetter &AG, 2042 CallGraphUpdater &CGUpdater) { 2043 if (Functions.empty()) 2044 return false; 2045 2046 LLVM_DEBUG(dbgs() << "[Attributor] Run on module with " << Functions.size() 2047 << " functions.\n"); 2048 2049 // Create an Attributor and initially empty information cache that is filled 2050 // while we identify default attribute opportunities. 2051 Attributor A(Functions, InfoCache, CGUpdater); 2052 2053 // Create shallow wrappers for all functions that are not IPO amendable 2054 if (AllowShallowWrappers) 2055 for (Function *F : Functions) 2056 if (!A.isFunctionIPOAmendable(*F)) 2057 createShallowWrapper(*F); 2058 2059 for (Function *F : Functions) { 2060 if (F->hasExactDefinition()) 2061 NumFnWithExactDefinition++; 2062 else 2063 NumFnWithoutExactDefinition++; 2064 2065 // We look at internal functions only on-demand but if any use is not a 2066 // direct call or outside the current set of analyzed functions, we have to 2067 // do it eagerly. 2068 if (F->hasLocalLinkage()) { 2069 if (llvm::all_of(F->uses(), [&Functions](const Use &U) { 2070 const auto *CB = dyn_cast<CallBase>(U.getUser()); 2071 return CB && CB->isCallee(&U) && 2072 Functions.count(const_cast<Function *>(CB->getCaller())); 2073 })) 2074 continue; 2075 } 2076 2077 // Populate the Attributor with abstract attribute opportunities in the 2078 // function and the information cache with IR information. 2079 A.identifyDefaultAbstractAttributes(*F); 2080 } 2081 2082 ChangeStatus Changed = A.run(); 2083 LLVM_DEBUG(dbgs() << "[Attributor] Done with " << Functions.size() 2084 << " functions, result: " << Changed << ".\n"); 2085 return Changed == ChangeStatus::CHANGED; 2086 } 2087 2088 PreservedAnalyses AttributorPass::run(Module &M, ModuleAnalysisManager &AM) { 2089 FunctionAnalysisManager &FAM = 2090 AM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager(); 2091 AnalysisGetter AG(FAM); 2092 2093 SetVector<Function *> Functions; 2094 for (Function &F : M) 2095 Functions.insert(&F); 2096 2097 CallGraphUpdater CGUpdater; 2098 BumpPtrAllocator Allocator; 2099 InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ nullptr); 2100 if (runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater)) { 2101 // FIXME: Think about passes we will preserve and add them here. 2102 return PreservedAnalyses::none(); 2103 } 2104 return PreservedAnalyses::all(); 2105 } 2106 2107 PreservedAnalyses AttributorCGSCCPass::run(LazyCallGraph::SCC &C, 2108 CGSCCAnalysisManager &AM, 2109 LazyCallGraph &CG, 2110 CGSCCUpdateResult &UR) { 2111 FunctionAnalysisManager &FAM = 2112 AM.getResult<FunctionAnalysisManagerCGSCCProxy>(C, CG).getManager(); 2113 AnalysisGetter AG(FAM); 2114 2115 SetVector<Function *> Functions; 2116 for (LazyCallGraph::Node &N : C) 2117 Functions.insert(&N.getFunction()); 2118 2119 if (Functions.empty()) 2120 return PreservedAnalyses::all(); 2121 2122 Module &M = *Functions.back()->getParent(); 2123 CallGraphUpdater CGUpdater; 2124 CGUpdater.initialize(CG, C, AM, UR); 2125 BumpPtrAllocator Allocator; 2126 InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ &Functions); 2127 if (runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater)) { 2128 // FIXME: Think about passes we will preserve and add them here. 2129 return PreservedAnalyses::none(); 2130 } 2131 return PreservedAnalyses::all(); 2132 } 2133 2134 namespace { 2135 2136 struct AttributorLegacyPass : public ModulePass { 2137 static char ID; 2138 2139 AttributorLegacyPass() : ModulePass(ID) { 2140 initializeAttributorLegacyPassPass(*PassRegistry::getPassRegistry()); 2141 } 2142 2143 bool runOnModule(Module &M) override { 2144 if (skipModule(M)) 2145 return false; 2146 2147 AnalysisGetter AG; 2148 SetVector<Function *> Functions; 2149 for (Function &F : M) 2150 Functions.insert(&F); 2151 2152 CallGraphUpdater CGUpdater; 2153 BumpPtrAllocator Allocator; 2154 InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ nullptr); 2155 return runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater); 2156 } 2157 2158 void getAnalysisUsage(AnalysisUsage &AU) const override { 2159 // FIXME: Think about passes we will preserve and add them here. 2160 AU.addRequired<TargetLibraryInfoWrapperPass>(); 2161 } 2162 }; 2163 2164 struct AttributorCGSCCLegacyPass : public CallGraphSCCPass { 2165 CallGraphUpdater CGUpdater; 2166 static char ID; 2167 2168 AttributorCGSCCLegacyPass() : CallGraphSCCPass(ID) { 2169 initializeAttributorCGSCCLegacyPassPass(*PassRegistry::getPassRegistry()); 2170 } 2171 2172 bool runOnSCC(CallGraphSCC &SCC) override { 2173 if (skipSCC(SCC)) 2174 return false; 2175 2176 SetVector<Function *> Functions; 2177 for (CallGraphNode *CGN : SCC) 2178 if (Function *Fn = CGN->getFunction()) 2179 if (!Fn->isDeclaration()) 2180 Functions.insert(Fn); 2181 2182 if (Functions.empty()) 2183 return false; 2184 2185 AnalysisGetter AG; 2186 CallGraph &CG = const_cast<CallGraph &>(SCC.getCallGraph()); 2187 CGUpdater.initialize(CG, SCC); 2188 Module &M = *Functions.back()->getParent(); 2189 BumpPtrAllocator Allocator; 2190 InformationCache InfoCache(M, AG, Allocator, /* CGSCC */ &Functions); 2191 return runAttributorOnFunctions(InfoCache, Functions, AG, CGUpdater); 2192 } 2193 2194 bool doFinalization(CallGraph &CG) override { return CGUpdater.finalize(); } 2195 2196 void getAnalysisUsage(AnalysisUsage &AU) const override { 2197 // FIXME: Think about passes we will preserve and add them here. 2198 AU.addRequired<TargetLibraryInfoWrapperPass>(); 2199 CallGraphSCCPass::getAnalysisUsage(AU); 2200 } 2201 }; 2202 2203 } // end anonymous namespace 2204 2205 Pass *llvm::createAttributorLegacyPass() { return new AttributorLegacyPass(); } 2206 Pass *llvm::createAttributorCGSCCLegacyPass() { 2207 return new AttributorCGSCCLegacyPass(); 2208 } 2209 2210 char AttributorLegacyPass::ID = 0; 2211 char AttributorCGSCCLegacyPass::ID = 0; 2212 2213 INITIALIZE_PASS_BEGIN(AttributorLegacyPass, "attributor", 2214 "Deduce and propagate attributes", false, false) 2215 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) 2216 INITIALIZE_PASS_END(AttributorLegacyPass, "attributor", 2217 "Deduce and propagate attributes", false, false) 2218 INITIALIZE_PASS_BEGIN(AttributorCGSCCLegacyPass, "attributor-cgscc", 2219 "Deduce and propagate attributes (CGSCC pass)", false, 2220 false) 2221 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) 2222 INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass) 2223 INITIALIZE_PASS_END(AttributorCGSCCLegacyPass, "attributor-cgscc", 2224 "Deduce and propagate attributes (CGSCC pass)", false, 2225 false) 2226