[llvm-commits] [bug_122] CVS: llvm/lib/VMCore/AsmWriter.cpp Module.cpp SlotCalculator.cpp SymbolTable.cpp Verifier.cpp
LLVM
llvm at cs.uiuc.edu
Wed May 12 11:33:15 PDT 2004
Changes in directory llvm/lib/VMCore:
AsmWriter.cpp updated: 1.128 -> 1.128.2.1
Module.cpp updated: 1.49 -> 1.49.2.1
SlotCalculator.cpp updated: 1.53 -> 1.53.2.1
SymbolTable.cpp updated: 1.42 -> 1.42.6.1
Verifier.cpp updated: 1.97 -> 1.97.2.1
---
Log message:
Change SymbolTable to not subclass from std::map but to embed one instead
and cleanup use of SymbolTable in rest of LLVM. Also, add some new methods
to SymbolTable for small/utility cases and substitute calls to them in
LLVM.
---
Diffs of the changes: (+135 -89)
Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.128 llvm/lib/VMCore/AsmWriter.cpp:1.128.2.1
--- llvm/lib/VMCore/AsmWriter.cpp:1.128 Wed Apr 28 14:24:28 2004
+++ llvm/lib/VMCore/AsmWriter.cpp Wed May 12 11:33:43 2004
@@ -105,18 +105,18 @@
std::map<const Type *, std::string> &TypeNames) {
if (!M) return;
const SymbolTable &ST = M->getSymbolTable();
- SymbolTable::const_iterator PI = ST.find(Type::TypeTy);
+ SymbolTable::type_const_iterator PI = ST.find(Type::TypeTy);
if (PI != ST.end()) {
- SymbolTable::type_const_iterator I = PI->second.begin();
- for (; I != PI->second.end(); ++I) {
+ SymbolTable::value_const_iterator VI = PI->second.begin();
+ for (; VI != PI->second.end(); ++VI) {
// As a heuristic, don't insert pointer to primitive types, because
// they are used too often to have a single useful name.
//
- const Type *Ty = cast<Type>(I->second);
+ const Type *Ty = cast<Type>(VI->second);
if (!isa<PointerType>(Ty) ||
!cast<PointerType>(Ty)->getElementType()->isPrimitiveType() ||
isa<OpaqueType>(cast<PointerType>(Ty)->getElementType()))
- TypeNames.insert(std::make_pair(Ty, getLLVMName(I->first)));
+ TypeNames.insert(std::make_pair(Ty, getLLVMName(VI->first)));
}
}
}
@@ -609,9 +609,9 @@
/// if a named constant is found, emit it's declaration...
///
void AssemblyWriter::printSymbolTable(const SymbolTable &ST) {
- for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) {
- SymbolTable::type_const_iterator I = ST.type_begin(TI->first);
- SymbolTable::type_const_iterator End = ST.type_end(TI->first);
+ for (SymbolTable::type_const_iterator TI = ST.begin(); TI != ST.end(); ++TI) {
+ SymbolTable::value_const_iterator I = ST.type_begin(TI->first);
+ SymbolTable::value_const_iterator End = ST.type_end(TI->first);
for (; I != End; ++I) {
const Value *V = I->second;
Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.49 llvm/lib/VMCore/Module.cpp:1.49.2.1
--- llvm/lib/VMCore/Module.cpp:1.49 Wed Apr 21 13:27:56 2004
+++ llvm/lib/VMCore/Module.cpp Wed May 12 11:33:43 2004
@@ -267,18 +267,7 @@
//
std::string Module::getTypeName(const Type *Ty) const {
const SymbolTable &ST = getSymbolTable();
- if (ST.find(Type::TypeTy) == ST.end())
- return ""; // No names for types...
-
- SymbolTable::type_const_iterator TI = ST.type_begin(Type::TypeTy);
- SymbolTable::type_const_iterator TE = ST.type_end(Type::TypeTy);
-
- while (TI != TE && TI->second != (const Value*)Ty)
- ++TI;
-
- if (TI != TE) // Must have found an entry!
- return TI->first;
- return ""; // Must not have found anything...
+ return ST.get_name( (const Value*) Ty );
}
Index: llvm/lib/VMCore/SlotCalculator.cpp
diff -u llvm/lib/VMCore/SlotCalculator.cpp:1.53 llvm/lib/VMCore/SlotCalculator.cpp:1.53.2.1
--- llvm/lib/VMCore/SlotCalculator.cpp:1.53 Tue Apr 27 10:13:09 2004
+++ llvm/lib/VMCore/SlotCalculator.cpp Wed May 12 11:33:43 2004
@@ -248,18 +248,19 @@
// into the values table...
//
void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
- for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
- for (SymbolTable::type_const_iterator TI = I->second.begin(),
- TE = I->second.end(); TI != TE; ++TI)
- getOrCreateSlot(TI->second);
+ for (SymbolTable::type_const_iterator TI = ST->begin(), TE = ST->end();
+ TI != TE; ++TI)
+ for (SymbolTable::value_const_iterator VI = TI->second.begin(),
+ VE = TI->second.end(); VI != VE; ++VI)
+ getOrCreateSlot(VI->second);
}
void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
- for (SymbolTable::const_iterator I = ST->begin(), E = ST->end(); I != E; ++I)
- for (SymbolTable::type_const_iterator TI = I->second.begin(),
- TE = I->second.end(); TI != TE; ++TI)
- if (isa<Constant>(TI->second) || isa<Type>(TI->second))
- getOrCreateSlot(TI->second);
+ for (SymbolTable::type_const_iterator TI = ST->begin(), TE = ST->end(); TI != TE; ++TI)
+ for (SymbolTable::value_const_iterator VI = TI->second.begin(),
+ VE = TI->second.end(); VI != VE; ++VI)
+ if (isa<Constant>(VI->second) || isa<Type>(VI->second))
+ getOrCreateSlot(VI->second);
}
@@ -453,12 +454,13 @@
}
const SymbolTable &ST = F->getSymbolTable();
- for (SymbolTable::const_iterator I = ST.begin(), E = ST.end(); I != E; ++I)
- for (SymbolTable::type_const_iterator TI = I->second.begin(),
- TE = I->second.end(); TI != TE; ++TI)
- if (isa<Constant>(TI->second) || isa<Type>(TI->second) ||
- isa<GlobalValue>(TI->second))
- getOrCreateCompactionTableSlot(TI->second);
+ for (SymbolTable::type_const_iterator TI = ST.begin(), TE = ST.end();
+ TI != TE; ++TI)
+ for (SymbolTable::value_const_iterator VI = TI->second.begin(),
+ VE = TI->second.end(); VI != VE; ++VI)
+ if (isa<Constant>(VI->second) || isa<Type>(VI->second) ||
+ isa<GlobalValue>(VI->second))
+ getOrCreateCompactionTableSlot(VI->second);
// Now that we have all of the values in the table, and know what types are
// referenced, make sure that there is at least the zero initializer in any
Index: llvm/lib/VMCore/SymbolTable.cpp
diff -u llvm/lib/VMCore/SymbolTable.cpp:1.42 llvm/lib/VMCore/SymbolTable.cpp:1.42.6.1
--- llvm/lib/VMCore/SymbolTable.cpp:1.42 Wed Dec 31 01:08:19 2003
+++ llvm/lib/VMCore/SymbolTable.cpp Wed May 12 11:33:43 2004
@@ -23,10 +23,10 @@
SymbolTable::~SymbolTable() {
// Drop all abstract type references in the type plane...
- iterator TyPlane = find(Type::TypeTy);
- if (TyPlane != end()) {
- VarMap &TyP = TyPlane->second;
- for (VarMap::iterator I = TyP.begin(), E = TyP.end(); I != E; ++I) {
+ type_iterator TyPlane = map.find(Type::TypeTy);
+ if (TyPlane != map.end()) {
+ ValueMap &TyP = TyPlane->second;
+ for (value_iterator I = TyP.begin(), E = TyP.end(); I != E; ++I) {
const Type *Ty = cast<Type>(I->second);
if (Ty->isAbstract()) // If abstract, drop the reference...
cast<DerivedType>(Ty)->removeAbstractTypeUser(this);
@@ -38,8 +38,8 @@
#ifndef NDEBUG // Only do this in -g mode...
bool LeftoverValues = true;
- for (iterator i = begin(); i != end(); ++i) {
- for (type_iterator I = i->second.begin(); I != i->second.end(); ++I)
+ for (type_iterator i = map.begin(); i != map.end(); ++i) {
+ for (value_iterator I = i->second.begin(); I != i->second.end(); ++I)
if (!isa<Constant>(I->second) && !isa<Type>(I->second)) {
std::cerr << "Value still in symbol table! Type = '"
<< i->first->getDescription() << "' Name = '"
@@ -57,12 +57,12 @@
// the specified type.
//
std::string SymbolTable::getUniqueName(const Type *Ty,
- const std::string &BaseName) {
- iterator I = find(Ty);
- if (I == end()) return BaseName;
+ const std::string &BaseName) const {
+ type_const_iterator I = map.find(Ty);
+ if (I == map.end()) return BaseName;
std::string TryName = BaseName;
- type_iterator End = I->second.end();
+ value_const_iterator End = I->second.end();
while (I->second.find(TryName) != End) // Loop until we find a free
TryName = BaseName + utostr(++LastUnique); // name in the symbol table
@@ -73,9 +73,9 @@
// lookup - Returns null on failure...
Value *SymbolTable::lookup(const Type *Ty, const std::string &Name) const {
- const_iterator I = find(Ty);
- if (I != end()) { // We have symbols in that plane...
- type_const_iterator J = I->second.find(Name);
+ type_const_iterator I = map.find(Ty);
+ if (I != map.end()) { // We have symbols in that plane...
+ value_const_iterator J = I->second.find(Name);
if (J != I->second.end()) // and the name is in our hash table...
return J->second;
}
@@ -87,17 +87,17 @@
assert(N->hasName() && "Value doesn't have name!");
if (InternallyInconsistent) return;
- iterator I = find(N->getType());
- assert(I != end() &&
+ type_iterator I = map.find(N->getType());
+ assert(I != map.end() &&
"Trying to remove a type that doesn't have a plane yet!");
removeEntry(I, I->second.find(N->getName()));
}
// removeEntry - Remove a value from the symbol table...
//
-Value *SymbolTable::removeEntry(iterator Plane, type_iterator Entry) {
+Value *SymbolTable::removeEntry(type_iterator Plane, value_iterator Entry) {
if (InternallyInconsistent) return 0;
- assert(Plane != super::end() &&
+ assert(Plane != map.end() &&
Entry != Plane->second.end() && "Invalid entry to remove!");
Value *Result = Entry->second;
@@ -123,7 +123,7 @@
cast<DerivedType>(Plane->first)->removeAbstractTypeUser(this);
}
- erase(Plane);
+ map.erase(Plane);
}
// If we are removing an abstract type, remove the symbol table from it's use
@@ -163,11 +163,11 @@
<< VTy->getDescription() << "\n";
#endif
- iterator I = find(VTy);
- if (I == end()) { // Not in collection yet... insert dummy entry
+ type_iterator I = map.find(VTy);
+ if (I == map.end()) { // Not in collection yet... insert dummy entry
// Insert a new empty element. I points to the new elements.
- I = super::insert(make_pair(VTy, VarMap())).first;
- assert(I != end() && "How did insert fail?");
+ I = map.insert(make_pair(VTy, ValueMap())).first;
+ assert(I != map.end() && "How did insert fail?");
// Check to see if the type is abstract. If so, it might be refined in the
// future, which would cause the plane of the old type to get merged into
@@ -196,17 +196,71 @@
}
}
+bool
+SymbolTable::hasTypes( void ) const {
+ type_const_iterator PI = map.find(Type::TypeTy);
+ if (PI == map.end()) return false;
+ return true;
+}
+
+bool
+SymbolTable::isEmpty( void ) const {
+ return map.empty();
+}
+
+std::string SymbolTable::get_name( const Value* v ) const {
+ if (map.find(Type::TypeTy) == map.end())
+ return ""; // No names for types...
+
+ value_const_iterator VI = type_begin(Type::TypeTy);
+ value_const_iterator VE = type_end(Type::TypeTy);
+
+ while (VI != VE && VI->second != v )
+ ++VI;
+
+ if (VI != VE) // Must have found an entry!
+ return VI->first;
+ return ""; // Must not have found anything...
+}
+
+bool SymbolTable::strip( void ) {
+ bool RemovedSymbol = false;
+ for (type_iterator I = map.begin(); I != map.end();) {
+ // Removing items from the plane can cause the plane itself to get deleted.
+ // If this happens, make sure we incremented our plane iterator already!
+ ValueMap &Plane = (I++)->second;
+ value_iterator B = Plane.begin(), Bend = Plane.end();
+ while (B != Bend) { // Found nonempty type plane!
+ Value *V = B->second;
+
+ if (isa<Constant>(V) || isa<Type>(V)) {
+ type_remove(B++);
+ RemovedSymbol = true;
+ } else {
+ ++B;
+ if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasInternalLinkage()){
+ // Set name to "", removing from symbol table!
+ V->setName("", this);
+ RemovedSymbol = true;
+ }
+ }
+ }
+ }
+
+ return RemovedSymbol;
+}
+
// This function is called when one of the types in the type plane are refined
void SymbolTable::refineAbstractType(const DerivedType *OldType,
const Type *NewType) {
// Search to see if we have any values of the type oldtype. If so, we need to
// move them into the newtype plane...
- iterator TPI = find(OldType);
- if (TPI != end()) {
+ type_iterator TPI = map.find(OldType);
+ if (TPI != map.end()) {
// Get a handle to the new type plane...
- iterator NewTypeIt = find(NewType);
- if (NewTypeIt == super::end()) { // If no plane exists, add one
- NewTypeIt = super::insert(make_pair(NewType, VarMap())).first;
+ type_iterator NewTypeIt = map.find(NewType);
+ if (NewTypeIt == map.end()) { // If no plane exists, add one
+ NewTypeIt = map.insert(make_pair(NewType, ValueMap())).first;
if (NewType->isAbstract()) {
cast<DerivedType>(NewType)->addAbstractTypeUser(this);
@@ -217,14 +271,14 @@
}
}
- VarMap &NewPlane = NewTypeIt->second;
- VarMap &OldPlane = TPI->second;
+ ValueMap &NewPlane = NewTypeIt->second;
+ ValueMap &OldPlane = TPI->second;
while (!OldPlane.empty()) {
std::pair<const std::string, Value*> V = *OldPlane.begin();
// Check to see if there is already a value in the symbol table that this
// would collide with.
- type_iterator TI = NewPlane.find(V.first);
+ value_iterator TI = NewPlane.find(V.first);
if (TI != NewPlane.end() && TI->second == V.second) {
// No action
@@ -294,18 +348,18 @@
OldType->removeAbstractTypeUser(this);
// Remove the plane that is no longer used
- erase(TPI);
+ map.erase(TPI);
}
- TPI = find(Type::TypeTy);
- if (TPI != end()) {
+ TPI = map.find(Type::TypeTy);
+ if (TPI != map.end()) {
// Loop over all of the types in the symbol table, replacing any references
// to OldType with references to NewType. Note that there may be multiple
// occurrences, and although we only need to remove one at a time, it's
// faster to remove them all in one pass.
//
- VarMap &TyPlane = TPI->second;
- for (VarMap::iterator I = TyPlane.begin(), E = TyPlane.end(); I != E; ++I)
+ ValueMap &TyPlane = TPI->second;
+ for (value_iterator I = TyPlane.begin(), E = TyPlane.end(); I != E; ++I)
if (I->second == (Value*)OldType) { // FIXME when Types aren't const.
#if DEBUG_ABSTYPE
std::cerr << "Removing type " << OldType->getDescription() << "\n";
@@ -324,21 +378,21 @@
}
void SymbolTable::typeBecameConcrete(const DerivedType *AbsTy) {
- iterator TPI = find(AbsTy);
+ type_iterator TPI = map.find(AbsTy);
// If there are any values in the symbol table of this type, then the type
// plan is a use of the abstract type which must be dropped.
- if (TPI != end())
+ if (TPI != map.end())
AbsTy->removeAbstractTypeUser(this);
- TPI = find(Type::TypeTy);
- if (TPI != end()) {
+ TPI = map.find(Type::TypeTy);
+ if (TPI != map.end()) {
// Loop over all of the types in the symbol table, dropping any abstract
// type user entries for AbsTy which occur because there are names for the
// type.
//
- VarMap &TyPlane = TPI->second;
- for (VarMap::iterator I = TyPlane.begin(), E = TyPlane.end(); I != E; ++I)
+ ValueMap &TyPlane = TPI->second;
+ for (value_iterator I = TyPlane.begin(), E = TyPlane.end(); I != E; ++I)
if (I->second == (Value*)AbsTy) // FIXME when Types aren't const.
AbsTy->removeAbstractTypeUser(this);
}
@@ -360,5 +414,7 @@
void SymbolTable::dump() const {
std::cout << "Symbol table dump:\n";
- for_each(begin(), end(), DumpPlane);
+ for_each(map.begin(), map.end(), DumpPlane);
}
+
+// vim: sw=2 ai
Index: llvm/lib/VMCore/Verifier.cpp
diff -u llvm/lib/VMCore/Verifier.cpp:1.97 llvm/lib/VMCore/Verifier.cpp:1.97.2.1
--- llvm/lib/VMCore/Verifier.cpp:1.97 Tue May 4 16:46:05 2004
+++ llvm/lib/VMCore/Verifier.cpp Wed May 12 11:33:43 2004
@@ -240,20 +240,19 @@
// verifySymbolTable - Verify that a function or module symbol table is ok
//
void Verifier::verifySymbolTable(SymbolTable &ST) {
- // Loop over all of the types in the symbol table...
- for (SymbolTable::iterator TI = ST.begin(), TE = ST.end(); TI != TE; ++TI)
- for (SymbolTable::type_iterator I = TI->second.begin(),
- E = TI->second.end(); I != E; ++I) {
- Value *V = I->second;
- // Check that there are no void typed values in the symbol table. Values
- // with a void type cannot be put into symbol tables because they cannot
- // have names!
- Assert1(V->getType() != Type::VoidTy,
- "Values with void type are not allowed to have names!", V);
- }
+ // Loop over all of the types in the symbol table...
+ for (SymbolTable::type_const_iterator TI = ST.begin(), TE = ST.end(); TI != TE; ++TI)
+ for (SymbolTable::value_const_iterator I = TI->second.begin(),
+ E = TI->second.end(); I != E; ++I) {
+ Value *V = I->second;
+ // Check that there are no void typed values in the symbol table. Values
+ // with a void type cannot be put into symbol tables because they cannot
+ // have names!
+ Assert1(V->getType() != Type::VoidTy,
+ "Values with void type are not allowed to have names!", V);
+ }
}
-
// visitFunction - Verify that a function is ok.
//
More information about the llvm-commits
mailing list