diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -217,23 +217,6 @@ return IRPosition(const_cast(CB), Kind(ArgNo)); } - /// Create a position describing the function scope of \p ICS. - static const IRPosition callsite_function(ImmutableCallSite ICS) { - return IRPosition::callsite_function(cast(*ICS.getInstruction())); - } - - /// Create a position describing the returned value of \p ICS. - static const IRPosition callsite_returned(ImmutableCallSite ICS) { - return IRPosition::callsite_returned(cast(*ICS.getInstruction())); - } - - /// Create a position describing the argument of \p ICS at position \p ArgNo. - static const IRPosition callsite_argument(ImmutableCallSite ICS, - unsigned ArgNo) { - return IRPosition::callsite_argument(cast(*ICS.getInstruction()), - ArgNo); - } - /// Create a position describing the argument of \p ACS at position \p ArgNo. static const IRPosition callsite_argument(AbstractCallSite ACS, unsigned ArgNo) { @@ -418,9 +401,9 @@ return; AttributeList AttrList; - CallSite CS = CallSite(&getAnchorValue()); - if (CS) - AttrList = CS.getAttributes(); + auto *CB = dyn_cast(&getAnchorValue()); + if (CB) + AttrList = CB->getAttributes(); else AttrList = getAssociatedFunction()->getAttributes(); @@ -428,8 +411,8 @@ for (Attribute::AttrKind AK : AKs) AttrList = AttrList.removeAttribute(Ctx, getAttrIdx(), AK); - if (CS) - CS.setAttributes(AttrList); + if (CB) + CB->setAttributes(AttrList); else getAssociatedFunction()->setAttributes(AttrList); } diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -228,7 +228,7 @@ case IRPosition::IRP_CALL_SITE: case IRPosition::IRP_CALL_SITE_RETURNED: case IRPosition::IRP_CALL_SITE_ARGUMENT: - Attrs = ImmutableCallSite(&IRP.getAnchorValue()).getAttributes(); + Attrs = cast(IRP.getAnchorValue()).getAttributes(); break; } @@ -253,7 +253,7 @@ case IRPosition::IRP_CALL_SITE: case IRPosition::IRP_CALL_SITE_RETURNED: case IRPosition::IRP_CALL_SITE_ARGUMENT: - CallSite(&IRP.getAnchorValue()).setAttributes(Attrs); + cast(IRP.getAnchorValue()).setAttributes(Attrs); break; case IRPosition::IRP_INVALID: case IRPosition::IRP_FLOAT: @@ -269,7 +269,7 @@ SubsumingPositionIterator::SubsumingPositionIterator(const IRPosition &IRP) { IRPositions.emplace_back(IRP); - ImmutableCallSite ICS(&IRP.getAnchorValue()); + const auto *CB = dyn_cast(&IRP.getAnchorValue()); switch (IRP.getPositionKind()) { case IRPosition::IRP_INVALID: case IRPosition::IRP_FLOAT: @@ -280,41 +280,40 @@ IRPositions.emplace_back(IRPosition::function(*IRP.getAnchorScope())); return; case IRPosition::IRP_CALL_SITE: - assert(ICS && "Expected call site!"); + assert(CB && "Expected call site!"); // TODO: We need to look at the operand bundles similar to the redirection // in CallBase. - if (!ICS.hasOperandBundles()) - if (const Function *Callee = ICS.getCalledFunction()) + if (!CB->hasOperandBundles()) + if (const Function *Callee = CB->getCalledFunction()) IRPositions.emplace_back(IRPosition::function(*Callee)); return; case IRPosition::IRP_CALL_SITE_RETURNED: - assert(ICS && "Expected call site!"); + assert(CB && "Expected call site!"); // TODO: We need to look at the operand bundles similar to the redirection // in CallBase. - if (!ICS.hasOperandBundles()) { - if (const Function *Callee = ICS.getCalledFunction()) { + if (!CB->hasOperandBundles()) { + if (const Function *Callee = CB->getCalledFunction()) { IRPositions.emplace_back(IRPosition::returned(*Callee)); IRPositions.emplace_back(IRPosition::function(*Callee)); for (const Argument &Arg : Callee->args()) if (Arg.hasReturnedAttr()) { IRPositions.emplace_back( - IRPosition::callsite_argument(ICS, Arg.getArgNo())); + IRPosition::callsite_argument(*CB, Arg.getArgNo())); IRPositions.emplace_back( - IRPosition::value(*ICS.getArgOperand(Arg.getArgNo()))); + IRPosition::value(*CB->getArgOperand(Arg.getArgNo()))); IRPositions.emplace_back(IRPosition::argument(Arg)); } } } - IRPositions.emplace_back( - IRPosition::callsite_function(cast(*ICS.getInstruction()))); + IRPositions.emplace_back(IRPosition::callsite_function(*CB)); return; case IRPosition::IRP_CALL_SITE_ARGUMENT: { int ArgNo = IRP.getArgNo(); - assert(ICS && ArgNo >= 0 && "Expected call site!"); + assert(CB && ArgNo >= 0 && "Expected call site!"); // TODO: We need to look at the operand bundles similar to the redirection // in CallBase. - if (!ICS.hasOperandBundles()) { - const Function *Callee = ICS.getCalledFunction(); + if (!CB->hasOperandBundles()) { + const Function *Callee = CB->getCalledFunction(); if (Callee && Callee->arg_size() > unsigned(ArgNo)) IRPositions.emplace_back(IRPosition::argument(*Callee->getArg(ArgNo))); if (Callee) @@ -369,8 +368,8 @@ return false; AttributeList AttrList; - if (ImmutableCallSite ICS = ImmutableCallSite(&getAnchorValue())) - AttrList = ICS.getAttributes(); + if (const auto *CB = dyn_cast(&getAnchorValue())) + AttrList = CB->getAttributes(); else AttrList = getAssociatedFunction()->getAttributes(); @@ -510,12 +509,12 @@ return isAssumedDead(IRPosition::value(*U.get()), QueryingAA, FnLivenessAA, CheckBBLivenessOnly, DepClass); - if (CallSite CS = CallSite(UserI)) { + if (auto *CB = dyn_cast(UserI)) { // For call site argument uses we can check if the argument is // unused/dead. - if (CS.isArgOperand(&U)) { + if (CB->isArgOperand(&U)) { const IRPosition &CSArgPos = - IRPosition::callsite_argument(CS, CS.getArgumentNo(&U)); + IRPosition::callsite_argument(*CB, CB->getArgOperandNo(&U)); return isAssumedDead(CSArgPos, QueryingAA, FnLivenessAA, CheckBBLivenessOnly, DepClass); } @@ -1617,8 +1616,8 @@ // Note: There are no concrete attributes now so this is initially empty. switch (I.getOpcode()) { default: - assert((!ImmutableCallSite(&I)) && (!isa(&I)) && - "New call site/base instruction type needs to be known in the " + assert(!isa(&I) && + "New call base instruction type needs to be known in the " "Attributor."); break; case Instruction::Call: @@ -1687,8 +1686,8 @@ InformationCache::FunctionInfo &FI = InfoCache.getFunctionInfo(F); if (!isModulePass() && !FI.CalledViaMustTail) { for (const Use &U : F.uses()) - if (ImmutableCallSite ICS = ImmutableCallSite(U.getUser())) - if (ICS.isCallee(&U) && ICS.isMustTailCall()) + if (const auto *CB = dyn_cast(U.getUser())) + if (CB->isCallee(&U) && CB->isMustTailCall()) FI.CalledViaMustTail = true; } @@ -1800,14 +1799,14 @@ } auto CallSitePred = [&](Instruction &I) -> bool { - CallSite CS(&I); - IRPosition CSRetPos = IRPosition::callsite_returned(CS); + auto *CB = dyn_cast(&I); + IRPosition CBRetPos = IRPosition::callsite_returned(*CB); // Call sites might be dead if they do not have side effects and no live // users. The return value might be dead if there are no live users. - getOrCreateAAFor(CSRetPos); + getOrCreateAAFor(CBRetPos); - Function *Callee = CS.getCalledFunction(); + Function *Callee = CB->getCalledFunction(); // TODO: Even if the callee is not known now we might be able to simplify // the call/callee. if (!Callee) @@ -1819,46 +1818,46 @@ !Callee->hasMetadata(LLVMContext::MD_callback)) return true; - if (!Callee->getReturnType()->isVoidTy() && !CS->use_empty()) { + if (!Callee->getReturnType()->isVoidTy() && !CB->use_empty()) { - IRPosition CSRetPos = IRPosition::callsite_returned(CS); + IRPosition CBRetPos = IRPosition::callsite_returned(*CB); // Call site return integer values might be limited by a constant range. if (Callee->getReturnType()->isIntegerTy()) - getOrCreateAAFor(CSRetPos); + getOrCreateAAFor(CBRetPos); } - for (int i = 0, e = CS.getNumArgOperands(); i < e; i++) { + for (int I = 0, E = CB->getNumArgOperands(); I < E; ++I) { - IRPosition CSArgPos = IRPosition::callsite_argument(CS, i); + IRPosition CBArgPos = IRPosition::callsite_argument(*CB, I); // Every call site argument might be dead. - getOrCreateAAFor(CSArgPos); + getOrCreateAAFor(CBArgPos); // Call site argument might be simplified. - getOrCreateAAFor(CSArgPos); + getOrCreateAAFor(CBArgPos); - if (!CS.getArgument(i)->getType()->isPointerTy()) + if (!CB->getArgOperand(I)->getType()->isPointerTy()) continue; // Call site argument attribute "non-null". - getOrCreateAAFor(CSArgPos); + getOrCreateAAFor(CBArgPos); // Call site argument attribute "no-alias". - getOrCreateAAFor(CSArgPos); + getOrCreateAAFor(CBArgPos); // Call site argument attribute "dereferenceable". - getOrCreateAAFor(CSArgPos); + getOrCreateAAFor(CBArgPos); // Call site argument attribute "align". - getOrCreateAAFor(CSArgPos); + getOrCreateAAFor(CBArgPos); // Call site argument attribute // "readnone/readonly/writeonly/..." - getOrCreateAAFor(CSArgPos); + getOrCreateAAFor(CBArgPos); // Call site argument attribute "nofree". - getOrCreateAAFor(CSArgPos); + getOrCreateAAFor(CBArgPos); } return true; }; @@ -1983,9 +1982,9 @@ // do it eagerly. if (F->hasLocalLinkage()) { if (llvm::all_of(F->uses(), [&Functions](const Use &U) { - ImmutableCallSite ICS(U.getUser()); - return ICS && ICS.isCallee(&U) && - Functions.count(const_cast(ICS.getCaller())); + const auto *CB = dyn_cast(U.getUser()); + return CB && CB->isCallee(&U) && + Functions.count(const_cast(CB->getCaller())); })) continue; } diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -280,11 +280,11 @@ if (V->getType()->isPointerTy()) { NewV = V->stripPointerCasts(); } else { - CallSite CS(V); - if (CS && CS.getCalledFunction()) { - for (Argument &Arg : CS.getCalledFunction()->args()) + auto *CB = dyn_cast(V); + if (CB && CB->getCalledFunction()) { + for (Argument &Arg : CB->getCalledFunction()->args()) if (Arg.hasReturnedAttr()) { - NewV = CS.getArgOperand(Arg.getArgNo()); + NewV = CB->getArgOperand(Arg.getArgNo()); break; } } @@ -688,9 +688,9 @@ if (!I.mayThrow()) return true; - if (ImmutableCallSite ICS = ImmutableCallSite(&I)) { + if (const auto *CB = dyn_cast(&I)) { const auto &NoUnwindAA = - A.getAAFor(*this, IRPosition::callsite_function(ICS)); + A.getAAFor(*this, IRPosition::callsite_function(*CB)); return NoUnwindAA.isAssumedNoUnwind(); } return false; @@ -1273,8 +1273,7 @@ } bool AANoSyncImpl::isVolatile(Instruction *I) { - assert(!ImmutableCallSite(I) && !isa(I) && - "Calls should not be checked here"); + assert(!isa(I) && "Calls should not be checked here"); switch (I->getOpcode()) { case Instruction::AtomicRMW: @@ -1299,12 +1298,12 @@ if (isa(&I) && isNoSyncIntrinsic(&I)) return true; - if (ImmutableCallSite ICS = ImmutableCallSite(&I)) { - if (ICS.hasFnAttr(Attribute::NoSync)) + if (const auto *CB = dyn_cast(&I)) { + if (CB->hasFnAttr(Attribute::NoSync)) return true; const auto &NoSyncAA = - A.getAAFor(*this, IRPosition::callsite_function(ICS)); + A.getAAFor(*this, IRPosition::callsite_function(*CB)); if (NoSyncAA.isAssumedNoSync()) return true; return false; @@ -1323,7 +1322,7 @@ return true; // non-convergent and readnone imply nosync. - return !ImmutableCallSite(&I).isConvergent(); + return !cast(I).isConvergent(); }; if (!A.checkForAllReadWriteInstructions(CheckRWInstForNoSync, *this) || @@ -1377,12 +1376,12 @@ /// See AbstractAttribute::updateImpl(...). ChangeStatus updateImpl(Attributor &A) override { auto CheckForNoFree = [&](Instruction &I) { - ImmutableCallSite ICS(&I); - if (ICS.hasFnAttr(Attribute::NoFree)) + const auto &CB = cast(I); + if (CB.hasFnAttr(Attribute::NoFree)) return true; const auto &NoFreeAA = - A.getAAFor(*this, IRPosition::callsite_function(ICS)); + A.getAAFor(*this, IRPosition::callsite_function(CB)); return NoFreeAA.isAssumedNoFree(); }; @@ -1559,17 +1558,17 @@ bool NullPointerIsDefined = F ? llvm::NullPointerIsDefined(F, PtrTy->getPointerAddressSpace()) : true; const DataLayout &DL = A.getInfoCache().getDL(); - if (ImmutableCallSite ICS = ImmutableCallSite(I)) { - if (ICS.isBundleOperand(U)) + if (const auto *CB = dyn_cast(I)) { + if (CB->isBundleOperand(U)) return 0; - if (ICS.isCallee(U)) { + if (CB->isCallee(U)) { IsNonNull |= !NullPointerIsDefined; return 0; } - unsigned ArgNo = ICS.getArgumentNo(U); - IRPosition IRP = IRPosition::callsite_argument(ICS, ArgNo); + unsigned ArgNo = CB->getArgOperandNo(U); + IRPosition IRP = IRPosition::callsite_argument(*CB, ArgNo); // As long as we only use known information there is no need to track // dependences here. auto &DerefAA = A.getAAFor(QueryingAA, IRP, @@ -1803,17 +1802,17 @@ // If the above check does not hold anymore we look at the calls. auto CheckForNoRecurse = [&](Instruction &I) { - ImmutableCallSite ICS(&I); - if (ICS.hasFnAttr(Attribute::NoRecurse)) + const auto &CB = cast(I); + if (CB.hasFnAttr(Attribute::NoRecurse)) return true; const auto &NoRecurseAA = - A.getAAFor(*this, IRPosition::callsite_function(ICS)); + A.getAAFor(*this, IRPosition::callsite_function(CB)); if (!NoRecurseAA.isAssumedNoRecurse()) return false; // Recursion to the same function - if (ICS.getCalledFunction() == getAnchorScope()) + if (CB.getCalledFunction() == getAnchorScope()) return false; return true; @@ -2114,7 +2113,7 @@ /// See AbstractAttribute::updateImpl(...). ChangeStatus updateImpl(Attributor &A) override { auto CheckForWillReturn = [&](Instruction &I) { - IRPosition IPos = IRPosition::callsite_function(ImmutableCallSite(&I)); + IRPosition IPos = IRPosition::callsite_function(cast(I)); const auto &WillReturnAA = A.getAAFor(*this, IPos); if (WillReturnAA.isKnownWillReturn()) return true; @@ -2321,8 +2320,8 @@ /// See AbstractAttribute::initialize(...). void initialize(Attributor &A) override { // See callsite argument attribute and callee argument attribute. - ImmutableCallSite ICS(&getAnchorValue()); - if (ICS.paramHasAttr(getArgNo(), Attribute::NoAlias)) + const auto &CB = cast(getAnchorValue()); + if (CB.paramHasAttr(getArgNo(), Attribute::NoAlias)) indicateOptimisticFixpoint(); Value &Val = getAssociatedValue(); if (isa(Val) && @@ -2335,32 +2334,32 @@ /// \p OtherArgNo of \p ICS (= the underlying call site). bool mayAliasWithArgument(Attributor &A, AAResults *&AAR, const AAMemoryBehavior &MemBehaviorAA, - ImmutableCallSite ICS, unsigned OtherArgNo) { + const CallBase &CB, unsigned OtherArgNo) { // We do not need to worry about aliasing with the underlying IRP. if (this->getArgNo() == (int)OtherArgNo) return false; // If it is not a pointer or pointer vector we do not alias. - const Value *ArgOp = ICS.getArgOperand(OtherArgNo); + const Value *ArgOp = CB.getArgOperand(OtherArgNo); if (!ArgOp->getType()->isPtrOrPtrVectorTy()) return false; - auto &ICSArgMemBehaviorAA = A.getAAFor( - *this, IRPosition::callsite_argument(ICS, OtherArgNo), + auto &CBArgMemBehaviorAA = A.getAAFor( + *this, IRPosition::callsite_argument(CB, OtherArgNo), /* TrackDependence */ false); // If the argument is readnone, there is no read-write aliasing. - if (ICSArgMemBehaviorAA.isAssumedReadNone()) { - A.recordDependence(ICSArgMemBehaviorAA, *this, DepClassTy::OPTIONAL); + if (CBArgMemBehaviorAA.isAssumedReadNone()) { + A.recordDependence(CBArgMemBehaviorAA, *this, DepClassTy::OPTIONAL); return false; } // If the argument is readonly and the underlying value is readonly, there // is no read-write aliasing. bool IsReadOnly = MemBehaviorAA.isAssumedReadOnly(); - if (ICSArgMemBehaviorAA.isAssumedReadOnly() && IsReadOnly) { + if (CBArgMemBehaviorAA.isAssumedReadOnly() && IsReadOnly) { A.recordDependence(MemBehaviorAA, *this, DepClassTy::OPTIONAL); - A.recordDependence(ICSArgMemBehaviorAA, *this, DepClassTy::OPTIONAL); + A.recordDependence(CBArgMemBehaviorAA, *this, DepClassTy::OPTIONAL); return false; } @@ -2457,10 +2456,10 @@ // Check there is no other pointer argument which could alias with the // value passed at this call site. // TODO: AbstractCallSite - ImmutableCallSite ICS(&getAnchorValue()); - for (unsigned OtherArgNo = 0; OtherArgNo < ICS.getNumArgOperands(); + const auto &CB = cast(getAnchorValue()); + for (unsigned OtherArgNo = 0; OtherArgNo < CB.getNumArgOperands(); OtherArgNo++) - if (mayAliasWithArgument(A, AAR, MemBehaviorAA, ICS, OtherArgNo)) + if (mayAliasWithArgument(A, AAR, MemBehaviorAA, CB, OtherArgNo)) return false; return true; @@ -2511,8 +2510,7 @@ /// For now, we can only deduce noalias if we have call sites. /// FIXME: add more support. - ImmutableCallSite ICS(&RV); - if (!ICS) + if (!isa(&RV)) return false; const IRPosition &RVPos = IRPosition::value(RV); @@ -2984,8 +2982,8 @@ // is a performance optimization for blocks with calls to a lot of internal // functions. It can however cause dead functions to be treated as live. for (const Instruction &I : BB) - if (ImmutableCallSite ICS = ImmutableCallSite(&I)) - if (const Function *F = ICS.getCalledFunction()) + if (const auto *CB = dyn_cast(&I)) + if (const Function *F = CB->getCalledFunction()) if (F->hasLocalLinkage()) A.markLiveInternalFunction(*F); return true; @@ -3477,12 +3475,12 @@ } MaybeAlign MA; - if (ImmutableCallSite ICS = ImmutableCallSite(I)) { - if (ICS.isBundleOperand(U) || ICS.isCallee(U)) + if (const auto *CB = dyn_cast(I)) { + if (CB->isBundleOperand(U) || CB->isCallee(U)) return 0; - unsigned ArgNo = ICS.getArgumentNo(U); - IRPosition IRP = IRPosition::callsite_argument(ICS, ArgNo); + unsigned ArgNo = CB->getArgOperandNo(U); + IRPosition IRP = IRPosition::callsite_argument(*CB, ArgNo); // As long as we only use known information there is no need to track // dependences here. auto &AlignAA = A.getAAFor(QueryingAA, IRP, @@ -3985,13 +3983,13 @@ // For now we only use special logic for call sites. However, the tracker // itself knows about a lot of other non-capturing cases already. - CallSite CS(UInst); - if (!CS || !CS.isArgOperand(U)) + auto *CB = dyn_cast(UInst); + if (!CB || !CB->isArgOperand(U)) return isCapturedIn(/* Memory */ true, /* Integer */ true, /* Return */ true); - unsigned ArgNo = CS.getArgumentNo(U); - const IRPosition &CSArgPos = IRPosition::callsite_argument(CS, ArgNo); + unsigned ArgNo = CB->getArgOperandNo(U); + const IRPosition &CSArgPos = IRPosition::callsite_argument(*CB, ArgNo); // If we have a abstract no-capture attribute for the argument we can use // it to justify a non-capture attribute here. This allows recursion! auto &ArgNoCaptureAA = A.getAAFor(NoCaptureAA, CSArgPos); @@ -3999,7 +3997,7 @@ return isCapturedIn(/* Memory */ false, /* Integer */ false, /* Return */ false); if (ArgNoCaptureAA.isAssumedNoCaptureMaybeReturned()) { - addPotentialCopy(CS); + addPotentialCopy(*CB); return isCapturedIn(/* Memory */ false, /* Integer */ false, /* Return */ false); } @@ -4010,9 +4008,7 @@ } /// Register \p CS as potential copy of the value we are checking. - void addPotentialCopy(CallSite CS) { - PotentialCopies.push_back(CS.getInstruction()); - } + void addPotentialCopy(CallBase &CB) { PotentialCopies.push_back(&CB); } /// See CaptureTracker::shouldExplore(...). bool shouldExplore(const Use *U) override { @@ -4992,10 +4988,9 @@ // Helper to check if for the given call site the associated argument is // passed to a callback where the privatization would be different. - auto IsCompatiblePrivArgOfCallback = [&](CallSite CS) { + auto IsCompatiblePrivArgOfCallback = [&](CallBase &CB) { SmallVector CallbackUses; - AbstractCallSite::getCallbackUses(cast(*CS.getInstruction()), - CallbackUses); + AbstractCallSite::getCallbackUses(CB, CallbackUses); for (const Use *U : CallbackUses) { AbstractCallSite CBACS(U); assert(CBACS && CBACS.isCallbackCall()); @@ -5012,7 +5007,7 @@ << CBArgNo << "@" << CBACS.getCalledFunction()->getName() << ")\n[AAPrivatizablePtr] " << CBArg << " : " << CBACS.getCallArgOperand(CBArg) << " vs " - << CS.getArgOperand(ArgNo) << "\n" + << CB.getArgOperand(ArgNo) << "\n" << "[AAPrivatizablePtr] " << CBArg << " : " << CBACS.getCallArgOperandNo(CBArg) << " vs " << ArgNo << "\n"; }); @@ -5094,7 +5089,7 @@ // here. auto IsCompatiblePrivArgOfOtherCallSite = [&](AbstractCallSite ACS) { if (ACS.isDirectCall()) - return IsCompatiblePrivArgOfCallback(CallSite(ACS.getInstruction())); + return IsCompatiblePrivArgOfCallback(*ACS.getInstruction()); if (ACS.isCallbackCall()) return IsCompatiblePrivArgOfDirectCS(ACS); return false; @@ -5727,9 +5722,9 @@ // If the instruction has an own memory behavior state, use it to restrict // the local state. No further analysis is required as the other memory // state is as optimistic as it gets. - if (ImmutableCallSite ICS = ImmutableCallSite(&I)) { + if (const auto *CB = dyn_cast(&I)) { const auto &MemBehaviorAA = A.getAAFor( - *this, IRPosition::callsite_function(ICS)); + *this, IRPosition::callsite_function(*CB)); intersectAssumedBits(MemBehaviorAA.getAssumed()); return !isAtFixpoint(); } @@ -5827,8 +5822,8 @@ // By default we follow all uses assuming UserI might leak information on U, // we have special handling for call sites operands though. - ImmutableCallSite ICS(UserI); - if (!ICS || !ICS.isArgOperand(U)) + const auto *CB = dyn_cast(UserI); + if (!CB || !CB->isArgOperand(U)) return true; // If the use is a call argument known not to be captured, the users of @@ -5838,9 +5833,9 @@ // call might the argument "through return", which we allow and for which we // need to check call users. if (U->get()->getType()->isPointerTy()) { - unsigned ArgNo = ICS.getArgumentNo(U); + unsigned ArgNo = CB->getArgOperandNo(U); const auto &ArgNoCaptureAA = A.getAAFor( - *this, IRPosition::callsite_argument(ICS, ArgNo), + *this, IRPosition::callsite_argument(*CB, ArgNo), /* TrackDependence */ true, DepClassTy::OPTIONAL); return !ArgNoCaptureAA.isAssumedNoCapture(); } @@ -5874,17 +5869,17 @@ case Instruction::Invoke: { // For call sites we look at the argument memory behavior attribute (this // could be recursive!) in order to restrict our own state. - ImmutableCallSite ICS(UserI); + const auto *CB = cast(UserI); // Give up on operand bundles. - if (ICS.isBundleOperand(U)) { + if (CB->isBundleOperand(U)) { indicatePessimisticFixpoint(); return; } // Calling a function does read the function pointer, maybe write it if the // function is self-modifying. - if (ICS.isCallee(U)) { + if (CB->isCallee(U)) { removeAssumedBits(NO_READS); break; } @@ -5893,9 +5888,9 @@ // argument. IRPosition Pos; if (U->get()->getType()->isPointerTy()) - Pos = IRPosition::callsite_argument(ICS, ICS.getArgumentNo(U)); + Pos = IRPosition::callsite_argument(*CB, CB->getArgOperandNo(U)); else - Pos = IRPosition::callsite_function(ICS); + Pos = IRPosition::callsite_function(*CB); const auto &MemBehaviorAA = A.getAAFor( *this, Pos, /* TrackDependence */ true, DepClassTy::OPTIONAL); @@ -6184,9 +6179,9 @@ Changed); return true; } - if (ImmutableCallSite ICS = ImmutableCallSite(&V)) { + if (const auto *CB = dyn_cast(&V)) { const auto &NoAliasAA = - A.getAAFor(*this, IRPosition::callsite_returned(ICS)); + A.getAAFor(*this, IRPosition::callsite_returned(*CB)); if (NoAliasAA.isAssumedNoAlias()) { updateStateAndAccessesMap(T, AccessKindAccessesMap, NO_MALLOCED_MEM, &I, &V, Changed); @@ -6226,32 +6221,32 @@ AAMemoryLocation::StateType AccessedLocs; AccessedLocs.intersectAssumedBits(NO_LOCATIONS); - if (ImmutableCallSite ICS = ImmutableCallSite(&I)) { + if (auto *CB = dyn_cast(&I)) { // First check if we assume any memory is access is visible. - const auto &ICSMemLocationAA = - A.getAAFor(*this, IRPosition::callsite_function(ICS)); + const auto &CBMemLocationAA = + A.getAAFor(*this, IRPosition::callsite_function(*CB)); LLVM_DEBUG(dbgs() << "[AAMemoryLocation] Categorize call site: " << I - << " [" << ICSMemLocationAA << "]\n"); + << " [" << CBMemLocationAA << "]\n"); - if (ICSMemLocationAA.isAssumedReadNone()) + if (CBMemLocationAA.isAssumedReadNone()) return NO_LOCATIONS; - if (ICSMemLocationAA.isAssumedInaccessibleMemOnly()) { + if (CBMemLocationAA.isAssumedInaccessibleMemOnly()) { updateStateAndAccessesMap(AccessedLocs, AccessKindAccessesMap, NO_INACCESSIBLE_MEM, &I, nullptr, Changed); return AccessedLocs.getAssumed(); } - uint32_t ICSAssumedNotAccessedLocs = - ICSMemLocationAA.getAssumedNotAccessedLocation(); + uint32_t CBAssumedNotAccessedLocs = + CBMemLocationAA.getAssumedNotAccessedLocation(); // Set the argmemonly and global bit as we handle them separately below. - uint32_t ICSAssumedNotAccessedLocsNoArgMem = - ICSAssumedNotAccessedLocs | NO_ARGUMENT_MEM | NO_GLOBAL_MEM; + uint32_t CBAssumedNotAccessedLocsNoArgMem = + CBAssumedNotAccessedLocs | NO_ARGUMENT_MEM | NO_GLOBAL_MEM; for (MemoryLocationsKind CurMLK = 1; CurMLK < NO_LOCATIONS; CurMLK *= 2) { - if (ICSAssumedNotAccessedLocsNoArgMem & CurMLK) + if (CBAssumedNotAccessedLocsNoArgMem & CurMLK) continue; updateStateAndAccessesMap(AccessedLocs, AccessKindAccessesMap, CurMLK, &I, nullptr, Changed); @@ -6259,7 +6254,7 @@ // Now handle global memory if it might be accessed. This is slightly tricky // as NO_GLOBAL_MEM has multiple bits set. - bool HasGlobalAccesses = ((~ICSAssumedNotAccessedLocs) & NO_GLOBAL_MEM); + bool HasGlobalAccesses = ((~CBAssumedNotAccessedLocs) & NO_GLOBAL_MEM); if (HasGlobalAccesses) { auto AccessPred = [&](const Instruction *, const Value *Ptr, AccessKind Kind, MemoryLocationsKind MLK) { @@ -6267,7 +6262,7 @@ Ptr, Changed); return true; }; - if (!ICSMemLocationAA.checkForAllAccessesToMemoryKind( + if (!CBMemLocationAA.checkForAllAccessesToMemoryKind( AccessPred, inverseLocation(NO_GLOBAL_MEM, false, false))) return AccessedLocs.getWorstState(); } @@ -6277,18 +6272,18 @@ << getMemoryLocationsAsStr(AccessedLocs.getAssumed()) << "\n"); // Now handle argument memory if it might be accessed. - bool HasArgAccesses = ((~ICSAssumedNotAccessedLocs) & NO_ARGUMENT_MEM); + bool HasArgAccesses = ((~CBAssumedNotAccessedLocs) & NO_ARGUMENT_MEM); if (HasArgAccesses) { - for (unsigned ArgNo = 0, e = ICS.getNumArgOperands(); ArgNo < e; + for (unsigned ArgNo = 0, E = CB->getNumArgOperands(); ArgNo < E; ++ArgNo) { // Skip non-pointer arguments. - const Value *ArgOp = ICS.getArgOperand(ArgNo); + const Value *ArgOp = CB->getArgOperand(ArgNo); if (!ArgOp->getType()->isPtrOrPtrVectorTy()) continue; // Skip readnone arguments. - const IRPosition &ArgOpIRP = IRPosition::callsite_argument(ICS, ArgNo); + const IRPosition &ArgOpIRP = IRPosition::callsite_argument(*CB, ArgNo); const auto &ArgOpMemLocationAA = A.getAAFor( *this, ArgOpIRP, /* TrackDependence */ true, DepClassTy::OPTIONAL);