[llvm-commits] [llvm] r74618 - /llvm/trunk/lib/VMCore/Type.cpp
Owen Anderson
resistor at mac.com
Wed Jul 1 10:22:38 PDT 2009
Author: resistor
Date: Wed Jul 1 12:22:27 2009
New Revision: 74618
URL: http://llvm.org/viewvc/llvm-project?rev=74618&view=rev
Log:
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.
Modified:
llvm/trunk/lib/VMCore/Type.cpp
Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=74618&r1=74617&r2=74618&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Wed Jul 1 12:22:27 2009
@@ -43,8 +43,8 @@
// 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 @@
// 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 @@
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 @@
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 @@
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 @@
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 *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::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);
}
More information about the llvm-commits
mailing list