CMake: removed lib/VMCore/DebugInfoBuilder.cpp.
[oota-llvm.git] / lib / VMCore / Type.cpp
index d7fe2d1cfbeea94daec09b222e85331f8d515ea6..be211949799ebfd0b6b342344bb9a6e0a7cef93e 100644 (file)
@@ -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
 //===----------------------------------------------------------------------===//
@@ -84,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;
   }
@@ -251,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));
@@ -396,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];
 }
 
@@ -423,7 +416,7 @@ 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);
@@ -647,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
@@ -709,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(),
@@ -724,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(),
@@ -740,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();
@@ -893,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.
@@ -1116,8 +1109,8 @@ FunctionType *FunctionType::get(const Type *ReturnType,
   if (FT)
     return FT;
 
-  FT = (FunctionType*) new char[sizeof(FunctionType) + 
-                                sizeof(PATypeHandle)*(Params.size()+1)];
+  FT = (FunctionType*) operator new(sizeof(FunctionType) +
+                                    sizeof(PATypeHandle)*(Params.size()+1));
   new (FT) FunctionType(ReturnType, Params, isVarArg);
   FunctionTypes->add(VT, FT);
 
@@ -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);
 
@@ -1418,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 << " "
@@ -1445,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);