summaryrefslogtreecommitdiffstats
path: root/lib/VMCore/TypeSymbolTable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore/TypeSymbolTable.cpp')
-rw-r--r--lib/VMCore/TypeSymbolTable.cpp60
1 files changed, 36 insertions, 24 deletions
diff --git a/lib/VMCore/TypeSymbolTable.cpp b/lib/VMCore/TypeSymbolTable.cpp
index 5ae60e2..f31ea66 100644
--- a/lib/VMCore/TypeSymbolTable.cpp
+++ b/lib/VMCore/TypeSymbolTable.cpp
@@ -14,8 +14,9 @@
#include "llvm/TypeSymbolTable.h"
#include "llvm/DerivedTypes.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/Streams.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/System/RWMutex.h"
#include "llvm/System/Threading.h"
#include <algorithm>
@@ -34,22 +35,22 @@ TypeSymbolTable::~TypeSymbolTable() {
}
}
-std::string TypeSymbolTable::getUniqueName(const std::string &BaseName) const {
+std::string TypeSymbolTable::getUniqueName(const StringRef &BaseName) const {
std::string TryName = BaseName;
- sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
+ sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
const_iterator End = tmap.end();
// See if the name exists
while (tmap.find(TryName) != End) // Loop until we find a free
- TryName = BaseName + utostr(++LastUnique); // name in the symbol table
+ TryName = BaseName.str() + utostr(++LastUnique); // name in the symbol table
return TryName;
}
// lookup a type by name - returns null on failure
-Type* TypeSymbolTable::lookup(const std::string& Name) const {
- sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
+Type* TypeSymbolTable::lookup(const StringRef &Name) const {
+ sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
const_iterator TI = tmap.find(Name);
Type* result = 0;
@@ -58,6 +59,17 @@ Type* TypeSymbolTable::lookup(const std::string& Name) const {
return result;
}
+TypeSymbolTable::iterator TypeSymbolTable::find(const StringRef &Name) {
+ sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
+ return tmap.find(Name);
+}
+
+TypeSymbolTable::const_iterator
+TypeSymbolTable::find(const StringRef &Name) const {
+ sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
+ return tmap.find(Name);
+}
+
// remove - Remove a type from the symbol table...
Type* TypeSymbolTable::remove(iterator Entry) {
TypeSymbolTableLock->writer_acquire();
@@ -67,7 +79,7 @@ Type* TypeSymbolTable::remove(iterator Entry) {
#if DEBUG_SYMBOL_TABLE
dump();
- cerr << " Removing Value: " << Result->getName() << "\n";
+ errs() << " Removing Value: " << Result->getDescription() << "\n";
#endif
tmap.erase(Entry);
@@ -78,9 +90,9 @@ Type* TypeSymbolTable::remove(iterator Entry) {
// list...
if (Result->isAbstract()) {
#if DEBUG_ABSTYPE
- cerr << "Removing abstract type from symtab"
- << Result->getDescription()
- << "\n";
+ errs() << "Removing abstract type from symtab"
+ << Result->getDescription()
+ << "\n";
#endif
cast<DerivedType>(Result)->removeAbstractTypeUser(this);
}
@@ -90,17 +102,17 @@ Type* TypeSymbolTable::remove(iterator Entry) {
// insert - Insert a type into the symbol table with the specified name...
-void TypeSymbolTable::insert(const std::string& Name, const Type* T) {
+void TypeSymbolTable::insert(const StringRef &Name, const Type* T) {
assert(T && "Can't insert null type into symbol table!");
TypeSymbolTableLock->writer_acquire();
- if (tmap.insert(make_pair(Name, T)).second) {
+ if (tmap.insert(std::make_pair(Name, T)).second) {
// Type inserted fine with no conflict.
#if DEBUG_SYMBOL_TABLE
dump();
- cerr << " Inserted type: " << Name << ": " << T->getDescription() << "\n";
+ errs() << " Inserted type: " << Name << ": " << T->getDescription() << "\n";
#endif
} else {
// If there is a name conflict...
@@ -112,8 +124,8 @@ void TypeSymbolTable::insert(const std::string& Name, const Type* T) {
#if DEBUG_SYMBOL_TABLE
dump();
- cerr << " Inserting type: " << UniqueName << ": "
- << T->getDescription() << "\n";
+ errs() << " Inserting type: " << UniqueName << ": "
+ << T->getDescription() << "\n";
#endif
// Insert the tmap entry
@@ -126,7 +138,7 @@ void TypeSymbolTable::insert(const std::string& Name, const Type* T) {
if (T->isAbstract()) {
cast<DerivedType>(T)->addAbstractTypeUser(this);
#if DEBUG_ABSTYPE
- cerr << "Added abstract type to ST: " << T->getDescription() << "\n";
+ errs() << "Added abstract type to ST: " << T->getDescription() << "\n";
#endif
}
}
@@ -134,7 +146,7 @@ void TypeSymbolTable::insert(const std::string& Name, const Type* T) {
// This function is called when one of the types in the type plane are refined
void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
const Type *NewType) {
- sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
+ sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
// 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
@@ -144,14 +156,14 @@ void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
for (iterator I = begin(), E = end(); I != E; ++I) {
if (I->second == (Type*)OldType) { // FIXME when Types aren't const.
#if DEBUG_ABSTYPE
- cerr << "Removing type " << OldType->getDescription() << "\n";
+ errs() << "Removing type " << OldType->getDescription() << "\n";
#endif
OldType->removeAbstractTypeUser(this);
I->second = (Type*)NewType; // TODO FIXME when types aren't const
if (NewType->isAbstract()) {
#if DEBUG_ABSTYPE
- cerr << "Added type " << NewType->getDescription() << "\n";
+ errs() << "Added type " << NewType->getDescription() << "\n";
#endif
cast<DerivedType>(NewType)->addAbstractTypeUser(this);
}
@@ -165,21 +177,21 @@ void TypeSymbolTable::typeBecameConcrete(const DerivedType *AbsTy) {
// 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.
- sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
+ sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
for (iterator TI = begin(), TE = end(); TI != TE; ++TI)
if (TI->second == const_cast<Type*>(static_cast<const Type*>(AbsTy)))
AbsTy->removeAbstractTypeUser(this);
}
static void DumpTypes(const std::pair<const std::string, const Type*>& T ) {
- cerr << " '" << T.first << "' = ";
+ errs() << " '" << T.first << "' = ";
T.second->dump();
- cerr << "\n";
+ errs() << "\n";
}
void TypeSymbolTable::dump() const {
- cerr << "TypeSymbolPlane: ";
- sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock);
+ errs() << "TypeSymbolPlane: ";
+ sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
for_each(tmap.begin(), tmap.end(), DumpTypes);
}
OpenPOWER on IntegriCloud