From: Devang Patel Date: Tue, 4 Mar 2008 18:57:05 +0000 (+0000) Subject: Add FunctionType ctor variant that takes SmallVector params. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=52f8ed8368890467ca807605a17afae81dc152fb;p=oota-llvm.git Add FunctionType ctor variant that takes SmallVector params. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47895 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/DerivedTypes.h b/include/llvm/DerivedTypes.h index 457d37d1fa8..b8378ace852 100644 --- a/include/llvm/DerivedTypes.h +++ b/include/llvm/DerivedTypes.h @@ -19,6 +19,7 @@ #define LLVM_DERIVED_TYPES_H #include "llvm/Type.h" +#include "llvm/ADT/SmallVector.h" namespace llvm { @@ -144,6 +145,8 @@ class FunctionType : public DerivedType { const FunctionType &operator=(const FunctionType &); // Do not implement FunctionType(const Type *Result, const std::vector &Params, bool IsVarArgs); + FunctionType(const Type *Result, const SmallVectorImpl &Params, + bool IsVarArgs); public: /// FunctionType::get - This static method is the primary way of constructing @@ -155,6 +158,12 @@ public: bool isVarArg ///< Whether this is a variable argument length function ); + static FunctionType *get( + const Type *Result, ///< The result type + const SmallVectorImpl &Params, ///< The types of the parameters + bool isVarArg ///< Whether this is a variable argument length function + ); + inline bool isVarArg() const { return isVarArgs; } inline const Type *getReturnType() const { return ContainedTys[0]; } diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 42c3770913d..4bddeca73fb 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -460,6 +460,30 @@ FunctionType::FunctionType(const Type *Result, setAbstract(isAbstract); } +FunctionType::FunctionType(const Type *Result, + const SmallVectorImpl &Params, + bool IsVarArgs) + : DerivedType(FunctionTyID), isVarArgs(IsVarArgs) { + ContainedTys = reinterpret_cast(this+1); + NumContainedTys = Params.size() + 1; // + 1 for result type + assert((Result->isFirstClassType() || Result == Type::VoidTy || + Result->getTypeID() == Type::StructTyID || + isa(Result)) && + "LLVM functions cannot return aggregates"); + bool isAbstract = Result->isAbstract(); + new (&ContainedTys[0]) PATypeHandle(Result, this); + + for (unsigned i = 0; i != Params.size(); ++i) { + assert((Params[i]->isFirstClassType() || isa(Params[i])) && + "Function arguments must be value types!"); + new (&ContainedTys[i+1]) PATypeHandle(Params[i],this); + isAbstract |= Params[i]->isAbstract(); + } + + // Calculate whether or not this type is abstract + setAbstract(isAbstract); +} + StructType::StructType(const std::vector &Types, bool isPacked) : CompositeType(StructTyID) { ContainedTys = reinterpret_cast(this + 1); @@ -1055,6 +1079,12 @@ public: ArgTypes.push_back(args[i]); } + FunctionValType(const Type *ret, const SmallVectorImpl &args, + bool isVA) : RetTy(ret), isVarArg(isVA) { + for (unsigned i = 0; i < args.size(); ++i) + ArgTypes.push_back(args[i]); + } + static FunctionValType get(const FunctionType *FT); static unsigned hashTypeStructure(const FunctionType *FT) { @@ -1108,6 +1138,27 @@ FunctionType *FunctionType::get(const Type *ReturnType, return FT; } +// FunctionType::get - The factory function for the FunctionType class... +FunctionType *FunctionType::get(const Type *ReturnType, + const SmallVectorImpl &Params, + bool isVarArg) { + FunctionValType VT(ReturnType, Params, isVarArg); + FunctionType *FT = FunctionTypes->get(VT); + if (FT) { + return FT; + } + + FT = (FunctionType*) new char[sizeof(FunctionType) + + sizeof(PATypeHandle)*(Params.size()+1)]; + new (FT) FunctionType(ReturnType, Params, isVarArg); + FunctionTypes->add(VT, FT); + +#ifdef DEBUG_MERGE_TYPES + DOUT << "Derived new type: " << FT << "\n"; +#endif + return FT; +} + //===----------------------------------------------------------------------===// // Array Type Factory... //