[llvm-commits] [llvm] r52338 - /llvm/trunk/lib/Linker/LinkModules.cpp
Chris Lattner
sabre at nondot.org
Mon Jun 16 11:11:40 PDT 2008
Author: lattner
Date: Mon Jun 16 13:11:40 2008
New Revision: 52338
URL: http://llvm.org/viewvc/llvm-project?rev=52338&view=rev
Log:
simplify RecursiveResolveTypes and ResolveTypes by pulling the naming out of
ResolveTypes into the one place that needs it.
Modified:
llvm/trunk/lib/Linker/LinkModules.cpp
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=52338&r1=52337&r2=52338&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Jun 16 13:11:40 2008
@@ -52,7 +52,6 @@
// Inputs:
// DestTy - The type to which we wish to resolve.
// SrcTy - The original type which we want to resolve.
-// Name - The name of the type.
//
// Outputs:
// DestST - The symbol table in which the new type should be placed.
@@ -62,7 +61,7 @@
// false - No errors.
//
static bool ResolveTypes(const Type *DestTy, const Type *SrcTy,
- TypeSymbolTable *DestST, const std::string &Name) {
+ TypeSymbolTable *DestST) {
if (DestTy == SrcTy) return false; // If already equal, noop
// Does the type already exist in the module?
@@ -76,8 +75,6 @@
if (DestTy) // Type _is_ in module, just opaque...
const_cast<OpaqueType*>(cast<OpaqueType>(DestTy))
->refineAbstractTypeTo(SrcTy);
- else if (!Name.empty())
- DestST->insert(Name, const_cast<Type*>(SrcTy));
}
return false;
}
@@ -94,8 +91,7 @@
// are compatible.
static bool RecursiveResolveTypesI(const PATypeHolder &DestTy,
const PATypeHolder &SrcTy,
- TypeSymbolTable *DestST,
- const std::string &Name,
+ TypeSymbolTable *DestST,
std::vector<std::pair<PATypeHolder, PATypeHolder> > &Pointers) {
const Type *SrcTyT = SrcTy.get();
const Type *DestTyT = DestTy.get();
@@ -103,7 +99,7 @@
// If we found our opaque type, resolve it now!
if (isa<OpaqueType>(DestTyT) || isa<OpaqueType>(SrcTyT))
- return ResolveTypes(DestTyT, SrcTyT, DestST, Name);
+ return ResolveTypes(DestTyT, SrcTyT, DestST);
// Two types cannot be resolved together if they are of different primitive
// type. For example, we cannot resolve an int to a float.
@@ -125,7 +121,7 @@
return true;
for (unsigned i = 0, e = getFT(DestTy)->getNumContainedTypes(); i != e; ++i)
if (RecursiveResolveTypesI(getFT(DestTy)->getContainedType(i),
- getFT(SrcTy)->getContainedType(i), DestST, "",
+ getFT(SrcTy)->getContainedType(i), DestST,
Pointers))
return true;
return false;
@@ -135,7 +131,7 @@
getST(SrcTy)->getNumContainedTypes()) return 1;
for (unsigned i = 0, e = getST(DestTy)->getNumContainedTypes(); i != e; ++i)
if (RecursiveResolveTypesI(getST(DestTy)->getContainedType(i),
- getST(SrcTy)->getContainedType(i), DestST, "",
+ getST(SrcTy)->getContainedType(i), DestST,
Pointers))
return true;
return false;
@@ -145,7 +141,7 @@
const ArrayType *SAT = cast<ArrayType>(SrcTy.get());
if (DAT->getNumElements() != SAT->getNumElements()) return true;
return RecursiveResolveTypesI(DAT->getElementType(), SAT->getElementType(),
- DestST, "", Pointers);
+ DestST, Pointers);
}
case Type::PointerTyID: {
// If this is a pointer type, check to see if we have already seen it. If
@@ -162,7 +158,7 @@
bool Result =
RecursiveResolveTypesI(cast<PointerType>(DestTy.get())->getElementType(),
cast<PointerType>(SrcTy.get())->getElementType(),
- DestST, "", Pointers);
+ DestST, Pointers);
Pointers.pop_back();
return Result;
}
@@ -172,10 +168,9 @@
static bool RecursiveResolveTypes(const PATypeHolder &DestTy,
const PATypeHolder &SrcTy,
- TypeSymbolTable *DestST,
- const std::string &Name){
+ TypeSymbolTable *DestST){
std::vector<std::pair<PATypeHolder, PATypeHolder> > PointerTypes;
- return RecursiveResolveTypesI(DestTy, SrcTy, DestST, Name, PointerTypes);
+ return RecursiveResolveTypesI(DestTy, SrcTy, DestST, PointerTypes);
}
@@ -203,7 +198,9 @@
// Check to see if this type name is already in the dest module...
Type *Entry = DestST->lookup(Name);
- if (ResolveTypes(Entry, RHS, DestST, Name)) {
+ if (Entry == 0 && !Name.empty())
+ DestST->insert(Name, const_cast<Type*>(RHS));
+ else if (ResolveTypes(Entry, RHS, DestST)) {
// They look different, save the types 'till later to resolve.
DelayedTypesToResolve.push_back(Name);
}
@@ -219,7 +216,7 @@
const std::string &Name = DelayedTypesToResolve[i];
Type *T1 = SrcST->lookup(Name);
Type *T2 = DestST->lookup(Name);
- if (!ResolveTypes(T2, T1, DestST, Name)) {
+ if (!ResolveTypes(T2, T1, DestST)) {
// We are making progress!
DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i);
--i;
@@ -235,7 +232,7 @@
PATypeHolder T1(SrcST->lookup(Name));
PATypeHolder T2(DestST->lookup(Name));
- if (!RecursiveResolveTypes(T2, T1, DestST, Name)) {
+ if (!RecursiveResolveTypes(T2, T1, DestST)) {
// We are making progress!
DelayedTypesToResolve.erase(DelayedTypesToResolve.begin()+i);
@@ -463,7 +460,7 @@
if (DGV && DGV->getType() != SGV->getType())
// If types don't agree due to opaque types, try to resolve them.
RecursiveResolveTypes(SGV->getType(), DGV->getType(),
- &Dest->getTypeSymbolTable(), "");
+ &Dest->getTypeSymbolTable());
}
// Check to see if may have to link the global with the alias
@@ -472,7 +469,7 @@
if (DGV && DGV->getType() != SGV->getType())
// If types don't agree due to opaque types, try to resolve them.
RecursiveResolveTypes(SGV->getType(), DGV->getType(),
- &Dest->getTypeSymbolTable(), "");
+ &Dest->getTypeSymbolTable());
}
if (DGV && DGV->hasInternalLinkage())
@@ -633,7 +630,7 @@
// If types don't agree due to opaque types, try to resolve them.
if (DGV && DGV->getType() != SGA->getType())
if (RecursiveResolveTypes(SGA->getType(), DGV->getType(),
- &Dest->getTypeSymbolTable(), ""))
+ &Dest->getTypeSymbolTable()))
return Error(Err, "Alias Collision on '" + SGA->getName()+
"': aliases have different types");
}
@@ -644,7 +641,7 @@
// If types don't agree due to opaque types, try to resolve them.
if (DGV && DGV->getType() != SGA->getType())
if (RecursiveResolveTypes(SGA->getType(), DGV->getType(),
- &Dest->getTypeSymbolTable(), ""))
+ &Dest->getTypeSymbolTable()))
return Error(Err, "Alias Collision on '" + SGA->getName()+
"': aliases have different types");
}
@@ -655,7 +652,7 @@
// If types don't agree due to opaque types, try to resolve them.
if (DGV && DGV->getType() != SGA->getType())
if (RecursiveResolveTypes(SGA->getType(), DGV->getType(),
- &Dest->getTypeSymbolTable(), ""))
+ &Dest->getTypeSymbolTable()))
return Error(Err, "Alias Collision on '" + SGA->getName()+
"': aliases have different types");
}
@@ -854,7 +851,7 @@
// If types don't agree because of opaque, try to resolve them.
if (SF->getType() != DF->getType())
RecursiveResolveTypes(SF->getType(), DF->getType(),
- &Dest->getTypeSymbolTable(), "");
+ &Dest->getTypeSymbolTable());
// Check visibility, merging if a definition overrides a prototype.
if (SF->getVisibility() != DF->getVisibility()) {
More information about the llvm-commits
mailing list