diff options
author | Chris Lattner <sabre@nondot.org> | 2006-01-14 00:07:34 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-01-14 00:07:34 +0000 |
commit | 8dff24f378045058444c18fa7bd03a138e3f883d (patch) | |
tree | db113c9bb82003e84eb579ffdd2b8012e184daf6 /lib/Target/TargetData.cpp | |
parent | 2790383f7387f0770e08f36ccefc9b621d88f98b (diff) | |
download | external_llvm-8dff24f378045058444c18fa7bd03a138e3f883d.zip external_llvm-8dff24f378045058444c18fa7bd03a138e3f883d.tar.gz external_llvm-8dff24f378045058444c18fa7bd03a138e3f883d.tar.bz2 |
Implement a new InvalidateStructLayoutInfo method and add some comments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25304 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r-- | lib/Target/TargetData.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 75e76fe..40b762d 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -131,6 +131,9 @@ TargetData::TargetData(const std::string &ToolName, const Module *M) { BoolAlignment = 1; } +/// Layouts - The lazy cache of structure layout information maintained by +/// TargetData. +/// static std::map<std::pair<const TargetData*,const StructType*>, StructLayout> *Layouts = 0; @@ -165,6 +168,21 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const { } } +/// InvalidateStructLayoutInfo - TargetData speculatively caches StructLayout +/// objects. If a TargetData object is alive when types are being refined and +/// removed, this method must be called whenever a StructType is removed to +/// avoid a dangling pointer in this cache. +void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const { + if (!Layouts) return; // No cache. + + std::map<std::pair<const TargetData*,const StructType*>, + StructLayout>::iterator I = Layouts->find(std::make_pair(this, Ty)); + if (I != Layouts->end()) + Layouts->erase(I); +} + + + static inline void getTypeInfo(const Type *Ty, const TargetData *TD, uint64_t &Size, unsigned char &Alignment) { assert(Ty->isSized() && "Cannot getTypeInfo() on a type that is unsized!"); |