X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FVMCore%2FType.cpp;h=c25bdf02f85d9b801008f6e10f855603e7d61573;hb=008f906afde4365dd30dde13bd22ae795c4112f9;hp=87fa581a573ea5c25670a8d86aae04dde7c0bd41;hpb=82072d47436a8e150bad42c9c3bf230617d53608;p=oota-llvm.git diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 87fa581a573..c25bdf02f85 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -115,20 +115,20 @@ static struct TypeType : public Type { // Static 'Type' data //===----------------------------------------------------------------------===// -const Type *Type::VoidTy = new Type("void" , VoidTyID), - *Type::BoolTy = new Type("bool" , BoolTyID), - *Type::SByteTy = new SignedIntType("sbyte" , SByteTyID, 1), - *Type::UByteTy = new UnsignedIntType("ubyte" , UByteTyID, 1), - *Type::ShortTy = new SignedIntType("short" , ShortTyID, 2), - *Type::UShortTy = new UnsignedIntType("ushort", UShortTyID, 2), - *Type::IntTy = new SignedIntType("int" , IntTyID, 4), - *Type::UIntTy = new UnsignedIntType("uint" , UIntTyID, 4), - *Type::LongTy = new SignedIntType("long" , LongTyID, 8), - *Type::ULongTy = new UnsignedIntType("ulong" , ULongTyID, 8), - *Type::FloatTy = new Type("float" , FloatTyID), - *Type::DoubleTy = new Type("double", DoubleTyID), - *Type::TypeTy = &TheTypeType, - *Type::LabelTy = new Type("label" , LabelTyID); +Type *Type::VoidTy = new Type("void" , VoidTyID), + *Type::BoolTy = new Type("bool" , BoolTyID), + *Type::SByteTy = new SignedIntType("sbyte" , SByteTyID, 1), + *Type::UByteTy = new UnsignedIntType("ubyte" , UByteTyID, 1), + *Type::ShortTy = new SignedIntType("short" , ShortTyID, 2), + *Type::UShortTy = new UnsignedIntType("ushort", UShortTyID, 2), + *Type::IntTy = new SignedIntType("int" , IntTyID, 4), + *Type::UIntTy = new UnsignedIntType("uint" , UIntTyID, 4), + *Type::LongTy = new SignedIntType("long" , LongTyID, 8), + *Type::ULongTy = new UnsignedIntType("ulong" , ULongTyID, 8), + *Type::FloatTy = new Type("float" , FloatTyID), + *Type::DoubleTy = new Type("double", DoubleTyID), + *Type::TypeTy = &TheTypeType, + *Type::LabelTy = new Type("label" , LabelTyID); //===----------------------------------------------------------------------===// @@ -140,7 +140,7 @@ MethodType::MethodType(const Type *Result, const vector &Params, ResultType(PATypeHandle(Result, this)), isVarArgs(IsVarArgs) { ParamTys.reserve(Params.size()); - for (unsigned i = 0; i < Params.size()-IsVarArgs; ++i) + for (unsigned i = 0; i < Params.size(); ++i) ParamTys.push_back(PATypeHandle(Params[i], this)); setDerivedTypeProperties(); @@ -155,8 +155,10 @@ ArrayType::ArrayType(const Type *ElType, int NumEl) StructType::StructType(const vector &Types) : DerivedType("", StructTyID) { ETypes.reserve(Types.size()); - for (unsigned i = 0; i < Types.size(); ++i) + for (unsigned i = 0; i < Types.size(); ++i) { + assert(Types[i] != Type::VoidTy && "Void type in method prototype!!"); ETypes.push_back(PATypeHandle(Types[i], this)); + } setDerivedTypeProperties(); } @@ -192,7 +194,7 @@ static string getTypeProps(const Type *Ty, vector &TypeStack, if (!Ty->isAbstract() && !Ty->isRecursive() && // Base case for the recursion Ty->getDescription().size()) { Result = Ty->getDescription(); // Primitive = leaf type - } else if (Ty->isOpaqueType()) { // Base case for the recursion + } else if (isa(Ty)) { // Base case for the recursion Result = Ty->getDescription(); // Opaque = leaf type isAbstract = true; // This whole type is abstract! } else { @@ -212,7 +214,7 @@ static string getTypeProps(const Type *Ty, vector &TypeStack, switch (Ty->getPrimitiveID()) { case Type::MethodTyID: { - const MethodType *MTy = (const MethodType*)Ty; + const MethodType *MTy = cast(Ty); Result = getTypeProps(MTy->getReturnType(), TypeStack, isAbstract, isRecursive)+" ("; for (MethodType::ParamTypes::const_iterator @@ -230,7 +232,7 @@ static string getTypeProps(const Type *Ty, vector &TypeStack, break; } case Type::StructTyID: { - const StructType *STy = (const StructType*)Ty; + const StructType *STy = cast(Ty); Result = "{ "; for (StructType::ElementTypes::const_iterator I = STy->getElementTypes().begin(), @@ -243,13 +245,13 @@ static string getTypeProps(const Type *Ty, vector &TypeStack, break; } case Type::PointerTyID: { - const PointerType *PTy = (const PointerType*)Ty; + const PointerType *PTy = cast(Ty); Result = getTypeProps(PTy->getValueType(), TypeStack, isAbstract, isRecursive) + " *"; break; } case Type::ArrayTyID: { - const ArrayType *ATy = (const ArrayType*)Ty; + const ArrayType *ATy = cast(Ty); int NumElements = ATy->getNumElements(); Result = "["; if (NumElements != -1) Result += itostr(NumElements) + " x "; @@ -298,6 +300,8 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2, if (Ty == Ty2) return true; if (Ty->getPrimitiveID() != Ty2->getPrimitiveID()) return false; if (Ty->isPrimitiveType()) return true; + if (isa(Ty)) + return false; // Two nonequal opaque types are never equal if (Ty != Ty2) { map::iterator I = EqTypes.find(Ty); @@ -310,17 +314,22 @@ static bool TypesEqual(const Type *Ty, const Type *Ty2, } // Iterate over the types and make sure the the contents are equivalent... - Type::contype_iterator I = Ty ->contype_begin(), IE = Ty ->contype_end(); - Type::contype_iterator I2 = Ty2->contype_begin(), IE2 = Ty2->contype_end(); + Type::subtype_iterator I = Ty ->subtype_begin(), IE = Ty ->subtype_end(); + Type::subtype_iterator I2 = Ty2->subtype_begin(), IE2 = Ty2->subtype_end(); for (; I != IE && I2 != IE2; ++I, ++I2) if (!TypesEqual(*I, *I2, EqTypes)) return false; - // One really annoying special case that breaks an otherwise nice simple + // Two really annoying special cases that breaks an otherwise nice simple // algorithm is the fact that arraytypes have sizes that differentiates types, - // consider this now. - if (Ty->isArrayType()) - if (((const ArrayType*)Ty)->getNumElements() != - ((const ArrayType*)Ty2)->getNumElements()) return false; + // and that method types can be varargs or not. Consider this now. + if (const ArrayType *ATy = dyn_cast(Ty)) { + if (ATy->getNumElements() != cast(Ty2)->getNumElements()) + return false; + } else if (const MethodType *MTy = dyn_cast(Ty)) { + if (MTy->isVarArg() != cast(Ty2)->isVarArg()) + return false; + } + return I == IE && I2 == IE2; // Types equal if both iterators are done } @@ -446,10 +455,12 @@ protected: class MethodValType : public ValTypeBase { PATypeHandle RetTy; vector > ArgTypes; + bool isVarArg; public: MethodValType(const Type *ret, const vector &args, - TypeMap &Tab) - : ValTypeBase(Tab), RetTy(ret, this) { + bool IVA, TypeMap &Tab) + : ValTypeBase(Tab), RetTy(ret, this), + isVarArg(IVA) { for (unsigned i = 0; i < args.size(); ++i) ArgTypes.push_back(PATypeHandle(args[i], this)); } @@ -458,7 +469,8 @@ public: // this MethodValType owns them, not the old one! // MethodValType(const MethodValType &MVT) - : ValTypeBase(MVT), RetTy(MVT.RetTy, this) { + : ValTypeBase(MVT), RetTy(MVT.RetTy, this), + isVarArg(MVT.isVarArg) { ArgTypes.reserve(MVT.ArgTypes.size()); for (unsigned i = 0; i < MVT.ArgTypes.size(); ++i) ArgTypes.push_back(PATypeHandle(MVT.ArgTypes[i], this)); @@ -472,8 +484,11 @@ public: } inline bool operator<(const MethodValType &MTV) const { - return RetTy.get() < MTV.RetTy.get() || - (RetTy.get() == MTV.RetTy.get() && ArgTypes < MTV.ArgTypes); + if (RetTy.get() < MTV.RetTy.get()) return true; + if (RetTy.get() > MTV.RetTy.get()) return false; + + if (ArgTypes < MTV.ArgTypes) return true; + return (ArgTypes == MTV.ArgTypes) && isVarArg < MTV.isVarArg; } }; @@ -482,13 +497,13 @@ static TypeMap MethodTypes; // MethodType::get - The factory function for the MethodType class... MethodType *MethodType::get(const Type *ReturnType, - const vector &Params) { - MethodValType VT(ReturnType, Params, MethodTypes); + const vector &Params, + bool isVarArg) { + MethodValType VT(ReturnType, Params, isVarArg, MethodTypes); MethodType *MT = MethodTypes.get(VT); if (MT) return MT; - bool IsVarArg = Params.size() && (Params[Params.size()-1] == Type::VoidTy); - MethodTypes.add(VT, MT = new MethodType(ReturnType, Params, IsVarArg)); + MethodTypes.add(VT, MT = new MethodType(ReturnType, Params, isVarArg)); #ifdef DEBUG_MERGE_TYPES cerr << "Derived new type: " << MT << endl; @@ -731,7 +746,7 @@ void DerivedType::refineAbstractTypeTo(const Type *NewType) { << (void*)this << " " << getDescription() << "] to [" << (void*)NewTy.get() << " " << NewTy->getDescription() << "]!\n"; #endif - AbstractTypeUsers.back()->refineAbstractType(this, NewTy); + User->refineAbstractType(this, NewTy); assert(AbstractTypeUsers.size() != OldSize && "AbsTyUser did not remove self from user list!");