Privatize the ValueHandle global map. Because this is used so heavily throughout the code base, locking all accesses to

it is not practical performance-wise.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79355 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2009-08-18 18:28:58 +00:00
parent 5caba3bcb1
commit 4d91943889
2 changed files with 21 additions and 21 deletions

View File

@ -171,6 +171,12 @@ public:
const IntegerType *Int32Ty; const IntegerType *Int32Ty;
const IntegerType *Int64Ty; const IntegerType *Int64Ty;
/// ValueHandles - This map keeps track of all of the value handles that are
/// watching a Value*. The Value::HasValueHandle bit is used to know
// whether or not a value has an entry in this map.
typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
ValueHandlesTy ValueHandles;
LLVMContextImpl(LLVMContext &C) : TheTrueVal(0), TheFalseVal(0), LLVMContextImpl(LLVMContext &C) : TheTrueVal(0), TheFalseVal(0),
VoidTy(new Type(C, Type::VoidTyID)), VoidTy(new Type(C, Type::VoidTyID)),
LabelTy(new Type(C, Type::LabelTyID)), LabelTy(new Type(C, Type::LabelTyID)),

View File

@ -11,6 +11,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "LLVMContextImpl.h"
#include "llvm/Constant.h" #include "llvm/Constant.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
@ -378,13 +379,6 @@ LLVMContext &Value::getContext() const { return VTy->getContext(); }
// ValueHandleBase Class // ValueHandleBase Class
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
/// ValueHandles - This map keeps track of all of the value handles that are
/// watching a Value*. The Value::HasValueHandle bit is used to know whether or
/// not a value has an entry in this map.
typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
static ManagedStatic<ValueHandlesTy> ValueHandles;
static ManagedStatic<sys::SmartRWMutex<true> > ValueHandlesLock;
/// AddToExistingUseList - Add this ValueHandle to the use list for VP, where /// AddToExistingUseList - Add this ValueHandle to the use list for VP, where
/// List is known to point into the existing use list. /// List is known to point into the existing use list.
void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) { void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
@ -403,11 +397,13 @@ void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
/// AddToUseList - Add this ValueHandle to the use list for VP. /// AddToUseList - Add this ValueHandle to the use list for VP.
void ValueHandleBase::AddToUseList() { void ValueHandleBase::AddToUseList() {
assert(VP && "Null pointer doesn't have a use list!"); assert(VP && "Null pointer doesn't have a use list!");
LLVMContextImpl *pImpl = VP->getContext().pImpl;
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); ValueHandleBase *&Entry = pImpl->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);
return; return;
@ -418,8 +414,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); DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
ValueHandlesTy &Handles = *ValueHandles;
const void *OldBucketPtr = Handles.getPointerIntoBucketsArray(); const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
ValueHandleBase *&Entry = Handles[VP]; ValueHandleBase *&Entry = Handles[VP];
@ -435,8 +430,8 @@ void ValueHandleBase::AddToUseList() {
} }
// Okay, reallocation did happen. Fix the Prev Pointers. // Okay, reallocation did happen. Fix the Prev Pointers.
for (ValueHandlesTy::iterator I = Handles.begin(), E = Handles.end(); for (DenseMap<Value*, ValueHandleBase*>::iterator I = Handles.begin(),
I != E; ++I) { E = Handles.end(); I != E; ++I) {
assert(I->second && I->first == I->second->VP && "List invariant broken!"); assert(I->second && I->first == I->second->VP && "List invariant broken!");
I->second->setPrevPtr(&I->second); I->second->setPrevPtr(&I->second);
} }
@ -460,8 +455,8 @@ 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); LLVMContextImpl *pImpl = VP->getContext().pImpl;
ValueHandlesTy &Handles = *ValueHandles; DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
if (Handles.isPointerIntoBucketsArray(PrevPtr)) { if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
Handles.erase(VP); Handles.erase(VP);
VP->HasValueHandle = false; VP->HasValueHandle = false;
@ -474,9 +469,8 @@ void ValueHandleBase::ValueIsDeleted(Value *V) {
// Get the linked list base, which is guaranteed to exist since the // Get the linked list base, which is guaranteed to exist since the
// HasValueHandle flag is set. // HasValueHandle flag is set.
ValueHandlesLock->reader_acquire(); LLVMContextImpl *pImpl = V->getContext().pImpl;
ValueHandleBase *Entry = (*ValueHandles)[V]; ValueHandleBase *Entry = pImpl->ValueHandles[V];
ValueHandlesLock->reader_release();
assert(Entry && "Value bit set but no entries exist"); assert(Entry && "Value bit set but no entries exist");
while (Entry) { while (Entry) {
@ -514,9 +508,9 @@ void ValueHandleBase::ValueIsRAUWd(Value *Old, Value *New) {
// Get the linked list base, which is guaranteed to exist since the // Get the linked list base, which is guaranteed to exist since the
// HasValueHandle flag is set. // HasValueHandle flag is set.
ValueHandlesLock->reader_acquire(); LLVMContextImpl *pImpl = Old->getContext().pImpl;
ValueHandleBase *Entry = (*ValueHandles)[Old]; ValueHandleBase *Entry = pImpl->ValueHandles[Old];
ValueHandlesLock->reader_release();
assert(Entry && "Value bit set but no entries exist"); assert(Entry && "Value bit set but no entries exist");
while (Entry) { while (Entry) {