From aba7d48764d31976279f7a077cb5b93a89e7e774 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Thu, 3 Dec 2009 01:54:07 +0000 Subject: [PATCH] Revert r90371. It was causing build failures. llvm-svn: 90383 --- llvm/lib/Target/TargetData.cpp | 65 ++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/llvm/lib/Target/TargetData.cpp b/llvm/lib/Target/TargetData.cpp index b99056134f95..e482e201f276 100644 --- a/llvm/lib/Target/TargetData.cpp +++ b/llvm/lib/Target/TargetData.cpp @@ -315,12 +315,11 @@ unsigned TargetData::getAlignmentInfo(AlignTypeEnum AlignType, : Alignments[BestMatchIdx].PrefAlign; } +typedef DenseMap LayoutInfoTy; + namespace { class StructLayoutMap : public AbstractTypeUser { -public: - typedef DenseMap LayoutInfoTy; -private: LayoutInfoTy LayoutInfo; /// refineAbstractType - The callback method invoked when an abstract type is @@ -329,9 +328,14 @@ private: /// virtual void refineAbstractType(const DerivedType *OldTy, const Type *) { - assert(LayoutInfo.find(cast(OldTy)) != LayoutInfo.end() && - "Abstract value not in local map!"); - InvalidateEntry(cast(OldTy)); + const StructType *STy = dyn_cast(OldTy); + assert(STy && "This can only track struct types."); + + LayoutInfoTy::iterator Iter = LayoutInfo.find(STy); + Iter->second->~StructLayout(); + free(Iter->second); + LayoutInfo.erase(Iter); + OldTy->removeAbstractTypeUser(this); } /// typeBecameConcrete - The other case which AbstractTypeUsers must be aware @@ -340,9 +344,14 @@ private: /// This method notifies ATU's when this occurs for a type. /// virtual void typeBecameConcrete(const DerivedType *AbsTy) { - assert(LayoutInfo.find(cast(AbsTy)) != LayoutInfo.end() && - "Abstract value not in local map!"); - InvalidateEntry(cast(AbsTy)); + const StructType *STy = dyn_cast(AbsTy); + assert(STy && "This can only track struct types."); + + LayoutInfoTy::iterator Iter = LayoutInfo.find(STy); + Iter->second->~StructLayout(); + free(Iter->second); + LayoutInfo.erase(Iter); + AbsTy->removeAbstractTypeUser(this); } public: @@ -356,21 +365,23 @@ public: if (Key && Key->isAbstract()) Key->removeAbstractTypeUser(this); - Value->~StructLayout(); - free(Value); + if (Value) { + Value->~StructLayout(); + free(Value); + } } } - void InvalidateEntry(const StructType *Ty) { - LayoutInfoTy::iterator I = LayoutInfo.find(Ty); - if (I == LayoutInfo.end()) return; - - I->second->~StructLayout(); - free(I->second); - LayoutInfo.erase(I); + LayoutInfoTy::iterator end() { + return LayoutInfo.end(); + } - if (Ty->isAbstract()) - Ty->removeAbstractTypeUser(this); + LayoutInfoTy::iterator find(const StructType *&Val) { + return LayoutInfo.find(Val); + } + + bool erase(LayoutInfoTy::iterator I) { + return LayoutInfo.erase(I); } StructLayout *&operator[](const StructType *STy) { @@ -381,7 +392,7 @@ public: virtual void dump() const {} }; -} // end anonymous namespace +} // end namespace llvm TargetData::~TargetData() { delete static_cast(LayoutMap); @@ -419,9 +430,17 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const { /// avoid a dangling pointer in this cache. void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const { if (!LayoutMap) return; // No cache. - + StructLayoutMap *STM = static_cast(LayoutMap); - STM->InvalidateEntry(Ty); + LayoutInfoTy::iterator I = STM->find(Ty); + if (I == STM->end()) return; + + I->second->~StructLayout(); + free(I->second); + STM->erase(I); + + if (Ty->isAbstract()) + Ty->removeAbstractTypeUser(STM); } std::string TargetData::getStringRepresentation() const {