diff options
Diffstat (limited to 'lib/VMCore/Value.cpp')
-rw-r--r-- | lib/VMCore/Value.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index 3af161fa08b9..c952b7888cdd 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -22,6 +22,8 @@ #include "llvm/Support/LeakDetector.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ValueHandle.h" +#include "llvm/System/RWMutex.h" +#include "llvm/System/Threading.h" #include "llvm/ADT/DenseMap.h" #include <algorithm> using namespace llvm; @@ -405,6 +407,7 @@ Value *Value::DoPHITranslation(const BasicBlock *CurBB, /// 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 /// List is known to point into the existing use list. @@ -427,9 +430,11 @@ void ValueHandleBase::AddToUseList() { if (VP->HasValueHandle) { // If this value already has a ValueHandle, then it must be in the // ValueHandles map already. + sys::SmartScopedReader<true> Reader(&*ValueHandlesLock); ValueHandleBase *&Entry = (*ValueHandles)[VP]; assert(Entry != 0 && "Value doesn't have any handles?"); - return AddToExistingUseList(&Entry); + AddToExistingUseList(&Entry); + return; } // Ok, it doesn't have any handles yet, so we must insert it into the @@ -437,6 +442,7 @@ void ValueHandleBase::AddToUseList() { // reallocate itself, which would invalidate all of the PrevP pointers that // point into the old table. Handle this by checking for reallocation and // updating the stale pointers only if needed. + sys::SmartScopedWriter<true> Writer(&*ValueHandlesLock); ValueHandlesTy &Handles = *ValueHandles; const void *OldBucketPtr = Handles.getPointerIntoBucketsArray(); @@ -448,8 +454,9 @@ void ValueHandleBase::AddToUseList() { // If reallocation didn't happen or if this was the first insertion, don't // walk the table. if (Handles.isPointerIntoBucketsArray(OldBucketPtr) || - Handles.size() == 1) + Handles.size() == 1) { return; + } // Okay, reallocation did happen. Fix the Prev Pointers. for (ValueHandlesTy::iterator I = Handles.begin(), E = Handles.end(); @@ -477,6 +484,7 @@ void ValueHandleBase::RemoveFromUseList() { // 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 // map. + sys::SmartScopedWriter<true> Writer(&*ValueHandlesLock); ValueHandlesTy &Handles = *ValueHandles; if (Handles.isPointerIntoBucketsArray(PrevPtr)) { Handles.erase(VP); @@ -490,7 +498,9 @@ void ValueHandleBase::ValueIsDeleted(Value *V) { // Get the linked list base, which is guaranteed to exist since the // HasValueHandle flag is set. + ValueHandlesLock->reader_acquire(); ValueHandleBase *Entry = (*ValueHandles)[V]; + ValueHandlesLock->reader_release(); assert(Entry && "Value bit set but no entries exist"); while (Entry) { @@ -528,7 +538,9 @@ void ValueHandleBase::ValueIsRAUWd(Value *Old, Value *New) { // Get the linked list base, which is guaranteed to exist since the // HasValueHandle flag is set. + ValueHandlesLock->reader_acquire(); ValueHandleBase *Entry = (*ValueHandles)[Old]; + ValueHandlesLock->reader_release(); assert(Entry && "Value bit set but no entries exist"); while (Entry) { |