mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-12 17:25:49 +00:00
stop making PATypeHolder's so crazily.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52364 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -157,69 +157,73 @@ protected:
|
|||||||
// RecursiveResolveTypes - This is just like ResolveTypes, except that it
|
// RecursiveResolveTypes - This is just like ResolveTypes, except that it
|
||||||
// recurses down into derived types, merging the used types if the parent types
|
// recurses down into derived types, merging the used types if the parent types
|
||||||
// are compatible.
|
// are compatible.
|
||||||
static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
|
static bool RecursiveResolveTypesI(const Type *DstTy, const Type *SrcTy,
|
||||||
const PATypeHolder &SrcTy,
|
|
||||||
LinkerTypeMap &Pointers) {
|
LinkerTypeMap &Pointers) {
|
||||||
const Type *SrcTyT = SrcTy.get();
|
if (DstTy == SrcTy) return false; // If already equal, noop
|
||||||
const Type *DestTyT = DestTy.get();
|
|
||||||
if (DestTyT == SrcTyT) return false; // If already equal, noop
|
|
||||||
|
|
||||||
// If we found our opaque type, resolve it now!
|
// If we found our opaque type, resolve it now!
|
||||||
if (isa<OpaqueType>(DestTyT) || isa<OpaqueType>(SrcTyT))
|
if (isa<OpaqueType>(DstTy) || isa<OpaqueType>(SrcTy))
|
||||||
return ResolveTypes(DestTyT, SrcTyT);
|
return ResolveTypes(DstTy, SrcTy);
|
||||||
|
|
||||||
// Two types cannot be resolved together if they are of different primitive
|
// Two types cannot be resolved together if they are of different primitive
|
||||||
// type. For example, we cannot resolve an int to a float.
|
// 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 neither type is abstract, then they really are just different types.
|
||||||
if (!DestTyT->isAbstract() && !SrcTyT->isAbstract())
|
if (!DstTy->isAbstract() && !SrcTy->isAbstract())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Otherwise, resolve the used type used by this derived type...
|
// Otherwise, resolve the used type used by this derived type...
|
||||||
switch (DestTyT->getTypeID()) {
|
switch (DstTy->getTypeID()) {
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
case Type::FunctionTyID: {
|
case Type::FunctionTyID: {
|
||||||
const FunctionType *DstFT = cast<FunctionType>(DestTyT);
|
const FunctionType *DstFT = cast<FunctionType>(DstTy);
|
||||||
const FunctionType *SrcFT = cast<FunctionType>(SrcTyT);
|
const FunctionType *SrcFT = cast<FunctionType>(SrcTy);
|
||||||
if (DstFT->isVarArg() != SrcFT->isVarArg() ||
|
if (DstFT->isVarArg() != SrcFT->isVarArg() ||
|
||||||
DstFT->getNumContainedTypes() != SrcFT->getNumContainedTypes())
|
DstFT->getNumContainedTypes() != SrcFT->getNumContainedTypes())
|
||||||
return true;
|
return true;
|
||||||
for (unsigned i = 0, e = DstFT->getNumContainedTypes(); i != e; ++i)
|
|
||||||
if (RecursiveResolveTypesI(DstFT->getContainedType(i),
|
// Use TypeHolder's so recursive resolution won't break us.
|
||||||
SrcFT->getContainedType(i), Pointers))
|
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 true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case Type::StructTyID: {
|
case Type::StructTyID: {
|
||||||
const StructType *DstST = cast<StructType>(DestTyT);
|
const StructType *DstST = cast<StructType>(DstTy);
|
||||||
const StructType *SrcST = cast<StructType>(SrcTyT);
|
const StructType *SrcST = cast<StructType>(SrcTy);
|
||||||
if (DstST->getNumContainedTypes() != SrcST->getNumContainedTypes())
|
if (DstST->getNumContainedTypes() != SrcST->getNumContainedTypes())
|
||||||
return true;
|
return true;
|
||||||
for (unsigned i = 0, e = DstST->getNumContainedTypes(); i != e; ++i)
|
|
||||||
if (RecursiveResolveTypesI(DstST->getContainedType(i),
|
PATypeHolder ST(SrcST), DT(DstST);
|
||||||
SrcST->getContainedType(i), Pointers))
|
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 true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
case Type::ArrayTyID: {
|
case Type::ArrayTyID: {
|
||||||
const ArrayType *DAT = cast<ArrayType>(DestTy.get());
|
const ArrayType *DAT = cast<ArrayType>(DstTy);
|
||||||
const ArrayType *SAT = cast<ArrayType>(SrcTy.get());
|
const ArrayType *SAT = cast<ArrayType>(SrcTy);
|
||||||
if (DAT->getNumElements() != SAT->getNumElements()) return true;
|
if (DAT->getNumElements() != SAT->getNumElements()) return true;
|
||||||
return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(),
|
return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(),
|
||||||
Pointers);
|
Pointers);
|
||||||
}
|
}
|
||||||
case Type::VectorTyID: {
|
case Type::VectorTyID: {
|
||||||
const VectorType *DVT = cast<VectorType>(DestTy.get());
|
const VectorType *DVT = cast<VectorType>(DstTy);
|
||||||
const VectorType *SVT = cast<VectorType>(SrcTy.get());
|
const VectorType *SVT = cast<VectorType>(SrcTy);
|
||||||
if (DVT->getNumElements() != SVT->getNumElements()) return true;
|
if (DVT->getNumElements() != SVT->getNumElements()) return true;
|
||||||
return RecursiveResolveTypesI(DVT->getElementType(), SVT->getElementType(),
|
return RecursiveResolveTypesI(DVT->getElementType(), SVT->getElementType(),
|
||||||
Pointers);
|
Pointers);
|
||||||
}
|
}
|
||||||
case Type::PointerTyID: {
|
case Type::PointerTyID: {
|
||||||
const PointerType *DstPT = cast<PointerType>(DestTy.get());
|
const PointerType *DstPT = cast<PointerType>(DstTy);
|
||||||
const PointerType *SrcPT = cast<PointerType>(SrcTy.get());
|
const PointerType *SrcPT = cast<PointerType>(SrcTy);
|
||||||
|
|
||||||
if (DstPT->getAddressSpace() != SrcPT->getAddressSpace())
|
if (DstPT->getAddressSpace() != SrcPT->getAddressSpace())
|
||||||
return true;
|
return true;
|
||||||
@@ -235,21 +239,20 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
|
|||||||
if (DstPT->isAbstract())
|
if (DstPT->isAbstract())
|
||||||
if (const Type *ExistingSrcTy = Pointers.lookup(DstPT))
|
if (const Type *ExistingSrcTy = Pointers.lookup(DstPT))
|
||||||
return ExistingSrcTy != SrcPT;
|
return ExistingSrcTy != SrcPT;
|
||||||
|
|
||||||
// Otherwise, add the current pointers to the vector to stop recursion on
|
// Otherwise, add the current pointers to the vector to stop recursion on
|
||||||
// this pair.
|
// this pair.
|
||||||
if (DstPT->isAbstract())
|
if (DstPT->isAbstract())
|
||||||
Pointers.insert(DstPT, SrcPT);
|
Pointers.insert(DstPT, SrcPT);
|
||||||
if (SrcPT->isAbstract())
|
if (SrcPT->isAbstract())
|
||||||
Pointers.insert(SrcPT, DstPT);
|
Pointers.insert(SrcPT, DstPT);
|
||||||
|
|
||||||
return RecursiveResolveTypesI(DstPT->getElementType(),
|
return RecursiveResolveTypesI(DstPT->getElementType(),
|
||||||
SrcPT->getElementType(), Pointers);
|
SrcPT->getElementType(), Pointers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
|
static bool RecursiveResolveTypes(const Type *DestTy, const Type *SrcTy) {
|
||||||
const PATypeHolder &SrcTy) {
|
|
||||||
LinkerTypeMap PointerTypes;
|
LinkerTypeMap PointerTypes;
|
||||||
return RecursiveResolveTypesI(DestTy, SrcTy, 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* }
|
// two types: { int* } and { opaque* }
|
||||||
for (unsigned i = 0, e = DelayedTypesToResolve.size(); i != e; ++i) {
|
for (unsigned i = 0, e = DelayedTypesToResolve.size(); i != e; ++i) {
|
||||||
const std::string &Name = DelayedTypesToResolve[i];
|
const std::string &Name = DelayedTypesToResolve[i];
|
||||||
PATypeHolder T1(SrcST->lookup(Name));
|
if (!RecursiveResolveTypes(SrcST->lookup(Name), DestST->lookup(Name))) {
|
||||||
PATypeHolder T2(DestST->lookup(Name));
|
|
||||||
|
|
||||||
if (!RecursiveResolveTypes(T2, T1)) {
|
|
||||||
// We are making progress!
|
// We are making progress!
|
||||||
DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i);
|
DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user