X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTarget%2FTargetData.cpp;h=5bcd6583635bed8003917f59b382932603738d17;hb=762ccea600158bb317dcccdff3303e942426cb71;hp=43f0ac8a94d282f9819709513774364671b5a30c;hpb=28998d1806f5717c841c614f5c6c08fd6de4cdbb;p=oota-llvm.git diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp index 43f0ac8a94d..5bcd6583635 100644 --- a/lib/Target/TargetData.cpp +++ b/lib/Target/TargetData.cpp @@ -24,6 +24,7 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/System/Mutex.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringExtras.h" #include @@ -131,8 +132,6 @@ const TargetAlignElem TargetData::InvalidAlignmentElem = // TargetData Class Implementation //===----------------------------------------------------------------------===// -typedef DenseMap LayoutInfoTy; - /*! A TargetDescription string consists of a sequence of hyphen-delimited specifiers for target endianness, pointer size and alignments, and various @@ -171,9 +170,9 @@ typedef DenseMap LayoutInfoTy; alignment will be used. */ void TargetData::init(const std::string &TargetDescription) { - LayoutMap = static_cast(new LayoutInfoTy()); std::string temp = TargetDescription; + LayoutMap = 0; LittleEndian = false; PointerMemSize = 8; PointerABIAlign = 8; @@ -236,28 +235,11 @@ void TargetData::init(const std::string &TargetDescription) { } } -TargetData::TargetData(const std::string &TargetDescription) - : ImmutablePass(&ID) { - init(TargetDescription); -} - TargetData::TargetData(const Module *M) : ImmutablePass(&ID) { init(M->getDataLayout()); } -TargetData::TargetData(const TargetData &TD) : - ImmutablePass(&ID), - LittleEndian(TD.isLittleEndian()), - PointerMemSize(TD.PointerMemSize), - PointerABIAlign(TD.PointerABIAlign), - PointerPrefAlign(TD.PointerPrefAlign), - Alignments(TD.Alignments) { - LayoutInfoTy *Other = static_cast(TD.LayoutMap); - LayoutMap = static_cast(new LayoutInfoTy(*Other)); -} - - void TargetData::setAlignment(AlignTypeEnum align_type, unsigned char abi_align, unsigned char pref_align, uint32_t bit_width) { @@ -336,11 +318,14 @@ unsigned TargetData::getAlignmentInfo(AlignTypeEnum AlignType, : Alignments[BestMatchIdx].PrefAlign; } -TargetData::~TargetData() { - assert(LayoutMap && "LayoutMap not initialized?"); - LayoutInfoTy &TheMap = *static_cast(LayoutMap); +typedef DenseMapLayoutInfoTy; +TargetData::~TargetData() { + if (!LayoutMap) + return; + // Remove any layouts for this TD. + LayoutInfoTy &TheMap = *static_cast(LayoutMap); for (LayoutInfoTy::iterator I = TheMap.begin(), E = TheMap.end(); I != E; ) { I->second->~StructLayout(); free(I->second); @@ -348,11 +333,12 @@ TargetData::~TargetData() { } delete static_cast(LayoutMap); - LayoutMap = 0; } const StructLayout *TargetData::getStructLayout(const StructType *Ty) const { - assert(LayoutMap && "LayoutMap not initialized?"); + if (!LayoutMap) + LayoutMap = static_cast(new LayoutInfoTy()); + LayoutInfoTy &TheMap = *static_cast(LayoutMap); StructLayout *&SL = TheMap[Ty]; @@ -377,8 +363,9 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const { /// 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 { - assert(LayoutMap && "LayoutMap not initialized?"); - LayoutInfoTy *LayoutInfo = static_cast(LayoutMap); + if (!LayoutMap) return; // No cache. + + LayoutInfoTy* LayoutInfo = static_cast(LayoutMap); LayoutInfoTy::iterator I = LayoutInfo->find(Ty); if (I == LayoutInfo->end()) return;