Minor cleanup and speedup. This reduces link-time for 252.eon from 35.5s

to 34.7s with a profile build.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17906 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2004-11-16 20:39:04 +00:00
parent 8511c351dc
commit bcb31d645d

View File

@@ -638,8 +638,6 @@ static bool TypeHasCycleThroughItself(const Type *Ty) {
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Derived Type Factory Functions // Derived Type Factory Functions
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@@ -653,7 +651,9 @@ template<class ValType, class TypeClass>
class TypeMap { class TypeMap {
std::map<ValType, PATypeHolder> Map; std::map<ValType, PATypeHolder> Map;
/// TypesByHash - Keep track of each type by its structure hash value. /// TypesByHash - Keep track of types by their structure hash value. Note
/// that we only keep track of types that have cycles through themselves in
/// this map.
/// ///
std::multimap<unsigned, PATypeHolder> TypesByHash; std::multimap<unsigned, PATypeHolder> TypesByHash;
public: public:
@@ -705,8 +705,7 @@ public:
Map.erase(ValType::get(Ty)); Map.erase(ValType::get(Ty));
// Remember the structural hash for the type before we start hacking on it, // Remember the structural hash for the type before we start hacking on it,
// in case we need it later. Also, check to see if the type HAD a cycle // in case we need it later.
// through it, if so, we know it will when we hack on it.
unsigned OldTypeHash = ValType::hashTypeStructure(Ty); unsigned OldTypeHash = ValType::hashTypeStructure(Ty);
// Find the type element we are refining... and change it now! // Find the type element we are refining... and change it now!
@@ -721,17 +720,19 @@ public:
// If there are no cycles going through this node, we can do a simple, // If there are no cycles going through this node, we can do a simple,
// efficient lookup in the map, instead of an inefficient nasty linear // efficient lookup in the map, instead of an inefficient nasty linear
// lookup. // lookup.
bool TypeHasCycle = Ty->isAbstract() && TypeHasCycleThroughItself(Ty); if (!Ty->isAbstract() || !TypeHasCycleThroughItself(Ty)) {
if (!TypeHasCycle) { typename std::map<ValType, PATypeHolder>::iterator I;
iterator I = Map.find(ValType::get(Ty)); bool Inserted;
if (I != Map.end()) {
// We already have this type in the table. Get rid of the newly refined ValType V = ValType::get(Ty);
// type. tie(I, Inserted) = Map.insert(std::make_pair(V, Ty));
assert(Ty->isAbstract() && "Replacing a non-abstract type?"); if (!Inserted) {
TypeClass *NewTy = cast<TypeClass>((Type*)I->second.get());
// Refined to a different type altogether? // Refined to a different type altogether?
RemoveFromTypesByHash(TypeHash, Ty); RemoveFromTypesByHash(TypeHash, Ty);
// We already have this type in the table. Get rid of the newly refined
// type.
TypeClass *NewTy = cast<TypeClass>((Type*)I->second.get());
Ty->refineAbstractTypeTo(NewTy); Ty->refineAbstractTypeTo(NewTy);
return; return;
} }
@@ -741,8 +742,8 @@ public:
// structurally identical to the newly refined type. If so, this type // structurally identical to the newly refined type. If so, this type
// gets refined to the pre-existing type. // gets refined to the pre-existing type.
// //
std::multimap<unsigned, PATypeHolder>::iterator I,E, Entry; std::multimap<unsigned, PATypeHolder>::iterator I, E, Entry;
tie(I, E) = TypesByHash.equal_range(TypeHash); tie(I, E) = TypesByHash.equal_range(OldTypeHash);
Entry = E; Entry = E;
for (; I != E; ++I) { for (; I != E; ++I) {
if (I->second != Ty) { if (I->second != Ty) {
@@ -768,20 +769,19 @@ public:
Entry = I; Entry = I;
} }
} }
// If there is no existing type of the same structure, we reinsert an
// updated record into the map.
Map.insert(std::make_pair(ValType::get(Ty), Ty));
} }
// If we succeeded, we need to insert the type into the cycletypes table. // If the hash codes differ, update TypesByHash
// There are several cases here, depending on whether the original type
// had the same hash code and was itself cyclic.
if (TypeHash != OldTypeHash) { if (TypeHash != OldTypeHash) {
RemoveFromTypesByHash(OldTypeHash, Ty); RemoveFromTypesByHash(OldTypeHash, Ty);
TypesByHash.insert(std::make_pair(TypeHash, Ty)); TypesByHash.insert(std::make_pair(TypeHash, Ty));
} }
// If there is no existing type of the same structure, we reinsert an
// updated record into the map.
Map.insert(std::make_pair(ValType::get(Ty), Ty));
// If the type is currently thought to be abstract, rescan all of our // If the type is currently thought to be abstract, rescan all of our
// subtypes to see if the type has just become concrete! // subtypes to see if the type has just become concrete!
if (Ty->isAbstract()) if (Ty->isAbstract())