mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-15 07:59:50 +00:00
I give up on trying to use reader/writer locks for recursive type refinement. Use a recursive mutex instead, which will (in theory) generate more contention, but is really
a much more natural fit for what's going on during recursive type refinement. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74618 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8b477ed579
commit
334143d304
@ -43,8 +43,8 @@ AbstractTypeUser::~AbstractTypeUser() {}
|
||||
// Type Class Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Reader/writer lock used for guarding access to the type maps.
|
||||
static ManagedStatic<sys::SmartRWMutex<true> > TypeMapLock;
|
||||
// Lock used for guarding access to the type maps.
|
||||
static ManagedStatic<sys::SmartMutex<true> > TypeMapLock;
|
||||
|
||||
// Recursive lock used for guarding access to AbstractTypeUsers.
|
||||
// NOTE: The true template parameter means this will no-op when we're not in
|
||||
@ -1006,23 +1006,13 @@ const IntegerType *IntegerType::get(unsigned NumBits) {
|
||||
|
||||
// First, see if the type is already in the table, for which
|
||||
// a reader lock suffices.
|
||||
TypeMapLock->reader_acquire();
|
||||
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||
ITy = IntegerTypes->get(IVT);
|
||||
TypeMapLock->reader_release();
|
||||
|
||||
if (!ITy) {
|
||||
// OK, not in the table, get a writer lock.
|
||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
||||
ITy = IntegerTypes->get(IVT);
|
||||
|
||||
// We need to _recheck_ the table in case someone
|
||||
// put it in between when we released the reader lock
|
||||
// and when we gained the writer lock!
|
||||
if (!ITy) {
|
||||
// Value not found. Derive a new type!
|
||||
ITy = new IntegerType(NumBits);
|
||||
IntegerTypes->add(IVT, ITy);
|
||||
}
|
||||
// Value not found. Derive a new type!
|
||||
ITy = new IntegerType(NumBits);
|
||||
IntegerTypes->add(IVT, ITy);
|
||||
}
|
||||
#ifdef DEBUG_MERGE_TYPES
|
||||
DOUT << "Derived new type: " << *ITy << "\n";
|
||||
@ -1089,23 +1079,14 @@ FunctionType *FunctionType::get(const Type *ReturnType,
|
||||
FunctionValType VT(ReturnType, Params, isVarArg);
|
||||
FunctionType *FT = 0;
|
||||
|
||||
TypeMapLock->reader_acquire();
|
||||
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||
FT = FunctionTypes->get(VT);
|
||||
TypeMapLock->reader_release();
|
||||
|
||||
if (!FT) {
|
||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
||||
|
||||
// Have to check again here, because it might have
|
||||
// been inserted between when we release the reader
|
||||
// lock and when we acquired the writer lock.
|
||||
FT = FunctionTypes->get(VT);
|
||||
if (!FT) {
|
||||
FT = (FunctionType*) operator new(sizeof(FunctionType) +
|
||||
sizeof(PATypeHandle)*(Params.size()+1));
|
||||
new (FT) FunctionType(ReturnType, Params, isVarArg);
|
||||
FunctionTypes->add(VT, FT);
|
||||
}
|
||||
FT = (FunctionType*) operator new(sizeof(FunctionType) +
|
||||
sizeof(PATypeHandle)*(Params.size()+1));
|
||||
new (FT) FunctionType(ReturnType, Params, isVarArg);
|
||||
FunctionTypes->add(VT, FT);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MERGE_TYPES
|
||||
@ -1148,19 +1129,12 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
|
||||
ArrayValType AVT(ElementType, NumElements);
|
||||
ArrayType *AT = 0;
|
||||
|
||||
TypeMapLock->reader_acquire();
|
||||
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||
AT = ArrayTypes->get(AVT);
|
||||
TypeMapLock->reader_release();
|
||||
|
||||
|
||||
if (!AT) {
|
||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
||||
|
||||
// Recheck. Might have changed between release and acquire.
|
||||
AT = ArrayTypes->get(AVT);
|
||||
if (!AT) {
|
||||
// Value not found. Derive a new type!
|
||||
ArrayTypes->add(AVT, AT = new ArrayType(ElementType, NumElements));
|
||||
}
|
||||
// Value not found. Derive a new type!
|
||||
ArrayTypes->add(AVT, AT = new ArrayType(ElementType, NumElements));
|
||||
}
|
||||
#ifdef DEBUG_MERGE_TYPES
|
||||
DOUT << "Derived new type: " << *AT << "\n";
|
||||
@ -1214,17 +1188,11 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
|
||||
VectorValType PVT(ElementType, NumElements);
|
||||
VectorType *PT = 0;
|
||||
|
||||
TypeMapLock->reader_acquire();
|
||||
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||
PT = VectorTypes->get(PVT);
|
||||
TypeMapLock->reader_release();
|
||||
|
||||
if (!PT) {
|
||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
||||
PT = VectorTypes->get(PVT);
|
||||
// Recheck. Might have changed between release and acquire.
|
||||
if (!PT) {
|
||||
VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
|
||||
}
|
||||
VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
|
||||
}
|
||||
#ifdef DEBUG_MERGE_TYPES
|
||||
DOUT << "Derived new type: " << *PT << "\n";
|
||||
@ -1282,21 +1250,15 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
|
||||
StructValType STV(ETypes, isPacked);
|
||||
StructType *ST = 0;
|
||||
|
||||
TypeMapLock->reader_acquire();
|
||||
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||
ST = StructTypes->get(STV);
|
||||
TypeMapLock->reader_release();
|
||||
|
||||
if (!ST) {
|
||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
||||
ST = StructTypes->get(STV);
|
||||
// Recheck. Might have changed between release and acquire.
|
||||
if (!ST) {
|
||||
// Value not found. Derive a new type!
|
||||
ST = (StructType*) operator new(sizeof(StructType) +
|
||||
sizeof(PATypeHandle) * ETypes.size());
|
||||
new (ST) StructType(ETypes, isPacked);
|
||||
StructTypes->add(STV, ST);
|
||||
}
|
||||
// Value not found. Derive a new type!
|
||||
ST = (StructType*) operator new(sizeof(StructType) +
|
||||
sizeof(PATypeHandle) * ETypes.size());
|
||||
new (ST) StructType(ETypes, isPacked);
|
||||
StructTypes->add(STV, ST);
|
||||
}
|
||||
#ifdef DEBUG_MERGE_TYPES
|
||||
DOUT << "Derived new type: " << *ST << "\n";
|
||||
@ -1367,18 +1329,12 @@ PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
|
||||
|
||||
PointerType *PT = 0;
|
||||
|
||||
TypeMapLock->reader_acquire();
|
||||
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||
PT = PointerTypes->get(PVT);
|
||||
TypeMapLock->reader_release();
|
||||
|
||||
if (!PT) {
|
||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
||||
PT = PointerTypes->get(PVT);
|
||||
// Recheck. Might have changed between release and acquire.
|
||||
if (!PT) {
|
||||
// Value not found. Derive a new type!
|
||||
PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
|
||||
}
|
||||
// Value not found. Derive a new type!
|
||||
PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
|
||||
}
|
||||
#ifdef DEBUG_MERGE_TYPES
|
||||
DOUT << "Derived new type: " << *PT << "\n";
|
||||
@ -1532,7 +1488,7 @@ void DerivedType::unlockedRefineAbstractTypeTo(const Type *NewType) {
|
||||
void DerivedType::refineAbstractTypeTo(const Type *NewType) {
|
||||
// All recursive calls will go through unlockedRefineAbstractTypeTo,
|
||||
// to avoid deadlock problems.
|
||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
||||
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||
unlockedRefineAbstractTypeTo(NewType);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user