mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-18 13:34:04 +00:00
[CallSite] Make construction from Value* (or Instruction*) explicit.
CallSite roughly behaves as a common base CallInst and InvokeInst. Bring the behavior closer to that model by making upcasts explicit. Downcasts remain implicit and work as before. Following dyn_cast as a mental model checking whether a Value *V isa CallSite now looks like this: if (auto CS = CallSite(V)) // think dyn_cast instead of: if (CallSite CS = V) This is an extra token but I think it is slightly clearer. Making the ctor explicit has the advantage of not accidentally creating nullptr CallSites, e.g. when you pass a Value * to a function taking a CallSite argument. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234601 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3905bb619c
commit
e749325463
@ -410,7 +410,7 @@ public:
|
||||
->getGEPCost(GEP->getPointerOperand(), Indices);
|
||||
}
|
||||
|
||||
if (ImmutableCallSite CS = U) {
|
||||
if (auto CS = ImmutableCallSite(U)) {
|
||||
const Function *F = CS.getCalledFunction();
|
||||
if (!F) {
|
||||
// Just use the called value type.
|
||||
|
@ -46,12 +46,13 @@ template <typename FunTy = const Function,
|
||||
class CallSiteBase {
|
||||
protected:
|
||||
PointerIntPair<InstrTy*, 1, bool> I;
|
||||
public:
|
||||
|
||||
CallSiteBase() : I(nullptr, false) {}
|
||||
CallSiteBase(CallTy *CI) : I(CI, true) { assert(CI); }
|
||||
CallSiteBase(InvokeTy *II) : I(II, false) { assert(II); }
|
||||
CallSiteBase(ValTy *II) { *this = get(II); }
|
||||
protected:
|
||||
explicit CallSiteBase(ValTy *II) { *this = get(II); }
|
||||
|
||||
private:
|
||||
/// CallSiteBase::get - This static method is sort of like a constructor. It
|
||||
/// will create an appropriate call site for a Call or Invoke instruction, but
|
||||
/// it can also create a null initialized CallSiteBase object for something
|
||||
@ -349,15 +350,15 @@ private:
|
||||
|
||||
class CallSite : public CallSiteBase<Function, Value, User, Instruction,
|
||||
CallInst, InvokeInst, User::op_iterator> {
|
||||
typedef CallSiteBase<Function, Value, User, Instruction,
|
||||
CallInst, InvokeInst, User::op_iterator> Base;
|
||||
typedef CallSite::CallSiteBase Base;
|
||||
|
||||
public:
|
||||
CallSite() {}
|
||||
CallSite(Base B) : Base(B) {}
|
||||
CallSite(Value* V) : Base(V) {}
|
||||
CallSite(CallInst *CI) : Base(CI) {}
|
||||
CallSite(InvokeInst *II) : Base(II) {}
|
||||
CallSite(Instruction *II) : Base(II) {}
|
||||
explicit CallSite(Instruction *II) : Base(II) {}
|
||||
explicit CallSite(Value *V) : Base(V) {}
|
||||
|
||||
bool operator==(const CallSite &CS) const { return I == CS.I; }
|
||||
bool operator!=(const CallSite &CS) const { return I != CS.I; }
|
||||
@ -371,13 +372,14 @@ private:
|
||||
|
||||
/// ImmutableCallSite - establish a view to a call site for examination
|
||||
class ImmutableCallSite : public CallSiteBase<> {
|
||||
typedef CallSiteBase<> Base;
|
||||
typedef ImmutableCallSite::CallSiteBase Base;
|
||||
|
||||
public:
|
||||
ImmutableCallSite() {}
|
||||
ImmutableCallSite(const Value* V) : Base(V) {}
|
||||
ImmutableCallSite(const CallInst *CI) : Base(CI) {}
|
||||
ImmutableCallSite(const InvokeInst *II) : Base(II) {}
|
||||
ImmutableCallSite(const Instruction *II) : Base(II) {}
|
||||
explicit ImmutableCallSite(const Instruction *II) : Base(II) {}
|
||||
explicit ImmutableCallSite(const Value *V) : Base(V) {}
|
||||
ImmutableCallSite(CallSite CS) : Base(CS.getInstruction()) {}
|
||||
};
|
||||
|
||||
|
@ -158,7 +158,7 @@ bool AAEval::runOnFunction(Function &F) {
|
||||
if (EvalAAMD && isa<StoreInst>(&*I))
|
||||
Stores.insert(&*I);
|
||||
Instruction &Inst = *I;
|
||||
if (CallSite CS = cast<Value>(&Inst)) {
|
||||
if (auto CS = CallSite(&Inst)) {
|
||||
Value *Callee = CS.getCalledValue();
|
||||
// Skip actual functions for direct function calls.
|
||||
if (!isa<Function>(Callee) && isInterestingPointer(Callee))
|
||||
|
@ -187,7 +187,7 @@ bool AliasSet::aliasesUnknownInst(Instruction *Inst, AliasAnalysis &AA) const {
|
||||
return false;
|
||||
|
||||
for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
|
||||
CallSite C1 = getUnknownInst(i), C2 = Inst;
|
||||
CallSite C1(getUnknownInst(i)), C2(Inst);
|
||||
if (!C1 || !C2 ||
|
||||
AA.getModRefInfo(C1, C2) != AliasAnalysis::NoModRef ||
|
||||
AA.getModRefInfo(C2, C1) != AliasAnalysis::NoModRef)
|
||||
|
@ -269,7 +269,7 @@ bool GlobalsModRef::AnalyzeUsesOfPointer(Value *V,
|
||||
} else if (Operator::getOpcode(I) == Instruction::BitCast) {
|
||||
if (AnalyzeUsesOfPointer(I, Readers, Writers, OkayStoreDest))
|
||||
return true;
|
||||
} else if (CallSite CS = I) {
|
||||
} else if (auto CS = CallSite(I)) {
|
||||
// Make sure that this is just the function being called, not that it is
|
||||
// passing into the function.
|
||||
if (!CS.isCallee(&U)) {
|
||||
|
@ -106,7 +106,7 @@ bool MemDepPrinter::runOnFunction(Function &F) {
|
||||
if (!Res.isNonLocal()) {
|
||||
Deps[Inst].insert(std::make_pair(getInstTypePair(Res),
|
||||
static_cast<BasicBlock *>(nullptr)));
|
||||
} else if (CallSite CS = cast<Value>(Inst)) {
|
||||
} else if (auto CS = CallSite(Inst)) {
|
||||
const MemoryDependenceAnalysis::NonLocalDepInfo &NLDI =
|
||||
MDA.getNonLocalCallDependency(CS);
|
||||
|
||||
|
@ -223,7 +223,7 @@ getCallSiteDependencyFrom(CallSite CS, bool isReadOnlyCall,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CallSite InstCS = cast<Value>(Inst)) {
|
||||
if (auto InstCS = CallSite(Inst)) {
|
||||
// Debug intrinsics don't cause dependences.
|
||||
if (isa<DbgInfoIntrinsic>(Inst)) continue;
|
||||
// If these two calls do not interfere, look past it.
|
||||
|
@ -2934,7 +2934,7 @@ bool llvm::isKnownNonNull(const Value *V, const TargetLibraryInfo *TLI) {
|
||||
if (const LoadInst *LI = dyn_cast<LoadInst>(V))
|
||||
return LI->getMetadata(LLVMContext::MD_nonnull);
|
||||
|
||||
if (ImmutableCallSite CS = V)
|
||||
if (auto CS = ImmutableCallSite(V))
|
||||
if (CS.isReturnNonNull())
|
||||
return true;
|
||||
|
||||
|
@ -525,7 +525,7 @@ static bool isDereferenceablePointer(const Value *V, const DataLayout &DL,
|
||||
|
||||
// Return values from call sites specifically marked as dereferenceable are
|
||||
// also okay.
|
||||
if (ImmutableCallSite CS = V) {
|
||||
if (auto CS = ImmutableCallSite(V)) {
|
||||
if (uint64_t Bytes = CS.getDereferenceableBytes(0)) {
|
||||
Type *Ty = V->getType()->getPointerElementType();
|
||||
if (Ty->isSized() && DL.getTypeStoreSize(Ty) <= Bytes)
|
||||
@ -595,7 +595,7 @@ bool Value::isDereferenceablePointer(const DataLayout &DL) const {
|
||||
APInt DerefBytes(Offset.getBitWidth(), 0);
|
||||
if (const Argument *A = dyn_cast<Argument>(BV))
|
||||
DerefBytes = A->getDereferenceableBytes();
|
||||
else if (ImmutableCallSite CS = BV)
|
||||
else if (auto CS = ImmutableCallSite(BV))
|
||||
DerefBytes = CS.getDereferenceableBytes(0);
|
||||
|
||||
if (DerefBytes.getBoolValue() && Offset.isNonNegative()) {
|
||||
|
@ -862,7 +862,7 @@ CallGraphNode *ArgPromotion::DoPromotion(Function *F,
|
||||
|
||||
// Update the callgraph to know that the callsite has been transformed.
|
||||
CallGraphNode *CalleeNode = CG[Call->getParent()->getParent()];
|
||||
CalleeNode->replaceCallEdge(Call, New, NF_CGN);
|
||||
CalleeNode->replaceCallEdge(CS, CallSite(New), NF_CGN);
|
||||
|
||||
if (!Call->use_empty()) {
|
||||
Call->replaceAllUsesWith(New);
|
||||
|
@ -482,7 +482,7 @@ DAE::Liveness DAE::SurveyUse(const Use *U,
|
||||
return Result;
|
||||
}
|
||||
|
||||
if (ImmutableCallSite CS = V) {
|
||||
if (auto CS = ImmutableCallSite(V)) {
|
||||
const Function *F = CS.getCalledFunction();
|
||||
if (F) {
|
||||
// Used in a direct call.
|
||||
|
@ -84,7 +84,7 @@ isOnlyCopiedFromConstantGlobal(Value *V, MemTransferInst *&TheCopy,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CallSite CS = I) {
|
||||
if (auto CS = CallSite(I)) {
|
||||
// If this is the function being called then we treat it like a load and
|
||||
// ignore it.
|
||||
if (CS.isCallee(&U))
|
||||
|
@ -45,7 +45,7 @@ bool llvm::objcarc::CanAlterRefCount(const Instruction *Inst, const Value *Ptr,
|
||||
default: break;
|
||||
}
|
||||
|
||||
ImmutableCallSite CS = static_cast<const Value *>(Inst);
|
||||
ImmutableCallSite CS(Inst);
|
||||
assert(CS && "Only calls can alter reference counts!");
|
||||
|
||||
// See if AliasAnalysis can help us with the call.
|
||||
@ -99,7 +99,7 @@ bool llvm::objcarc::CanUse(const Instruction *Inst, const Value *Ptr,
|
||||
// of any other dynamic reference-counted pointers.
|
||||
if (!IsPotentialRetainableObjPtr(ICI->getOperand(1), *PA.getAA()))
|
||||
return false;
|
||||
} else if (ImmutableCallSite CS = static_cast<const Value *>(Inst)) {
|
||||
} else if (auto CS = ImmutableCallSite(Inst)) {
|
||||
// For calls, just check the arguments (and not the callee operand).
|
||||
for (ImmutableCallSite::arg_iterator OI = CS.arg_begin(),
|
||||
OE = CS.arg_end(); OI != OE; ++OI) {
|
||||
|
@ -168,7 +168,7 @@ static bool hasMemoryWrite(Instruction *I, const TargetLibraryInfo *TLI) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (CallSite CS = I) {
|
||||
if (auto CS = CallSite(I)) {
|
||||
if (Function *F = CS.getCalledFunction()) {
|
||||
if (TLI && TLI->has(LibFunc::strcpy) &&
|
||||
F->getName() == TLI->getName(LibFunc::strcpy)) {
|
||||
@ -262,7 +262,7 @@ static bool isRemovable(Instruction *I) {
|
||||
}
|
||||
}
|
||||
|
||||
if (CallSite CS = I)
|
||||
if (auto CS = CallSite(I))
|
||||
return CS.getInstruction()->use_empty();
|
||||
|
||||
return false;
|
||||
@ -306,7 +306,7 @@ static Value *getStoredPointerOperand(Instruction *I) {
|
||||
}
|
||||
}
|
||||
|
||||
CallSite CS = I;
|
||||
CallSite CS(I);
|
||||
// All the supported functions so far happen to have dest as their first
|
||||
// argument.
|
||||
return CS.getArgument(0);
|
||||
@ -780,7 +780,7 @@ bool DSE::handleEndBlock(BasicBlock &BB) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CallSite CS = cast<Value>(BBI)) {
|
||||
if (auto CS = CallSite(BBI)) {
|
||||
// Remove allocation function calls from the list of dead stack objects;
|
||||
// there can't be any references before the definition.
|
||||
if (isAllocLikeFn(BBI, TLI))
|
||||
|
@ -1045,7 +1045,7 @@ bool MemCpyOpt::iterateOnFunction(Function &F) {
|
||||
RepeatInstruction = processMemCpy(M);
|
||||
else if (MemMoveInst *M = dyn_cast<MemMoveInst>(I))
|
||||
RepeatInstruction = processMemMove(M);
|
||||
else if (CallSite CS = (Value*)I) {
|
||||
else if (auto CS = CallSite(I)) {
|
||||
for (unsigned i = 0, e = CS.arg_size(); i != e; ++i)
|
||||
if (CS.isByValArgument(i))
|
||||
MadeChange |= processByValArgument(CS, i);
|
||||
|
@ -217,7 +217,7 @@ static bool containsUnconditionalCallSafepoint(Loop *L, BasicBlock *Header,
|
||||
BasicBlock *Current = Pred;
|
||||
while (true) {
|
||||
for (Instruction &I : *Current) {
|
||||
if (CallSite CS = &I)
|
||||
if (auto CS = CallSite(&I))
|
||||
// Note: Technically, needing a safepoint isn't quite the right
|
||||
// condition here. We should instead be checking if the target method
|
||||
// has an
|
||||
@ -424,8 +424,7 @@ static Instruction *findLocationForEntrySafepoint(Function &F,
|
||||
// We need to stop going forward as soon as we see a call that can
|
||||
// grow the stack (i.e. the call target has a non-zero frame
|
||||
// size).
|
||||
if (CallSite CS = cursor) {
|
||||
(void)CS; // Silence an unused variable warning by gcc 4.8.2
|
||||
if (CallSite(cursor)) {
|
||||
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(cursor)) {
|
||||
// llvm.assume(...) are not really calls.
|
||||
if (II->getIntrinsicID() == Intrinsic::assume) {
|
||||
|
@ -150,7 +150,7 @@ static bool analyzeGlobalAux(const Value *V, GlobalStatus &GS,
|
||||
if (MSI->isVolatile())
|
||||
return true;
|
||||
GS.StoredType = GlobalStatus::Stored;
|
||||
} else if (ImmutableCallSite C = I) {
|
||||
} else if (auto C = ImmutableCallSite(I)) {
|
||||
if (!C.isCallee(&U))
|
||||
return true;
|
||||
GS.IsLoaded = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user