Daniel Dunbar
2008-Aug-13 23:08 UTC
[LLVMdev] Cleanup of constant sequence type construction
The methods for constructing constant sequencish types (struct, array, vector) aren't consistent and we are missing a few useful convenience methods. I would like to change the interfaces to each support four construction methods: (a) With and without a type. (b) With a vector or an array + size. Here: -- ConstantStruct { static Constant *get(const StructType *T, Constant*const* Vals, unsigned NumVals, bool Packed = false); static Constant *get(const StructType *T, const std::vector<Constant*> &V); static Constant *get(Constant*const* Vals, unsigned NumVals, bool Packed = false); static Constant *get(const std::vector<Constant*> &V, bool Packed = false); } ConstantAray { static Constant *get(const ArrayType *T, Constant*const* Vals, unsigned NumVals); static Constant *get(const ArrayType *T, const std::vector<Constant*> &); static Constant *get(Constant*const* Vals, unsigned NumVals); static Constant *get(const std::vector<Constant*> &); } ConstantVector { static Constant *get(const VectorType *T, Constant*const* Vals, unsigned NumVals); static Constant *get(const VectorType *T, const std::vector<Constant*> &); static Constant *get(Constant*const* Vals, unsigned NumVals); static Constant *get(const std::vector<Constant*> &V); } -- While I am at it it would make sense to make the array + size methods more efficient (not construct a vector). Any problems? - Daniel
Devang Patel
2008-Aug-13 23:26 UTC
[LLVMdev] Cleanup of constant sequence type construction
On Aug 13, 2008, at 4:08 PM, Daniel Dunbar wrote:> The methods for constructing constant sequencish types (struct, > array, vector) aren't > consistent and we are missing a few useful convenience methods. I > would like to change > the interfaces to each support four construction methods: > (a) With and without a type.What is the use of ConstantStruct without a type ?> (b) With a vector or an array + size. > > [snip]> > While I am at it it would make sense to make the array + size > methods more > efficient (not construct a vector).Why not ?> Any problems?One suggestion, while you're here, add methods that use SmallVector (IMO removing methods that use std::vector is a good idea). - Devang
Chris Lattner
2008-Aug-23 04:24 UTC
[LLVMdev] Cleanup of constant sequence type construction
On Aug 13, 2008, at 4:08 PM, Daniel Dunbar wrote:> The methods for constructing constant sequencish types (struct, > array, vector) aren't > consistent and we are missing a few useful convenience methods.Very true.> I would like to change > the interfaces to each support four construction methods: > (a) With and without a type. > (b) With a vector or an array + size.I'd strongly prefer to get rid of the versions of these that take a vector and just take "element pointer + numelements" ranges for sequential containers. Adding versions that take small vectors and vectors and arrays all seem like overkill. std::vector is an internal implementation detail, exposing it through the API is badness. The issue with the types is more subtle. In some cases (e.g. structs) the type is never needed, and should be removed (the vals/numvals/ packed version of the ctor is all we should have). In other cases, e.g. ConstantArray, you need to pass in the type: otherwise you can't make an array of zero length, because you don't know the element type. ConstantVectors can never have length zero, so they should just have the Vals/NumVals version. I really think we should remove the "convenience" methods and standardize on the ones that don't assume an input container. -Chris> > > Here: > -- > ConstantStruct { > static Constant *get(const StructType *T, > Constant*const* Vals, unsigned NumVals, > bool Packed = false); > static Constant *get(const StructType *T, const > std::vector<Constant*> &V); > static Constant *get(Constant*const* Vals, unsigned NumVals, > bool Packed = false); > static Constant *get(const std::vector<Constant*> &V, bool Packed = > false); > } > > ConstantAray { > static Constant *get(const ArrayType *T, > Constant*const* Vals, unsigned NumVals); > static Constant *get(const ArrayType *T, const > std::vector<Constant*> &); > static Constant *get(Constant*const* Vals, unsigned NumVals); > static Constant *get(const std::vector<Constant*> &); > } > > ConstantVector { > static Constant *get(const VectorType *T, > Constant*const* Vals, unsigned NumVals); > static Constant *get(const VectorType *T, const > std::vector<Constant*> &); > static Constant *get(Constant*const* Vals, unsigned NumVals); > static Constant *get(const std::vector<Constant*> &V); > } > -- > > While I am at it it would make sense to make the array + size > methods more > efficient (not construct a vector). > > Any problems? > > - Daniel > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev