simplify some code.

llvm-svn: 52350
This commit is contained in:
Chris Lattner 2008-06-16 19:55:40 +00:00
parent ccafce3d4c
commit 85b66d18b9
1 changed files with 21 additions and 24 deletions

View File

@ -75,13 +75,6 @@ static bool ResolveTypes(const Type *DestTy, const Type *SrcTy) {
return false; return false;
} }
static const FunctionType *getFT(const PATypeHolder &TH) {
return cast<FunctionType>(TH.get());
}
static const StructType *getST(const PATypeHolder &TH) {
return cast<StructType>(TH.get());
}
// 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.
@ -105,24 +98,25 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
default: default:
return true; return true;
case Type::FunctionTyID: { case Type::FunctionTyID: {
if (cast<FunctionType>(DestTyT)->isVarArg() != const FunctionType *DstFT = cast<FunctionType>(DestTyT);
cast<FunctionType>(SrcTyT)->isVarArg() || const FunctionType *SrcFT = cast<FunctionType>(SrcTyT);
cast<FunctionType>(DestTyT)->getNumContainedTypes() != if (DstFT->isVarArg() != SrcFT->isVarArg() ||
cast<FunctionType>(SrcTyT)->getNumContainedTypes()) DstFT->getNumContainedTypes() != SrcFT->getNumContainedTypes())
return true; return true;
for (unsigned i = 0, e = getFT(DestTy)->getNumContainedTypes(); i != e; ++i) for (unsigned i = 0, e = DstFT->getNumContainedTypes(); i != e; ++i)
if (RecursiveResolveTypesI(getFT(DestTy)->getContainedType(i), if (RecursiveResolveTypesI(DstFT->getContainedType(i),
getFT(SrcTy)->getContainedType(i), Pointers)) SrcFT->getContainedType(i), Pointers))
return true; return true;
return false; return false;
} }
case Type::StructTyID: { case Type::StructTyID: {
if (getST(DestTy)->getNumContainedTypes() != const StructType *DstST = cast<StructType>(DestTyT);
getST(SrcTy)->getNumContainedTypes()) const StructType *SrcST = cast<StructType>(SrcTyT);
if (DstST->getNumContainedTypes() != SrcST->getNumContainedTypes())
return true; return true;
for (unsigned i = 0, e = getST(DestTy)->getNumContainedTypes(); i != e; ++i) for (unsigned i = 0, e = DstST->getNumContainedTypes(); i != e; ++i)
if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i), if (RecursiveResolveTypesI(DstST->getContainedType(i),
getST(SrcTy)->getContainedType(i), Pointers)) SrcST->getContainedType(i), Pointers))
return true; return true;
return false; return false;
} }
@ -141,6 +135,12 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
Pointers); Pointers);
} }
case Type::PointerTyID: { case Type::PointerTyID: {
const PointerType *DstPT = cast<PointerType>(DestTy.get());
const PointerType *SrcPT = cast<PointerType>(SrcTy.get());
if (DstPT->getAddressSpace() != SrcPT->getAddressSpace())
return true;
// If this is a pointer type, check to see if we have already seen it. If // If this is a pointer type, check to see if we have already seen it. If
// so, we are in a recursive branch. Cut off the search now. We cannot use // so, we are in a recursive branch. Cut off the search now. We cannot use
// an associative container for this search, because the type pointers (keys // an associative container for this search, because the type pointers (keys
@ -152,11 +152,8 @@ static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
// 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.
Pointers.push_back(std::make_pair(DestTyT, SrcTyT)); Pointers.push_back(std::make_pair(DestTyT, SrcTyT));
bool Result = return RecursiveResolveTypesI(DstPT->getElementType(),
RecursiveResolveTypesI(cast<PointerType>(DestTy.get())->getElementType(), SrcPT->getElementType(), Pointers);
cast<PointerType>(SrcTy.get())->getElementType(),
Pointers);
return Result;
} }
} }
} }