Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.217 -> 1.218 --- Log message: cleanup ConstantInt to use a single DenseMap for uniquing instead of the heavy-weight ValueMap class. This reduces mem usage bc reading kc++ by 29K, even though it only creates 2955 constant ints! --- Diffs of the changes: (+63 -50) Constants.cpp | 113 ++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 63 insertions(+), 50 deletions(-) Index: llvm/lib/VMCore/Constants.cpp diff -u llvm/lib/VMCore/Constants.cpp:1.217 llvm/lib/VMCore/Constants.cpp:1.218 --- llvm/lib/VMCore/Constants.cpp:1.217 Tue Feb 20 00:11:36 2007 +++ llvm/lib/VMCore/Constants.cpp Tue Feb 20 00:39:57 2007 @@ -22,6 +22,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MathExtras.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallVector.h" #include <algorithm> #include <map> @@ -134,16 +135,74 @@ //===----------------------------------------------------------------------===// -// ConstantXXX Classes -//===----------------------------------------------------------------------===// - +// ConstantInt //===----------------------------------------------------------------------===// -// Normal Constructors ConstantInt::ConstantInt(const IntegerType *Ty, uint64_t V) : Constant(Ty, ConstantIntVal, 0, 0), Val(V) { } +ConstantInt *ConstantInt::TheTrueVal = 0; +ConstantInt *ConstantInt::TheFalseVal = 0; + +namespace llvm { + void CleanupTrueFalse(void *) { + ConstantInt::ResetTrueFalse(); + } +} + +static ManagedCleanup<llvm::CleanupTrueFalse> TrueFalseCleanup; + +ConstantInt *ConstantInt::CreateTrueFalseVals(bool WhichOne) { + assert(TheTrueVal == 0 && TheFalseVal == 0); + TheTrueVal = get(Type::Int1Ty, 1); + TheFalseVal = get(Type::Int1Ty, 0); + + // Ensure that llvm_shutdown nulls out TheTrueVal/TheFalseVal. + TrueFalseCleanup.Register(); + + return WhichOne ? TheTrueVal : TheFalseVal; +} + + +//---- ConstantInt::get() implementations... +// +// Provide DenseMapKeyInfo for all pointers. +namespace { + struct DenseMapIntegerKeyInfo { + typedef std::pair<uint64_t, const IntegerType*> KeyTy; + static inline KeyTy getEmptyKey() { return KeyTy(0, 0); } + static inline KeyTy getTombstoneKey() { return KeyTy(1, 0); } + static unsigned getHashValue(const KeyTy &Key) { + return DenseMapKeyInfo<void*>::getHashValue(Key.second) ^ Key.first; + } + static bool isPod() { return true; } + }; +} + + +typedef DenseMap<DenseMapIntegerKeyInfo::KeyTy, ConstantInt*, +DenseMapIntegerKeyInfo> IntMapTy; +static ManagedStatic<IntMapTy> IntConstants; + +// Get a ConstantInt from an int64_t. Note here that we canoncialize the value +// to a uint64_t value that has been zero extended down to the size of the +// integer type of the ConstantInt. This allows the getZExtValue method to +// just return the stored value while getSExtValue has to convert back to sign +// extended. getZExtValue is more common in LLVM than getSExtValue(). +ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) { + const IntegerType *ITy = cast<IntegerType>(Ty); + V &= ITy->getBitMask(); + ConstantInt *&Slot = (*IntConstants)[std::make_pair(uint64_t(V), ITy)]; + if (Slot) return Slot; + return Slot = new ConstantInt(ITy, V); +} + +//===----------------------------------------------------------------------===// +// ConstantXXX Classes +//===----------------------------------------------------------------------===// + + ConstantFP::ConstantFP(const Type *Ty, double V) : Constant(Ty, ConstantFPVal, 0, 0) { assert(isValueValidForType(Ty, V) && "Value too large for type!"); @@ -598,15 +657,6 @@ /// AbstractTypeMapTy AbstractTypeMap; - private: - void clear(std::vector<Constant *> &Constants) { - for(typename MapTy::iterator I = Map.begin(); I != Map.end(); ++I) - Constants.push_back(I->second); - Map.clear(); - AbstractTypeMap.clear(); - InverseMap.clear(); - } - public: typename MapTy::iterator map_end() { return Map.end(); } @@ -796,43 +846,6 @@ } -//---- ConstantInt::get() implementations... -// -static ManagedStatic<ValueMap<uint64_t, IntegerType, ConstantInt> >IntConstants; - - -// Get a ConstantInt from an int64_t. Note here that we canoncialize the value -// to a uint64_t value that has been zero extended down to the size of the -// integer type of the ConstantInt. This allows the getZExtValue method to -// just return the stored value while getSExtValue has to convert back to sign -// extended. getZExtValue is more common in LLVM than getSExtValue(). -ConstantInt *ConstantInt::get(const Type *Ty, int64_t V) { - const IntegerType *ITy = cast<IntegerType>(Ty); - return IntConstants->getOrCreate(ITy, V & ITy->getBitMask()); -} - -ConstantInt *ConstantInt::TheTrueVal = 0; -ConstantInt *ConstantInt::TheFalseVal = 0; - -void CleanupTrueFalse(void *) { - ConstantInt::ResetTrueFalse(); -} - -static ManagedCleanup<CleanupTrueFalse> TrueFalseCleanup; - -ConstantInt *ConstantInt::CreateTrueFalseVals(bool WhichOne) { - assert(TheTrueVal == 0 && TheFalseVal == 0); - TheTrueVal = get(Type::Int1Ty, 1); - TheFalseVal = get(Type::Int1Ty, 0); - - // Ensure that llvm_shutdown nulls out TheTrueVal/TheFalseVal. - TrueFalseCleanup.Register(); - - return WhichOne ? TheTrueVal : TheFalseVal; -} - - - //---- ConstantFP::get() implementation... // _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits