mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-30 16:53:02 +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. llvm-svn: 74618
This commit is contained in:
parent
81b8dabb53
commit
fbe8d883a0
@ -43,8 +43,8 @@ AbstractTypeUser::~AbstractTypeUser() {}
|
|||||||
// Type Class Implementation
|
// Type Class Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
// Reader/writer lock used for guarding access to the type maps.
|
// Lock used for guarding access to the type maps.
|
||||||
static ManagedStatic<sys::SmartRWMutex<true> > TypeMapLock;
|
static ManagedStatic<sys::SmartMutex<true> > TypeMapLock;
|
||||||
|
|
||||||
// Recursive lock used for guarding access to AbstractTypeUsers.
|
// Recursive lock used for guarding access to AbstractTypeUsers.
|
||||||
// NOTE: The true template parameter means this will no-op when we're not in
|
// 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
|
// First, see if the type is already in the table, for which
|
||||||
// a reader lock suffices.
|
// a reader lock suffices.
|
||||||
TypeMapLock->reader_acquire();
|
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||||
ITy = IntegerTypes->get(IVT);
|
ITy = IntegerTypes->get(IVT);
|
||||||
TypeMapLock->reader_release();
|
|
||||||
|
|
||||||
if (!ITy) {
|
if (!ITy) {
|
||||||
// OK, not in the table, get a writer lock.
|
// Value not found. Derive a new type!
|
||||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
ITy = new IntegerType(NumBits);
|
||||||
ITy = IntegerTypes->get(IVT);
|
IntegerTypes->add(IVT, ITy);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_MERGE_TYPES
|
#ifdef DEBUG_MERGE_TYPES
|
||||||
DOUT << "Derived new type: " << *ITy << "\n";
|
DOUT << "Derived new type: " << *ITy << "\n";
|
||||||
@ -1089,23 +1079,14 @@ FunctionType *FunctionType::get(const Type *ReturnType,
|
|||||||
FunctionValType VT(ReturnType, Params, isVarArg);
|
FunctionValType VT(ReturnType, Params, isVarArg);
|
||||||
FunctionType *FT = 0;
|
FunctionType *FT = 0;
|
||||||
|
|
||||||
TypeMapLock->reader_acquire();
|
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||||
FT = FunctionTypes->get(VT);
|
FT = FunctionTypes->get(VT);
|
||||||
TypeMapLock->reader_release();
|
|
||||||
|
|
||||||
if (!FT) {
|
if (!FT) {
|
||||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
FT = (FunctionType*) operator new(sizeof(FunctionType) +
|
||||||
|
sizeof(PATypeHandle)*(Params.size()+1));
|
||||||
// Have to check again here, because it might have
|
new (FT) FunctionType(ReturnType, Params, isVarArg);
|
||||||
// been inserted between when we release the reader
|
FunctionTypes->add(VT, FT);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_MERGE_TYPES
|
#ifdef DEBUG_MERGE_TYPES
|
||||||
@ -1148,19 +1129,12 @@ ArrayType *ArrayType::get(const Type *ElementType, uint64_t NumElements) {
|
|||||||
ArrayValType AVT(ElementType, NumElements);
|
ArrayValType AVT(ElementType, NumElements);
|
||||||
ArrayType *AT = 0;
|
ArrayType *AT = 0;
|
||||||
|
|
||||||
TypeMapLock->reader_acquire();
|
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||||
AT = ArrayTypes->get(AVT);
|
AT = ArrayTypes->get(AVT);
|
||||||
TypeMapLock->reader_release();
|
|
||||||
|
|
||||||
if (!AT) {
|
if (!AT) {
|
||||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
// Value not found. Derive a new type!
|
||||||
|
ArrayTypes->add(AVT, AT = new ArrayType(ElementType, NumElements));
|
||||||
// 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_MERGE_TYPES
|
#ifdef DEBUG_MERGE_TYPES
|
||||||
DOUT << "Derived new type: " << *AT << "\n";
|
DOUT << "Derived new type: " << *AT << "\n";
|
||||||
@ -1214,17 +1188,11 @@ VectorType *VectorType::get(const Type *ElementType, unsigned NumElements) {
|
|||||||
VectorValType PVT(ElementType, NumElements);
|
VectorValType PVT(ElementType, NumElements);
|
||||||
VectorType *PT = 0;
|
VectorType *PT = 0;
|
||||||
|
|
||||||
TypeMapLock->reader_acquire();
|
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||||
PT = VectorTypes->get(PVT);
|
PT = VectorTypes->get(PVT);
|
||||||
TypeMapLock->reader_release();
|
|
||||||
|
|
||||||
if (!PT) {
|
if (!PT) {
|
||||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
|
||||||
PT = VectorTypes->get(PVT);
|
|
||||||
// Recheck. Might have changed between release and acquire.
|
|
||||||
if (!PT) {
|
|
||||||
VectorTypes->add(PVT, PT = new VectorType(ElementType, NumElements));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_MERGE_TYPES
|
#ifdef DEBUG_MERGE_TYPES
|
||||||
DOUT << "Derived new type: " << *PT << "\n";
|
DOUT << "Derived new type: " << *PT << "\n";
|
||||||
@ -1282,21 +1250,15 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
|
|||||||
StructValType STV(ETypes, isPacked);
|
StructValType STV(ETypes, isPacked);
|
||||||
StructType *ST = 0;
|
StructType *ST = 0;
|
||||||
|
|
||||||
TypeMapLock->reader_acquire();
|
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||||
ST = StructTypes->get(STV);
|
ST = StructTypes->get(STV);
|
||||||
TypeMapLock->reader_release();
|
|
||||||
|
|
||||||
if (!ST) {
|
if (!ST) {
|
||||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
// Value not found. Derive a new type!
|
||||||
ST = StructTypes->get(STV);
|
ST = (StructType*) operator new(sizeof(StructType) +
|
||||||
// Recheck. Might have changed between release and acquire.
|
sizeof(PATypeHandle) * ETypes.size());
|
||||||
if (!ST) {
|
new (ST) StructType(ETypes, isPacked);
|
||||||
// Value not found. Derive a new type!
|
StructTypes->add(STV, ST);
|
||||||
ST = (StructType*) operator new(sizeof(StructType) +
|
|
||||||
sizeof(PATypeHandle) * ETypes.size());
|
|
||||||
new (ST) StructType(ETypes, isPacked);
|
|
||||||
StructTypes->add(STV, ST);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_MERGE_TYPES
|
#ifdef DEBUG_MERGE_TYPES
|
||||||
DOUT << "Derived new type: " << *ST << "\n";
|
DOUT << "Derived new type: " << *ST << "\n";
|
||||||
@ -1367,18 +1329,12 @@ PointerType *PointerType::get(const Type *ValueType, unsigned AddressSpace) {
|
|||||||
|
|
||||||
PointerType *PT = 0;
|
PointerType *PT = 0;
|
||||||
|
|
||||||
TypeMapLock->reader_acquire();
|
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||||
PT = PointerTypes->get(PVT);
|
PT = PointerTypes->get(PVT);
|
||||||
TypeMapLock->reader_release();
|
|
||||||
|
|
||||||
if (!PT) {
|
if (!PT) {
|
||||||
sys::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
// Value not found. Derive a new type!
|
||||||
PT = PointerTypes->get(PVT);
|
PointerTypes->add(PVT, PT = new PointerType(ValueType, AddressSpace));
|
||||||
// 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_MERGE_TYPES
|
#ifdef DEBUG_MERGE_TYPES
|
||||||
DOUT << "Derived new type: " << *PT << "\n";
|
DOUT << "Derived new type: " << *PT << "\n";
|
||||||
@ -1532,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::SmartScopedWriter<true> Writer(&*TypeMapLock);
|
sys::SmartScopedLock<true> L(&*TypeMapLock);
|
||||||
unlockedRefineAbstractTypeTo(NewType);
|
unlockedRefineAbstractTypeTo(NewType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user