Alex Susu via llvm-dev
2016-Nov-09 09:30 UTC
[llvm-dev] Using ConstantDataVector instead of ConstantVector
Hello. I'm curious why can't I convert a Value like <16 x i16> <i16 2, i16 2, i16 2, i16 2, i16 2, i16 2, i16 2... i16 2> to ConstantVector - using llvm::dyn_cast<llvm::ConstantVector>() returns NULL. However, converting it with dyn_cast to ConstantDataVector fortunately works. Note that at http://llvm.org/docs/doxygen/html/classllvm_1_1ConstantDataVector.html it is written "A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double", etc. This is a bit misleading, since vectors of bigger sizes can be used. Thank you, Alex
Friedman, Eli via llvm-dev
2016-Nov-09 17:54 UTC
[llvm-dev] Using ConstantDataVector instead of ConstantVector
On 11/9/2016 1:30 AM, Alex Susu via llvm-dev wrote:> Hello. > I'm curious why can't I convert a Value like > <16 x i16> <i16 2, i16 2, i16 2, i16 2, i16 2, i16 2, i16 2... > i16 2> > to ConstantVector - using llvm::dyn_cast<llvm::ConstantVector>() > returns NULL. > > However, converting it with dyn_cast to ConstantDataVector > fortunately works. > > Note that at > http://llvm.org/docs/doxygen/html/classllvm_1_1ConstantDataVector.html > it is written "A vector constant whose element type is a simple > 1/2/4/8-byte integer or float/double", etc. This is a bit misleading, > since vectors of bigger sizes can be used.I think you somehow found some old doxygen pages? http://llvm.org/doxygen/classllvm_1_1Constant.html is what it looks like on trunk. The class hierarchy is set up the way it is because it's convenient for the implementation; essentially, ConstantAggregate subclasses are constants which use other constants, and ConstantData subclasses don't use other constants. You can use Constant::getAggregateElement() if you need to iterate over the elements of a constant of vector type. -Eli -- Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Mehdi Amini via llvm-dev
2016-Nov-09 20:17 UTC
[llvm-dev] Using ConstantDataVector instead of ConstantVector
> On Nov 9, 2016, at 1:30 AM, Alex Susu via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Hello. > I'm curious why can't I convert a Value like > <16 x i16> <i16 2, i16 2, i16 2, i16 2, i16 2, i16 2, i16 2... i16 2> > to ConstantVector - using llvm::dyn_cast<llvm::ConstantVector>() returns NULL. > > However, converting it with dyn_cast to ConstantDataVector fortunately works. > > Note that at http://llvm.org/docs/doxygen/html/classllvm_1_1ConstantDataVector.html it is written "A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double", etc. This is a bit misleading, since vectors of bigger sizes can be used.This is the *individual element* type, did you misread and thought it was the number of elements in the vector? Or to total byte size of the vector? The implementation is clear limiting to these elements AFAICT. — Mehdi