Make DomTree and PostDomTree thin wrappers around DomTreeBase, rather than inheriting...
[oota-llvm.git] / lib / VMCore / Type.cpp
index e4c89f182a173f6c0fffcea3da1a0768ae6571db..3e085f4027feb69d994042b38ea218ced53a183a 100644 (file)
@@ -11,7 +11,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/AbstractTypeUser.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/ParameterAttributes.h"
 #include "llvm/Constants.h"
@@ -63,13 +62,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 
@@ -113,10 +105,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;
   }
@@ -131,10 +126,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();
@@ -170,6 +179,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;
@@ -250,7 +262,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...
@@ -300,7 +328,6 @@ static std::string getTypeDescription(const Type *Ty,
     }
     break;
   }
-  case Type::PackedStructTyID:
   case Type::StructTyID: {
     const StructType *STy = cast<StructType>(Ty);
     if (STy->isPacked())
@@ -391,10 +418,13 @@ 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 {
@@ -414,7 +444,7 @@ const IntegerType *Type::Int64Ty = new BuiltinIntegerType(64);
 
 FunctionType::FunctionType(const Type *Result,
                            const std::vector<const Type*> &Params,
-                           bool IsVarArgs, ParamAttrsList *Attrs) 
+                           bool IsVarArgs, const ParamAttrsList *Attrs) 
   : DerivedType(FunctionTyID), isVarArgs(IsVarArgs), ParamAttrs(Attrs) {
   ContainedTys = reinterpret_cast<PATypeHandle*>(this+1);
   NumContainedTys = Params.size() + 1; // + 1 for result type
@@ -639,20 +669,13 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2,
       return false;
     const ParamAttrsList *Attrs1 = FTy->getParamAttrs();
     const ParamAttrsList *Attrs2 = FTy2->getParamAttrs();
-    if ((!Attrs1 && Attrs2 && !Attrs2->empty()) ||
-        (!Attrs2 && Attrs1 && !Attrs1->empty()) ||
+    if ((!Attrs1 && Attrs2) || (!Attrs2 && Attrs1) ||
         (Attrs1 && Attrs2 && (Attrs1->size() != Attrs2->size() ||
-         (Attrs1->size() > 0 && 
-          Attrs1->getParamAttrs(0) != Attrs2->getParamAttrs(0)))))
+         (Attrs1->getParamAttrs(0) != Attrs2->getParamAttrs(0)))))
       return false;
-    ParamAttrsList PAL1;
-    if (Attrs1)
-      PAL1 = *Attrs1;
-    ParamAttrsList PAL2;
-    if (Attrs2)
-      PAL2 = *Attrs2;
+
     for (unsigned i = 0, e = FTy2->getNumParams(); i != e; ++i) {
-      if (PAL1.getParamAttrs(i+1) != PAL2.getParamAttrs(i+1))
+      if (Attrs1 && Attrs1->getParamAttrs(i+1) != Attrs2->getParamAttrs(i+1))
         return false;
       if (!TypesEqual(FTy->getParamType(i), FTy2->getParamType(i), EqTypes))
         return false;
@@ -1061,15 +1084,10 @@ public:
     if (ParamAttrs)
       if (MTV.ParamAttrs)
         return *ParamAttrs < *MTV.ParamAttrs;
-      else if (ParamAttrs->empty())
-        return true;
       else
         return false;
     else if (MTV.ParamAttrs)
-      if (MTV.ParamAttrs->empty())
-        return false;
-      else
-        return true;
+      return true;
     return false;
   }
 };
@@ -1093,29 +1111,23 @@ FunctionValType FunctionValType::get(const FunctionType *FT) {
 FunctionType *FunctionType::get(const Type *ReturnType,
                                 const std::vector<const Type*> &Params,
                                 bool isVarArg,
-                                ParamAttrsList *Attrs) {
+                                const ParamAttrsList *Attrs) {
 
   FunctionValType VT(ReturnType, Params, isVarArg, Attrs);
-  FunctionType *MT = FunctionTypes->get(VT);
-  if (MT) { 
-    delete Attrs; // not needed any more
-    return MT;
+  FunctionType *FT = FunctionTypes->get(VT);
+  if (FT) { 
+    return FT;
   }
 
-
-  MT = (FunctionType*) new char[sizeof(FunctionType) + 
+  FT = (FunctionType*) new char[sizeof(FunctionType) + 
                                 sizeof(PATypeHandle)*(Params.size()+1)];
-  new (MT) FunctionType(ReturnType, Params, isVarArg, Attrs);
-  FunctionTypes->add(VT, MT);
+  new (FT) FunctionType(ReturnType, Params, isVarArg, Attrs);
+  FunctionTypes->add(VT, FT);
 
 #ifdef DEBUG_MERGE_TYPES
-  DOUT << "Derived new type: " << MT << "\n";
+  DOUT << "Derived new type: " << FT << "\n";
 #endif
-  return MT;
-}
-
-FunctionType::~FunctionType() {
-  delete ParamAttrs;
+  return FT;
 }
 
 bool FunctionType::isStructReturn() const {
@@ -1196,7 +1208,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(ElementType && "Can't get vector of null types!");
   assert(isPowerOf2_32(NumElements) && "Vector length should be a power of 2!");
 
   VectorValType PVT(ElementType, NumElements);