summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-08-05 23:16:16 +0000
committerOwen Anderson <resistor@mac.com>2009-08-05 23:16:16 +0000
commit03cb69fbd1ef003f94710f2d497515692ff5445a (patch)
tree09edb1b4c08827055064fa639d024649076349d7 /llvm/lib/VMCore
parente148ceaf65e3704935b8bf0fdc0c7f44283acf6c (diff)
downloadbcm5719-llvm-03cb69fbd1ef003f94710f2d497515692ff5445a.tar.gz
bcm5719-llvm-03cb69fbd1ef003f94710f2d497515692ff5445a.zip
Privatize the StructType table, which unfortunately involves routing contexts through a number of APIs.
llvm-svn: 78258
Diffstat (limited to 'llvm/lib/VMCore')
-rw-r--r--llvm/lib/VMCore/ConstantFold.cpp6
-rw-r--r--llvm/lib/VMCore/Constants.cpp13
-rw-r--r--llvm/lib/VMCore/Core.cpp5
-rw-r--r--llvm/lib/VMCore/LLVMContextImpl.h1
-rw-r--r--llvm/lib/VMCore/Type.cpp21
5 files changed, 27 insertions, 19 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index 081c7801400..da9b6aa9784 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/lib/VMCore/ConstantFold.cpp
@@ -519,7 +519,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
Ops[i] = const_cast<Constant*>(Op);
}
if (isa<StructType>(AggTy))
- return ConstantStruct::get(Ops);
+ return ConstantStruct::get(Context, Ops);
else
return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
}
@@ -548,7 +548,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
Ops[i] = const_cast<Constant*>(Op);
}
if (isa<StructType>(AggTy))
- return ConstantStruct::get(Ops);
+ return ConstantStruct::get(Context, Ops);
else
return ConstantArray::get(cast<ArrayType>(AggTy), Ops);
}
@@ -565,7 +565,7 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
}
Constant *C;
if (isa<StructType>(Agg->getType()))
- C = ConstantStruct::get(Ops);
+ C = ConstantStruct::get(Context, Ops);
else
C = ConstantArray::get(cast<ArrayType>(Agg->getType()), Ops);
return C;
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index d5f3eb972a7..161afe47e2a 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -532,18 +532,20 @@ Constant* ConstantStruct::get(const StructType* T,
return ConstantAggregateZero::get(T);
}
-Constant* ConstantStruct::get(const std::vector<Constant*>& V, bool packed) {
+Constant* ConstantStruct::get(LLVMContext &Context,
+ 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);
+ return get(StructType::get(Context, StructEls, packed), V);
}
-Constant* ConstantStruct::get(Constant* const *Vals, unsigned NumVals,
+Constant* ConstantStruct::get(LLVMContext &Context,
+ Constant* const *Vals, unsigned NumVals,
bool Packed) {
// FIXME: make this the primary ctor method.
- return get(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
+ return get(Context, std::vector<Constant*>(Vals, Vals+NumVals), Packed);
}
ConstantVector::ConstantVector(const VectorType *T,
@@ -1355,7 +1357,8 @@ Constant* ConstantExpr::getSizeOf(const Type* Ty) {
Constant* ConstantExpr::getAlignOf(const Type* Ty) {
// alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
- const Type *AligningTy = StructType::get(Type::Int8Ty, Ty, NULL);
+ const Type *AligningTy = StructType::get(Ty->getContext(),
+ Type::Int8Ty, Ty, NULL);
Constant *NullPtr = Constant::getNullValue(AligningTy->getPointerTo());
Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
Constant *One = ConstantInt::get(Type::Int32Ty, 1);
diff --git a/llvm/lib/VMCore/Core.cpp b/llvm/lib/VMCore/Core.cpp
index 89983500b7b..6cce6782eea 100644
--- a/llvm/lib/VMCore/Core.cpp
+++ b/llvm/lib/VMCore/Core.cpp
@@ -217,7 +217,7 @@ LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
*E = ElementTypes + ElementCount; I != E; ++I)
Tys.push_back(unwrap(*I));
- return wrap(StructType::get(Tys, Packed != 0));
+ return wrap(StructType::get(getGlobalContext(), Tys, Packed != 0));
}
unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
@@ -411,7 +411,8 @@ LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
int Packed) {
- return wrap(ConstantStruct::get(unwrap<Constant>(ConstantVals, Count),
+ return wrap(ConstantStruct::get(getGlobalContext(),
+ unwrap<Constant>(ConstantVals, Count),
Count, Packed != 0));
}
diff --git a/llvm/lib/VMCore/LLVMContextImpl.h b/llvm/lib/VMCore/LLVMContextImpl.h
index 3ce1234adfa..966f54b3e22 100644
--- a/llvm/lib/VMCore/LLVMContextImpl.h
+++ b/llvm/lib/VMCore/LLVMContextImpl.h
@@ -132,6 +132,7 @@ struct LLVMContextImpl {
TypeMap<VectorValType, VectorType> VectorTypes;
TypeMap<PointerValType, PointerType> PointerTypes;
TypeMap<FunctionValType, FunctionType> FunctionTypes;
+ TypeMap<StructValType, StructType> StructTypes;
LLVMContextImpl() : TheTrueVal(0), TheFalseVal(0) { }
};
diff --git a/llvm/lib/VMCore/Type.cpp b/llvm/lib/VMCore/Type.cpp
index 61549f8850c..ac55096ac8a 100644
--- a/llvm/lib/VMCore/Type.cpp
+++ b/llvm/lib/VMCore/Type.cpp
@@ -849,22 +849,23 @@ bool VectorType::isValidElementType(const Type *ElemTy) {
// Struct Type Factory...
//
-static ManagedStatic<TypeMap<StructValType, StructType> > StructTypes;
-
-StructType *StructType::get(const std::vector<const Type*> &ETypes,
+StructType *StructType::get(LLVMContext &Context,
+ const std::vector<const Type*> &ETypes,
bool isPacked) {
StructValType STV(ETypes, isPacked);
StructType *ST = 0;
+ LLVMContextImpl *pImpl = Context.pImpl;
+
sys::SmartScopedLock<true> L(*TypeMapLock);
- ST = StructTypes->get(STV);
+ ST = pImpl->StructTypes.get(STV);
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);
+ pImpl->StructTypes.add(STV, ST);
}
#ifdef DEBUG_MERGE_TYPES
DOUT << "Derived new type: " << *ST << "\n";
@@ -872,7 +873,7 @@ StructType *StructType::get(const std::vector<const Type*> &ETypes,
return ST;
}
-StructType *StructType::get(const Type *type, ...) {
+StructType *StructType::get(LLVMContext &Context, const Type *type, ...) {
va_list ap;
std::vector<const llvm::Type*> StructFields;
va_start(ap, type);
@@ -880,7 +881,7 @@ StructType *StructType::get(const Type *type, ...) {
StructFields.push_back(type);
type = va_arg(ap, llvm::Type*);
}
- return llvm::StructType::get(StructFields);
+ return llvm::StructType::get(Context, StructFields);
}
bool StructType::isValidElementType(const Type *ElemTy) {
@@ -1146,11 +1147,13 @@ void VectorType::typeBecameConcrete(const DerivedType *AbsTy) {
//
void StructType::refineAbstractType(const DerivedType *OldType,
const Type *NewType) {
- StructTypes->RefineAbstractType(this, OldType, NewType);
+ LLVMContextImpl *pImpl = OldType->getContext().pImpl;
+ pImpl->StructTypes.RefineAbstractType(this, OldType, NewType);
}
void StructType::typeBecameConcrete(const DerivedType *AbsTy) {
- StructTypes->TypeBecameConcrete(this, AbsTy);
+ LLVMContextImpl *pImpl = AbsTy->getContext().pImpl;
+ pImpl->StructTypes.TypeBecameConcrete(this, AbsTy);
}
// refineAbstractType - Called when a contained type is found to be more
OpenPOWER on IntegriCloud