From a4477f9b31ce0b6fadc5365ff9355679c1ecb954 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 16 Jun 2008 21:17:12 +0000 Subject: [PATCH] stop making PATypeHolder's so crazily. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52364 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 66 +++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index afc9a427110..27c71b16186 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -157,69 +157,73 @@ protected: // RecursiveResolveTypes - This is just like ResolveTypes, except that it // recurses down into derived types, merging the used types if the parent types // are compatible. -static bool RecursiveResolveTypesI(const PATypeHolder &DestTy, - const PATypeHolder &SrcTy, +static bool RecursiveResolveTypesI(const Type *DstTy, const Type *SrcTy, LinkerTypeMap &Pointers) { - const Type *SrcTyT = SrcTy.get(); - const Type *DestTyT = DestTy.get(); - if (DestTyT == SrcTyT) return false; // If already equal, noop + if (DstTy == SrcTy) return false; // If already equal, noop // If we found our opaque type, resolve it now! - if (isa(DestTyT) || isa(SrcTyT)) - return ResolveTypes(DestTyT, SrcTyT); + if (isa(DstTy) || isa(SrcTy)) + return ResolveTypes(DstTy, SrcTy); // Two types cannot be resolved together if they are of different primitive // type. For example, we cannot resolve an int to a float. - if (DestTyT->getTypeID() != SrcTyT->getTypeID()) return true; + if (DstTy->getTypeID() != SrcTy->getTypeID()) return true; // If neither type is abstract, then they really are just different types. - if (!DestTyT->isAbstract() && !SrcTyT->isAbstract()) + if (!DstTy->isAbstract() && !SrcTy->isAbstract()) return true; // Otherwise, resolve the used type used by this derived type... - switch (DestTyT->getTypeID()) { + switch (DstTy->getTypeID()) { default: return true; case Type::FunctionTyID: { - const FunctionType *DstFT = cast(DestTyT); - const FunctionType *SrcFT = cast(SrcTyT); + const FunctionType *DstFT = cast(DstTy); + const FunctionType *SrcFT = cast(SrcTy); if (DstFT->isVarArg() != SrcFT->isVarArg() || DstFT->getNumContainedTypes() != SrcFT->getNumContainedTypes()) return true; - for (unsigned i = 0, e = DstFT->getNumContainedTypes(); i != e; ++i) - if (RecursiveResolveTypesI(DstFT->getContainedType(i), - SrcFT->getContainedType(i), Pointers)) + + // Use TypeHolder's so recursive resolution won't break us. + PATypeHolder ST(SrcFT), DT(DstFT); + for (unsigned i = 0, e = DstFT->getNumContainedTypes(); i != e; ++i) { + const Type *SE = ST->getContainedType(i), *DE = DT->getContainedType(i); + if (SE != DE && RecursiveResolveTypesI(DE, SE, Pointers)) return true; + } return false; } case Type::StructTyID: { - const StructType *DstST = cast(DestTyT); - const StructType *SrcST = cast(SrcTyT); + const StructType *DstST = cast(DstTy); + const StructType *SrcST = cast(SrcTy); if (DstST->getNumContainedTypes() != SrcST->getNumContainedTypes()) return true; - for (unsigned i = 0, e = DstST->getNumContainedTypes(); i != e; ++i) - if (RecursiveResolveTypesI(DstST->getContainedType(i), - SrcST->getContainedType(i), Pointers)) + + PATypeHolder ST(SrcST), DT(DstST); + for (unsigned i = 0, e = DstST->getNumContainedTypes(); i != e; ++i) { + const Type *SE = ST->getContainedType(i), *DE = DT->getContainedType(i); + if (SE != DE && RecursiveResolveTypesI(DE, SE, Pointers)) return true; + } return false; } case Type::ArrayTyID: { - const ArrayType *DAT = cast(DestTy.get()); - const ArrayType *SAT = cast(SrcTy.get()); + const ArrayType *DAT = cast(DstTy); + const ArrayType *SAT = cast(SrcTy); if (DAT->getNumElements() != SAT->getNumElements()) return true; return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(), Pointers); } case Type::VectorTyID: { - const VectorType *DVT = cast(DestTy.get()); - const VectorType *SVT = cast(SrcTy.get()); + const VectorType *DVT = cast(DstTy); + const VectorType *SVT = cast(SrcTy); if (DVT->getNumElements() != SVT->getNumElements()) return true; return RecursiveResolveTypesI(DVT->getElementType(), SVT->getElementType(), Pointers); } case Type::PointerTyID: { - const PointerType *DstPT = cast(DestTy.get()); - const PointerType *SrcPT = cast(SrcTy.get()); + const PointerType *DstPT = cast(DstTy); + const PointerType *SrcPT = cast(SrcTy); if (DstPT->getAddressSpace() != SrcPT->getAddressSpace()) return true; @@ -235,21 +239,20 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy, if (DstPT->isAbstract()) if (const Type *ExistingSrcTy = Pointers.lookup(DstPT)) return ExistingSrcTy != SrcPT; - // Otherwise, add the current pointers to the vector to stop recursion on // this pair. if (DstPT->isAbstract()) Pointers.insert(DstPT, SrcPT); if (SrcPT->isAbstract()) Pointers.insert(SrcPT, DstPT); + return RecursiveResolveTypesI(DstPT->getElementType(), SrcPT->getElementType(), Pointers); } } } -static bool RecursiveResolveTypes(const PATypeHolder &DestTy, - const PATypeHolder &SrcTy) { +static bool RecursiveResolveTypes(const Type *DestTy, const Type *SrcTy) { LinkerTypeMap PointerTypes; return RecursiveResolveTypesI(DestTy, SrcTy, PointerTypes); } @@ -312,10 +315,7 @@ static bool LinkTypes(Module *Dest, const Module *Src, std::string *Err) { // two types: { int* } and { opaque* } for (unsigned i = 0, e = DelayedTypesToResolve.size(); i != e; ++i) { const std::string &Name = DelayedTypesToResolve[i]; - PATypeHolder T1(SrcST->lookup(Name)); - PATypeHolder T2(DestST->lookup(Name)); - - if (!RecursiveResolveTypes(T2, T1)) { + if (!RecursiveResolveTypes(SrcST->lookup(Name), DestST->lookup(Name))) { // We are making progress! DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i); -- 2.34.1