[LLVMdev] Mutating the elements of a ConstantArray

Chris Lattner clattner at apple.com
Tue Mar 31 17:52:16 PDT 2009


On Mar 31, 2009, at 5:07 PM, Nick Johnson wrote:
> Thanks,
>
> Just one question more:  why does Constant::getVectorElements()
> operate on a SmallVector<T>, while ConstantArray::get() operate on a
> std::vector<T> ?  What is the distinction between these uses?

SmallVector is optimized for the case when the vector is small, to not  
go to the heap.  This is the "small string optimization" for vectors.   
More details here:
http://llvm.org/docs/ProgrammersManual.html#datastructure

As far API design goes, we're in a mixed state.  I'd strongly prefer  
to get rid of std::vector from the various interfaces, f.e. creating a  
constant array currently requires passing in an std::vector.  For  
these sorts of interfaces, we should migrate to passing in a "Constant  
*const* / unsigned" pair.  This allows use with a C array, a  
SmallVector, std::vector, or any other container with sequential  
storage.

For the "get data" APIs, we should migrate to returning in a  
SmallVectorImpl<t>& like Constant::getVectorElements() does.

-Chris



More information about the llvm-dev mailing list