Index: include/llvm/Constant.h =================================================================== RCS file: /var/cvs/llvm/llvm/include/llvm/Constant.h,v retrieving revision 1.18 diff -u -r1.18 Constant.h --- include/llvm/Constant.h 16 Oct 2004 18:05:10 -0000 1.18 +++ include/llvm/Constant.h 12 Nov 2004 12:28:31 -0000 @@ -25,7 +25,6 @@ : User(Ty, vty, Name) {} ~Constant() {} - void destroyConstantImpl(); public: // setName - Specialize setName to handle symbol table majik... virtual void setName(const std::string &name, SymbolTable *ST = 0); @@ -60,7 +59,12 @@ /// destroyConstantImpl as the last thing they do, to destroy all users and /// delete this. virtual void destroyConstant() { assert(0 && "Not reached!"); } - + + // Don't call this!!! Has to be public because there is no way to make + // a template class a friend... Only ValueMap.clear() in Constants.cpp + // is allowed to call it (apart from destroyConstant methods) + void destroyConstantImpl(); + //// Methods for support type inquiry through isa, cast, and dyn_cast: static inline bool classof(const Constant *) { return true; } static inline bool classof(const GlobalValue *) { return true; } Index: include/llvm/Constants.h =================================================================== RCS file: /var/cvs/llvm/llvm/include/llvm/Constants.h,v retrieving revision 1.63 diff -u -r1.63 Constants.h --- include/llvm/Constants.h 24 Oct 2004 03:18:30 -0000 1.63 +++ include/llvm/Constants.h 10 Nov 2004 12:52:29 -0000 @@ -662,6 +662,8 @@ } }; +void clearAllValueMaps(void); + } // End llvm namespace #endif Index: include/llvm/Type.h =================================================================== RCS file: /var/cvs/llvm/llvm/include/llvm/Type.h,v retrieving revision 1.66 diff -u -r1.66 Type.h --- include/llvm/Type.h 12 Oct 2004 20:35:04 -0000 1.66 +++ include/llvm/Type.h 11 Nov 2004 08:58:37 -0000 @@ -120,6 +120,7 @@ /// to be implemented MUCH more efficiently, and dynamically very few types do /// not contain any elements (most are derived). std::vector ContainedTys; + friend void clearAllTypeMaps(void); public: virtual void print(std::ostream &O) const; @@ -246,7 +247,7 @@ /// getNumContainedTypes - Return the number of types in the derived type. /// - unsigned getNumContainedTypes() const { return ContainedTys.size(); } + size_t getNumContainedTypes() const { return ContainedTys.size(); } //===--------------------------------------------------------------------===// // Static members exported by the Type class itself. Useful for getting @@ -288,7 +289,7 @@ } void dropRef() const { - assert(isAbstract() && "Cannot drop a refernce to a non-abstract type!"); + assert(isAbstract() && "Cannot drop a reference to a non-abstract type!"); assert(RefCount && "No objects are currently referencing this object!"); // If this is the last PATypeHolder using this object, and there are no @@ -394,6 +395,7 @@ } std::ostream &operator<<(std::ostream &OS, const Type &T); +void clearAllTypeMaps(void); } // End llvm namespace Index: include/llvm/Value.h =================================================================== RCS file: /var/cvs/llvm/llvm/include/llvm/Value.h,v retrieving revision 1.66 diff -u -r1.66 Value.h --- include/llvm/Value.h 27 Oct 2004 16:14:47 -0000 1.66 +++ include/llvm/Value.h 11 Nov 2004 10:09:15 -0000 @@ -50,6 +50,8 @@ void operator=(const Value &); // Do not implement Value(const Value &); // Do not implement + friend void clearAllValueMaps(); + public: Value(const Type *Ty, unsigned scid, const std::string &name = ""); virtual ~Value(); @@ -90,7 +92,7 @@ typedef UseListIteratorWrapper use_iterator; typedef UseListConstIteratorWrapper use_const_iterator; - unsigned use_size() const { return Uses.size(); } + size_t use_size() const { return Uses.size(); } bool use_empty() const { return Uses.empty(); } use_iterator use_begin() { return Uses.begin(); } use_const_iterator use_begin() const { return Uses.begin(); } Index: lib/VMCore/Constants.cpp =================================================================== RCS file: /var/cvs/llvm/llvm/lib/VMCore/Constants.cpp,v retrieving revision 1.111 diff -u -r1.111 Constants.cpp --- lib/VMCore/Constants.cpp 28 Oct 2004 06:43:38 -0000 1.111 +++ lib/VMCore/Constants.cpp 12 Nov 2004 12:46:57 -0000 @@ -729,6 +728,17 @@ void dump() const { std::cerr << "Constant.cpp: ValueMap\n"; } + + void clear() { + for(MapIterator I = Map.begin(); I != Map.end();) + { + Constant *C = I->second; + ++I; + C->destroyConstantImpl(); + } + Map.clear(); + AbstractTypeMap.clear(); + } }; } @@ -1401,3 +1411,26 @@ return Instruction::getOpcodeName(getOpcode()); } +namespace llvm { + void clearAllValueMaps(void) { + DoubleConstants.clear(); + FloatConstants.clear(); + SIntConstants.clear(); + UIntConstants.clear(); + AggZeroConstants.clear(); + ArrayConstants.clear(); + StructConstants.clear(); + PackedConstants.clear(); + NullPtrConstants.clear(); + UndefValueConstants.clear(); + ExprConstants.clear(); +/* + for(std::set::iterator I = Constants.begin(); I != Constants.end();) + { + Constant *C = *I; + ++I; + C->destroyConstantImpl(); + } +*/ + } +} \ No newline at end of file Index: lib/VMCore/LeakDetector.cpp =================================================================== RCS file: /var/cvs/llvm/llvm/lib/VMCore/LeakDetector.cpp,v retrieving revision 1.11 diff -u -r1.11 LeakDetector.cpp --- lib/VMCore/LeakDetector.cpp 1 Sep 2004 22:55:37 -0000 1.11 +++ lib/VMCore/LeakDetector.cpp 10 Nov 2004 17:27:11 -0000 @@ -82,21 +82,15 @@ const char* const Name; }; - typedef LeakDetectorImpl Objects; - typedef LeakDetectorImpl LLVMObjects; + static LeakDetectorImpl Objects("GENERIC"); + static LeakDetectorImpl LLVMObjects("LLVM"); - Objects& getObjects() { - static Objects *o = 0; - if (o == 0) - o = new Objects("GENERIC"); - return *o; + LeakDetectorImpl& getObjects() { + return Objects; } - LLVMObjects& getLLVMObjects() { - static LLVMObjects *o = 0; - if (o == 0) - o = new LLVMObjects("LLVM"); - return *o; + static LeakDetectorImpl& getLLVMObjects() { + return LLVMObjects; } } Index: lib/VMCore/Type.cpp =================================================================== RCS file: /var/cvs/llvm/llvm/lib/VMCore/Type.cpp,v retrieving revision 1.116 diff -u -r1.116 Type.cpp --- lib/VMCore/Type.cpp 7 Oct 2004 19:20:48 -0000 1.116 +++ lib/VMCore/Type.cpp 11 Nov 2004 09:14:34 -0000 @@ -357,6 +357,10 @@ Type *Type::LabelTy = &TheLabelTy; +namespace llvm { + std::vector DerivedTypes; +} + //===----------------------------------------------------------------------===// // Derived Type Constructors //===----------------------------------------------------------------------===// @@ -779,6 +783,11 @@ } void dump() const { print("dump output"); } + + void clear() { + TypesByHash.clear(); + Map.clear(); + } }; } @@ -846,6 +855,7 @@ if (MT) return MT; FunctionTypes.add(VT, MT = new FunctionType(ReturnType, Params, isVarArg)); + DerivedTypes.push_back(MT); #ifdef DEBUG_MERGE_TYPES std::cerr << "Derived new type: " << MT << "\n"; @@ -895,6 +905,7 @@ // Value not found. Derive a new type! ArrayTypes.add(AVT, AT = new ArrayType(ElementType, NumElements)); + DerivedTypes.push_back(AT); #ifdef DEBUG_MERGE_TYPES std::cerr << "Derived new type: " << *AT << "\n"; @@ -945,6 +956,7 @@ // Value not found. Derive a new type! PackedTypes.add(PVT, PT = new PackedType(ElementType, NumElements)); + DerivedTypes.push_back(PT); #ifdef DEBUG_MERGE_TYPES std::cerr << "Derived new type: " << *PT << "\n"; @@ -998,6 +1010,7 @@ // Value not found. Derive a new type! StructTypes.add(STV, ST = new StructType(ETypes)); + DerivedTypes.push_back(ST); #ifdef DEBUG_MERGE_TYPES std::cerr << "Derived new type: " << *ST << "\n"; @@ -1050,6 +1063,7 @@ // Value not found. Derive a new type! PointerTypes.add(PVT, PT = new PointerType(ValueType)); + DerivedTypes.push_back(PT); #ifdef DEBUG_MERGE_TYPES std::cerr << "Derived new type: " << *PT << "\n"; @@ -1278,6 +1292,26 @@ T.print(OS); return OS; } + +void clearAllTypeMaps(void) +{ + FunctionTypes.clear(); + PointerTypes.clear(); + StructTypes.clear(); + ArrayTypes.clear(); + PackedTypes.clear(); + for(std::vector::iterator I = DerivedTypes.begin(); I != DerivedTypes.end(); ++I) + { + DerivedType *DT = *I; + DT->ContainedTys.clear(); + } + for(std::vector::iterator I = DerivedTypes.begin(); I != DerivedTypes.end(); ++I) + { + Type *DT = *I; + delete DT; + } + DerivedTypes.clear(); +} } // vim: sw=2