Verify loop info.
[oota-llvm.git] / lib / VMCore / Type.cpp
index 10063126e54d2c50f345128ff1806b83100e4f6a..9b34dd840c8d7471aa5d860a618b009747dee5aa 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 
@@ -250,7 +242,18 @@ 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::LabelTyID:  return (*ConcreteTypeDescriptions)[Ty] = "label";
+      }
+    }
   }
 
   // Check to see if the Type is already on the stack...
@@ -300,7 +303,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 +393,10 @@ 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::LabelTy  = new Type(Type::LabelTyID);
 
 namespace {
   struct BuiltinIntegerType : public IntegerType {
@@ -414,7 +416,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
@@ -433,7 +435,6 @@ FunctionType::FunctionType(const Type *Result,
 
   // Calculate whether or not this type is abstract
   setAbstract(isAbstract);
-
 }
 
 StructType::StructType(const std::vector<const Type*> &Types, bool isPacked)
@@ -640,20 +641,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;
@@ -1062,15 +1056,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;
   }
 };
@@ -1094,29 +1083,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 {
@@ -1197,7 +1180,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);