[llvm-commits] [llvm] r47895 - in /llvm/trunk: include/llvm/DerivedTypes.h lib/VMCore/Type.cpp

Devang Patel dpatel at apple.com
Tue Mar 4 10:57:06 PST 2008


Author: dpatel
Date: Tue Mar  4 12:57:05 2008
New Revision: 47895

URL: http://llvm.org/viewvc/llvm-project?rev=47895&view=rev
Log:
Add FunctionType ctor variant that takes SmallVector params.

Modified:
    llvm/trunk/include/llvm/DerivedTypes.h
    llvm/trunk/lib/VMCore/Type.cpp

Modified: llvm/trunk/include/llvm/DerivedTypes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DerivedTypes.h?rev=47895&r1=47894&r2=47895&view=diff

==============================================================================
--- llvm/trunk/include/llvm/DerivedTypes.h (original)
+++ llvm/trunk/include/llvm/DerivedTypes.h Tue Mar  4 12:57:05 2008
@@ -19,6 +19,7 @@
 #define LLVM_DERIVED_TYPES_H
 
 #include "llvm/Type.h"
+#include "llvm/ADT/SmallVector.h"
 
 namespace llvm {
 
@@ -144,6 +145,8 @@
   const FunctionType &operator=(const FunctionType &);  // Do not implement
   FunctionType(const Type *Result, const std::vector<const Type*> &Params,
                bool IsVarArgs);
+  FunctionType(const Type *Result, const SmallVectorImpl<const Type*> &Params,
+               bool IsVarArgs);
 
 public:
   /// FunctionType::get - This static method is the primary way of constructing
@@ -155,6 +158,12 @@
     bool isVarArg  ///< Whether this is a variable argument length function
   );
 
+  static FunctionType *get(
+    const Type *Result, ///< The result type
+    const SmallVectorImpl<const Type*> &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]; }
 

Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=47895&r1=47894&r2=47895&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Tue Mar  4 12:57:05 2008
@@ -460,6 +460,30 @@
   setAbstract(isAbstract);
 }
 
+FunctionType::FunctionType(const Type *Result,
+                           const SmallVectorImpl<const Type *> &Params,
+                           bool IsVarArgs)
+  : DerivedType(FunctionTyID), isVarArgs(IsVarArgs) {
+  ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
+  NumContainedTys = Params.size() + 1; // + 1 for result type
+  assert((Result->isFirstClassType() || Result == Type::VoidTy ||
+          Result->getTypeID() == Type::StructTyID ||
+          isa<OpaqueType>(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<OpaqueType>(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<const Type*> &Types, bool isPacked)
   : CompositeType(StructTyID) {
   ContainedTys = reinterpret_cast<PATypeHandle*>(this + 1);
@@ -1055,6 +1079,12 @@
       ArgTypes.push_back(args[i]);
   }
 
+  FunctionValType(const Type *ret, const SmallVectorImpl<const Type*> &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 @@
   return FT;
 }
 
+// FunctionType::get - The factory function for the FunctionType class...
+FunctionType *FunctionType::get(const Type *ReturnType,
+                                const SmallVectorImpl<const Type*> &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...
 //





More information about the llvm-commits mailing list