From b065b06c12dba6001b8140df2744d0c856ef6ea1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 20 Jun 2011 04:01:31 +0000 Subject: Revamp the "ConstantStruct::get" methods. Previously, these were scattered all over the place in different styles and variants. Standardize on two preferred entrypoints: one that takes a StructType and ArrayRef, and one that takes StructType and varargs. In cases where there isn't a struct type convenient, we now add a ConstantStruct::getAnon method (whose name will make more sense after a few more patches land). It would be "really really nice" if the ConstantStruct::get and ConstantVector::get methods didn't make temporary std::vectors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@133412 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Constants.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index eabc3a5..268f920 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -422,14 +422,29 @@ protected: ConstantStruct(const StructType *T, const std::vector &Val); public: // ConstantStruct accessors - static Constant *get(const StructType *T, const std::vector &V); - static Constant *get(LLVMContext &Context, - const std::vector &V, bool Packed); - static Constant *get(LLVMContext &Context, - Constant *const *Vals, unsigned NumVals, bool Packed); - static Constant *get(LLVMContext &Context, bool Packed, - Constant * Val, ...) END_WITH_NULL; - + static Constant *get(const StructType *T, ArrayRef V); + static Constant *get(const StructType *T, ...) END_WITH_NULL; + + /// getAnon - Return an anonymous struct that has the specified + /// elements. If the struct is possibly empty, then you must specify a + /// context. + static Constant *getAnon(ArrayRef V, bool Packed = false) { + return get(getTypeForElements(V, Packed), V); + } + static Constant *getAnon(LLVMContext &Ctx, + ArrayRef V, bool Packed = false) { + return get(getTypeForElements(Ctx, V, Packed), V); + } + + /// getTypeForElements - Return an anonymous struct type to use for a constant + /// with the specified set of elements. The list must not be empty. + static StructType *getTypeForElements(ArrayRef V, + bool Packed = false); + /// getTypeForElements - This version of the method allows an empty list. + static StructType *getTypeForElements(LLVMContext &Ctx, + ArrayRef V, + bool Packed = false); + /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant); -- cgit v1.1