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 18 Nov 2004 17:41:59 -0000 @@ -92,6 +92,8 @@ "implemented for all constants that have operands!"); assert(0 && "Constants that do not have operands cannot be using 'From'!"); } + + static void clearAllValueMaps(); }; } // End llvm namespace 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 18 Nov 2004 17:41:34 -0000 @@ -288,7 +288,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 @@ -296,6 +296,9 @@ if (--RefCount == 0) RefCountIsZero(); } + + static void clearAllTypeMaps(); + private: /// isSizedDerivedType - Derived types like structures and arrays are sized /// iff all of the members of the type are sized as well. Since asking for 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 19 Nov 2004 10:43:14 -0000 @@ -612,6 +612,19 @@ typedef std::map AbstractTypeMapTy; AbstractTypeMapTy AbstractTypeMap; + + friend void Constant::clearAllValueMaps(); + private: + void clear(std::vector &Constants) + { + for(MapIterator I = Map.begin(); I != Map.end(); I++) + { + Constants.push_back(I->second); + } + Map.clear(); + AbstractTypeMap.clear(); + } + public: // getOrCreate - Return the specified constant from the map, creating it if // necessary. @@ -1401,3 +1414,29 @@ return Instruction::getOpcodeName(getOpcode()); } +void Constant::clearAllValueMaps() +{ + std::vector Constants; + + DoubleConstants.clear(Constants); + FloatConstants.clear(Constants); + SIntConstants.clear(Constants); + UIntConstants.clear(Constants); + AggZeroConstants.clear(Constants); + ArrayConstants.clear(Constants); + StructConstants.clear(Constants); + PackedConstants.clear(Constants); + NullPtrConstants.clear(Constants); + UndefValueConstants.clear(Constants); + ExprConstants.clear(Constants); + + for(std::vector::iterator I = Constants.begin(); I != Constants.end();) { + Constant *C = *I++; + C->dropAllReferences(); + } + for(std::vector::iterator I = Constants.begin(); I != Constants.end();) { + Constant *C = *I++; + C->destroyConstantImpl(); + } + Constants.clear(); +} Index: lib/VMCore/Type.cpp =================================================================== RCS file: /var/cvs/llvm/llvm/lib/VMCore/Type.cpp,v retrieving revision 1.118 diff -u -r1.118 Type.cpp --- lib/VMCore/Type.cpp 16 Nov 2004 20:39:04 -0000 1.118 +++ lib/VMCore/Type.cpp 19 Nov 2004 10:43:18 -0000 @@ -656,6 +656,19 @@ /// this map. /// std::multimap TypesByHash; + + friend void Type::clearAllTypeMaps(); + +private: + void clear(std::vector &DerivedTypes) + { + for(std::map::iterator I = Map.begin(); I != Map.end(); I++) + { + DerivedTypes.push_back(I->second.get()); + } + TypesByHash.clear(); + Map.clear(); + } public: typedef typename std::map::iterator iterator; ~TypeMap() { print("ON EXIT"); } @@ -1301,4 +1314,25 @@ } } +void Type::clearAllTypeMaps() +{ + std::vector DerivedTypes; + + FunctionTypes.clear(DerivedTypes); + PointerTypes.clear(DerivedTypes); + StructTypes.clear(DerivedTypes); + ArrayTypes.clear(DerivedTypes); + PackedTypes.clear(DerivedTypes); + + for(std::vector::iterator I = DerivedTypes.begin(); I != DerivedTypes.end();) { + Type *DT = *I++; + DT->ContainedTys.clear(); + } + for(std::vector::iterator I = DerivedTypes.begin(); I != DerivedTypes.end();) { + Type *DT = *I++; + delete DT; + } + DerivedTypes.clear(); +} + // vim: sw=2