aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/TargetData.cpp
diff options
context:
space:
mode:
authorRoman Divacky <rdivacky@FreeBSD.org>2009-12-15 18:09:07 +0000
committerRoman Divacky <rdivacky@FreeBSD.org>2009-12-15 18:09:07 +0000
commit571945e6affd20b19264ec22495da418d0fbdbb4 (patch)
tree076117cdf3579003f07cad4cdf0593347ce58150 /lib/Target/TargetData.cpp
parent06f9d4012fb8acea3e9861d5722b5965dbb724d9 (diff)
downloadsrc-571945e6affd20b19264ec22495da418d0fbdbb4.tar.gz
src-571945e6affd20b19264ec22495da418d0fbdbb4.zip
Update LLVM to 91430.
Notes
Notes: svn path=/vendor/llvm/dist/; revision=200581
Diffstat (limited to 'lib/Target/TargetData.cpp')
-rw-r--r--lib/Target/TargetData.cpp126
1 files changed, 41 insertions, 85 deletions
diff --git a/lib/Target/TargetData.cpp b/lib/Target/TargetData.cpp
index fc71bc3ab1fe..9434a1901ffd 100644
--- a/lib/Target/TargetData.cpp
+++ b/lib/Target/TargetData.cpp
@@ -117,14 +117,6 @@ TargetAlignElem::operator==(const TargetAlignElem &rhs) const {
&& TypeBitWidth == rhs.TypeBitWidth);
}
-std::ostream &
-TargetAlignElem::dump(std::ostream &os) const {
- return os << AlignType
- << TypeBitWidth
- << ":" << (int) (ABIAlign * 8)
- << ":" << (int) (PrefAlign * 8);
-}
-
const TargetAlignElem TargetData::InvalidAlignmentElem =
TargetAlignElem::get((AlignTypeEnum) -1, 0, 0, 0);
@@ -323,11 +315,10 @@ unsigned TargetData::getAlignmentInfo(AlignTypeEnum AlignType,
: Alignments[BestMatchIdx].PrefAlign;
}
-typedef DenseMap<const StructType*, StructLayout*> LayoutInfoTy;
-
-namespace llvm {
+namespace {
class StructLayoutMap : public AbstractTypeUser {
+ typedef DenseMap<const StructType*, StructLayout*> LayoutInfoTy;
LayoutInfoTy LayoutInfo;
/// refineAbstractType - The callback method invoked when an abstract type is
@@ -336,19 +327,11 @@ class StructLayoutMap : public AbstractTypeUser {
///
virtual void refineAbstractType(const DerivedType *OldTy,
const Type *) {
- const StructType *STy = dyn_cast<const StructType>(OldTy);
- if (!STy) {
- OldTy->removeAbstractTypeUser(this);
- return;
- }
-
- StructLayout *SL = LayoutInfo[STy];
- if (SL) {
- SL->~StructLayout();
- free(SL);
- LayoutInfo[STy] = NULL;
- }
-
+ const StructType *STy = cast<const StructType>(OldTy);
+ LayoutInfoTy::iterator Iter = LayoutInfo.find(STy);
+ Iter->second->~StructLayout();
+ free(Iter->second);
+ LayoutInfo.erase(Iter);
OldTy->removeAbstractTypeUser(this);
}
@@ -358,70 +341,43 @@ class StructLayoutMap : public AbstractTypeUser {
/// This method notifies ATU's when this occurs for a type.
///
virtual void typeBecameConcrete(const DerivedType *AbsTy) {
- const StructType *STy = dyn_cast<const StructType>(AbsTy);
- if (!STy) {
- AbsTy->removeAbstractTypeUser(this);
- return;
- }
-
- StructLayout *SL = LayoutInfo[STy];
- if (SL) {
- SL->~StructLayout();
- free(SL);
- LayoutInfo[STy] = NULL;
- }
-
+ const StructType *STy = cast<const StructType>(AbsTy);
+ LayoutInfoTy::iterator Iter = LayoutInfo.find(STy);
+ Iter->second->~StructLayout();
+ free(Iter->second);
+ LayoutInfo.erase(Iter);
AbsTy->removeAbstractTypeUser(this);
}
- bool insert(const Type *Ty) {
- if (Ty->isAbstract())
- Ty->addAbstractTypeUser(this);
- return true;
- }
-
public:
virtual ~StructLayoutMap() {
// Remove any layouts.
for (LayoutInfoTy::iterator
- I = LayoutInfo.begin(), E = LayoutInfo.end(); I != E; ++I)
- if (StructLayout *SL = I->second) {
- SL->~StructLayout();
- free(SL);
- }
- }
+ I = LayoutInfo.begin(), E = LayoutInfo.end(); I != E; ++I) {
+ const Type *Key = I->first;
+ StructLayout *Value = I->second;
- inline LayoutInfoTy::iterator begin() {
- return LayoutInfo.begin();
- }
- inline LayoutInfoTy::iterator end() {
- return LayoutInfo.end();
- }
- inline LayoutInfoTy::const_iterator begin() const {
- return LayoutInfo.begin();
- }
- inline LayoutInfoTy::const_iterator end() const {
- return LayoutInfo.end();
- }
+ if (Key->isAbstract())
+ Key->removeAbstractTypeUser(this);
- LayoutInfoTy::iterator find(const StructType *&Val) {
- return LayoutInfo.find(Val);
- }
- LayoutInfoTy::const_iterator find(const StructType *&Val) const {
- return LayoutInfo.find(Val);
+ Value->~StructLayout();
+ free(Value);
+ }
}
- bool erase(const StructType *&Val) {
- return LayoutInfo.erase(Val);
- }
- bool erase(LayoutInfoTy::iterator I) {
- return LayoutInfo.erase(I);
+ 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);
+
+ if (Ty->isAbstract())
+ Ty->removeAbstractTypeUser(this);
}
- StructLayout *&operator[](const Type *Key) {
- const StructType *STy = dyn_cast<const StructType>(Key);
- assert(STy && "Trying to access the struct layout map with a non-struct!");
- insert(STy);
+ StructLayout *&operator[](const StructType *STy) {
return LayoutInfo[STy];
}
@@ -429,17 +385,18 @@ public:
virtual void dump() const {}
};
-} // end namespace llvm
+} // end anonymous namespace
TargetData::~TargetData() {
- delete LayoutMap;
+ delete static_cast<StructLayoutMap*>(LayoutMap);
}
const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
if (!LayoutMap)
LayoutMap = new StructLayoutMap();
- StructLayout *&SL = (*LayoutMap)[Ty];
+ StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
+ StructLayout *&SL = (*STM)[Ty];
if (SL) return SL;
// Otherwise, create the struct layout. Because it is variable length, we
@@ -453,6 +410,10 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
SL = L;
new (L) StructLayout(Ty, *this);
+
+ if (Ty->isAbstract())
+ Ty->addAbstractTypeUser(STM);
+
return L;
}
@@ -463,15 +424,10 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
if (!LayoutMap) return; // No cache.
- DenseMap<const StructType*, StructLayout*>::iterator I = LayoutMap->find(Ty);
- if (I == LayoutMap->end()) return;
-
- I->second->~StructLayout();
- free(I->second);
- LayoutMap->erase(I);
+ StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
+ STM->InvalidateEntry(Ty);
}
-
std::string TargetData::getStringRepresentation() const {
std::string Result;
raw_string_ostream OS(Result);