CMake: removed lib/VMCore/DebugInfoBuilder.cpp.
[oota-llvm.git] / lib / VMCore / Type.cpp
index a195437e7c3e37463fe3a7fd07ece9304b86d6c2..be211949799ebfd0b6b342344bb9a6e0a7cef93e 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -11,7 +11,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/AbstractTypeUser.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Constants.h"
 #include "llvm/ADT/DepthFirstIterator.h"
@@ -23,6 +22,7 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Debug.h"
 #include <algorithm>
+#include <cstdarg>
 using namespace llvm;
 
 // DEBUG_MERGE_TYPES - Enable this #define to see how and when derived types are
@@ -34,21 +34,6 @@ using namespace llvm;
 AbstractTypeUser::~AbstractTypeUser() {}
 
 
-//===----------------------------------------------------------------------===//
-//                         Type PATypeHolder Implementation
-//===----------------------------------------------------------------------===//
-
-/// get - This implements the forwarding part of the union-find algorithm for
-/// abstract types.  Before every access to the Type*, we check to see if the
-/// type we are pointing to is forwarding to a new type.  If so, we drop our
-/// reference to the type.
-///
-Type* PATypeHolder::get() const {
-  const Type *NewTy = Ty->getForwardedType();
-  if (!NewTy) return const_cast<Type*>(Ty);
-  return *const_cast<PATypeHolder*>(this) = NewTy;
-}
-
 //===----------------------------------------------------------------------===//
 //                         Type Class Implementation
 //===----------------------------------------------------------------------===//
@@ -62,13 +47,6 @@ static ManagedStatic<std::map<const Type*,
 static ManagedStatic<std::map<const Type*,
                               std::string> > AbstractTypeDescriptions;
 
-Type::Type(const char *Name, TypeID id)
-  : ID(id), Abstract(false),  SubclassData(0), RefCount(0), ForwardType(0),
-    NumContainedTys(0),  ContainedTys(0) {
-  assert(Name && Name[0] && "Should use other ctor if no name!");
-  (*ConcreteTypeDescriptions)[this] = Name;
-}
-
 /// Because of the way Type subclasses are allocated, this function is necessary
 /// to use the correct kind of "delete" operator to deallocate the Type object.
 /// Some type objects (FunctionTy, StructTy) allocate additional space after 
@@ -91,13 +69,13 @@ void Type::destroy() const {
     // Now call the destructor for the subclass directly because we're going
     // to delete this as an array of char.
     if (isa<FunctionType>(this))
-      ((FunctionType*)this)->FunctionType::~FunctionType();
+      static_cast<const FunctionType*>(this)->FunctionType::~FunctionType();
     else
-      ((StructType*)this)->StructType::~StructType();
+      static_cast<const StructType*>(this)->StructType::~StructType();
 
     // Finally, remove the memory as an array deallocation of the chars it was
     // constructed from.
-    delete [] reinterpret_cast<const char*>(this); 
+    operator delete(const_cast<Type *>(this));
 
     return;
   }
@@ -112,10 +90,13 @@ void Type::destroy() const {
 
 const Type *Type::getPrimitiveType(TypeID IDNumber) {
   switch (IDNumber) {
-  case VoidTyID  : return VoidTy;
-  case FloatTyID : return FloatTy;
-  case DoubleTyID: return DoubleTy;
-  case LabelTyID : return LabelTy;
+  case VoidTyID      : return VoidTy;
+  case FloatTyID     : return FloatTy;
+  case DoubleTyID    : return DoubleTy;
+  case X86_FP80TyID  : return X86_FP80Ty;
+  case FP128TyID     : return FP128Ty;
+  case PPC_FP128TyID : return PPC_FP128Ty;
+  case LabelTyID     : return LabelTy;
   default:
     return 0;
   }
@@ -130,10 +111,24 @@ const Type *Type::getVAArgsPromotedType() const {
     return this;
 }
 
+/// isIntOrIntVector - Return true if this is an integer type or a vector of
+/// integer types.
+///
+bool Type::isIntOrIntVector() const {
+  if (isInteger())
+    return true;
+  if (ID != Type::VectorTyID) return false;
+  
+  return cast<VectorType>(this)->getElementType()->isInteger();
+}
+
 /// isFPOrFPVector - Return true if this is a FP type or a vector of FP types.
 ///
 bool Type::isFPOrFPVector() const {
-  if (ID == Type::FloatTyID || ID == Type::DoubleTyID) return true;
+  if (ID == Type::FloatTyID || ID == Type::DoubleTyID || 
+      ID == Type::FP128TyID || ID == Type::X86_FP80TyID || 
+      ID == Type::PPC_FP128TyID)
+    return true;
   if (ID != Type::VectorTyID) return false;
   
   return cast<VectorType>(this)->getElementType()->isFloatingPoint();
@@ -169,6 +164,9 @@ unsigned Type::getPrimitiveSizeInBits() const {
   switch (getTypeID()) {
   case Type::FloatTyID: return 32;
   case Type::DoubleTyID: return 64;
+  case Type::X86_FP80TyID: return 80;
+  case Type::FP128TyID: return 128;
+  case Type::PPC_FP128TyID: return 128;
   case Type::IntegerTyID: return cast<IntegerType>(this)->getBitWidth();
   case Type::VectorTyID:  return cast<VectorType>(this)->getBitWidth();
   default: return 0;
@@ -238,8 +236,8 @@ static std::string getTypeDescription(const Type *Ty,
                                       std::vector<const Type *> &TypeStack) {
   if (isa<OpaqueType>(Ty)) {                     // Base case for the recursion
     std::map<const Type*, std::string>::iterator I =
-      AbstractTypeDescriptions->lower_bound(Ty);
-    if (I != AbstractTypeDescriptions->end() && I->first == Ty)
+      AbstractTypeDescriptions->find(Ty);
+    if (I != AbstractTypeDescriptions->end())
       return I->second;
     std::string Desc = "opaque";
     AbstractTypeDescriptions->insert(std::make_pair(Ty, Desc));
@@ -249,7 +247,23 @@ static std::string getTypeDescription(const Type *Ty,
   if (!Ty->isAbstract()) {                       // Base case for the recursion
     std::map<const Type*, std::string>::iterator I =
       ConcreteTypeDescriptions->find(Ty);
-    if (I != ConcreteTypeDescriptions->end()) return I->second;
+    if (I != ConcreteTypeDescriptions->end()) 
+      return I->second;
+    
+    if (Ty->isPrimitiveType()) {
+      switch (Ty->getTypeID()) {
+      default: assert(0 && "Unknown prim type!");
+      case Type::VoidTyID:   return (*ConcreteTypeDescriptions)[Ty] = "void";
+      case Type::FloatTyID:  return (*ConcreteTypeDescriptions)[Ty] = "float";
+      case Type::DoubleTyID: return (*ConcreteTypeDescriptions)[Ty] = "double";
+      case Type::X86_FP80TyID: 
+            return (*ConcreteTypeDescriptions)[Ty] = "x86_fp80";
+      case Type::FP128TyID: return (*ConcreteTypeDescriptions)[Ty] = "fp128";
+      case Type::PPC_FP128TyID: 
+          return (*ConcreteTypeDescriptions)[Ty] = "ppc_fp128";
+      case Type::LabelTyID:  return (*ConcreteTypeDescriptions)[Ty] = "label";
+      }
+    }
   }
 
   // Check to see if the Type is already on the stack...
@@ -278,13 +292,10 @@ static std::string getTypeDescription(const Type *Ty,
     if (!Result.empty())
       Result += " ";
     Result += getTypeDescription(FTy->getReturnType(), TypeStack) + " (";
-    unsigned Idx = 1;
     for (FunctionType::param_iterator I = FTy->param_begin(),
-           E = FTy->param_end(); I != E; ++I) {
+         E = FTy->param_end(); I != E; ++I) {
       if (I != FTy->param_begin())
         Result += ", ";
-      Result +=  FunctionType::getParamAttrsText(FTy->getParamAttrs(Idx));
-      Idx++;
       Result += getTypeDescription(*I, TypeStack);
     }
     if (FTy->isVarArg()) {
@@ -292,12 +303,8 @@ static std::string getTypeDescription(const Type *Ty,
       Result += "...";
     }
     Result += ")";
-    if (FTy->getParamAttrs(0)) {
-      Result += " " + FunctionType::getParamAttrsText(FTy->getParamAttrs(0));
-    }
     break;
   }
-  case Type::PackedStructTyID:
   case Type::StructTyID: {
     const StructType *STy = cast<StructType>(Ty);
     if (STy->isPacked())
@@ -317,7 +324,10 @@ static std::string getTypeDescription(const Type *Ty,
   }
   case Type::PointerTyID: {
     const PointerType *PTy = cast<PointerType>(Ty);
-    Result = getTypeDescription(PTy->getElementType(), TypeStack) + " *";
+    Result = getTypeDescription(PTy->getElementType(), TypeStack);
+    if (unsigned AddressSpace = PTy->getAddressSpace())
+      Result += " addrspace(" + utostr(AddressSpace) + ")";
+    Result += " *";
     break;
   }
   case Type::ArrayTyID: {
@@ -371,16 +381,24 @@ bool StructType::indexValid(const Value *V) const {
   // Structure indexes require 32-bit integer constants.
   if (V->getType() == Type::Int32Ty)
     if (const ConstantInt *CU = dyn_cast<ConstantInt>(V))
-      return CU->getZExtValue() < NumContainedTys;
+      return indexValid(CU->getZExtValue());
   return false;
 }
 
+bool StructType::indexValid(unsigned V) const {
+  return V < NumContainedTys;
+}
+
 // getTypeAtIndex - Given an index value into the type, return the type of the
 // element.  For a structure type, this must be a constant value...
 //
 const Type *StructType::getTypeAtIndex(const Value *V) const {
-  assert(indexValid(V) && "Invalid structure index!");
   unsigned Idx = (unsigned)cast<ConstantInt>(V)->getZExtValue();
+  return getTypeAtIndex(Idx);
+}
+
+const Type *StructType::getTypeAtIndex(unsigned Idx) const {
+  assert(indexValid(Idx) && "Invalid structure index!");
   return ContainedTys[Idx];
 }
 
@@ -388,14 +406,17 @@ const Type *StructType::getTypeAtIndex(const Value *V) const {
 //                          Primitive 'Type' data
 //===----------------------------------------------------------------------===//
 
-const Type *Type::VoidTy   = new Type("void", Type::VoidTyID);
-const Type *Type::FloatTy  = new Type("float", Type::FloatTyID);
-const Type *Type::DoubleTy = new Type("double", Type::DoubleTyID);
-const Type *Type::LabelTy  = new Type("label", Type::LabelTyID);
+const Type *Type::VoidTy       = new Type(Type::VoidTyID);
+const Type *Type::FloatTy      = new Type(Type::FloatTyID);
+const Type *Type::DoubleTy     = new Type(Type::DoubleTyID);
+const Type *Type::X86_FP80Ty   = new Type(Type::X86_FP80TyID);
+const Type *Type::FP128Ty      = new Type(Type::FP128TyID);
+const Type *Type::PPC_FP128Ty  = new Type(Type::PPC_FP128TyID);
+const Type *Type::LabelTy      = new Type(Type::LabelTyID);
 
 namespace {
   struct BuiltinIntegerType : public IntegerType {
-    BuiltinIntegerType(unsigned W) : IntegerType(W) {}
+    explicit BuiltinIntegerType(unsigned W) : IntegerType(W) {}
   };
 }
 const IntegerType *Type::Int1Ty  = new BuiltinIntegerType(1);
@@ -409,15 +430,35 @@ const IntegerType *Type::Int64Ty = new BuiltinIntegerType(64);
 //                          Derived Type Constructors
 //===----------------------------------------------------------------------===//
 
+/// isValidReturnType - Return true if the specified type is valid as a return
+/// type.
+bool FunctionType::isValidReturnType(const Type *RetTy) {
+  if (RetTy->isFirstClassType())
+    return true;
+  if (RetTy == Type::VoidTy || isa<OpaqueType>(RetTy))
+    return true;
+  
+  // If this is a multiple return case, verify that each return is a first class
+  // value and that there is at least one value.
+  const StructType *SRetTy = dyn_cast<StructType>(RetTy);
+  if (SRetTy == 0 || SRetTy->getNumElements() == 0)
+    return false;
+  
+  for (unsigned i = 0, e = SRetTy->getNumElements(); i != e; ++i)
+    if (!SRetTy->getElementType(i)->isFirstClassType())
+      return false;
+  return true;
+}
+
 FunctionType::FunctionType(const Type *Result,
                            const std::vector<const Type*> &Params,
-                           bool IsVarArgs, const ParamAttrsList &Attrs) 
-  : DerivedType(FunctionTyID), isVarArgs(IsVarArgs), ParamAttrs(0) {
+                           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 ||
-         isa<OpaqueType>(Result)) &&
-         "LLVM functions cannot return aggregates");
+  assert(isValidReturnType(Result) && "invalid return type for function");
+    
+    
   bool isAbstract = Result->isAbstract();
   new (&ContainedTys[0]) PATypeHandle(Result, this);
 
@@ -428,15 +469,8 @@ FunctionType::FunctionType(const Type *Result,
     isAbstract |= Params[i]->isAbstract();
   }
 
-  // Set the ParameterAttributes
-  if (!Attrs.empty()) 
-    ParamAttrs = new ParamAttrsList(Attrs);
-  else
-    ParamAttrs = 0;
-
   // Calculate whether or not this type is abstract
   setAbstract(isAbstract);
-
 }
 
 StructType::StructType(const std::vector<const Type*> &Types, bool isPacked)
@@ -475,7 +509,9 @@ VectorType::VectorType(const Type *ElType, unsigned NumEl)
 }
 
 
-PointerType::PointerType(const Type *E) : SequentialType(PointerTyID, E) {
+PointerType::PointerType(const Type *E, unsigned AddrSpace)
+  : SequentialType(PointerTyID, E) {
+  AddressSpace = AddrSpace;
   // Calculate whether or not this type is abstract
   setAbstract(E->isAbstract());
 }
@@ -507,6 +543,7 @@ void DerivedType::dropAllTypeUses() {
 }
 
 
+namespace {
 
 /// TypePromotionGraph and graph traits - this is designed to allow us to do
 /// efficient SCC processing of type graphs.  This is the exact same as
@@ -517,6 +554,8 @@ struct TypePromotionGraph {
   TypePromotionGraph(Type *T) : Ty(T) {}
 };
 
+}
+
 namespace llvm {
   template <> struct GraphTraits<TypePromotionGraph> {
     typedef Type NodeType;
@@ -601,8 +640,8 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
   if (isa<OpaqueType>(Ty))
     return false;  // Two unequal opaque types are never equal
 
-  std::map<const Type*, const Type*>::iterator It = EqTypes.lower_bound(Ty);
-  if (It != EqTypes.end() && It->first == Ty)
+  std::map<const Type*, const Type*>::iterator It = EqTypes.find(Ty);
+  if (It != EqTypes.end())
     return It->second == Ty2;    // Looping back on a type, check for equality
 
   // Otherwise, add the mapping to the table to make sure we don't get
@@ -617,8 +656,9 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
     const IntegerType *ITy2 = cast<IntegerType>(Ty2);
     return ITy->getBitWidth() == ITy2->getBitWidth();
   } else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
-    return TypesEqual(PTy->getElementType(),
-                      cast<PointerType>(Ty2)->getElementType(), EqTypes);
+    const PointerType *PTy2 = cast<PointerType>(Ty2);
+    return PTy->getAddressSpace() == PTy2->getAddressSpace() &&
+           TypesEqual(PTy->getElementType(), PTy2->getElementType(), EqTypes);
   } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
     const StructType *STy2 = cast<StructType>(Ty2);
     if (STy->getNumElements() != STy2->getNumElements()) return false;
@@ -639,13 +679,9 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
     const FunctionType *FTy2 = cast<FunctionType>(Ty2);
     if (FTy->isVarArg() != FTy2->isVarArg() ||
         FTy->getNumParams() != FTy2->getNumParams() ||
-        FTy->getNumAttrs() != FTy2->getNumAttrs() ||
-        FTy->getParamAttrs(0) != FTy2->getParamAttrs(0) ||
         !TypesEqual(FTy->getReturnType(), FTy2->getReturnType(), EqTypes))
       return false;
     for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) {
-      if (FTy->getParamAttrs(i+1) != FTy->getParamAttrs(i+1))
-        return false;
       if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes))
         return false;
     }
@@ -666,11 +702,11 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2) {
 // ever reach a non-abstract type, we know that we don't need to search the
 // subgraph.
 static bool AbstractTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
-                                std::set<const Type*> &VisitedTypes) {
+                                SmallPtrSet<const Type*, 128> &VisitedTypes) {
   if (TargetTy == CurTy) return true;
   if (!CurTy->isAbstract()) return false;
 
-  if (!VisitedTypes.insert(CurTy).second)
+  if (!VisitedTypes.insert(CurTy))
     return false;  // Already been here.
 
   for (Type::subtype_iterator I = CurTy->subtype_begin(),
@@ -681,10 +717,10 @@ static bool AbstractTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
 }
 
 static bool ConcreteTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
-                                        std::set<const Type*> &VisitedTypes) {
+                                SmallPtrSet<const Type*, 128> &VisitedTypes) {
   if (TargetTy == CurTy) return true;
 
-  if (!VisitedTypes.insert(CurTy).second)
+  if (!VisitedTypes.insert(CurTy))
     return false;  // Already been here.
 
   for (Type::subtype_iterator I = CurTy->subtype_begin(),
@@ -697,7 +733,7 @@ static bool ConcreteTypeHasCycleThrough(const Type *TargetTy, const Type *CurTy,
 /// TypeHasCycleThroughItself - Return true if the specified type has a cycle
 /// back to itself.
 static bool TypeHasCycleThroughItself(const Type *Ty) {
-  std::set<const Type*> VisitedTypes;
+  SmallPtrSet<const Type*, 128> VisitedTypes;
 
   if (Ty->isAbstract()) {  // Optimized case for abstract types.
     for (Type::subtype_iterator I = Ty->subtype_begin(), E = Ty->subtype_end();
@@ -743,6 +779,9 @@ static unsigned getSubElementHash(const Type *Ty) {
     case Type::StructTyID:
       HashVal ^= cast<StructType>(SubTy)->getNumElements();
       break;
+    case Type::PointerTyID:
+      HashVal ^= cast<PointerType>(SubTy)->getAddressSpace();
+      break;
     }
   }
   return HashVal ? HashVal : 1;  // Do not return zero unless opaque subty.
@@ -847,7 +886,7 @@ public:
     // The old record is now out-of-date, because one of the children has been
     // updated.  Remove the obsolete entry from the map.
     unsigned NumErased = Map.erase(ValType::get(Ty));
-    assert(NumErased && "Element not found!");
+    assert(NumErased && "Element not found!"); NumErased = NumErased;
 
     // Remember the structural hash for the type before we start hacking on it,
     // in case we need it later.
@@ -1024,22 +1063,16 @@ namespace llvm {
 class FunctionValType {
   const Type *RetTy;
   std::vector<const Type*> ArgTypes;
-  std::vector<FunctionType::ParameterAttributes> ParamAttrs;
   bool isVarArg;
 public:
   FunctionValType(const Type *ret, const std::vector<const Type*> &args,
-                  bool IVA, const FunctionType::ParamAttrsList &attrs) 
-    : RetTy(ret), isVarArg(IVA) {
-    for (unsigned i = 0; i < args.size(); ++i)
-      ArgTypes.push_back(args[i]);
-    for (unsigned i = 0; i < attrs.size(); ++i)
-      ParamAttrs.push_back(attrs[i]);
-  }
+                  bool isVA) : RetTy(ret), ArgTypes(args), isVarArg(isVA) {}
 
   static FunctionValType get(const FunctionType *FT);
 
   static unsigned hashTypeStructure(const FunctionType *FT) {
-    return FT->getNumParams()*64+FT->getNumAttrs()*2+FT->isVarArg();
+    unsigned Result = FT->getNumParams()*2 + FT->isVarArg();
+    return Result;
   }
 
   inline bool operator<(const FunctionValType &MTV) const {
@@ -1048,7 +1081,8 @@ public:
     if (isVarArg < MTV.isVarArg) return true;
     if (isVarArg > MTV.isVarArg) return false;
     if (ArgTypes < MTV.ArgTypes) return true;
-    return ArgTypes == MTV.ArgTypes && ParamAttrs < MTV.ParamAttrs;
+    if (ArgTypes > MTV.ArgTypes) return false;
+    return false;
   }
 };
 }
@@ -1059,71 +1093,31 @@ static ManagedStatic<TypeMap<FunctionValType, FunctionType> > FunctionTypes;
 FunctionValType FunctionValType::get(const FunctionType *FT) {
   // Build up a FunctionValType
   std::vector<const Type *> ParamTypes;
-  std::vector<FunctionType::ParameterAttributes> ParamAttrs;
   ParamTypes.reserve(FT->getNumParams());
   for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i)
     ParamTypes.push_back(FT->getParamType(i));
-  for (unsigned i = 0, e = FT->getNumAttrs(); i != e; ++i)
-    ParamAttrs.push_back(FT->getParamAttrs(i));
-  return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg(),
-                         ParamAttrs);
+  return FunctionValType(FT->getReturnType(), ParamTypes, FT->isVarArg());
 }
 
 
 // FunctionType::get - The factory function for the FunctionType class...
 FunctionType *FunctionType::get(const Type *ReturnType,
                                 const std::vector<const Type*> &Params,
-                                bool isVarArg,
-                                const std::vector<ParameterAttributes> &Attrs) {
-  bool noAttrs = true;
-  for (unsigned i = 0, e = Attrs.size(); i < e; ++i)
-    if (Attrs[i] != FunctionType::NoAttributeSet) {
-      noAttrs = false;
-      break;
-    }
-  const std::vector<FunctionType::ParameterAttributes> NullAttrs;
-  const std::vector<FunctionType::ParameterAttributes> *TheAttrs = &Attrs;
-  if (noAttrs)
-    TheAttrs = &NullAttrs;
-  FunctionValType VT(ReturnType, Params, isVarArg, *TheAttrs);
-  FunctionType *MT = FunctionTypes->get(VT);
-  if (MT) return MT;
-
-  MT = (FunctionType*) new char[sizeof(FunctionType) + 
-                                sizeof(PATypeHandle)*(Params.size()+1)];
-  new (MT) FunctionType(ReturnType, Params, isVarArg, *TheAttrs);
-  FunctionTypes->add(VT, MT);
+                                bool isVarArg) {
+  FunctionValType VT(ReturnType, Params, isVarArg);
+  FunctionType *FT = FunctionTypes->get(VT);
+  if (FT)
+    return FT;
+
+  FT = (FunctionType*) operator new(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: " << MT << "\n";
+  DOUT << "Derived new type: " << FT << "\n";
 #endif
-  return MT;
-}
-
-FunctionType::ParameterAttributes 
-FunctionType::getParamAttrs(unsigned Idx) const {
-  if (!ParamAttrs)
-    return NoAttributeSet;
-  if (Idx >= ParamAttrs->size())
-    return NoAttributeSet;
-  return (*ParamAttrs)[Idx];
-}
-
-std::string FunctionType::getParamAttrsText(ParameterAttributes Attr) {
-  std::string Result;
-  if (Attr & ZExtAttribute)
-    Result += "zext ";
-  if (Attr & SExtAttribute)
-    Result += "sext ";
-  if (Attr & NoReturnAttribute)
-    Result += "noreturn ";
-  if (Attr & NoUnwindAttribute)
-    Result += "nounwind ";
-  if (Attr & InRegAttribute)
-    Result += "inreg ";
-  if (Attr & StructRetAttribute)
-    Result += "sret ";  
-  return Result;
+  return FT;
 }
 
 //===----------------------------------------------------------------------===//
@@ -1198,8 +1192,7 @@ static ManagedStatic<TypeMap<VectorValType, VectorType> > VectorTypes;
 
 
 VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
-  assert(ElementType && "Can't get packed of null types!");
-  assert(isPowerOf2_32(NumElements) && "Vector length should be a power of 2!");
+  assert(ElementType && "Can't get vector of null types!");
 
   VectorValType PVT(ElementType, NumElements);
   VectorType *PT = VectorTypes->get(PVT);
@@ -1258,8 +1251,8 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
   if (ST) return ST;
 
   // Value not found.  Derive a new type!
-  ST = (StructType*) new char[sizeof(StructType) + 
-                              sizeof(PATypeHandle) * ETypes.size()];
+  ST = (StructType*) operator new(sizeof(StructType) +
+                                  sizeof(PATypeHandle) * ETypes.size());
   new (ST) StructType(ETypes, isPacked);
   StructTypes->add(STV, ST);
 
@@ -1269,6 +1262,17 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
   return ST;
 }
 
+StructType *StructType::get(const Type *type, ...) {
+  va_list ap;
+  std::vector<const llvm::Type*> StructFields;
+  va_start(ap, type);
+  while (type) {
+    StructFields.push_back(type);
+    type = va_arg(ap, llvm::Type*);
+  }
+  return llvm::StructType::get(StructFields);
+}
+
 
 
 //===----------------------------------------------------------------------===//
@@ -1280,11 +1284,12 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
 namespace llvm {
 class PointerValType {
   const Type *ValTy;
+  unsigned AddressSpace;
 public:
-  PointerValType(const Type *val) : ValTy(val) {}
+  PointerValType(const Type *val, unsigned as) : ValTy(val), AddressSpace(as) {}
 
   static PointerValType get(const PointerType *PT) {
-    return PointerValType(PT->getElementType());
+    return PointerValType(PT->getElementType(), PT->getAddressSpace());
   }
 
   static unsigned hashTypeStructure(const PointerType *PT) {
@@ -1292,25 +1297,26 @@ public:
   }
 
   bool operator<(const PointerValType &MTV) const {
-    return ValTy < MTV.ValTy;
+    if (AddressSpace < MTV.AddressSpace) return true;
+    return AddressSpace == MTV.AddressSpace && ValTy < MTV.ValTy;
   }
 };
 }
 
 static ManagedStatic<TypeMap<PointerValType, PointerType> > PointerTypes;
 
-PointerType *PointerType::get(const Type *ValueType) {
+PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
   assert(ValueType && "Can't get a pointer to <null> type!");
   assert(ValueType != Type::VoidTy &&
          "Pointer to void is not valid, use sbyte* instead!");
   assert(ValueType != Type::LabelTy && "Pointer to label is not valid!");
-  PointerValType PVT(ValueType);
+  PointerValType PVT(ValueType, AddressSpace);
 
   PointerType *PT = PointerTypes->get(PVT);
   if (PT) return PT;
 
   // Value not found.  Derive a new type!
-  PointerTypes->add(PVT, PT = new PointerType(ValueType));
+  PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
 
 #ifdef DEBUG_MERGE_TYPES
   DOUT << "Derived new type: " << *PT << "\n";
@@ -1405,7 +1411,7 @@ void DerivedType::refineAbstractTypeTo(const Type *NewType) {
   while (!AbstractTypeUsers.empty() && NewTy != this) {
     AbstractTypeUser *User = AbstractTypeUsers.back();
 
-    unsigned OldSize = AbstractTypeUsers.size();
+    unsigned OldSize = AbstractTypeUsers.size(); OldSize=OldSize;
 #ifdef DEBUG_MERGE_TYPES
     DOUT << " REFINING user " << OldSize-1 << "[" << (void*)User
          << "] of abstract type [" << (void*)this << " "
@@ -1432,7 +1438,7 @@ void DerivedType::notifyUsesThatTypeBecameConcrete() {
   DOUT << "typeIsREFINED type: " << (void*)this << " " << *this << "\n";
 #endif
 
-  unsigned OldSize = AbstractTypeUsers.size();
+  unsigned OldSize = AbstractTypeUsers.size(); OldSize=OldSize;
   while (!AbstractTypeUsers.empty()) {
     AbstractTypeUser *ATU = AbstractTypeUsers.back();
     ATU->typeBecameConcrete(this);