Have scoped mutexes take referenes instead of pointers.

llvm-svn: 74931
This commit is contained in:
Owen Anderson 2009-07-07 18:33:04 +00:00
parent f840ed7ed4
commit 5c96ef7c4e
18 changed files with 76 additions and 78 deletions

View File

@ -131,15 +131,15 @@ namespace llvm
template<bool mt_only> template<bool mt_only>
class SmartScopedLock { class SmartScopedLock {
SmartMutex<mt_only>* mtx; SmartMutex<mt_only>& mtx;
public: public:
SmartScopedLock(SmartMutex<mt_only>* m) : mtx(m) { SmartScopedLock(SmartMutex<mt_only>& m) : mtx(m) {
mtx->acquire(); mtx.acquire();
} }
~SmartScopedLock() { ~SmartScopedLock() {
mtx->release(); mtx.release();
} }
}; };

View File

@ -141,15 +141,14 @@ namespace llvm
/// ScopedReader - RAII acquisition of a reader lock /// ScopedReader - RAII acquisition of a reader lock
template<bool mt_only> template<bool mt_only>
struct SmartScopedReader { struct SmartScopedReader {
SmartRWMutex<mt_only>* mutex; SmartRWMutex<mt_only>& mutex;
explicit SmartScopedReader(SmartRWMutex<mt_only>* m) { explicit SmartScopedReader(SmartRWMutex<mt_only>& m) : mutex(m) {
mutex = m; mutex.reader_acquire();
mutex->reader_acquire();
} }
~SmartScopedReader() { ~SmartScopedReader() {
mutex->reader_release(); mutex.reader_release();
} }
}; };
typedef SmartScopedReader<false> ScopedReader; typedef SmartScopedReader<false> ScopedReader;
@ -157,15 +156,14 @@ namespace llvm
/// ScopedWriter - RAII acquisition of a writer lock /// ScopedWriter - RAII acquisition of a writer lock
template<bool mt_only> template<bool mt_only>
struct SmartScopedWriter { struct SmartScopedWriter {
SmartRWMutex<mt_only>* mutex; SmartRWMutex<mt_only>& mutex;
explicit SmartScopedWriter(SmartRWMutex<mt_only>* m) { explicit SmartScopedWriter(SmartRWMutex<mt_only>& m) : mutex(m) {
mutex = m; mutex.writer_acquire();
mutex->writer_acquire();
} }
~SmartScopedWriter() { ~SmartScopedWriter() {
mutex->writer_release(); mutex.writer_release();
} }
}; };
typedef SmartScopedWriter<false> ScopedWriter; typedef SmartScopedWriter<false> ScopedWriter;

View File

@ -5010,7 +5010,7 @@ static ManagedStatic<sys::SmartMutex<true> > VTMutex;
/// getValueTypeList - Return a pointer to the specified value type. /// getValueTypeList - Return a pointer to the specified value type.
/// ///
const MVT *SDNode::getValueTypeList(MVT VT) { const MVT *SDNode::getValueTypeList(MVT VT) {
sys::SmartScopedLock<true> Lock(&*VTMutex); sys::SmartScopedLock<true> Lock(*VTMutex);
if (VT.isExtended()) { if (VT.isExtended()) {
return &(*EVTs->insert(VT).first); return &(*EVTs->insert(VT).first);
} else { } else {

View File

@ -42,7 +42,7 @@ namespace {
namespace llvmc { namespace llvmc {
PluginLoader::PluginLoader() { PluginLoader::PluginLoader() {
llvm::sys::SmartScopedLock<true> Lock(&*PluginMutex); llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
if (!pluginListInitialized) { if (!pluginListInitialized) {
for (PluginRegistry::iterator B = PluginRegistry::begin(), for (PluginRegistry::iterator B = PluginRegistry::begin(),
E = PluginRegistry::end(); B != E; ++B) E = PluginRegistry::end(); B != E; ++B)
@ -53,7 +53,7 @@ namespace llvmc {
} }
PluginLoader::~PluginLoader() { PluginLoader::~PluginLoader() {
llvm::sys::SmartScopedLock<true> Lock(&*PluginMutex); llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
if (pluginListInitialized) { if (pluginListInitialized) {
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
B != E; ++B) B != E; ++B)
@ -63,14 +63,14 @@ namespace llvmc {
} }
void PluginLoader::PopulateLanguageMap(LanguageMap& langMap) { void PluginLoader::PopulateLanguageMap(LanguageMap& langMap) {
llvm::sys::SmartScopedLock<true> Lock(&*PluginMutex); llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
B != E; ++B) B != E; ++B)
(*B)->PopulateLanguageMap(langMap); (*B)->PopulateLanguageMap(langMap);
} }
void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) { void PluginLoader::PopulateCompilationGraph(CompilationGraph& graph) {
llvm::sys::SmartScopedLock<true> Lock(&*PluginMutex); llvm::sys::SmartScopedLock<true> Lock(*PluginMutex);
for (PluginList::iterator B = Plugins.begin(), E = Plugins.end(); for (PluginList::iterator B = Plugins.begin(), E = Plugins.end();
B != E; ++B) B != E; ++B)
(*B)->PopulateCompilationGraph(graph); (*B)->PopulateCompilationGraph(graph);

View File

@ -97,7 +97,7 @@ static ExFunc lookupFunction(const Function *F) {
ExtName += getTypeID(FT->getContainedType(i)); ExtName += getTypeID(FT->getContainedType(i));
ExtName += "_" + F->getName(); ExtName += "_" + F->getName();
sys::ScopedLock Writer(&*FunctionsLock); sys::ScopedLock Writer(*FunctionsLock);
ExFunc FnPtr = FuncNames[ExtName]; ExFunc FnPtr = FuncNames[ExtName];
if (FnPtr == 0) if (FnPtr == 0)
FnPtr = FuncNames["lle_X_"+F->getName()]; FnPtr = FuncNames["lle_X_"+F->getName()];
@ -539,7 +539,7 @@ GenericValue lle_X_fprintf(const FunctionType *FT,
void Interpreter::initializeExternalFunctions() { void Interpreter::initializeExternalFunctions() {
sys::ScopedLock Writer(&*FunctionsLock); sys::ScopedLock Writer(*FunctionsLock);
FuncNames["lle_X_atexit"] = lle_X_atexit; FuncNames["lle_X_atexit"] = lle_X_atexit;
FuncNames["lle_X_exit"] = lle_X_exit; FuncNames["lle_X_exit"] = lle_X_exit;
FuncNames["lle_X_abort"] = lle_X_abort; FuncNames["lle_X_abort"] = lle_X_abort;

View File

@ -55,7 +55,7 @@ static FactMapType &getFactMap() {
} }
static void eraseFromFactMap(unsigned ID) { static void eraseFromFactMap(unsigned ID) {
sys::SmartScopedWriter<true> Writer(&*AnnotationsLock); sys::SmartScopedWriter<true> Writer(*AnnotationsLock);
TheFactMap->erase(ID); TheFactMap->erase(ID);
} }
@ -66,7 +66,7 @@ AnnotationID AnnotationManager::getID(const char *Name) { // Name -> ID
AnnotationsLock->reader_release(); AnnotationsLock->reader_release();
if (I == E) { if (I == E) {
sys::SmartScopedWriter<true> Writer(&*AnnotationsLock); sys::SmartScopedWriter<true> Writer(*AnnotationsLock);
I = IDMap->find(Name); I = IDMap->find(Name);
if (I == IDMap->end()) { if (I == IDMap->end()) {
unsigned newCount = sys::AtomicIncrement(&IDCounter); unsigned newCount = sys::AtomicIncrement(&IDCounter);
@ -91,7 +91,7 @@ AnnotationID AnnotationManager::getID(const char *Name, Factory Fact,
// only be used for debugging. // only be used for debugging.
// //
const char *AnnotationManager::getName(AnnotationID ID) { // ID -> Name const char *AnnotationManager::getName(AnnotationID ID) { // ID -> Name
sys::SmartScopedReader<true> Reader(&*AnnotationsLock); sys::SmartScopedReader<true> Reader(*AnnotationsLock);
IDMapType &TheMap = *IDMap; IDMapType &TheMap = *IDMap;
for (IDMapType::iterator I = TheMap.begin(); ; ++I) { for (IDMapType::iterator I = TheMap.begin(); ; ++I) {
assert(I != TheMap.end() && "Annotation ID is unknown!"); assert(I != TheMap.end() && "Annotation ID is unknown!");
@ -106,7 +106,7 @@ const char *AnnotationManager::getName(AnnotationID ID) { // ID -> Name
void AnnotationManager::registerAnnotationFactory(AnnotationID ID, AnnFactory F, void AnnotationManager::registerAnnotationFactory(AnnotationID ID, AnnFactory F,
void *ExtraData) { void *ExtraData) {
if (F) { if (F) {
sys::SmartScopedWriter<true> Writer(&*AnnotationsLock); sys::SmartScopedWriter<true> Writer(*AnnotationsLock);
getFactMap()[ID.ID] = std::make_pair(F, ExtraData); getFactMap()[ID.ID] = std::make_pair(F, ExtraData);
} else { } else {
eraseFromFactMap(ID.ID); eraseFromFactMap(ID.ID);

View File

@ -25,7 +25,7 @@ static ManagedStatic<std::vector<std::string> > Plugins;
static ManagedStatic<sys::SmartMutex<true> > PluginsLock; static ManagedStatic<sys::SmartMutex<true> > PluginsLock;
void PluginLoader::operator=(const std::string &Filename) { void PluginLoader::operator=(const std::string &Filename) {
sys::SmartScopedLock<true> Lock(&*PluginsLock); sys::SmartScopedLock<true> Lock(*PluginsLock);
std::string Error; std::string Error;
if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) { if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
cerr << "Error opening '" << Filename << "': " << Error cerr << "Error opening '" << Filename << "': " << Error
@ -36,12 +36,12 @@ void PluginLoader::operator=(const std::string &Filename) {
} }
unsigned PluginLoader::getNumPlugins() { unsigned PluginLoader::getNumPlugins() {
sys::SmartScopedLock<true> Lock(&*PluginsLock); sys::SmartScopedLock<true> Lock(*PluginsLock);
return Plugins.isConstructed() ? Plugins->size() : 0; return Plugins.isConstructed() ? Plugins->size() : 0;
} }
std::string &PluginLoader::getPlugin(unsigned num) { std::string &PluginLoader::getPlugin(unsigned num) {
sys::SmartScopedLock<true> Lock(&*PluginsLock); sys::SmartScopedLock<true> Lock(*PluginsLock);
assert(Plugins.isConstructed() && num < Plugins->size() && assert(Plugins.isConstructed() && num < Plugins->size() &&
"Asking for an out of bounds plugin"); "Asking for an out of bounds plugin");
return (*Plugins)[num]; return (*Plugins)[num];

View File

@ -65,7 +65,7 @@ static ManagedStatic<sys::Mutex> StatLock;
void Statistic::RegisterStatistic() { void Statistic::RegisterStatistic() {
// If stats are enabled, inform StatInfo that this statistic should be // If stats are enabled, inform StatInfo that this statistic should be
// printed. // printed.
sys::ScopedLock Writer(&*StatLock); sys::ScopedLock Writer(*StatLock);
if (!Initialized) { if (!Initialized) {
if (Enabled) if (Enabled)
StatInfo->addStatistic(this); StatInfo->addStatistic(this);

View File

@ -145,7 +145,7 @@ static TimeRecord getTimeRecord(bool Start) {
static ManagedStatic<std::vector<Timer*> > ActiveTimers; static ManagedStatic<std::vector<Timer*> > ActiveTimers;
void Timer::startTimer() { void Timer::startTimer() {
sys::SmartScopedLock<true> L(&Lock); sys::SmartScopedLock<true> L(Lock);
Started = true; Started = true;
ActiveTimers->push_back(this); ActiveTimers->push_back(this);
TimeRecord TR = getTimeRecord(true); TimeRecord TR = getTimeRecord(true);
@ -157,7 +157,7 @@ void Timer::startTimer() {
} }
void Timer::stopTimer() { void Timer::stopTimer() {
sys::SmartScopedLock<true> L(&Lock); sys::SmartScopedLock<true> L(Lock);
TimeRecord TR = getTimeRecord(false); TimeRecord TR = getTimeRecord(false);
Elapsed += TR.Elapsed; Elapsed += TR.Elapsed;
UserTime += TR.UserTime; UserTime += TR.UserTime;
@ -229,7 +229,7 @@ static ManagedStatic<Name2Timer> NamedTimers;
static ManagedStatic<Name2Pair> NamedGroupedTimers; static ManagedStatic<Name2Pair> NamedGroupedTimers;
static Timer &getNamedRegionTimer(const std::string &Name) { static Timer &getNamedRegionTimer(const std::string &Name) {
sys::SmartScopedLock<true> L(&*TimerLock); sys::SmartScopedLock<true> L(*TimerLock);
Name2Timer::iterator I = NamedTimers->find(Name); Name2Timer::iterator I = NamedTimers->find(Name);
if (I != NamedTimers->end()) if (I != NamedTimers->end())
return I->second; return I->second;
@ -239,7 +239,7 @@ static Timer &getNamedRegionTimer(const std::string &Name) {
static Timer &getNamedRegionTimer(const std::string &Name, static Timer &getNamedRegionTimer(const std::string &Name,
const std::string &GroupName) { const std::string &GroupName) {
sys::SmartScopedLock<true> L(&*TimerLock); sys::SmartScopedLock<true> L(*TimerLock);
Name2Pair::iterator I = NamedGroupedTimers->find(GroupName); Name2Pair::iterator I = NamedGroupedTimers->find(GroupName);
if (I == NamedGroupedTimers->end()) { if (I == NamedGroupedTimers->end()) {
@ -365,7 +365,7 @@ llvm::GetLibSupportInfoOutputFile() {
void TimerGroup::removeTimer() { void TimerGroup::removeTimer() {
sys::SmartScopedLock<true> L(&*TimerLock); sys::SmartScopedLock<true> L(*TimerLock);
if (--NumTimers == 0 && !TimersToPrint.empty()) { // Print timing report... if (--NumTimers == 0 && !TimersToPrint.empty()) { // Print timing report...
// Sort the timers in descending order by amount of time taken... // Sort the timers in descending order by amount of time taken...
std::sort(TimersToPrint.begin(), TimersToPrint.end(), std::sort(TimersToPrint.begin(), TimersToPrint.end(),
@ -434,12 +434,12 @@ void TimerGroup::removeTimer() {
} }
void TimerGroup::addTimer() { void TimerGroup::addTimer() {
sys::SmartScopedLock<true> L(&*TimerLock); sys::SmartScopedLock<true> L(*TimerLock);
++NumTimers; ++NumTimers;
} }
void TimerGroup::addTimerToPrint(const Timer &T) { void TimerGroup::addTimerToPrint(const Timer &T) {
sys::SmartScopedLock<true> L(&*TimerLock); sys::SmartScopedLock<true> L(*TimerLock);
TimersToPrint.push_back(Timer(true, T)); TimersToPrint.push_back(Timer(true, T));
} }

View File

@ -352,7 +352,7 @@ TargetData::~TargetData() {
if (!LayoutInfo.isConstructed()) if (!LayoutInfo.isConstructed())
return; return;
sys::SmartScopedLock<true> Lock(&*LayoutLock); sys::SmartScopedLock<true> Lock(*LayoutLock);
// Remove any layouts for this TD. // Remove any layouts for this TD.
LayoutInfoTy &TheMap = *LayoutInfo; LayoutInfoTy &TheMap = *LayoutInfo;
for (LayoutInfoTy::iterator I = TheMap.begin(), E = TheMap.end(); I != E; ) { for (LayoutInfoTy::iterator I = TheMap.begin(), E = TheMap.end(); I != E; ) {
@ -369,7 +369,7 @@ TargetData::~TargetData() {
const StructLayout *TargetData::getStructLayout(const StructType *Ty) const { const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
LayoutInfoTy &TheMap = *LayoutInfo; LayoutInfoTy &TheMap = *LayoutInfo;
sys::SmartScopedLock<true> Lock(&*LayoutLock); sys::SmartScopedLock<true> Lock(*LayoutLock);
StructLayout *&SL = TheMap[LayoutKey(this, Ty)]; StructLayout *&SL = TheMap[LayoutKey(this, Ty)];
if (SL) return SL; if (SL) return SL;
@ -394,7 +394,7 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const { void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
if (!LayoutInfo.isConstructed()) return; // No cache. if (!LayoutInfo.isConstructed()) return; // No cache.
sys::SmartScopedLock<true> Lock(&*LayoutLock); sys::SmartScopedLock<true> Lock(*LayoutLock);
LayoutInfoTy::iterator I = LayoutInfo->find(LayoutKey(this, Ty)); LayoutInfoTy::iterator I = LayoutInfo->find(LayoutKey(this, Ty));
if (I == LayoutInfo->end()) return; if (I == LayoutInfo->end()) return;

View File

@ -307,7 +307,7 @@ ConstantInt *ConstantInt::get(const APInt& V) {
ConstantsLock->reader_release(); ConstantsLock->reader_release();
if (!Slot) { if (!Slot) {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
ConstantInt *&NewSlot = (*IntConstants)[Key]; ConstantInt *&NewSlot = (*IntConstants)[Key];
if (!Slot) { if (!Slot) {
NewSlot = new ConstantInt(ITy, V); NewSlot = new ConstantInt(ITy, V);
@ -414,7 +414,7 @@ ConstantFP *ConstantFP::get(const APFloat &V) {
ConstantsLock->reader_release(); ConstantsLock->reader_release();
if (!Slot) { if (!Slot) {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
ConstantFP *&NewSlot = (*FPConstants)[Key]; ConstantFP *&NewSlot = (*FPConstants)[Key];
if (!NewSlot) { if (!NewSlot) {
const Type *Ty; const Type *Ty;
@ -1231,7 +1231,7 @@ public:
/// getOrCreate - Return the specified constant from the map, creating it if /// getOrCreate - Return the specified constant from the map, creating it if
/// necessary. /// necessary.
ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) { ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
sys::SmartScopedLock<true> Lock(&ValueMapLock); sys::SmartScopedLock<true> Lock(ValueMapLock);
MapKey Lookup(Ty, V); MapKey Lookup(Ty, V);
ConstantClass* Result = 0; ConstantClass* Result = 0;
@ -1249,7 +1249,7 @@ public:
} }
void remove(ConstantClass *CP) { void remove(ConstantClass *CP) {
sys::SmartScopedLock<true> Lock(&ValueMapLock); sys::SmartScopedLock<true> Lock(ValueMapLock);
typename MapTy::iterator I = FindExistingElement(CP); typename MapTy::iterator I = FindExistingElement(CP);
assert(I != Map.end() && "Constant not found in constant table!"); assert(I != Map.end() && "Constant not found in constant table!");
assert(I->second == CP && "Didn't find correct element?"); assert(I->second == CP && "Didn't find correct element?");
@ -1334,7 +1334,7 @@ public:
} }
void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) { void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
sys::SmartScopedLock<true> Lock(&ValueMapLock); sys::SmartScopedLock<true> Lock(ValueMapLock);
typename AbstractTypeMapTy::iterator I = typename AbstractTypeMapTy::iterator I =
AbstractTypeMap.find(cast<Type>(OldTy)); AbstractTypeMap.find(cast<Type>(OldTy));
@ -1793,7 +1793,7 @@ MDString::MDString(const char *begin, const char *end)
static ManagedStatic<StringMap<MDString*> > MDStringCache; static ManagedStatic<StringMap<MDString*> > MDStringCache;
MDString *MDString::get(const char *StrBegin, const char *StrEnd) { MDString *MDString::get(const char *StrBegin, const char *StrEnd) {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue( StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(
StrBegin, StrEnd); StrBegin, StrEnd);
MDString *&S = Entry.getValue(); MDString *&S = Entry.getValue();
@ -1804,7 +1804,7 @@ MDString *MDString::get(const char *StrBegin, const char *StrEnd) {
} }
MDString *MDString::get(const std::string &Str) { MDString *MDString::get(const std::string &Str) {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue( StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(
Str.data(), Str.data() + Str.size()); Str.data(), Str.data() + Str.size());
MDString *&S = Entry.getValue(); MDString *&S = Entry.getValue();
@ -1815,7 +1815,7 @@ MDString *MDString::get(const std::string &Str) {
} }
void MDString::destroyConstant() { void MDString::destroyConstant() {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd)); MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd));
destroyConstantImpl(); destroyConstantImpl();
} }
@ -1847,7 +1847,7 @@ MDNode *MDNode::get(Value*const* Vals, unsigned NumVals) {
ConstantsLock->reader_release(); ConstantsLock->reader_release();
if (!N) { if (!N) {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint); N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint);
if (!N) { if (!N) {
// InsertPoint will have been set by the FindNodeOrInsertPos call. // InsertPoint will have been set by the FindNodeOrInsertPos call.
@ -1859,7 +1859,7 @@ MDNode *MDNode::get(Value*const* Vals, unsigned NumVals) {
} }
void MDNode::destroyConstant() { void MDNode::destroyConstant() {
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
MDNodeSet->RemoveNode(this); MDNodeSet->RemoveNode(this);
destroyConstantImpl(); destroyConstantImpl();
@ -2790,7 +2790,7 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
Replacement = ConstantAggregateZero::get(getType()); Replacement = ConstantAggregateZero::get(getType());
} else { } else {
// Check to see if we have this array type already. // Check to see if we have this array type already.
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
bool Exists; bool Exists;
ArrayConstantsTy::MapTy::iterator I = ArrayConstantsTy::MapTy::iterator I =
ArrayConstants->InsertOrGetItem(Lookup, Exists); ArrayConstants->InsertOrGetItem(Lookup, Exists);
@ -2866,7 +2866,7 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
Replacement = ConstantAggregateZero::get(getType()); Replacement = ConstantAggregateZero::get(getType());
} else { } else {
// Check to see if we have this array type already. // Check to see if we have this array type already.
sys::SmartScopedWriter<true> Writer(&*ConstantsLock); sys::SmartScopedWriter<true> Writer(*ConstantsLock);
bool Exists; bool Exists;
StructConstantsTy::MapTy::iterator I = StructConstantsTy::MapTy::iterator I =
StructConstants->InsertOrGetItem(Lookup, Exists); StructConstants->InsertOrGetItem(Lookup, Exists);

View File

@ -242,18 +242,18 @@ static StringPool *GCNamePool;
static ManagedStatic<sys::SmartRWMutex<true> > GCLock; static ManagedStatic<sys::SmartRWMutex<true> > GCLock;
bool Function::hasGC() const { bool Function::hasGC() const {
sys::SmartScopedReader<true> Reader(&*GCLock); sys::SmartScopedReader<true> Reader(*GCLock);
return GCNames && GCNames->count(this); return GCNames && GCNames->count(this);
} }
const char *Function::getGC() const { const char *Function::getGC() const {
assert(hasGC() && "Function has no collector"); assert(hasGC() && "Function has no collector");
sys::SmartScopedReader<true> Reader(&*GCLock); sys::SmartScopedReader<true> Reader(*GCLock);
return *(*GCNames)[this]; return *(*GCNames)[this];
} }
void Function::setGC(const char *Str) { void Function::setGC(const char *Str) {
sys::SmartScopedWriter<true> Writer(&*GCLock); sys::SmartScopedWriter<true> Writer(*GCLock);
if (!GCNamePool) if (!GCNamePool)
GCNamePool = new StringPool(); GCNamePool = new StringPool();
if (!GCNames) if (!GCNames)
@ -262,7 +262,7 @@ void Function::setGC(const char *Str) {
} }
void Function::clearGC() { void Function::clearGC() {
sys::SmartScopedWriter<true> Writer(&*GCLock); sys::SmartScopedWriter<true> Writer(*GCLock);
if (GCNames) { if (GCNames) {
GCNames->erase(this); GCNames->erase(this);
if (GCNames->empty()) { if (GCNames->empty()) {

View File

@ -54,7 +54,7 @@ namespace {
// immediately, it is added to the CachedValue Value. If it is // immediately, it is added to the CachedValue Value. If it is
// immediately removed, no set search need be performed. // immediately removed, no set search need be performed.
void addGarbage(const T* o) { void addGarbage(const T* o) {
sys::SmartScopedWriter<true> Writer(&*LeakDetectorLock); sys::SmartScopedWriter<true> Writer(*LeakDetectorLock);
if (Cache) { if (Cache) {
assert(Ts.count(Cache) == 0 && "Object already in set!"); assert(Ts.count(Cache) == 0 && "Object already in set!");
Ts.insert(Cache); Ts.insert(Cache);
@ -63,7 +63,7 @@ namespace {
} }
void removeGarbage(const T* o) { void removeGarbage(const T* o) {
sys::SmartScopedWriter<true> Writer(&*LeakDetectorLock); sys::SmartScopedWriter<true> Writer(*LeakDetectorLock);
if (o == Cache) if (o == Cache)
Cache = 0; // Cache hit Cache = 0; // Cache hit
else else
@ -73,7 +73,7 @@ namespace {
bool hasGarbage(const std::string& Message) { bool hasGarbage(const std::string& Message) {
addGarbage(0); // Flush the Cache addGarbage(0); // Flush the Cache
sys::SmartScopedReader<true> Reader(&*LeakDetectorLock); sys::SmartScopedReader<true> Reader(*LeakDetectorLock);
assert(Cache == 0 && "No value should be cached anymore!"); assert(Cache == 0 && "No value should be cached anymore!");
if (!Ts.empty()) { if (!Ts.empty()) {

View File

@ -233,7 +233,7 @@ void PassInfo::registerPass() {
getPassRegistrar()->RegisterPass(*this); getPassRegistrar()->RegisterPass(*this);
// Notify any listeners. // Notify any listeners.
sys::SmartScopedLock<true> Lock(&ListenersLock); sys::SmartScopedLock<true> Lock(ListenersLock);
if (Listeners) if (Listeners)
for (std::vector<PassRegistrationListener*>::iterator for (std::vector<PassRegistrationListener*>::iterator
I = Listeners->begin(), E = Listeners->end(); I != E; ++I) I = Listeners->begin(), E = Listeners->end(); I != E; ++I)
@ -286,14 +286,14 @@ RegisterAGBase::RegisterAGBase(const char *Name, intptr_t InterfaceID,
// PassRegistrationListener ctor - Add the current object to the list of // PassRegistrationListener ctor - Add the current object to the list of
// PassRegistrationListeners... // PassRegistrationListeners...
PassRegistrationListener::PassRegistrationListener() { PassRegistrationListener::PassRegistrationListener() {
sys::SmartScopedLock<true> Lock(&ListenersLock); sys::SmartScopedLock<true> Lock(ListenersLock);
if (!Listeners) Listeners = new std::vector<PassRegistrationListener*>(); if (!Listeners) Listeners = new std::vector<PassRegistrationListener*>();
Listeners->push_back(this); Listeners->push_back(this);
} }
// dtor - Remove object from list of listeners... // dtor - Remove object from list of listeners...
PassRegistrationListener::~PassRegistrationListener() { PassRegistrationListener::~PassRegistrationListener() {
sys::SmartScopedLock<true> Lock(&ListenersLock); sys::SmartScopedLock<true> Lock(ListenersLock);
std::vector<PassRegistrationListener*>::iterator I = std::vector<PassRegistrationListener*>::iterator I =
std::find(Listeners->begin(), Listeners->end(), this); std::find(Listeners->begin(), Listeners->end(), this);
assert(Listeners && I != Listeners->end() && assert(Listeners && I != Listeners->end() &&

View File

@ -392,7 +392,7 @@ public:
if (dynamic_cast<PMDataManager *>(P)) if (dynamic_cast<PMDataManager *>(P))
return; return;
sys::SmartScopedLock<true> Lock(&*TimingInfoMutex); sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
std::map<Pass*, Timer>::iterator I = TimingData.find(P); std::map<Pass*, Timer>::iterator I = TimingData.find(P);
if (I == TimingData.end()) if (I == TimingData.end())
I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first; I=TimingData.insert(std::make_pair(P, Timer(P->getPassName(), TG))).first;
@ -403,7 +403,7 @@ public:
if (dynamic_cast<PMDataManager *>(P)) if (dynamic_cast<PMDataManager *>(P))
return; return;
sys::SmartScopedLock<true> Lock(&*TimingInfoMutex); sys::SmartScopedLock<true> Lock(*TimingInfoMutex);
std::map<Pass*, Timer>::iterator I = TimingData.find(P); std::map<Pass*, Timer>::iterator I = TimingData.find(P);
assert(I != TimingData.end() && "passStarted/passEnded not nested right!"); assert(I != TimingData.end() && "passStarted/passEnded not nested right!");
I->second.stopTimer(); I->second.stopTimer();

View File

@ -1006,7 +1006,7 @@ const IntegerType *IntegerType::get(unsigned NumBits) {
// First, see if the type is already in the table, for which // First, see if the type is already in the table, for which
// a reader lock suffices. // a reader lock suffices.
sys::SmartScopedLock<true> L(&*TypeMapLock); sys::SmartScopedLock<true> L(*TypeMapLock);
ITy = IntegerTypes->get(IVT); ITy = IntegerTypes->get(IVT);
if (!ITy) { if (!ITy) {
@ -1079,7 +1079,7 @@ FunctionType *FunctionType::get(const Type *ReturnType,
FunctionValType VT(ReturnType, Params, isVarArg); FunctionValType VT(ReturnType, Params, isVarArg);
FunctionType *FT = 0; FunctionType *FT = 0;
sys::SmartScopedLock<true> L(&*TypeMapLock); sys::SmartScopedLock<true> L(*TypeMapLock);
FT = FunctionTypes->get(VT); FT = FunctionTypes->get(VT);
if (!FT) { if (!FT) {
@ -1129,7 +1129,7 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
ArrayValType AVT(ElementType, NumElements); ArrayValType AVT(ElementType, NumElements);
ArrayType *AT = 0; ArrayType *AT = 0;
sys::SmartScopedLock<true> L(&*TypeMapLock); sys::SmartScopedLock<true> L(*TypeMapLock);
AT = ArrayTypes->get(AVT); AT = ArrayTypes->get(AVT);
if (!AT) { if (!AT) {
@ -1188,7 +1188,7 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
VectorValType PVT(ElementType, NumElements); VectorValType PVT(ElementType, NumElements);
VectorType *PT = 0; VectorType *PT = 0;
sys::SmartScopedLock<true> L(&*TypeMapLock); sys::SmartScopedLock<true> L(*TypeMapLock);
PT = VectorTypes->get(PVT); PT = VectorTypes->get(PVT);
if (!PT) { if (!PT) {
@ -1250,7 +1250,7 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
StructValType STV(ETypes, isPacked); StructValType STV(ETypes, isPacked);
StructType *ST = 0; StructType *ST = 0;
sys::SmartScopedLock<true> L(&*TypeMapLock); sys::SmartScopedLock<true> L(*TypeMapLock);
ST = StructTypes->get(STV); ST = StructTypes->get(STV);
if (!ST) { if (!ST) {
@ -1329,7 +1329,7 @@ PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
PointerType *PT = 0; PointerType *PT = 0;
sys::SmartScopedLock<true> L(&*TypeMapLock); sys::SmartScopedLock<true> L(*TypeMapLock);
PT = PointerTypes->get(PVT); PT = PointerTypes->get(PVT);
if (!PT) { if (!PT) {
@ -1488,7 +1488,7 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) {
void DerivedType::refineAbstractTypeTo(const Type *NewType) { void DerivedType::refineAbstractTypeTo(const Type *NewType) {
// All recursive calls will go through unlockedRefineAbstractTypeTo, // All recursive calls will go through unlockedRefineAbstractTypeTo,
// to avoid deadlock problems. // to avoid deadlock problems.
sys::SmartScopedLock<true> L(&*TypeMapLock); sys::SmartScopedLock<true> L(*TypeMapLock);
unlockedRefineAbstractTypeTo(NewType); unlockedRefineAbstractTypeTo(NewType);
} }

View File

@ -37,7 +37,7 @@ TypeSymbolTable::~TypeSymbolTable() {
std::string TypeSymbolTable::getUniqueName(const std::string &BaseName) const { std::string TypeSymbolTable::getUniqueName(const std::string &BaseName) const {
std::string TryName = BaseName; std::string TryName = BaseName;
sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock); sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
const_iterator End = tmap.end(); const_iterator End = tmap.end();
@ -49,7 +49,7 @@ std::string TypeSymbolTable::getUniqueName(const std::string &BaseName) const {
// lookup a type by name - returns null on failure // lookup a type by name - returns null on failure
Type* TypeSymbolTable::lookup(const std::string& Name) const { Type* TypeSymbolTable::lookup(const std::string& Name) const {
sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock); sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
const_iterator TI = tmap.find(Name); const_iterator TI = tmap.find(Name);
Type* result = 0; Type* result = 0;
@ -134,7 +134,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 // This function is called when one of the types in the type plane are refined
void TypeSymbolTable::refineAbstractType(const DerivedType *OldType, void TypeSymbolTable::refineAbstractType(const DerivedType *OldType,
const Type *NewType) { 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 // 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 // to OldType with references to NewType. Note that there may be multiple
@ -165,7 +165,7 @@ void TypeSymbolTable::typeBecameConcrete(const DerivedType *AbsTy) {
// Loop over all of the types in the symbol table, dropping any abstract // 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 user entries for AbsTy which occur because there are names for the
// type. // type.
sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock); sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
for (iterator TI = begin(), TE = end(); TI != TE; ++TI) for (iterator TI = begin(), TE = end(); TI != TE; ++TI)
if (TI->second == const_cast<Type*>(static_cast<const Type*>(AbsTy))) if (TI->second == const_cast<Type*>(static_cast<const Type*>(AbsTy)))
AbsTy->removeAbstractTypeUser(this); AbsTy->removeAbstractTypeUser(this);
@ -179,7 +179,7 @@ static void DumpTypes(const std::pair<const std::string, const Type*>& T ) {
void TypeSymbolTable::dump() const { void TypeSymbolTable::dump() const {
cerr << "TypeSymbolPlane: "; cerr << "TypeSymbolPlane: ";
sys::SmartScopedReader<true> Reader(&*TypeSymbolTableLock); sys::SmartScopedReader<true> Reader(*TypeSymbolTableLock);
for_each(tmap.begin(), tmap.end(), DumpTypes); for_each(tmap.begin(), tmap.end(), DumpTypes);
} }

View File

@ -430,7 +430,7 @@ void ValueHandleBase::AddToUseList() {
if (VP->HasValueHandle) { if (VP->HasValueHandle) {
// If this value already has a ValueHandle, then it must be in the // If this value already has a ValueHandle, then it must be in the
// ValueHandles map already. // ValueHandles map already.
sys::SmartScopedReader<true> Reader(&*ValueHandlesLock); sys::SmartScopedReader<true> Reader(*ValueHandlesLock);
ValueHandleBase *&Entry = (*ValueHandles)[VP]; ValueHandleBase *&Entry = (*ValueHandles)[VP];
assert(Entry != 0 && "Value doesn't have any handles?"); assert(Entry != 0 && "Value doesn't have any handles?");
AddToExistingUseList(&Entry); AddToExistingUseList(&Entry);
@ -442,7 +442,7 @@ void ValueHandleBase::AddToUseList() {
// reallocate itself, which would invalidate all of the PrevP pointers that // reallocate itself, which would invalidate all of the PrevP pointers that
// point into the old table. Handle this by checking for reallocation and // point into the old table. Handle this by checking for reallocation and
// updating the stale pointers only if needed. // updating the stale pointers only if needed.
sys::SmartScopedWriter<true> Writer(&*ValueHandlesLock); sys::SmartScopedWriter<true> Writer(*ValueHandlesLock);
ValueHandlesTy &Handles = *ValueHandles; ValueHandlesTy &Handles = *ValueHandles;
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray(); const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
@ -484,7 +484,7 @@ void ValueHandleBase::RemoveFromUseList() {
// If the Next pointer was null, then it is possible that this was the last // If the Next pointer was null, then it is possible that this was the last
// ValueHandle watching VP. If so, delete its entry from the ValueHandles // ValueHandle watching VP. If so, delete its entry from the ValueHandles
// map. // map.
sys::SmartScopedWriter<true> Writer(&*ValueHandlesLock); sys::SmartScopedWriter<true> Writer(*ValueHandlesLock);
ValueHandlesTy &Handles = *ValueHandles; ValueHandlesTy &Handles = *ValueHandles;
if (Handles.isPointerIntoBucketsArray(PrevPtr)) { if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
Handles.erase(VP); Handles.erase(VP);