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 | a4de9baf407aa54eb46a27977093d99fc6ae9235 (patch) | |
tree | d36e9f3df9ccdde17b69c8fa183d9146817e4d1e | |
parent | 48c60c0285e476125d20a50baea9ae81f619102e (diff) | |
download | bcm5719-llvm-a4de9baf407aa54eb46a27977093d99fc6ae9235.tar.gz bcm5719-llvm-a4de9baf407aa54eb46a27977093d99fc6ae9235.zip |
Implement a new InvalidateStructLayoutInfo method and add some comments
llvm-svn: 25304
-rw-r--r-- | llvm/lib/Target/TargetData.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Target/TargetData.cpp b/llvm/lib/Target/TargetData.cpp index 75e76fe1860..40b762d8e73 100644 --- a/llvm/lib/Target/TargetData.cpp +++ b/llvm/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!"); |