[llvm] r234601 - [CallSite] Make construction from Value* (or Instruction*) explicit.

David Blaikie dblaikie at gmail.com
Fri Apr 10 08:16:52 PDT 2015


On Fri, Apr 10, 2015 at 7:50 AM, Benjamin Kramer <benny.kra at googlemail.com>
wrote:

> Author: d0k
> Date: Fri Apr 10 09:50:08 2015
> New Revision: 234601
>
> URL: http://llvm.org/viewvc/llvm-project?rev=234601&view=rev
> Log:
> [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.
>

I take it you came across instances of this problem? They are outright bugs
where the author intended to pass some other variable?


>
> Modified:
>     llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
>     llvm/trunk/include/llvm/IR/CallSite.h
>     llvm/trunk/lib/Analysis/AliasAnalysisEvaluator.cpp
>     llvm/trunk/lib/Analysis/AliasSetTracker.cpp
>     llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp
>     llvm/trunk/lib/Analysis/MemDepPrinter.cpp
>     llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
>     llvm/trunk/lib/Analysis/ValueTracking.cpp
>     llvm/trunk/lib/IR/Value.cpp
>     llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
>     llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
>     llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
>     llvm/trunk/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
>     llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
>     llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
>     llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp
>     llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp
>
> Modified: llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h (original)
> +++ llvm/trunk/include/llvm/Analysis/TargetTransformInfoImpl.h Fri Apr 10
> 09:50:08 2015
> @@ -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.
>
> Modified: llvm/trunk/include/llvm/IR/CallSite.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/CallSite.h?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/IR/CallSite.h (original)
> +++ llvm/trunk/include/llvm/IR/CallSite.h Fri Apr 10 09:50:08 2015
> @@ -46,12 +46,13 @@ template <typename FunTy = const Functio
>  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()) {}
>  };
>
>
> Modified: llvm/trunk/lib/Analysis/AliasAnalysisEvaluator.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasAnalysisEvaluator.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/AliasAnalysisEvaluator.cpp (original)
> +++ llvm/trunk/lib/Analysis/AliasAnalysisEvaluator.cpp Fri Apr 10 09:50:08
> 2015
> @@ -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))
>
> Modified: llvm/trunk/lib/Analysis/AliasSetTracker.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/AliasSetTracker.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/AliasSetTracker.cpp (original)
> +++ llvm/trunk/lib/Analysis/AliasSetTracker.cpp Fri Apr 10 09:50:08 2015
> @@ -187,7 +187,7 @@ bool AliasSet::aliasesUnknownInst(Instru
>      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)
>
> Modified: llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp (original)
> +++ llvm/trunk/lib/Analysis/IPA/GlobalsModRef.cpp Fri Apr 10 09:50:08 2015
> @@ -269,7 +269,7 @@ bool GlobalsModRef::AnalyzeUsesOfPointer
>      } 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)) {
>
> Modified: llvm/trunk/lib/Analysis/MemDepPrinter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemDepPrinter.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/MemDepPrinter.cpp (original)
> +++ llvm/trunk/lib/Analysis/MemDepPrinter.cpp Fri Apr 10 09:50:08 2015
> @@ -106,7 +106,7 @@ bool MemDepPrinter::runOnFunction(Functi
>      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);
>
>
> Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
> +++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Fri Apr 10
> 09:50:08 2015
> @@ -223,7 +223,7 @@ getCallSiteDependencyFrom(CallSite CS, b
>        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.
>
> Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
> +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Apr 10 09:50:08 2015
> @@ -2934,7 +2934,7 @@ bool llvm::isKnownNonNull(const Value *V
>    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;
>
>
> Modified: llvm/trunk/lib/IR/Value.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/IR/Value.cpp (original)
> +++ llvm/trunk/lib/IR/Value.cpp Fri Apr 10 09:50:08 2015
> @@ -525,7 +525,7 @@ static bool isDereferenceablePointer(con
>
>    // 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(con
>      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()) {
>
> Modified: llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp Fri Apr 10
> 09:50:08 2015
> @@ -862,7 +862,7 @@ CallGraphNode *ArgPromotion::DoPromotion
>
>      // 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);
>
> Modified: llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp (original)
> +++ llvm/trunk/lib/Transforms/IPO/DeadArgumentElimination.cpp Fri Apr 10
> 09:50:08 2015
> @@ -482,7 +482,7 @@ DAE::Liveness DAE::SurveyUse(const Use *
>        return Result;
>      }
>
> -    if (ImmutableCallSite CS = V) {
> +    if (auto CS = ImmutableCallSite(V)) {
>        const Function *F = CS.getCalledFunction();
>        if (F) {
>          // Used in a direct call.
>
> Modified:
> llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> (original)
> +++ llvm/trunk/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
> Fri Apr 10 09:50:08 2015
> @@ -84,7 +84,7 @@ isOnlyCopiedFromConstantGlobal(Value *V,
>          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))
>
> Modified: llvm/trunk/lib/Transforms/ObjCARC/DependencyAnalysis.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/DependencyAnalysis.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/ObjCARC/DependencyAnalysis.cpp (original)
> +++ llvm/trunk/lib/Transforms/ObjCARC/DependencyAnalysis.cpp Fri Apr 10
> 09:50:08 2015
> @@ -45,7 +45,7 @@ bool llvm::objcarc::CanAlterRefCount(con
>    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 Instruc
>      // 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) {
>
> Modified: llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/DeadStoreElimination.cpp Fri Apr 10
> 09:50:08 2015
> @@ -168,7 +168,7 @@ static bool hasMemoryWrite(Instruction *
>        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(In
>      }
>    }
>
> -  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))
>
> Modified: llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/MemCpyOptimizer.cpp Fri Apr 10
> 09:50:08 2015
> @@ -1045,7 +1045,7 @@ bool MemCpyOpt::iterateOnFunction(Functi
>          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);
>
> Modified: llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp Fri Apr 10
> 09:50:08 2015
> @@ -217,7 +217,7 @@ static bool containsUnconditionalCallSaf
>    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 *findLocationForEntry
>      // 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) {
>
> Modified: llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp?rev=234601&r1=234600&r2=234601&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/GlobalStatus.cpp Fri Apr 10 09:50:08
> 2015
> @@ -150,7 +150,7 @@ static bool analyzeGlobalAux(const Value
>          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;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150410/edfc5d0a/attachment.html>


More information about the llvm-commits mailing list