aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-06-20 00:24:58 +0000
committerOwen Anderson <resistor@mac.com>2009-06-20 00:24:58 +0000
commit04fb7c36a9977127f32558dc01c39a9c2388bc39 (patch)
treeca25bb398da7dc1232611d29ce1d1b301341dfe0 /lib/VMCore
parentd5fb7906130989a579d1bfe4490b414331e94fee (diff)
downloadexternal_llvm-04fb7c36a9977127f32558dc01c39a9c2388bc39.zip
external_llvm-04fb7c36a9977127f32558dc01c39a9c2388bc39.tar.gz
external_llvm-04fb7c36a9977127f32558dc01c39a9c2388bc39.tar.bz2
Revert r73790, and replace it with a significantly less ugly solution. Rather than trying to make the global reader-writer lock work,
create separate recursive mutexes for each value map. The recursive-ness fixes the double-acquiring issue, which having one per ValueMap lets us continue to maintain some concurrency. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73801 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/ConstantFold.cpp111
-rw-r--r--lib/VMCore/Constants.cpp542
-rw-r--r--lib/VMCore/Globals.cpp2
3 files changed, 278 insertions, 377 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 4b2a3f2..6c39214 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -40,8 +40,7 @@ using namespace llvm;
/// specified vector type. At this point, we know that the elements of the
/// input vector constant are all simple integer or FP values.
static Constant *BitCastConstantVector(ConstantVector *CV,
- const VectorType *DstTy,
- bool locked) {
+ const VectorType *DstTy) {
// If this cast changes element count then we can't handle it here:
// doing so requires endianness information. This should be handled by
// Analysis/ConstantFolding.cpp
@@ -61,7 +60,7 @@ static Constant *BitCastConstantVector(ConstantVector *CV,
const Type *DstEltTy = DstTy->getElementType();
for (unsigned i = 0; i != NumElts; ++i)
Result.push_back(ConstantExpr::getBitCast(CV->getOperand(i), DstEltTy));
- return ConstantVector::get(Result, locked);
+ return ConstantVector::get(Result);
}
/// This function determines which opcode to use to fold two constant cast
@@ -89,8 +88,7 @@ foldConstantCastPair(
Type::Int64Ty);
}
-static Constant *FoldBitCast(Constant *V, const Type *DestTy,
- bool locked = true) {
+static Constant *FoldBitCast(Constant *V, const Type *DestTy) {
const Type *SrcTy = V->getType();
if (SrcTy == DestTy)
return V; // no-op cast
@@ -101,7 +99,7 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
if (const PointerType *DPTy = dyn_cast<PointerType>(DestTy))
if (PTy->getAddressSpace() == DPTy->getAddressSpace()) {
SmallVector<Value*, 8> IdxList;
- IdxList.push_back(Constant::getNullValue(Type::Int32Ty, locked));
+ IdxList.push_back(Constant::getNullValue(Type::Int32Ty));
const Type *ElTy = PTy->getElementType();
while (ElTy != DPTy->getElementType()) {
if (const StructType *STy = dyn_cast<StructType>(ElTy)) {
@@ -119,8 +117,7 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
}
if (ElTy == DPTy->getElementType())
- return ConstantExpr::getGetElementPtr(V, &IdxList[0],
- IdxList.size(), locked);
+ return ConstantExpr::getGetElementPtr(V, &IdxList[0], IdxList.size());
}
// Handle casts from one vector constant to another. We know that the src
@@ -132,24 +129,23 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
SrcTy = NULL;
// First, check for null. Undef is already handled.
if (isa<ConstantAggregateZero>(V))
- return Constant::getNullValue(DestTy, locked);
+ return Constant::getNullValue(DestTy);
if (ConstantVector *CV = dyn_cast<ConstantVector>(V))
- return BitCastConstantVector(CV, DestPTy, locked);
+ return BitCastConstantVector(CV, DestPTy);
}
// Canonicalize scalar-to-vector bitcasts into vector-to-vector bitcasts
// This allows for other simplifications (although some of them
// can only be handled by Analysis/ConstantFolding.cpp).
if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
- return ConstantExpr::getBitCast(ConstantVector::get(&V, 1, locked),
- DestPTy, locked);
+ return ConstantExpr::getBitCast(ConstantVector::get(&V, 1), DestPTy);
}
// Finally, implement bitcast folding now. The code below doesn't handle
// bitcast right.
if (isa<ConstantPointerNull>(V)) // ptr->ptr cast.
- return ConstantPointerNull::get(cast<PointerType>(DestTy), locked);
+ return ConstantPointerNull::get(cast<PointerType>(DestTy));
// Handle integral constant input.
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
@@ -160,7 +156,7 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
if (DestTy->isFloatingPoint())
return ConstantFP::get(APFloat(CI->getValue(),
- DestTy != Type::PPC_FP128Ty), locked);
+ DestTy != Type::PPC_FP128Ty));
// Otherwise, can't fold this (vector?)
return 0;
@@ -169,22 +165,22 @@ static Constant *FoldBitCast(Constant *V, const Type *DestTy,
// Handle ConstantFP input.
if (const ConstantFP *FP = dyn_cast<ConstantFP>(V))
// FP -> Integral.
- return ConstantInt::get(FP->getValueAPF().bitcastToAPInt(), locked);
+ return ConstantInt::get(FP->getValueAPF().bitcastToAPInt());
return 0;
}
Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
- const Type *DestTy, bool locked) {
+ const Type *DestTy) {
if (isa<UndefValue>(V)) {
// zext(undef) = 0, because the top bits will be zero.
// sext(undef) = 0, because the top bits will all be the same.
// [us]itofp(undef) = 0, because the result value is bounded.
if (opc == Instruction::ZExt || opc == Instruction::SExt ||
opc == Instruction::UIToFP || opc == Instruction::SIToFP)
- return Constant::getNullValue(DestTy, locked);
- return UndefValue::get(DestTy, locked);
+ return Constant::getNullValue(DestTy);
+ return UndefValue::get(DestTy);
}
// No compile-time operations on this type yet.
if (V->getType() == Type::PPC_FP128Ty || DestTy == Type::PPC_FP128Ty)
@@ -196,7 +192,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
if (CE->isCast()) {
// Try hard to fold cast of cast because they are often eliminable.
if (unsigned newOpc = foldConstantCastPair(opc, CE, DestTy))
- return ConstantExpr::getCast(newOpc, CE->getOperand(0), DestTy, locked);
+ return ConstantExpr::getCast(newOpc, CE->getOperand(0), DestTy);
} else if (CE->getOpcode() == Instruction::GetElementPtr) {
// If all of the indexes in the GEP are null values, there is no pointer
// adjustment going on. We might as well cast the source pointer.
@@ -208,7 +204,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
}
if (isAllNull)
// This is casting one pointer type to another, always BitCast
- return ConstantExpr::getPointerCast(CE->getOperand(0), DestTy, locked);
+ return ConstantExpr::getPointerCast(CE->getOperand(0), DestTy);
}
}
@@ -224,8 +220,8 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
const Type *DstEltTy = DestVecTy->getElementType();
for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
res.push_back(ConstantExpr::getCast(opc,
- CV->getOperand(i), DstEltTy, locked));
- return ConstantVector::get(DestVecTy, res, locked);
+ CV->getOperand(i), DstEltTy));
+ return ConstantVector::get(DestVecTy, res);
}
// We actually have to do a cast now. Perform the cast according to the
@@ -242,7 +238,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
DestTy == Type::FP128Ty ? APFloat::IEEEquad :
APFloat::Bogus,
APFloat::rmNearestTiesToEven, &ignored);
- return ConstantFP::get(Val, locked);
+ return ConstantFP::get(Val);
}
return 0; // Can't fold.
case Instruction::FPToUI:
@@ -255,16 +251,16 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
(void) V.convertToInteger(x, DestBitWidth, opc==Instruction::FPToSI,
APFloat::rmTowardZero, &ignored);
APInt Val(DestBitWidth, 2, x);
- return ConstantInt::get(Val, locked);
+ return ConstantInt::get(Val);
}
return 0; // Can't fold.
case Instruction::IntToPtr: //always treated as unsigned
if (V->isNullValue()) // Is it an integral null value?
- return ConstantPointerNull::get(cast<PointerType>(DestTy), locked);
+ return ConstantPointerNull::get(cast<PointerType>(DestTy));
return 0; // Other pointer types cannot be casted
case Instruction::PtrToInt: // always treated as unsigned
if (V->isNullValue()) // is it a null pointer value?
- return ConstantInt::get(DestTy, 0, locked);
+ return ConstantInt::get(DestTy, 0);
return 0; // Other pointer types cannot be casted
case Instruction::UIToFP:
case Instruction::SIToFP:
@@ -276,7 +272,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
(void)apf.convertFromAPInt(api,
opc==Instruction::SIToFP,
APFloat::rmNearestTiesToEven);
- return ConstantFP::get(apf, locked);
+ return ConstantFP::get(apf);
}
return 0;
case Instruction::ZExt:
@@ -284,7 +280,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
APInt Result(CI->getValue());
Result.zext(BitWidth);
- return ConstantInt::get(Result, locked);
+ return ConstantInt::get(Result);
}
return 0;
case Instruction::SExt:
@@ -292,7 +288,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
APInt Result(CI->getValue());
Result.sext(BitWidth);
- return ConstantInt::get(Result, locked);
+ return ConstantInt::get(Result);
}
return 0;
case Instruction::Trunc:
@@ -300,11 +296,11 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
uint32_t BitWidth = cast<IntegerType>(DestTy)->getBitWidth();
APInt Result(CI->getValue());
Result.trunc(BitWidth);
- return ConstantInt::get(Result, locked);
+ return ConstantInt::get(Result);
}
return 0;
case Instruction::BitCast:
- return FoldBitCast(const_cast<Constant*>(V), DestTy, locked);
+ return FoldBitCast(const_cast<Constant*>(V), DestTy);
default:
assert(!"Invalid CE CastInst opcode");
break;
@@ -316,7 +312,7 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
Constant *llvm::ConstantFoldSelectInstruction(const Constant *Cond,
const Constant *V1,
- const Constant *V2, bool locked) {
+ const Constant *V2) {
if (const ConstantInt *CB = dyn_cast<ConstantInt>(Cond))
return const_cast<Constant*>(CB->getZExtValue() ? V1 : V2);
@@ -570,22 +566,21 @@ Constant *llvm::ConstantFoldInsertValueInstruction(const Constant *Agg,
static Constant *EvalVectorOp(const ConstantVector *V1,
const ConstantVector *V2,
const VectorType *VTy,
- Constant *(*FP)(Constant*, Constant*, bool)) {
+ Constant *(*FP)(Constant*, Constant*)) {
std::vector<Constant*> Res;
const Type *EltTy = VTy->getElementType();
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
const Constant *C1 = V1 ? V1->getOperand(i) : Constant::getNullValue(EltTy);
const Constant *C2 = V2 ? V2->getOperand(i) : Constant::getNullValue(EltTy);
Res.push_back(FP(const_cast<Constant*>(C1),
- const_cast<Constant*>(C2), true));
+ const_cast<Constant*>(C2)));
}
return ConstantVector::get(Res);
}
Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
const Constant *C1,
- const Constant *C2,
- bool locked) {
+ const Constant *C2) {
// No compile-time operations on this type yet.
if (C1->getType() == Type::PPC_FP128Ty)
return 0;
@@ -597,29 +592,29 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
if (isa<UndefValue>(C1) && isa<UndefValue>(C2))
// Handle undef ^ undef -> 0 special case. This is a common
// idiom (misuse).
- return Constant::getNullValue(C1->getType(), locked);
+ return Constant::getNullValue(C1->getType());
// Fallthrough
case Instruction::Add:
case Instruction::Sub:
- return UndefValue::get(C1->getType(), locked);
+ return UndefValue::get(C1->getType());
case Instruction::Mul:
case Instruction::And:
- return Constant::getNullValue(C1->getType(), locked);
+ return Constant::getNullValue(C1->getType());
case Instruction::UDiv:
case Instruction::SDiv:
case Instruction::URem:
case Instruction::SRem:
if (!isa<UndefValue>(C2)) // undef / X -> 0
- return Constant::getNullValue(C1->getType(), locked);
+ return Constant::getNullValue(C1->getType());
return const_cast<Constant*>(C2); // X / undef -> undef
case Instruction::Or: // X | undef -> -1
if (const VectorType *PTy = dyn_cast<VectorType>(C1->getType()))
- return ConstantVector::getAllOnesValue(PTy, locked);
- return ConstantInt::getAllOnesValue(C1->getType(), locked);
+ return ConstantVector::getAllOnesValue(PTy);
+ return ConstantInt::getAllOnesValue(C1->getType());
case Instruction::LShr:
if (isa<UndefValue>(C2) && isa<UndefValue>(C1))
return const_cast<Constant*>(C1); // undef lshr undef -> undef
- return Constant::getNullValue(C1->getType(), locked); // X lshr undef -> 0
+ return Constant::getNullValue(C1->getType()); // X lshr undef -> 0
// undef lshr X -> 0
case Instruction::AShr:
if (!isa<UndefValue>(C2))
@@ -630,7 +625,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
return const_cast<Constant*>(C1); // X ashr undef --> X
case Instruction::Shl:
// undef << X -> 0 or X << undef -> 0
- return Constant::getNullValue(C1->getType(), locked);
+ return Constant::getNullValue(C1->getType());
}
}
@@ -1577,7 +1572,7 @@ Constant *llvm::ConstantFoldCompareInstruction(unsigned short pred,
Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
Constant* const *Idxs,
- unsigned NumIdx, bool locked) {
+ unsigned NumIdx) {
if (NumIdx == 0 ||
(NumIdx == 1 && Idxs[0]->isNullValue()))
return const_cast<Constant*>(C);
@@ -1588,8 +1583,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
(Value **)Idxs,
(Value **)Idxs+NumIdx);
assert(Ty != 0 && "Invalid indices for GEP!");
- return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace()),
- locked);
+ return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace()));
}
Constant *Idx0 = Idxs[0];
@@ -1607,8 +1601,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
(Value**)Idxs+NumIdx);
assert(Ty != 0 && "Invalid indices for GEP!");
return
- ConstantPointerNull::get(PointerType::get(Ty,Ptr->getAddressSpace()),
- locked);
+ ConstantPointerNull::get(PointerType::get(Ty,Ptr->getAddressSpace()));
}
}
@@ -1636,22 +1629,20 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
if (!Idx0->isNullValue()) {
const Type *IdxTy = Combined->getType();
if (IdxTy != Idx0->getType()) {
- Constant *C1 = ConstantExpr::getSExtOrBitCast(Idx0, Type::Int64Ty,
- locked);
+ Constant *C1 = ConstantExpr::getSExtOrBitCast(Idx0, Type::Int64Ty);
Constant *C2 = ConstantExpr::getSExtOrBitCast(Combined,
- Type::Int64Ty,
- locked);
- Combined = ConstantExpr::get(Instruction::Add, C1, C2, locked);
+ Type::Int64Ty);
+ Combined = ConstantExpr::get(Instruction::Add, C1, C2);
} else {
Combined =
- ConstantExpr::get(Instruction::Add, Idx0, Combined, locked);
+ ConstantExpr::get(Instruction::Add, Idx0, Combined);
}
}
NewIndices.push_back(Combined);
NewIndices.insert(NewIndices.end(), Idxs+1, Idxs+NumIdx);
return ConstantExpr::getGetElementPtr(CE->getOperand(0), &NewIndices[0],
- NewIndices.size(), locked);
+ NewIndices.size());
}
}
@@ -1668,7 +1659,7 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
dyn_cast<ArrayType>(cast<PointerType>(C->getType())->getElementType()))
if (CAT->getElementType() == SAT->getElementType())
return ConstantExpr::getGetElementPtr(
- (Constant*)CE->getOperand(0), Idxs, NumIdx, locked);
+ (Constant*)CE->getOperand(0), Idxs, NumIdx);
}
// Fold: getelementptr (i8* inttoptr (i64 1 to i8*), i32 -1)
@@ -1686,10 +1677,10 @@ Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
Offset = ConstantExpr::getSExt(Offset, Base->getType());
else if (Base->getType()->getPrimitiveSizeInBits() <
Offset->getType()->getPrimitiveSizeInBits())
- Base = ConstantExpr::getZExt(Base, Offset->getType(), locked);
+ Base = ConstantExpr::getZExt(Base, Offset->getType());
- Base = ConstantExpr::getAdd(Base, Offset, locked);
- return ConstantExpr::getIntToPtr(Base, CE->getType(), locked);
+ Base = ConstantExpr::getAdd(Base, Offset);
+ return ConstantExpr::getIntToPtr(Base, CE->getType());
}
}
return 0;
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 138a196..c164a3b 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -25,6 +25,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/System/Mutex.h"
#include "llvm/System/RWMutex.h"
#include "llvm/System/Threading.h"
#include "llvm/ADT/DenseMap.h"
@@ -127,27 +128,27 @@ bool Constant::ContainsRelocations(unsigned Kind) const {
}
// Static constructor to create a '0' constant of arbitrary type...
-Constant *Constant::getNullValue(const Type *Ty, bool locked) {
+Constant *Constant::getNullValue(const Type *Ty) {
static uint64_t zero[2] = {0, 0};
switch (Ty->getTypeID()) {
case Type::IntegerTyID:
- return ConstantInt::get(Ty, 0, locked);
+ return ConstantInt::get(Ty, 0);
case Type::FloatTyID:
- return ConstantFP::get(APFloat(APInt(32, 0)), locked);
+ return ConstantFP::get(APFloat(APInt(32, 0)));
case Type::DoubleTyID:
- return ConstantFP::get(APFloat(APInt(64, 0)), locked);
+ return ConstantFP::get(APFloat(APInt(64, 0)));
case Type::X86_FP80TyID:
- return ConstantFP::get(APFloat(APInt(80, 2, zero)), locked);
+ return ConstantFP::get(APFloat(APInt(80, 2, zero)));
case Type::FP128TyID:
- return ConstantFP::get(APFloat(APInt(128, 2, zero), true), locked);
+ return ConstantFP::get(APFloat(APInt(128, 2, zero), true));
case Type::PPC_FP128TyID:
- return ConstantFP::get(APFloat(APInt(128, 2, zero)), locked);
+ return ConstantFP::get(APFloat(APInt(128, 2, zero)));
case Type::PointerTyID:
- return ConstantPointerNull::get(cast<PointerType>(Ty), locked);
+ return ConstantPointerNull::get(cast<PointerType>(Ty));
case Type::StructTyID:
case Type::ArrayTyID:
case Type::VectorTyID:
- return ConstantAggregateZero::get(Ty, locked);
+ return ConstantAggregateZero::get(Ty);
default:
// Function, Label, or Opaque type?
assert(!"Cannot create a null constant of that type!");
@@ -162,22 +163,21 @@ Constant *Constant::getAllOnesValue(const Type *Ty) {
}
// Static constructor to create an integral constant with all bits set
-ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty, bool locked) {
+ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty) {
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
- return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()), locked);
+ return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
return 0;
}
/// @returns the value for a vector integer constant of the given type that
/// has all its bits set to true.
/// @brief Get the all ones value
-ConstantVector *ConstantVector::getAllOnesValue(const VectorType *Ty,
- bool locked) {
+ConstantVector *ConstantVector::getAllOnesValue(const VectorType *Ty) {
std::vector<Constant*> Elts;
Elts.resize(Ty->getNumElements(),
- ConstantInt::getAllOnesValue(Ty->getElementType(), locked));
+ ConstantInt::getAllOnesValue(Ty->getElementType()));
assert(Elts[0] && "Not a vector integer type!");
- return cast<ConstantVector>(ConstantVector::get(Elts, locked));
+ return cast<ConstantVector>(ConstantVector::get(Elts));
}
@@ -276,19 +276,17 @@ typedef DenseMap<DenseMapAPIntKeyInfo::KeyTy, ConstantInt*,
static ManagedStatic<IntMapTy> IntConstants;
ConstantInt *ConstantInt::get(const IntegerType *Ty,
- uint64_t V, bool isSigned, bool locked) {
- return get(APInt(Ty->getBitWidth(), V, isSigned), locked);
+ uint64_t V, bool isSigned) {
+ return get(APInt(Ty->getBitWidth(), V, isSigned));
}
-Constant *ConstantInt::get(const Type *Ty, uint64_t V,
- bool isSigned, bool locked) {
+Constant *ConstantInt::get(const Type *Ty, uint64_t V, bool isSigned) {
Constant *C = get(cast<IntegerType>(Ty->getScalarType()), V, isSigned);
// For vectors, broadcast the value.
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
return
- ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C),
- locked);
+ ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
return C;
}
@@ -298,42 +296,38 @@ Constant *ConstantInt::get(const Type *Ty, uint64_t V,
// operator== and operator!= to ensure that the DenseMap doesn't attempt to
// compare APInt's of different widths, which would violate an APInt class
// invariant which generates an assertion.
-ConstantInt *ConstantInt::get(const APInt& V, bool locked) {
+ConstantInt *ConstantInt::get(const APInt& V) {
// Get the corresponding integer type for the bit width of the value.
const IntegerType *ITy = IntegerType::get(V.getBitWidth());
// get an existing value or the insertion position
DenseMapAPIntKeyInfo::KeyTy Key(V, ITy);
- if (locked) ConstantsLock->reader_acquire();
+ ConstantsLock->reader_acquire();
ConstantInt *&Slot = (*IntConstants)[Key];
- if (locked) ConstantsLock->reader_release();
+ ConstantsLock->reader_release();
if (!Slot) {
- if (locked) {
- sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
- ConstantInt *&NewSlot = (*IntConstants)[Key];
- if (!Slot) {
- NewSlot = new ConstantInt(ITy, V);
- }
- return NewSlot;
- } else {
- Slot = new ConstantInt(ITy, V);
+ sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
+ ConstantInt *&NewSlot = (*IntConstants)[Key];
+ if (!Slot) {
+ NewSlot = new ConstantInt(ITy, V);
}
+
+ return NewSlot;
+ } else {
+ return Slot;
}
-
- return Slot;
}
-Constant *ConstantInt::get(const Type *Ty, const APInt &V, bool locked) {
- ConstantInt *C = ConstantInt::get(V, locked);
+Constant *ConstantInt::get(const Type *Ty, const APInt &V) {
+ ConstantInt *C = ConstantInt::get(V);
assert(C->getType() == Ty->getScalarType() &&
"ConstantInt type doesn't match the type implied by its value!");
// For vectors, broadcast the value.
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
return
- ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C),
- locked);
+ ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
return C;
}
@@ -412,37 +406,17 @@ typedef DenseMap<DenseMapAPFloatKeyInfo::KeyTy, ConstantFP*,
static ManagedStatic<FPMapTy> FPConstants;
-ConstantFP *ConstantFP::get(const APFloat &V, bool locked) {
+ConstantFP *ConstantFP::get(const APFloat &V) {
DenseMapAPFloatKeyInfo::KeyTy Key(V);
- if (locked) ConstantsLock->reader_acquire();
+ ConstantsLock->reader_acquire();
ConstantFP *&Slot = (*FPConstants)[Key];
- if (locked) ConstantsLock->reader_release();
+ ConstantsLock->reader_release();
if (!Slot) {
- if (locked) {
- sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
- ConstantFP *&NewSlot = (*FPConstants)[Key];
- if (!NewSlot) {
- const Type *Ty;
- if (&V.getSemantics() == &APFloat::IEEEsingle)
- Ty = Type::FloatTy;
- else if (&V.getSemantics() == &APFloat::IEEEdouble)
- Ty = Type::DoubleTy;
- else if (&V.getSemantics() == &APFloat::x87DoubleExtended)
- Ty = Type::X86_FP80Ty;
- else if (&V.getSemantics() == &APFloat::IEEEquad)
- Ty = Type::FP128Ty;
- else {
- assert(&V.getSemantics() == &APFloat::PPCDoubleDouble &&
- "Unknown FP format");
- Ty = Type::PPC_FP128Ty;
- }
- NewSlot = new ConstantFP(Ty, V);
- }
-
- return NewSlot;
- } else {
+ sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
+ ConstantFP *&NewSlot = (*FPConstants)[Key];
+ if (!NewSlot) {
const Type *Ty;
if (&V.getSemantics() == &APFloat::IEEEsingle)
Ty = Type::FloatTy;
@@ -457,8 +431,10 @@ ConstantFP *ConstantFP::get(const APFloat &V, bool locked) {
"Unknown FP format");
Ty = Type::PPC_FP128Ty;
}
- Slot = new ConstantFP(Ty, V);
+ NewSlot = new ConstantFP(Ty, V);
}
+
+ return NewSlot;
}
return Slot;
@@ -467,18 +443,17 @@ ConstantFP *ConstantFP::get(const APFloat &V, bool locked) {
/// get() - This returns a constant fp for the specified value in the
/// specified type. This should only be used for simple constant values like
/// 2.0/1.0 etc, that are known-valid both as double and as the target format.
-Constant *ConstantFP::get(const Type *Ty, double V, bool locked) {
+Constant *ConstantFP::get(const Type *Ty, double V) {
APFloat FV(V);
bool ignored;
FV.convert(*TypeToFloatSemantics(Ty->getScalarType()),
APFloat::rmNearestTiesToEven, &ignored);
- Constant *C = get(FV, locked);
+ Constant *C = get(FV);
// For vectors, broadcast the value.
if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
return
- ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C),
- locked);
+ ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
return C;
}
@@ -882,50 +857,50 @@ Constant *ConstantExpr::getNot(Constant *C) {
return get(Instruction::Xor, C,
Constant::getAllOnesValue(C->getType()));
}
-Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::Add, C1, C2, locked);
+Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2) {
+ return get(Instruction::Add, C1, C2);
}
-Constant *ConstantExpr::getFAdd(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::FAdd, C1, C2, locked);
+Constant *ConstantExpr::getFAdd(Constant *C1, Constant *C2) {
+ return get(Instruction::FAdd, C1, C2);
}
-Constant *ConstantExpr::getSub(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::Sub, C1, C2, locked);
+Constant *ConstantExpr::getSub(Constant *C1, Constant *C2) {
+ return get(Instruction::Sub, C1, C2);
}
-Constant *ConstantExpr::getFSub(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::FSub, C1, C2, locked);
+Constant *ConstantExpr::getFSub(Constant *C1, Constant *C2) {
+ return get(Instruction::FSub, C1, C2);
}
-Constant *ConstantExpr::getMul(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::Mul, C1, C2, locked);
+Constant *ConstantExpr::getMul(Constant *C1, Constant *C2) {
+ return get(Instruction::Mul, C1, C2);
}
-Constant *ConstantExpr::getFMul(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::FMul, C1, C2, locked);
+Constant *ConstantExpr::getFMul(Constant *C1, Constant *C2) {
+ return get(Instruction::FMul, C1, C2);
}
-Constant *ConstantExpr::getUDiv(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::UDiv, C1, C2, locked);
+Constant *ConstantExpr::getUDiv(Constant *C1, Constant *C2) {
+ return get(Instruction::UDiv, C1, C2);
}
-Constant *ConstantExpr::getSDiv(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::SDiv, C1, C2, locked);
+Constant *ConstantExpr::getSDiv(Constant *C1, Constant *C2) {
+ return get(Instruction::SDiv, C1, C2);
}
-Constant *ConstantExpr::getFDiv(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::FDiv, C1, C2, locked);
+Constant *ConstantExpr::getFDiv(Constant *C1, Constant *C2) {
+ return get(Instruction::FDiv, C1, C2);
}
-Constant *ConstantExpr::getURem(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::URem, C1, C2, locked);
+Constant *ConstantExpr::getURem(Constant *C1, Constant *C2) {
+ return get(Instruction::URem, C1, C2);
}
-Constant *ConstantExpr::getSRem(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::SRem, C1, C2, locked);
+Constant *ConstantExpr::getSRem(Constant *C1, Constant *C2) {
+ return get(Instruction::SRem, C1, C2);
}
-Constant *ConstantExpr::getFRem(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::FRem, C1, C2, locked);
+Constant *ConstantExpr::getFRem(Constant *C1, Constant *C2) {
+ return get(Instruction::FRem, C1, C2);
}
-Constant *ConstantExpr::getAnd(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::And, C1, C2, locked);
+Constant *ConstantExpr::getAnd(Constant *C1, Constant *C2) {
+ return get(Instruction::And, C1, C2);
}
-Constant *ConstantExpr::getOr(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::Or, C1, C2, locked);
+Constant *ConstantExpr::getOr(Constant *C1, Constant *C2) {
+ return get(Instruction::Or, C1, C2);
}
-Constant *ConstantExpr::getXor(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::Xor, C1, C2, locked);
+Constant *ConstantExpr::getXor(Constant *C1, Constant *C2) {
+ return get(Instruction::Xor, C1, C2);
}
unsigned ConstantExpr::getPredicate() const {
assert(getOpcode() == Instruction::FCmp ||
@@ -934,14 +909,14 @@ unsigned ConstantExpr::getPredicate() const {
getOpcode() == Instruction::VICmp);
return ((const CompareConstantExpr*)this)->predicate;
}
-Constant *ConstantExpr::getShl(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::Shl, C1, C2, locked);
+Constant *ConstantExpr::getShl(Constant *C1, Constant *C2) {
+ return get(Instruction::Shl, C1, C2);
}
-Constant *ConstantExpr::getLShr(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::LShr, C1, C2, locked);
+Constant *ConstantExpr::getLShr(Constant *C1, Constant *C2) {
+ return get(Instruction::LShr, C1, C2);
}
-Constant *ConstantExpr::getAShr(Constant *C1, Constant *C2, bool locked) {
- return get(Instruction::AShr, C1, C2, locked);
+Constant *ConstantExpr::getAShr(Constant *C1, Constant *C2) {
+ return get(Instruction::AShr, C1, C2);
}
/// getWithOperandReplaced - Return a constant expression identical to this
@@ -1178,6 +1153,9 @@ namespace llvm {
/// AbstractTypeMap - Map for abstract type constants.
///
AbstractTypeMapTy AbstractTypeMap;
+
+ /// ValueMapLock - Mutex for this map.
+ sys::SmartMutex<true> ValueMapLock;
public:
// NOTE: This function is not locked. It is the caller's responsibility
@@ -1253,36 +1231,7 @@ public:
/// getOrCreate - Return the specified constant from the map, creating it if
/// necessary.
ConstantClass *getOrCreate(const TypeClass *Ty, const ValType &V) {
- MapKey Lookup(Ty, V);
- ConstantClass* Result = 0;
-
- ConstantsLock->reader_acquire();
- typename MapTy::iterator I = Map.find(Lookup);
- // Is it in the map?
- if (I != Map.end())
- Result = static_cast<ConstantClass *>(I->second);
- ConstantsLock->reader_release();
-
- if (!Result) {
- sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
- I = Map.find(Lookup);
- // Is it in the map?
- if (I != Map.end())
- Result = static_cast<ConstantClass *>(I->second);
- if (!Result) {
- // If no preexisting value, create one now...
- Result = Create(Ty, V, I);
- }
- }
-
- return Result;
- }
-
- /// unlockedGetOrCreate - Return the specified constant from the map,
- /// creating it if necessary. This version performs no locking, and should
- /// only be used during recursive type refinement, when the locks are
- /// already held.
- ConstantClass *unlockedGetOrCreate(const TypeClass *Ty, const ValType &V) {
+ sys::SmartScopedLock<true> Lock(&ValueMapLock);
MapKey Lookup(Ty, V);
ConstantClass* Result = 0;
@@ -1299,8 +1248,8 @@ public:
return Result;
}
- void remove(ConstantClass *CP, bool locked = true) {
- if (locked) ConstantsLock->writer_acquire();
+ void remove(ConstantClass *CP) {
+ sys::SmartScopedLock<true> Lock(&ValueMapLock);
typename MapTy::iterator I = FindExistingElement(CP);
assert(I != Map.end() && "Constant not found in constant table!");
assert(I->second == CP && "Didn't find correct element?");
@@ -1348,8 +1297,6 @@ public:
}
Map.erase(I);
-
- if (locked) ConstantsLock->writer_release();
}
@@ -1387,7 +1334,7 @@ public:
}
void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
- ConstantsLock->writer_acquire();
+ sys::SmartScopedLock<true> Lock(&ValueMapLock);
typename AbstractTypeMapTy::iterator I =
AbstractTypeMap.find(cast<Type>(OldTy));
@@ -1405,14 +1352,11 @@ public:
I = AbstractTypeMap.find(cast<Type>(OldTy));
} while (I != AbstractTypeMap.end());
-
- ConstantsLock->writer_release();
}
// If the type became concrete without being refined to any other existing
// type, we just remove ourselves from the ATU list.
void typeBecameConcrete(const DerivedType *AbsTy) {
- sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
AbsTy->removeAbstractTypeUser(this);
}
@@ -1439,10 +1383,10 @@ namespace llvm {
struct ConvertConstantType<ConstantAggregateZero, Type> {
static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
// Make everyone now use a constant of the new type...
- Constant *New = ConstantAggregateZero::get(NewTy, false);
+ Constant *New = ConstantAggregateZero::get(NewTy);
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
- OldC->destroyConstant(false); // This constant is now dead, destroy it.
+ OldC->destroyConstant(); // This constant is now dead, destroy it.
}
};
}
@@ -1452,19 +1396,19 @@ static ManagedStatic<ValueMap<char, Type,
static char getValType(ConstantAggregateZero *CPZ) { return 0; }
-ConstantAggregateZero *ConstantAggregateZero::get(const Type *Ty, bool locked) {
+ConstantAggregateZero *ConstantAggregateZero::get(const Type *Ty) {
assert((isa<StructType>(Ty) || isa<ArrayType>(Ty) || isa<VectorType>(Ty)) &&
"Cannot create an aggregate zero of non-aggregate type!");
-
- return locked ? AggZeroConstants->getOrCreate(Ty, 0) :
- AggZeroConstants->unlockedGetOrCreate(Ty, 0);
+
+ // Implicitly locked.
+ return AggZeroConstants->getOrCreate(Ty, 0);
}
/// destroyConstant - Remove the constant from the constant table...
///
-void ConstantAggregateZero::destroyConstant(bool locked) {
+void ConstantAggregateZero::destroyConstant() {
// Implicitly locked.
- AggZeroConstants->remove(this, locked);
+ AggZeroConstants->remove(this);
destroyConstantImpl();
}
@@ -1478,10 +1422,10 @@ namespace llvm {
std::vector<Constant*> C;
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
C.push_back(cast<Constant>(OldC->getOperand(i)));
- Constant *New = ConstantArray::get(NewTy, C, false);
+ Constant *New = ConstantArray::get(NewTy, C);
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
- OldC->destroyConstant(false); // This constant is now dead, destroy it.
+ OldC->destroyConstant(); // This constant is now dead, destroy it.
}
};
}
@@ -1499,36 +1443,29 @@ typedef ValueMap<std::vector<Constant*>, ArrayType,
static ManagedStatic<ArrayConstantsTy> ArrayConstants;
Constant *ConstantArray::get(const ArrayType *Ty,
- const std::vector<Constant*> &V,
- bool locked) {
+ const std::vector<Constant*> &V) {
// If this is an all-zero array, return a ConstantAggregateZero object
if (!V.empty()) {
Constant *C = V[0];
if (!C->isNullValue()) {
- if (locked)
- // Implicitly locked.
- return ArrayConstants->getOrCreate(Ty, V);
- else
- return ArrayConstants->unlockedGetOrCreate(Ty, V);
+ // Implicitly locked.
+ return ArrayConstants->getOrCreate(Ty, V);
}
for (unsigned i = 1, e = V.size(); i != e; ++i)
if (V[i] != C) {
- if (locked)
- // Implicitly locked.
- return ArrayConstants->getOrCreate(Ty, V);
- else
- return ArrayConstants->unlockedGetOrCreate(Ty, V);
+ // Implicitly locked.
+ return ArrayConstants->getOrCreate(Ty, V);
}
}
- return ConstantAggregateZero::get(Ty, locked);
+ return ConstantAggregateZero::get(Ty);
}
/// destroyConstant - Remove the constant from the constant table...
///
-void ConstantArray::destroyConstant(bool locked) {
+void ConstantArray::destroyConstant() {
// Implicitly locked.
- ArrayConstants->remove(this, locked);
+ ArrayConstants->remove(this);
destroyConstantImpl();
}
@@ -1538,8 +1475,7 @@ void ConstantArray::destroyConstant(bool locked) {
/// Otherwise, the length parameter specifies how much of the string to use
/// and it won't be null terminated.
///
-Constant *ConstantArray::get(const std::string &Str,
- bool AddNull, bool locked) {
+Constant *ConstantArray::get(const std::string &Str, bool AddNull) {
std::vector<Constant*> ElementVals;
for (unsigned i = 0; i < Str.length(); ++i)
ElementVals.push_back(ConstantInt::get(Type::Int8Ty, Str[i]));
@@ -1550,7 +1486,7 @@ Constant *ConstantArray::get(const std::string &Str,
}
ArrayType *ATy = ArrayType::get(Type::Int8Ty, ElementVals.size());
- return ConstantArray::get(ATy, ElementVals, locked);
+ return ConstantArray::get(ATy, ElementVals);
}
/// isString - This method returns true if the array is an array of i8, and
@@ -1614,11 +1550,11 @@ namespace llvm {
std::vector<Constant*> C;
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
C.push_back(cast<Constant>(OldC->getOperand(i)));
- Constant *New = ConstantStruct::get(NewTy, C, false);
+ Constant *New = ConstantStruct::get(NewTy, C);
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
- OldC->destroyConstant(false); // This constant is now dead, destroy it.
+ OldC->destroyConstant(); // This constant is now dead, destroy it.
}
};
}
@@ -1636,31 +1572,29 @@ static std::vector<Constant*> getValType(ConstantStruct *CS) {
}
Constant *ConstantStruct::get(const StructType *Ty,
- const std::vector<Constant*> &V,
- bool locked) {
+ const std::vector<Constant*> &V) {
// Create a ConstantAggregateZero value if all elements are zeros...
for (unsigned i = 0, e = V.size(); i != e; ++i)
if (!V[i]->isNullValue())
- return locked ? StructConstants->getOrCreate(Ty, V) :
- StructConstants->unlockedGetOrCreate(Ty, V);
+ // Implicitly locked.
+ return StructConstants->getOrCreate(Ty, V);
- return ConstantAggregateZero::get(Ty, locked);
+ return ConstantAggregateZero::get(Ty);
}
-Constant *ConstantStruct::get(const std::vector<Constant*> &V, bool packed,
- bool locked) {
+Constant *ConstantStruct::get(const std::vector<Constant*> &V, bool packed) {
std::vector<const Type*> StructEls;
StructEls.reserve(V.size());
for (unsigned i = 0, e = V.size(); i != e; ++i)
StructEls.push_back(V[i]->getType());
- return get(StructType::get(StructEls, packed), V, locked);
+ return get(StructType::get(StructEls, packed), V);
}
// destroyConstant - Remove the constant from the constant table...
//
-void ConstantStruct::destroyConstant(bool locked) {
+void ConstantStruct::destroyConstant() {
// Implicitly locked.
- StructConstants->remove(this, locked);
+ StructConstants->remove(this);
destroyConstantImpl();
}
@@ -1674,10 +1608,10 @@ namespace llvm {
std::vector<Constant*> C;
for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
C.push_back(cast<Constant>(OldC->getOperand(i)));
- Constant *New = ConstantVector::get(NewTy, C, false);
+ Constant *New = ConstantVector::get(NewTy, C);
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
- OldC->destroyConstant(false); // This constant is now dead, destroy it.
+ OldC->destroyConstant(); // This constant is now dead, destroy it.
}
};
}
@@ -1694,8 +1628,7 @@ static ManagedStatic<ValueMap<std::vector<Constant*>, VectorType,
ConstantVector> > VectorConstants;
Constant *ConstantVector::get(const VectorType *Ty,
- const std::vector<Constant*> &V,
- bool locked) {
+ const std::vector<Constant*> &V) {
assert(!V.empty() && "Vectors can't be empty");
// If this is an all-undef or alll-zero vector, return a
// ConstantAggregateZero or UndefValue.
@@ -1712,24 +1645,24 @@ Constant *ConstantVector::get(const VectorType *Ty,
}
if (isZero)
- return ConstantAggregateZero::get(Ty, locked);
+ return ConstantAggregateZero::get(Ty);
if (isUndef)
- return UndefValue::get(Ty, locked);
+ return UndefValue::get(Ty);
- return locked ? VectorConstants->getOrCreate(Ty, V) :
- VectorConstants->unlockedGetOrCreate(Ty, V);
+ // Implicitly locked.
+ return VectorConstants->getOrCreate(Ty, V);
}
-Constant *ConstantVector::get(const std::vector<Constant*> &V, bool locked) {
+Constant *ConstantVector::get(const std::vector<Constant*> &V) {
assert(!V.empty() && "Cannot infer type if V is empty");
- return get(VectorType::get(V.front()->getType(),V.size()), V, locked);
+ return get(VectorType::get(V.front()->getType(),V.size()), V);
}
// destroyConstant - Remove the constant from the constant table...
//
-void ConstantVector::destroyConstant(bool locked) {
+void ConstantVector::destroyConstant() {
// Implicitly locked.
- VectorConstants->remove(this, locked);
+ VectorConstants->remove(this);
destroyConstantImpl();
}
@@ -1776,10 +1709,10 @@ namespace llvm {
struct ConvertConstantType<ConstantPointerNull, PointerType> {
static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) {
// Make everyone now use a constant of the new type...
- Constant *New = ConstantPointerNull::get(NewTy, false);
+ Constant *New = ConstantPointerNull::get(NewTy);
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
- OldC->destroyConstant(false); // This constant is now dead, destroy it.
+ OldC->destroyConstant(); // This constant is now dead, destroy it.
}
};
}
@@ -1792,18 +1725,16 @@ static char getValType(ConstantPointerNull *) {
}
-ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty,
- bool locked) {
+ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) {
// Implicitly locked.
- return locked ? NullPtrConstants->getOrCreate(Ty, 0) :
- NullPtrConstants->unlockedGetOrCreate(Ty, 0);
+ return NullPtrConstants->getOrCreate(Ty, 0);
}
// destroyConstant - Remove the constant from the constant table...
//
-void ConstantPointerNull::destroyConstant(bool locked) {
+void ConstantPointerNull::destroyConstant() {
// Implicitly locked.
- NullPtrConstants->remove(this, locked);
+ NullPtrConstants->remove(this);
destroyConstantImpl();
}
@@ -1824,10 +1755,10 @@ namespace llvm {
struct ConvertConstantType<UndefValue, Type> {
static void convert(UndefValue *OldC, const Type *NewTy) {
// Make everyone now use a constant of the new type.
- Constant *New = UndefValue::get(NewTy, false);
+ Constant *New = UndefValue::get(NewTy);
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
- OldC->destroyConstant(false); // This constant is now dead, destroy it.
+ OldC->destroyConstant(); // This constant is now dead, destroy it.
}
};
}
@@ -1839,16 +1770,16 @@ static char getValType(UndefValue *) {
}
-UndefValue *UndefValue::get(const Type *Ty, bool locked) {
- return locked ? UndefValueConstants->getOrCreate(Ty, 0) :
- UndefValueConstants->unlockedGetOrCreate(Ty, 0);
+UndefValue *UndefValue::get(const Type *Ty) {
+ // Implicitly locked.
+ return UndefValueConstants->getOrCreate(Ty, 0);
}
// destroyConstant - Remove the constant from the constant table.
//
-void UndefValue::destroyConstant(bool locked) {
+void UndefValue::destroyConstant() {
// Implicitly locked.
- UndefValueConstants->remove(this, locked);
+ UndefValueConstants->remove(this);
destroyConstantImpl();
}
@@ -1861,25 +1792,21 @@ MDString::MDString(const char *begin, const char *end)
static ManagedStatic<StringMap<MDString*> > MDStringCache;
-MDString *MDString::get(const char *StrBegin, const char *StrEnd, bool locked) {
- if (locked) ConstantsLock->writer_acquire();
-
+MDString *MDString::get(const char *StrBegin, const char *StrEnd) {
+ sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(
StrBegin, StrEnd);
MDString *&S = Entry.getValue();
if (!S) S = new MDString(Entry.getKeyData(),
Entry.getKeyData() + Entry.getKeyLength());
- if (locked) ConstantsLock->writer_release();
-
return S;
}
-void MDString::destroyConstant(bool locked) {
- if (locked) ConstantsLock->writer_acquire();
+void MDString::destroyConstant() {
+ sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd));
destroyConstantImpl();
- if (locked) ConstantsLock->writer_release();
}
//---- MDNode::get() implementation
@@ -1898,26 +1825,20 @@ void MDNode::Profile(FoldingSetNodeID &ID) const {
ID.AddPointer(*I);
}
-MDNode *MDNode::get(Value*const* Vals, unsigned NumVals, bool locked) {
+MDNode *MDNode::get(Value*const* Vals, unsigned NumVals) {
FoldingSetNodeID ID;
for (unsigned i = 0; i != NumVals; ++i)
ID.AddPointer(Vals[i]);
- if (locked) ConstantsLock->reader_acquire();
+ ConstantsLock->reader_acquire();
void *InsertPoint;
MDNode *N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint);
- if (locked) ConstantsLock->reader_release();
+ ConstantsLock->reader_release();
if (!N) {
- if (locked) {
- sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
- N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint);
- if (!N) {
- // InsertPoint will have been set by the FindNodeOrInsertPos call.
- N = new(0) MDNode(Vals, NumVals);
- MDNodeSet->InsertNode(N, InsertPoint);
- }
- } else {
+ sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
+ N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint);
+ if (!N) {
// InsertPoint will have been set by the FindNodeOrInsertPos call.
N = new(0) MDNode(Vals, NumVals);
MDNodeSet->InsertNode(N, InsertPoint);
@@ -1926,11 +1847,11 @@ MDNode *MDNode::get(Value*const* Vals, unsigned NumVals, bool locked) {
return N;
}
-void MDNode::destroyConstant(bool locked) {
- if (locked) ConstantsLock->writer_acquire();
+void MDNode::destroyConstant() {
+ sys::SmartScopedWriter<true> Writer(&*ConstantsLock);
MDNodeSet->RemoveNode(this);
+
destroyConstantImpl();
- if (locked) ConstantsLock->writer_release();
}
//---- ConstantExpr::get() implementations...
@@ -2041,30 +1962,30 @@ namespace llvm {
case Instruction::IntToPtr:
case Instruction::BitCast:
New = ConstantExpr::getCast(OldC->getOpcode(), OldC->getOperand(0),
- NewTy, false);
+ NewTy);
break;
case Instruction::Select:
New = ConstantExpr::getSelectTy(NewTy, OldC->getOperand(0),
OldC->getOperand(1),
- OldC->getOperand(2), false);
+ OldC->getOperand(2));
break;
default:
assert(OldC->getOpcode() >= Instruction::BinaryOpsBegin &&
OldC->getOpcode() < Instruction::BinaryOpsEnd);
New = ConstantExpr::getTy(NewTy, OldC->getOpcode(), OldC->getOperand(0),
- OldC->getOperand(1), false);
+ OldC->getOperand(1));
break;
case Instruction::GetElementPtr:
// Make everyone now use a constant of the new type...
std::vector<Value*> Idx(OldC->op_begin()+1, OldC->op_end());
New = ConstantExpr::getGetElementPtrTy(NewTy, OldC->getOperand(0),
- &Idx[0], Idx.size(), false);
+ &Idx[0], Idx.size());
break;
}
assert(New != OldC && "Didn't replace constant??");
OldC->uncheckedReplaceAllUsesWith(New);
- OldC->destroyConstant(false); // This constant is now dead, destroy it.
+ OldC->destroyConstant(); // This constant is now dead, destroy it.
}
};
} // end namespace llvm
@@ -2087,10 +2008,10 @@ static ManagedStatic<ValueMap<ExprMapKeyType, Type,
/// This is a utility function to handle folding of casts and lookup of the
/// cast in the ExprConstants map. It is used by the various get* methods below.
static inline Constant *getFoldedCast(
- Instruction::CastOps opc, Constant *C, const Type *Ty, bool locked) {
+ Instruction::CastOps opc, Constant *C, const Type *Ty) {
assert(Ty->isFirstClassType() && "Cannot cast to an aggregate type!");
// Fold a few common cases
- if (Constant *FC = ConstantFoldCastInstruction(opc, C, Ty, locked))
+ if (Constant *FC = ConstantFoldCastInstruction(opc, C, Ty))
return FC;
// Look up the constant in the table first to ensure uniqueness
@@ -2098,12 +2019,10 @@ static inline Constant *getFoldedCast(
ExprMapKeyType Key(opc, argVec);
// Implicitly locked.
- return locked ? ExprConstants->getOrCreate(Ty, Key) :
- ExprConstants->unlockedGetOrCreate(Ty, Key);
+ return ExprConstants->getOrCreate(Ty, Key);
}
-Constant *ConstantExpr::getCast(unsigned oc, Constant *C, const Type *Ty,
- bool locked) {
+Constant *ConstantExpr::getCast(unsigned oc, Constant *C, const Type *Ty) {
Instruction::CastOps opc = Instruction::CastOps(oc);
assert(Instruction::isCast(opc) && "opcode out of range");
assert(C && Ty && "Null arguments to getCast");
@@ -2113,18 +2032,18 @@ Constant *ConstantExpr::getCast(unsigned oc, Constant *C, const Type *Ty,
default:
assert(0 && "Invalid cast opcode");
break;
- case Instruction::Trunc: return getTrunc(C, Ty, locked);
- case Instruction::ZExt: return getZExt(C, Ty, locked);
- case Instruction::SExt: return getSExt(C, Ty, locked);
- case Instruction::FPTrunc: return getFPTrunc(C, Ty, locked);
- case Instruction::FPExt: return getFPExtend(C, Ty, locked);
- case Instruction::UIToFP: return getUIToFP(C, Ty, locked);
- case Instruction::SIToFP: return getSIToFP(C, Ty, locked);
- case Instruction::FPToUI: return getFPToUI(C, Ty, locked);
- case Instruction::FPToSI: return getFPToSI(C, Ty, locked);
- case Instruction::PtrToInt: return getPtrToInt(C, Ty, locked);
- case Instruction::IntToPtr: return getIntToPtr(C, Ty, locked);
- case Instruction::BitCast: return getBitCast(C, Ty, locked);
+ case Instruction::Trunc: return getTrunc(C, Ty);
+ case Instruction::ZExt: return getZExt(C, Ty);
+ case Instruction::SExt: return getSExt(C, Ty);
+ case Instruction::FPTrunc: return getFPTrunc(C, Ty);
+ case Instruction::FPExt: return getFPExtend(C, Ty);
+ case Instruction::UIToFP: return getUIToFP(C, Ty);
+ case Instruction::SIToFP: return getSIToFP(C, Ty);
+ case Instruction::FPToUI: return getFPToUI(C, Ty);
+ case Instruction::FPToSI: return getFPToSI(C, Ty);
+ case Instruction::PtrToInt: return getPtrToInt(C, Ty);
+ case Instruction::IntToPtr: return getIntToPtr(C, Ty);
+ case Instruction::BitCast: return getBitCast(C, Ty);
}
return 0;
}
@@ -2135,11 +2054,10 @@ Constant *ConstantExpr::getZExtOrBitCast(Constant *C, const Type *Ty) {
return getCast(Instruction::ZExt, C, Ty);
}
-Constant *ConstantExpr::getSExtOrBitCast(Constant *C, const Type *Ty,
- bool locked) {
+Constant *ConstantExpr::getSExtOrBitCast(Constant *C, const Type *Ty) {
if (C->getType()->getScalarSizeInBits() == Ty->getScalarSizeInBits())
- return getCast(Instruction::BitCast, C, Ty, locked);
- return getCast(Instruction::SExt, C, Ty, locked);
+ return getCast(Instruction::BitCast, C, Ty);
+ return getCast(Instruction::SExt, C, Ty);
}
Constant *ConstantExpr::getTruncOrBitCast(Constant *C, const Type *Ty) {
@@ -2148,14 +2066,13 @@ Constant *ConstantExpr::getTruncOrBitCast(Constant *C, const Type *Ty) {
return getCast(Instruction::Trunc, C, Ty);
}
-Constant *ConstantExpr::getPointerCast(Constant *S, const Type *Ty,
- bool locked) {
+Constant *ConstantExpr::getPointerCast(Constant *S, const Type *Ty) {
assert(isa<PointerType>(S->getType()) && "Invalid cast");
assert((Ty->isInteger() || isa<PointerType>(Ty)) && "Invalid cast");
if (Ty->isInteger())
- return getCast(Instruction::PtrToInt, S, Ty, locked);
- return getCast(Instruction::BitCast, S, Ty, locked);
+ return getCast(Instruction::PtrToInt, S, Ty);
+ return getCast(Instruction::BitCast, S, Ty);
}
Constant *ConstantExpr::getIntegerCast(Constant *C, const Type *Ty,
@@ -2183,7 +2100,7 @@ Constant *ConstantExpr::getFPCast(Constant *C, const Type *Ty) {
return getCast(opcode, C, Ty);
}
-Constant *ConstantExpr::getTrunc(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getTrunc(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2194,10 +2111,10 @@ Constant *ConstantExpr::getTrunc(Constant *C, const Type *Ty, bool locked) {
assert(C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
"SrcTy must be larger than DestTy for Trunc!");
- return getFoldedCast(Instruction::Trunc, C, Ty, locked);
+ return getFoldedCast(Instruction::Trunc, C, Ty);
}
-Constant *ConstantExpr::getSExt(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getSExt(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2208,10 +2125,10 @@ Constant *ConstantExpr::getSExt(Constant *C, const Type *Ty, bool locked) {
assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
"SrcTy must be smaller than DestTy for SExt!");
- return getFoldedCast(Instruction::SExt, C, Ty, locked);
+ return getFoldedCast(Instruction::SExt, C, Ty);
}
-Constant *ConstantExpr::getZExt(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getZExt(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2222,10 +2139,10 @@ Constant *ConstantExpr::getZExt(Constant *C, const Type *Ty, bool locked) {
assert(C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
"SrcTy must be smaller than DestTy for ZExt!");
- return getFoldedCast(Instruction::ZExt, C, Ty, locked);
+ return getFoldedCast(Instruction::ZExt, C, Ty);
}
-Constant *ConstantExpr::getFPTrunc(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getFPTrunc(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2234,10 +2151,10 @@ Constant *ConstantExpr::getFPTrunc(Constant *C, const Type *Ty, bool locked) {
assert(C->getType()->isFPOrFPVector() && Ty->isFPOrFPVector() &&
C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&&
"This is an illegal floating point truncation!");
- return getFoldedCast(Instruction::FPTrunc, C, Ty, locked);
+ return getFoldedCast(Instruction::FPTrunc, C, Ty);
}
-Constant *ConstantExpr::getFPExtend(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getFPExtend(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2246,10 +2163,10 @@ Constant *ConstantExpr::getFPExtend(Constant *C, const Type *Ty, bool locked) {
assert(C->getType()->isFPOrFPVector() && Ty->isFPOrFPVector() &&
C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&&
"This is an illegal floating point extension!");
- return getFoldedCast(Instruction::FPExt, C, Ty, locked);
+ return getFoldedCast(Instruction::FPExt, C, Ty);
}
-Constant *ConstantExpr::getUIToFP(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getUIToFP(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2257,10 +2174,10 @@ Constant *ConstantExpr::getUIToFP(Constant *C, const Type *Ty, bool locked) {
assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
assert(C->getType()->isIntOrIntVector() && Ty->isFPOrFPVector() &&
"This is an illegal uint to floating point cast!");
- return getFoldedCast(Instruction::UIToFP, C, Ty, locked);
+ return getFoldedCast(Instruction::UIToFP, C, Ty);
}
-Constant *ConstantExpr::getSIToFP(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getSIToFP(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2268,10 +2185,10 @@ Constant *ConstantExpr::getSIToFP(Constant *C, const Type *Ty, bool locked) {
assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
assert(C->getType()->isIntOrIntVector() && Ty->isFPOrFPVector() &&
"This is an illegal sint to floating point cast!");
- return getFoldedCast(Instruction::SIToFP, C, Ty, locked);
+ return getFoldedCast(Instruction::SIToFP, C, Ty);
}
-Constant *ConstantExpr::getFPToUI(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getFPToUI(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2279,10 +2196,10 @@ Constant *ConstantExpr::getFPToUI(Constant *C, const Type *Ty, bool locked) {
assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
assert(C->getType()->isFPOrFPVector() && Ty->isIntOrIntVector() &&
"This is an illegal floating point to uint cast!");
- return getFoldedCast(Instruction::FPToUI, C, Ty, locked);
+ return getFoldedCast(Instruction::FPToUI, C, Ty);
}
-Constant *ConstantExpr::getFPToSI(Constant *C, const Type *Ty, bool locked) {
+Constant *ConstantExpr::getFPToSI(Constant *C, const Type *Ty) {
#ifndef NDEBUG
bool fromVec = C->getType()->getTypeID() == Type::VectorTyID;
bool toVec = Ty->getTypeID() == Type::VectorTyID;
@@ -2290,25 +2207,22 @@ Constant *ConstantExpr::getFPToSI(Constant *C, const Type *Ty, bool locked) {
assert((fromVec == toVec) && "Cannot convert from scalar to/from vector");
assert(C->getType()->isFPOrFPVector() && Ty->isIntOrIntVector() &&
"This is an illegal floating point to sint cast!");
- return getFoldedCast(Instruction::FPToSI, C, Ty, locked);
+ return getFoldedCast(Instruction::FPToSI, C, Ty);
}
-Constant *ConstantExpr::getPtrToInt(Constant *C, const Type *DstTy,
- bool locked) {
+Constant *ConstantExpr::getPtrToInt(Constant *C, const Type *DstTy) {
assert(isa<PointerType>(C->getType()) && "PtrToInt source must be pointer");
assert(DstTy->isInteger() && "PtrToInt destination must be integral");
- return getFoldedCast(Instruction::PtrToInt, C, DstTy, locked);
+ return getFoldedCast(Instruction::PtrToInt, C, DstTy);
}
-Constant *ConstantExpr::getIntToPtr(Constant *C, const Type *DstTy,
- bool locked) {
+Constant *ConstantExpr::getIntToPtr(Constant *C, const Type *DstTy) {
assert(C->getType()->isInteger() && "IntToPtr source must be integral");
assert(isa<PointerType>(DstTy) && "IntToPtr destination must be a pointer");
- return getFoldedCast(Instruction::IntToPtr, C, DstTy, locked);
+ return getFoldedCast(Instruction::IntToPtr, C, DstTy);
}
-Constant *ConstantExpr::getBitCast(Constant *C, const Type *DstTy,
- bool locked) {
+Constant *ConstantExpr::getBitCast(Constant *C, const Type *DstTy) {
// BitCast implies a no-op cast of type only. No bits change. However, you
// can't cast pointers to anything but pointers.
#ifndef NDEBUG
@@ -2328,7 +2242,7 @@ Constant *ConstantExpr::getBitCast(Constant *C, const Type *DstTy,
// speedily.
if (C->getType() == DstTy) return C;
- return getFoldedCast(Instruction::BitCast, C, DstTy, locked);
+ return getFoldedCast(Instruction::BitCast, C, DstTy);
}
Constant *ConstantExpr::getAlignOf(const Type *Ty) {
@@ -2351,7 +2265,7 @@ Constant *ConstantExpr::getSizeOf(const Type *Ty) {
}
Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
- Constant *C1, Constant *C2, bool locked) {
+ Constant *C1, Constant *C2) {
// Check the operands for consistency first
assert(Opcode >= Instruction::BinaryOpsBegin &&
Opcode < Instruction::BinaryOpsEnd &&
@@ -2360,14 +2274,14 @@ Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
"Operand types in binary constant expression should match");
if (ReqTy == C1->getType() || ReqTy == Type::Int1Ty)
- if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2, locked))
+ if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
return FC; // Fold a few common cases...
std::vector<Constant*> argVec(1, C1); argVec.push_back(C2);
ExprMapKeyType Key(Opcode, argVec);
- return locked ? ExprConstants->getOrCreate(ReqTy, Key) :
- ExprConstants->unlockedGetOrCreate(ReqTy, Key);
+ // Implicitly locked.
+ return ExprConstants->getOrCreate(ReqTy, Key);
}
Constant *ConstantExpr::getCompareTy(unsigned short predicate,
@@ -2392,8 +2306,7 @@ Constant *ConstantExpr::getCompareTy(unsigned short predicate,
}
}
-Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2,
- bool locked) {
+Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2) {
// API compatibility: Adjust integer opcodes to floating-point opcodes.
if (C1->getType()->isFPOrFPVector()) {
if (Opcode == Instruction::Add) Opcode = Instruction::FAdd;
@@ -2458,7 +2371,7 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2,
}
#endif
- return getTy(C1->getType(), Opcode, C1, C2, locked);
+ return getTy(C1->getType(), Opcode, C1, C2);
}
Constant *ConstantExpr::getCompare(unsigned short pred,
@@ -2468,11 +2381,11 @@ Constant *ConstantExpr::getCompare(unsigned short pred,
}
Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
- Constant *V1, Constant *V2, bool locked) {
+ Constant *V1, Constant *V2) {
assert(!SelectInst::areInvalidOperands(C, V1, V2)&&"Invalid select operands");
if (ReqTy == V1->getType())
- if (Constant *SC = ConstantFoldSelectInstruction(C, V1, V2, locked))
+ if (Constant *SC = ConstantFoldSelectInstruction(C, V1, V2))
return SC; // Fold common cases
std::vector<Constant*> argVec(3, C);
@@ -2480,20 +2393,19 @@ Constant *ConstantExpr::getSelectTy(const Type *ReqTy, Constant *C,
argVec[2] = V2;
ExprMapKeyType Key(Instruction::Select, argVec);
- return locked ? ExprConstants->getOrCreate(ReqTy, Key) :
- ExprConstants->unlockedGetOrCreate(ReqTy, Key);
+ // Implicitly locked.
+ return ExprConstants->getOrCreate(ReqTy, Key);
}
Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
Value* const *Idxs,
- unsigned NumIdx, bool locked) {
+ unsigned NumIdx) {
assert(GetElementPtrInst::getIndexedType(C->getType(), Idxs,
Idxs+NumIdx) ==
cast<PointerType>(ReqTy)->getElementType() &&
"GEP indices invalid!");
- if (Constant *FC = ConstantFoldGetElementPtr(C, (Constant**)Idxs,
- NumIdx, locked))
+ if (Constant *FC = ConstantFoldGetElementPtr(C, (Constant**)Idxs, NumIdx))
return FC; // Fold a few common cases...
assert(isa<PointerType>(C->getType()) &&
@@ -2507,24 +2419,22 @@ Constant *ConstantExpr::getGetElementPtrTy(const Type *ReqTy, Constant *C,
const ExprMapKeyType Key(Instruction::GetElementPtr, ArgVec);
// Implicitly locked.
- return locked ? ExprConstants->getOrCreate(ReqTy, Key) :
- ExprConstants->unlockedGetOrCreate(ReqTy, Key);
+ return ExprConstants->getOrCreate(ReqTy, Key);
}
Constant *ConstantExpr::getGetElementPtr(Constant *C, Value* const *Idxs,
- unsigned NumIdx, bool locked) {
+ unsigned NumIdx) {
// Get the result type of the getelementptr!
const Type *Ty =
GetElementPtrInst::getIndexedType(C->getType(), Idxs, Idxs+NumIdx);
assert(Ty && "GEP indices invalid!");
unsigned As = cast<PointerType>(C->getType())->getAddressSpace();
- return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs,
- NumIdx, locked);
+ return getGetElementPtrTy(PointerType::get(Ty, As), C, Idxs, NumIdx);
}
Constant *ConstantExpr::getGetElementPtr(Constant *C, Constant* const *Idxs,
- unsigned NumIdx, bool locked) {
- return getGetElementPtr(C, (Value* const *)Idxs, NumIdx, locked);
+ unsigned NumIdx) {
+ return getGetElementPtr(C, (Value* const *)Idxs, NumIdx);
}
@@ -2803,8 +2713,9 @@ Constant *ConstantExpr::getZeroValueForNegationExpr(const Type *Ty) {
// destroyConstant - Remove the constant from the constant table...
//
-void ConstantExpr::destroyConstant(bool locked) {
- ExprConstants->remove(this, locked);
+void ConstantExpr::destroyConstant() {
+ // Implicitly locked.
+ ExprConstants->remove(this);
destroyConstantImpl();
}
@@ -2941,7 +2852,6 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
Constant *Replacement = 0;
if (isAllZeros) {
- // We're
Replacement = ConstantAggregateZero::get(getType());
} else {
// Check to see if we have this array type already.
diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp
index a7799ea..5abe1f9 100644
--- a/lib/VMCore/Globals.cpp
+++ b/lib/VMCore/Globals.cpp
@@ -75,7 +75,7 @@ void GlobalValue::removeDeadConstantUsers() const {
/// Override destroyConstant to make sure it doesn't get called on
/// GlobalValue's because they shouldn't be treated like other constants.
-void GlobalValue::destroyConstant(bool locked) {
+void GlobalValue::destroyConstant() {
assert(0 && "You can't GV->destroyConstant()!");
abort();
}