Banish ConstantsLock. It's serving no purpose other than slowing things down

at the moment.

llvm-svn: 84529
This commit is contained in:
Owen Anderson 2009-10-19 20:11:52 +00:00
parent 296544e15f
commit 5dab84ca9c
3 changed files with 22 additions and 60 deletions

View File

@ -232,7 +232,6 @@ ConstantInt::ConstantInt(const IntegerType *Ty, const APInt& V)
ConstantInt* ConstantInt::getTrue(LLVMContext &Context) {
LLVMContextImpl *pImpl = Context.pImpl;
sys::SmartScopedWriter<true>(pImpl->ConstantsLock);
if (pImpl->TheTrueVal)
return pImpl->TheTrueVal;
else
@ -242,7 +241,6 @@ ConstantInt* ConstantInt::getTrue(LLVMContext &Context) {
ConstantInt* ConstantInt::getFalse(LLVMContext &Context) {
LLVMContextImpl *pImpl = Context.pImpl;
sys::SmartScopedWriter<true>(pImpl->ConstantsLock);
if (pImpl->TheFalseVal)
return pImpl->TheFalseVal;
else
@ -261,22 +259,9 @@ ConstantInt *ConstantInt::get(LLVMContext &Context, const APInt& V) {
const IntegerType *ITy = IntegerType::get(Context, V.getBitWidth());
// get an existing value or the insertion position
DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
Context.pImpl->ConstantsLock.reader_acquire();
ConstantInt *&Slot = Context.pImpl->IntConstants[Key];
Context.pImpl->ConstantsLock.reader_release();
if (!Slot) {
sys::SmartScopedWriter<true> Writer(Context.pImpl->ConstantsLock);
ConstantInt *&NewSlot = Context.pImpl->IntConstants[Key];
if (!Slot) {
NewSlot = new ConstantInt(ITy, V);
}
return NewSlot;
} else {
return Slot;
}
if (!Slot) Slot = new ConstantInt(ITy, V);
return Slot;
}
Constant* ConstantInt::get(const Type* Ty, uint64_t V, bool isSigned) {
@ -405,32 +390,24 @@ ConstantFP* ConstantFP::get(LLVMContext &Context, const APFloat& V) {
LLVMContextImpl* pImpl = Context.pImpl;
pImpl->ConstantsLock.reader_acquire();
ConstantFP *&Slot = pImpl->FPConstants[Key];
pImpl->ConstantsLock.reader_release();
if (!Slot) {
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
ConstantFP *&NewSlot = pImpl->FPConstants[Key];
if (!NewSlot) {
const Type *Ty;
if (&V.getSemantics() == &APFloat::IEEEsingle)
Ty = Type::getFloatTy(Context);
else if (&V.getSemantics() == &APFloat::IEEEdouble)
Ty = Type::getDoubleTy(Context);
else if (&V.getSemantics() == &APFloat::x87DoubleExtended)
Ty = Type::getX86_FP80Ty(Context);
else if (&V.getSemantics() == &APFloat::IEEEquad)
Ty = Type::getFP128Ty(Context);
else {
assert(&V.getSemantics() == &APFloat::PPCDoubleDouble &&
"Unknown FP format");
Ty = Type::getPPC_FP128Ty(Context);
}
NewSlot = new ConstantFP(Ty, V);
const Type *Ty;
if (&V.getSemantics() == &APFloat::IEEEsingle)
Ty = Type::getFloatTy(Context);
else if (&V.getSemantics() == &APFloat::IEEEdouble)
Ty = Type::getDoubleTy(Context);
else if (&V.getSemantics() == &APFloat::x87DoubleExtended)
Ty = Type::getX86_FP80Ty(Context);
else if (&V.getSemantics() == &APFloat::IEEEquad)
Ty = Type::getFP128Ty(Context);
else {
assert(&V.getSemantics() == &APFloat::PPCDoubleDouble &&
"Unknown FP format");
Ty = Type::getPPC_FP128Ty(Context);
}
return NewSlot;
Slot = new ConstantFP(Ty, V);
}
return Slot;
@ -1908,7 +1885,6 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
Replacement = ConstantAggregateZero::get(getType());
} else {
// Check to see if we have this array type already.
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
bool Exists;
LLVMContextImpl::ArrayConstantsTy::MapTy::iterator I =
pImpl->ArrayConstants.InsertOrGetItem(Lookup, Exists);
@ -1987,7 +1963,6 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
Replacement = ConstantAggregateZero::get(getType());
} else {
// Check to see if we have this array type already.
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
bool Exists;
LLVMContextImpl::StructConstantsTy::MapTy::iterator I =
pImpl->StructConstants.InsertOrGetItem(Lookup, Exists);

View File

@ -96,7 +96,6 @@ struct DenseMapAPFloatKeyInfo {
class LLVMContextImpl {
public:
sys::SmartRWMutex<true> ConstantsLock;
typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
DenseMapAPIntKeyInfo> IntMapTy;
IntMapTy IntConstants;

View File

@ -52,7 +52,6 @@ void MetadataBase::resizeOperands(unsigned NumOps) {
//
MDString *MDString::get(LLVMContext &Context, const StringRef &Str) {
LLVMContextImpl *pImpl = Context.pImpl;
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
StringMapEntry<MDString *> &Entry =
pImpl->MDStringCache.GetOrCreateValue(Str);
MDString *&S = Entry.getValue();
@ -93,12 +92,10 @@ MDNode *MDNode::get(LLVMContext &Context, Value*const* Vals, unsigned NumVals) {
void *InsertPoint;
MDNode *N;
{
sys::SmartScopedReader<true> Reader(pImpl->ConstantsLock);
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
}
if (N) return N;
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (!N) {
// InsertPoint will have been set by the FindNodeOrInsertPos call.
@ -118,7 +115,6 @@ void MDNode::dropAllReferences() {
MDNode::~MDNode() {
{
LLVMContextImpl *pImpl = getType()->getContext().pImpl;
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
pImpl->MDNodeSet.RemoveNode(this);
}
dropAllReferences();
@ -147,10 +143,7 @@ void MDNode::replaceElement(Value *From, Value *To) {
return;
// Remove "this" from the context map.
{
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
pImpl->MDNodeSet.RemoveNode(this);
}
pImpl->MDNodeSet.RemoveNode(this);
// MDNode only lists metadata elements in operand list, because MDNode
// used by MDNode is considered a valid use. However on the side, MDNode
@ -186,10 +179,8 @@ void MDNode::replaceElement(Value *From, Value *To) {
// node with updated "this" node.
FoldingSetNodeID ID;
Profile(ID);
pImpl->ConstantsLock.reader_acquire();
void *InsertPoint;
MDNode *N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
pImpl->ConstantsLock.reader_release();
if (N) {
N->replaceAllUsesWith(this);
@ -197,14 +188,11 @@ void MDNode::replaceElement(Value *From, Value *To) {
N = 0;
}
{
sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (!N) {
// InsertPoint will have been set by the FindNodeOrInsertPos call.
N = this;
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
}
N = pImpl->MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
if (!N) {
// InsertPoint will have been set by the FindNodeOrInsertPos call.
N = this;
pImpl->MDNodeSet.InsertNode(N, InsertPoint);
}
}