[LLVMdev] Cleanup of constant sequence type construction
Chris Lattner
clattner at apple.com
Fri Aug 22 21:24:23 PDT 2008
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
More information about the llvm-dev
mailing list