From: Dan Gohman Date: Tue, 25 Aug 2009 16:00:35 +0000 (+0000) Subject: Allocate the basic types inside the LLVMContextImpl instance, X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=63a03cf58505aa839f721f212cd1518ebf133979;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79997 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index 1433ef9af00..4016c0aa05a 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -147,6 +147,21 @@ public: // multithreaded mode. sys::SmartMutex 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 @@ public: TypeMap FunctionTypes; TypeMap StructTypes; TypeMap 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 @@ public: 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) { } }; } diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index 36dcbccdce7..696ac96ae6a 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -304,55 +304,55 @@ const Type *StructType::getTypeAtIndex(unsigned Idx) const { //===----------------------------------------------------------------------===// 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; } //===----------------------------------------------------------------------===//