[llvm] r215966 - IR: Reduce RAUW traffic in ConstantVector

David Majnemer david.majnemer at gmail.com
Tue Aug 19 08:51:10 PDT 2014


On Tuesday, August 19, 2014, Aaron Ballman <aaron at aaronballman.com> wrote:

> I have reverted from this revision to r215957 (skipping only 215961 &
> 215962 as they were unrelated) due to breaking MSVC with asserts. The
> assert is one in std::equal because it cannot be passed a nullptr,
> which your commits seemed to be doing.


MSVC's STL is over zealous in this regard, it's a known bug; they really do
not like nullptr iterators in some places. :/


> Since the patches all built on
> top of one another, I had to revert them in a block, sorry if this
> causes problems for you!
>
> ~Aaron
>
> On Mon, Aug 18, 2014 at 10:24 PM, Duncan P. N. Exon Smith
> <dexonsmith at apple.com <javascript:;>> wrote:
> > Author: dexonsmith
> > Date: Mon Aug 18 21:24:46 2014
> > New Revision: 215966
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=215966&view=rev
> > Log:
> > IR: Reduce RAUW traffic in ConstantVector
> >
> > Avoid creating a new `ConstantVector` on an RAUW of one of its members.
> > This reduces RAUW traffic on any containing constant.
> >
> > This is part of PR20515.
> >
> > Modified:
> >     llvm/trunk/lib/IR/Constants.cpp
> >
> > Modified: llvm/trunk/lib/IR/Constants.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=215966&r1=215965&r2=215966&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/IR/Constants.cpp (original)
> > +++ llvm/trunk/lib/IR/Constants.cpp Mon Aug 18 21:24:46 2014
> > @@ -2810,17 +2810,41 @@ void ConstantStruct::replaceUsesOfWithOn
> >  void ConstantVector::replaceUsesOfWithOnConstant(Value *From, Value *To,
> >                                                   Use *U) {
> >    assert(isa<Constant>(To) && "Cannot make Constant refer to
> non-constant!");
> > +  Constant *ToC = cast<Constant>(To);
> >
> >    SmallVector<Constant*, 8> Values;
> >    Values.reserve(getNumOperands());  // Build replacement array...
> > +  unsigned NumUpdated = 0;
> >    for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
> >      Constant *Val = getOperand(i);
> > -    if (Val == From) Val = cast<Constant>(To);
> > +    if (Val == From) {
> > +      ++NumUpdated;
> > +      Val = ToC;
> > +    }
> >      Values.push_back(Val);
> >    }
> >
> > -  Constant *Replacement = get(Values);
> > -  replaceUsesOfWithOnConstantImpl(Replacement);
> > +  if (Constant *C = getImpl(Values)) {
> > +    replaceUsesOfWithOnConstantImpl(C);
> > +    return;
> > +  }
> > +
> > +  // Update to the new value.  Optimize for the case when we have a
> single
> > +  // operand that we're changing, but handle bulk updates efficiently.
> > +  auto &pImpl = getType()->getContext().pImpl;
> > +  pImpl->VectorConstants.remove(this);
> > +
> > +  if (NumUpdated == 1) {
> > +    unsigned OperandToUpdate = U - OperandList;
> > +    assert(getOperand(OperandToUpdate) == From && "ReplaceAllUsesWith
> broken!");
> > +    setOperand(OperandToUpdate, ToC);
> > +  } else {
> > +    for (unsigned I = 0, E = getNumOperands(); I != E; ++I)
> > +      if (getOperand(I) == From)
> > +        setOperand(I, ToC);
> > +  }
> > +
> > +  pImpl->VectorConstants.insert(this);
> >  }
> >
> >  void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV,
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu <javascript:;>
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu <javascript:;>
> 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/20140819/da54f314/attachment.html>


More information about the llvm-commits mailing list