[llvm-commits] [llvm] r79997 - in /llvm/trunk/lib/VMCore: LLVMContextImpl.h Type.cpp
Dan Gohman
gohman at apple.com
Tue Aug 25 09:00:35 PDT 2009
Author: djg
Date: Tue Aug 25 11:00:35 2009
New Revision: 79997
URL: http://llvm.org/viewvc/llvm-project?rev=79997&view=rev
Log:
Allocate the basic types inside the LLVMContextImpl instance,
rather than separately with new. Move the members above the
TypeMap members to avoid destruction order issues. This fixes
a leak of these objects, and eliminates an extra level of
indirection in Type::getInt32Ty and friends.
Modified:
llvm/trunk/lib/VMCore/LLVMContextImpl.h
llvm/trunk/lib/VMCore/Type.cpp
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=79997&r1=79996&r2=79997&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Tue Aug 25 11:00:35 2009
@@ -147,6 +147,21 @@
// multithreaded mode.
sys::SmartMutex<true> AbstractTypeUsersLock;
+ // Basic type instances.
+ const Type VoidTy;
+ const Type LabelTy;
+ const Type FloatTy;
+ const Type DoubleTy;
+ const Type MetadataTy;
+ const Type X86_FP80Ty;
+ const Type FP128Ty;
+ const Type PPC_FP128Ty;
+ const IntegerType Int1Ty;
+ const IntegerType Int8Ty;
+ const IntegerType Int16Ty;
+ const IntegerType Int32Ty;
+ const IntegerType Int64Ty;
+
// Concrete/Abstract TypeDescriptions - We lazily calculate type descriptions
// for types as they are needed. Because resolution of types must invalidate
// all of the abstract type descriptions, we keep them in a seperate map to
@@ -160,22 +175,7 @@
TypeMap<FunctionValType, FunctionType> FunctionTypes;
TypeMap<StructValType, StructType> StructTypes;
TypeMap<IntegerValType, IntegerType> IntegerTypes;
-
- const Type *VoidTy;
- const Type *LabelTy;
- const Type *FloatTy;
- const Type *DoubleTy;
- const Type *MetadataTy;
- const Type *X86_FP80Ty;
- const Type *FP128Ty;
- const Type *PPC_FP128Ty;
-
- const IntegerType *Int1Ty;
- const IntegerType *Int8Ty;
- const IntegerType *Int16Ty;
- const IntegerType *Int32Ty;
- const IntegerType *Int64Ty;
-
+
/// ValueHandles - This map keeps track of all of the value handles that are
/// watching a Value*. The Value::HasValueHandle bit is used to know
// whether or not a value has an entry in this map.
@@ -183,42 +183,19 @@
ValueHandlesTy ValueHandles;
LLVMContextImpl(LLVMContext &C) : TheTrueVal(0), TheFalseVal(0),
- VoidTy(new Type(C, Type::VoidTyID)),
- LabelTy(new Type(C, Type::LabelTyID)),
- FloatTy(new Type(C, Type::FloatTyID)),
- DoubleTy(new Type(C, Type::DoubleTyID)),
- MetadataTy(new Type(C, Type::MetadataTyID)),
- X86_FP80Ty(new Type(C, Type::X86_FP80TyID)),
- FP128Ty(new Type(C, Type::FP128TyID)),
- PPC_FP128Ty(new Type(C, Type::PPC_FP128TyID)),
- Int1Ty(new IntegerType(C, 1)),
- Int8Ty(new IntegerType(C, 8)),
- Int16Ty(new IntegerType(C, 16)),
- Int32Ty(new IntegerType(C, 32)),
- Int64Ty(new IntegerType(C, 64)) { }
-
- ~LLVMContextImpl() {
- // In principle, we should delete the member types here. However,
- // this causes destruction order issues with the types in the TypeMaps.
- // For now, just leak this, which is at least not a regression from the
- // previous behavior, though still undesirable.
-#if 0
- delete VoidTy;
- delete LabelTy;
- delete FloatTy;
- delete DoubleTy;
- delete MetadataTy;
- delete X86_FP80Ty;
- delete FP128Ty;
- delete PPC_FP128Ty;
-
- delete Int1Ty;
- delete Int8Ty;
- delete Int16Ty;
- delete Int32Ty;
- delete Int64Ty;
-#endif
- }
+ VoidTy(C, Type::VoidTyID),
+ LabelTy(C, Type::LabelTyID),
+ FloatTy(C, Type::FloatTyID),
+ DoubleTy(C, Type::DoubleTyID),
+ MetadataTy(C, Type::MetadataTyID),
+ X86_FP80Ty(C, Type::X86_FP80TyID),
+ FP128Ty(C, Type::FP128TyID),
+ PPC_FP128Ty(C, Type::PPC_FP128TyID),
+ Int1Ty(C, 1),
+ Int8Ty(C, 8),
+ Int16Ty(C, 16),
+ Int32Ty(C, 32),
+ Int64Ty(C, 64) { }
};
}
Modified: llvm/trunk/lib/VMCore/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Type.cpp?rev=79997&r1=79996&r2=79997&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Type.cpp (original)
+++ llvm/trunk/lib/VMCore/Type.cpp Tue Aug 25 11:00:35 2009
@@ -304,55 +304,55 @@
//===----------------------------------------------------------------------===//
const Type *Type::getVoidTy(LLVMContext &C) {
- return C.pImpl->VoidTy;
+ return &C.pImpl->VoidTy;
}
const Type *Type::getLabelTy(LLVMContext &C) {
- return C.pImpl->LabelTy;
+ return &C.pImpl->LabelTy;
}
const Type *Type::getFloatTy(LLVMContext &C) {
- return C.pImpl->FloatTy;
+ return &C.pImpl->FloatTy;
}
const Type *Type::getDoubleTy(LLVMContext &C) {
- return C.pImpl->DoubleTy;
+ return &C.pImpl->DoubleTy;
}
const Type *Type::getMetadataTy(LLVMContext &C) {
- return C.pImpl->MetadataTy;
+ return &C.pImpl->MetadataTy;
}
const Type *Type::getX86_FP80Ty(LLVMContext &C) {
- return C.pImpl->X86_FP80Ty;
+ return &C.pImpl->X86_FP80Ty;
}
const Type *Type::getFP128Ty(LLVMContext &C) {
- return C.pImpl->FP128Ty;
+ return &C.pImpl->FP128Ty;
}
const Type *Type::getPPC_FP128Ty(LLVMContext &C) {
- return C.pImpl->PPC_FP128Ty;
+ return &C.pImpl->PPC_FP128Ty;
}
const IntegerType *Type::getInt1Ty(LLVMContext &C) {
- return C.pImpl->Int1Ty;
+ return &C.pImpl->Int1Ty;
}
const IntegerType *Type::getInt8Ty(LLVMContext &C) {
- return C.pImpl->Int8Ty;
+ return &C.pImpl->Int8Ty;
}
const IntegerType *Type::getInt16Ty(LLVMContext &C) {
- return C.pImpl->Int16Ty;
+ return &C.pImpl->Int16Ty;
}
const IntegerType *Type::getInt32Ty(LLVMContext &C) {
- return C.pImpl->Int32Ty;
+ return &C.pImpl->Int32Ty;
}
const IntegerType *Type::getInt64Ty(LLVMContext &C) {
- return C.pImpl->Int64Ty;
+ return &C.pImpl->Int64Ty;
}
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list