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
//===----------------------------------------------------------------------===//
// 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;
}
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));
// 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];
}
namespace {
struct BuiltinIntegerType : public IntegerType {
- BuiltinIntegerType(unsigned W) : IntegerType(W) {}
+ explicit BuiltinIntegerType(unsigned W) : IntegerType(W) {}
};
}
const IntegerType *Type::Int1Ty = new BuiltinIntegerType(1);
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
// 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(),
}
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(),
/// 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();
// 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.
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);
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);
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 << " "
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);