mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 21:32:39 +00:00
This initial code is meant to convert TargetData to use an AbstractTypesUser so
that it doesn't have dangling pointers when abstract types are resolved. This modifies it somewhat to address comments: making the "StructLayoutMap" an anonymous structure, calling "removeAbstractTypeUser" when appropriate, and adding asserts where helpful. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90362 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e731fa2957
commit
dd5eb02304
@ -30,7 +30,6 @@ class Type;
|
|||||||
class IntegerType;
|
class IntegerType;
|
||||||
class StructType;
|
class StructType;
|
||||||
class StructLayout;
|
class StructLayout;
|
||||||
class StructLayoutMap;
|
|
||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
class LLVMContext;
|
class LLVMContext;
|
||||||
|
|
||||||
@ -86,7 +85,7 @@ private:
|
|||||||
static const TargetAlignElem InvalidAlignmentElem;
|
static const TargetAlignElem InvalidAlignmentElem;
|
||||||
|
|
||||||
// The StructType -> StructLayout map.
|
// The StructType -> StructLayout map.
|
||||||
mutable StructLayoutMap *LayoutMap;
|
mutable void *LayoutMap;
|
||||||
|
|
||||||
//! Set/initialize target alignments
|
//! Set/initialize target alignments
|
||||||
void setAlignment(AlignTypeEnum align_type, unsigned char abi_align,
|
void setAlignment(AlignTypeEnum align_type, unsigned char abi_align,
|
||||||
|
@ -325,7 +325,7 @@ unsigned TargetData::getAlignmentInfo(AlignTypeEnum AlignType,
|
|||||||
|
|
||||||
typedef DenseMap<const StructType*, StructLayout*> LayoutInfoTy;
|
typedef DenseMap<const StructType*, StructLayout*> LayoutInfoTy;
|
||||||
|
|
||||||
namespace llvm {
|
namespace {
|
||||||
|
|
||||||
class StructLayoutMap : public AbstractTypeUser {
|
class StructLayoutMap : public AbstractTypeUser {
|
||||||
LayoutInfoTy LayoutInfo;
|
LayoutInfoTy LayoutInfo;
|
||||||
@ -337,18 +337,12 @@ class StructLayoutMap : public AbstractTypeUser {
|
|||||||
virtual void refineAbstractType(const DerivedType *OldTy,
|
virtual void refineAbstractType(const DerivedType *OldTy,
|
||||||
const Type *) {
|
const Type *) {
|
||||||
const StructType *STy = dyn_cast<const StructType>(OldTy);
|
const StructType *STy = dyn_cast<const StructType>(OldTy);
|
||||||
if (!STy) {
|
assert(STy && "This can only track struct types.");
|
||||||
OldTy->removeAbstractTypeUser(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
StructLayout *SL = LayoutInfo[STy];
|
|
||||||
if (SL) {
|
|
||||||
SL->~StructLayout();
|
|
||||||
free(SL);
|
|
||||||
LayoutInfo[STy] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
LayoutInfoTy::iterator Iter = LayoutInfo.find(STy);
|
||||||
|
Iter->second->~StructLayout();
|
||||||
|
free(Iter->second);
|
||||||
|
LayoutInfo.erase(Iter);
|
||||||
OldTy->removeAbstractTypeUser(this);
|
OldTy->removeAbstractTypeUser(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,69 +353,46 @@ class StructLayoutMap : public AbstractTypeUser {
|
|||||||
///
|
///
|
||||||
virtual void typeBecameConcrete(const DerivedType *AbsTy) {
|
virtual void typeBecameConcrete(const DerivedType *AbsTy) {
|
||||||
const StructType *STy = dyn_cast<const StructType>(AbsTy);
|
const StructType *STy = dyn_cast<const StructType>(AbsTy);
|
||||||
if (!STy) {
|
assert(STy && "This can only track struct types.");
|
||||||
AbsTy->removeAbstractTypeUser(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
StructLayout *SL = LayoutInfo[STy];
|
|
||||||
if (SL) {
|
|
||||||
SL->~StructLayout();
|
|
||||||
free(SL);
|
|
||||||
LayoutInfo[STy] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
LayoutInfoTy::iterator Iter = LayoutInfo.find(STy);
|
||||||
|
Iter->second->~StructLayout();
|
||||||
|
free(Iter->second);
|
||||||
|
LayoutInfo.erase(Iter);
|
||||||
AbsTy->removeAbstractTypeUser(this);
|
AbsTy->removeAbstractTypeUser(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool insert(const Type *Ty) {
|
|
||||||
if (Ty->isAbstract())
|
|
||||||
Ty->addAbstractTypeUser(this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~StructLayoutMap() {
|
virtual ~StructLayoutMap() {
|
||||||
// Remove any layouts.
|
// Remove any layouts.
|
||||||
for (LayoutInfoTy::iterator
|
for (LayoutInfoTy::iterator
|
||||||
I = LayoutInfo.begin(), E = LayoutInfo.end(); I != E; ++I)
|
I = LayoutInfo.begin(), E = LayoutInfo.end(); I != E; ++I) {
|
||||||
if (StructLayout *SL = I->second) {
|
const Type *Key = I->first;
|
||||||
SL->~StructLayout();
|
StructLayout *Value = I->second;
|
||||||
free(SL);
|
|
||||||
|
if (Key && Key->isAbstract())
|
||||||
|
Key->removeAbstractTypeUser(this);
|
||||||
|
|
||||||
|
if (Value) {
|
||||||
|
Value->~StructLayout();
|
||||||
|
free(Value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline LayoutInfoTy::iterator begin() {
|
LayoutInfoTy::iterator end() {
|
||||||
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();
|
return LayoutInfo.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
LayoutInfoTy::iterator find(const StructType *&Val) {
|
LayoutInfoTy::iterator find(const StructType *&Val) {
|
||||||
return LayoutInfo.find(Val);
|
return LayoutInfo.find(Val);
|
||||||
}
|
}
|
||||||
LayoutInfoTy::const_iterator find(const StructType *&Val) const {
|
|
||||||
return LayoutInfo.find(Val);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool erase(const StructType *&Val) {
|
|
||||||
return LayoutInfo.erase(Val);
|
|
||||||
}
|
|
||||||
bool erase(LayoutInfoTy::iterator I) {
|
bool erase(LayoutInfoTy::iterator I) {
|
||||||
return LayoutInfo.erase(I);
|
return LayoutInfo.erase(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
StructLayout *&operator[](const Type *Key) {
|
StructLayout *&operator[](const StructType *STy) {
|
||||||
const StructType *STy = dyn_cast<const StructType>(Key);
|
|
||||||
assert(STy && "Trying to access the struct layout map with a non-struct!");
|
|
||||||
insert(STy);
|
|
||||||
return LayoutInfo[STy];
|
return LayoutInfo[STy];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,14 +403,15 @@ public:
|
|||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
TargetData::~TargetData() {
|
TargetData::~TargetData() {
|
||||||
delete LayoutMap;
|
delete static_cast<StructLayoutMap*>(LayoutMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
|
const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
|
||||||
if (!LayoutMap)
|
if (!LayoutMap)
|
||||||
LayoutMap = new StructLayoutMap();
|
LayoutMap = new StructLayoutMap();
|
||||||
|
|
||||||
StructLayout *&SL = (*LayoutMap)[Ty];
|
StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
|
||||||
|
StructLayout *&SL = (*STM)[Ty];
|
||||||
if (SL) return SL;
|
if (SL) return SL;
|
||||||
|
|
||||||
// Otherwise, create the struct layout. Because it is variable length, we
|
// Otherwise, create the struct layout. Because it is variable length, we
|
||||||
@ -453,6 +425,10 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
|
|||||||
SL = L;
|
SL = L;
|
||||||
|
|
||||||
new (L) StructLayout(Ty, *this);
|
new (L) StructLayout(Ty, *this);
|
||||||
|
|
||||||
|
if (Ty->isAbstract())
|
||||||
|
Ty->addAbstractTypeUser(STM);
|
||||||
|
|
||||||
return L;
|
return L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -463,14 +439,17 @@ const StructLayout *TargetData::getStructLayout(const StructType *Ty) const {
|
|||||||
void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
|
void TargetData::InvalidateStructLayoutInfo(const StructType *Ty) const {
|
||||||
if (!LayoutMap) return; // No cache.
|
if (!LayoutMap) return; // No cache.
|
||||||
|
|
||||||
DenseMap<const StructType*, StructLayout*>::iterator I = LayoutMap->find(Ty);
|
StructLayoutMap *STM = static_cast<StructLayoutMap*>(LayoutMap);
|
||||||
if (I == LayoutMap->end()) return;
|
LayoutInfoTy::iterator I = STM->find(Ty);
|
||||||
|
if (I == STM->end()) return;
|
||||||
|
|
||||||
I->second->~StructLayout();
|
I->second->~StructLayout();
|
||||||
free(I->second);
|
free(I->second);
|
||||||
LayoutMap->erase(I);
|
STM->erase(I);
|
||||||
}
|
|
||||||
|
|
||||||
|
if (Ty->isAbstract())
|
||||||
|
Ty->removeAbstractTypeUser(STM);
|
||||||
|
}
|
||||||
|
|
||||||
std::string TargetData::getStringRepresentation() const {
|
std::string TargetData::getStringRepresentation() const {
|
||||||
std::string Result;
|
std::string Result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user