mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-13 23:26:25 +00:00
* Move DerivedType::addAbstractTypeUser from DerivedType.h
* Refactor a bunch of code. Types now only remove one subelement at a time when they are told that they have changed * Improve debugging output, add more assertions... * FIX Bugs: * test/Regression/Assembler/2002-04-04-PureVirtMethCall.ll * test/Regression/Assembler/2002-04-04-PureVirtMethCall2.ll * The change to fix these bugs was the to ValTypeBase::refineAbstractType method. Basically we #if 0'd out the chunk of code there and make the table get reorganized EVEN IF the type has the same pointer. Merging opportunities were being missed! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2121 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -36,6 +36,7 @@ void PATypeHolder::dump() const {
|
|||||||
cerr << "PATypeHolder(" << (void*)this << ")\n";
|
cerr << "PATypeHolder(" << (void*)this << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Type::Type(const string &name, PrimitiveID id)
|
Type::Type(const string &name, PrimitiveID id)
|
||||||
: Value(Type::TypeTy, Value::TypeVal) {
|
: Value(Type::TypeTy, Value::TypeVal) {
|
||||||
setDescription(name);
|
setDescription(name);
|
||||||
@@ -444,6 +445,7 @@ public:
|
|||||||
// corrected.
|
// corrected.
|
||||||
//
|
//
|
||||||
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
|
||||||
|
assert(OldTy == NewTy || OldTy->isAbstract());
|
||||||
if (OldTy == NewTy) {
|
if (OldTy == NewTy) {
|
||||||
if (!OldTy->isAbstract()) {
|
if (!OldTy->isAbstract()) {
|
||||||
// Check to see if the type just became concrete.
|
// Check to see if the type just became concrete.
|
||||||
@@ -508,16 +510,18 @@ protected:
|
|||||||
virtual void typeBecameConcrete(const DerivedType *Ty) = 0;
|
virtual void typeBecameConcrete(const DerivedType *Ty) = 0;
|
||||||
|
|
||||||
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
|
virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy) {
|
||||||
|
assert(OldTy == NewTy || OldTy->isAbstract());
|
||||||
if (OldTy == NewTy) {
|
if (OldTy == NewTy) {
|
||||||
if (!OldTy->isAbstract())
|
if (!OldTy->isAbstract())
|
||||||
typeBecameConcrete(OldTy);
|
typeBecameConcrete(OldTy);
|
||||||
return;
|
// MUST fall through here to update map, even if the type pointers stay
|
||||||
|
// the same!
|
||||||
}
|
}
|
||||||
TypeMap<ValType, TypeClass> &Table = MyTable; // Copy MyTable reference
|
TypeMap<ValType, TypeClass> &Table = MyTable; // Copy MyTable reference
|
||||||
ValType Tmp(*(ValType*)this); // Copy this.
|
ValType Tmp(*(ValType*)this); // Copy this.
|
||||||
PATypeHandle<TypeClass> OldType(Table.get(*(ValType*)this), this);
|
PATypeHandle<TypeClass> OldType(Table.get(*(ValType*)this), this);
|
||||||
Table.remove(*(ValType*)this); // Destroy's this!
|
Table.remove(*(ValType*)this); // Destroy's this!
|
||||||
#if 1
|
#if 0
|
||||||
// Refine temporary to new state...
|
// Refine temporary to new state...
|
||||||
Tmp.doRefinement(OldTy, NewTy);
|
Tmp.doRefinement(OldTy, NewTy);
|
||||||
|
|
||||||
@@ -668,7 +672,8 @@ public:
|
|||||||
StructValType(const vector<const Type*> &args,
|
StructValType(const vector<const Type*> &args,
|
||||||
TypeMap<StructValType, StructType> &Tab)
|
TypeMap<StructValType, StructType> &Tab)
|
||||||
: ValTypeBase<StructValType, StructType>(Tab) {
|
: ValTypeBase<StructValType, StructType>(Tab) {
|
||||||
for (unsigned i = 0; i < args.size(); ++i)
|
ElTypes.reserve(args.size());
|
||||||
|
for (unsigned i = 0, e = args.size(); i != e; ++i)
|
||||||
ElTypes.push_back(PATypeHandle<Type>(args[i], this));
|
ElTypes.push_back(PATypeHandle<Type>(args[i], this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,7 +683,7 @@ public:
|
|||||||
StructValType(const StructValType &SVT)
|
StructValType(const StructValType &SVT)
|
||||||
: ValTypeBase<StructValType, StructType>(SVT){
|
: ValTypeBase<StructValType, StructType>(SVT){
|
||||||
ElTypes.reserve(SVT.ElTypes.size());
|
ElTypes.reserve(SVT.ElTypes.size());
|
||||||
for (unsigned i = 0; i < SVT.ElTypes.size(); ++i)
|
for (unsigned i = 0, e = SVT.ElTypes.size(); i != e; ++i)
|
||||||
ElTypes.push_back(PATypeHandle<Type>(SVT.ElTypes[i], this));
|
ElTypes.push_back(PATypeHandle<Type>(SVT.ElTypes[i], this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -772,6 +777,23 @@ PointerType *PointerType::get(const Type *ValueType) {
|
|||||||
// Derived Type Refinement Functions
|
// Derived Type Refinement Functions
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
// addAbstractTypeUser - Notify an abstract type that there is a new user of
|
||||||
|
// it. This function is called primarily by the PATypeHandle class.
|
||||||
|
//
|
||||||
|
void DerivedType::addAbstractTypeUser(AbstractTypeUser *U) const {
|
||||||
|
assert(isAbstract() && "addAbstractTypeUser: Current type not abstract!");
|
||||||
|
if (U == (AbstractTypeUser*)0x2568a8) {
|
||||||
|
cerr << "Found bad guy!\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG_MERGE_TYPES
|
||||||
|
cerr << " addAbstractTypeUser[" << (void*)this << ", " << getDescription()
|
||||||
|
<< "][" << AbstractTypeUsers.size() << "] User = " << U << endl;
|
||||||
|
#endif
|
||||||
|
AbstractTypeUsers.push_back(U);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// removeAbstractTypeUser - Notify an abstract type that a user of the class
|
// removeAbstractTypeUser - Notify an abstract type that a user of the class
|
||||||
// no longer has a handle to the type. This function is called primarily by
|
// no longer has a handle to the type. This function is called primarily by
|
||||||
// the PATypeHandle class. When there are no users of the abstract type, it
|
// the PATypeHandle class. When there are no users of the abstract type, it
|
||||||
@@ -897,12 +919,12 @@ void DerivedType::typeIsRefined() {
|
|||||||
++isRefining;
|
++isRefining;
|
||||||
|
|
||||||
#ifdef DEBUG_MERGE_TYPES
|
#ifdef DEBUG_MERGE_TYPES
|
||||||
cerr << "typeIsREFINED type: " << (void*)this <<" "<<getDescription() << endl;
|
cerr << "typeIsREFINED type: " << (void*)this <<" "<<getDescription() << "\n";
|
||||||
#endif
|
#endif
|
||||||
for (unsigned i = 0; i < AbstractTypeUsers.size(); ) {
|
for (unsigned i = 0; i < AbstractTypeUsers.size(); ) {
|
||||||
AbstractTypeUser *ATU = AbstractTypeUsers[i];
|
AbstractTypeUser *ATU = AbstractTypeUsers[i];
|
||||||
#ifdef DEBUG_MERGE_TYPES
|
#ifdef DEBUG_MERGE_TYPES
|
||||||
cerr << " typeIsREFINED user " << i << " of abstract type ["
|
cerr << " typeIsREFINED user " << i << "[" << ATU << "] of abstract type ["
|
||||||
<< (void*)this << " " << getDescription() << "]\n";
|
<< (void*)this << " " << getDescription() << "]\n";
|
||||||
#endif
|
#endif
|
||||||
ATU->refineAbstractType(this, this);
|
ATU->refineAbstractType(this, this);
|
||||||
@@ -944,20 +966,21 @@ void FunctionType::refineAbstractType(const DerivedType *OldType,
|
|||||||
<< OldType->getDescription() << "], " << (void*)NewType << " ["
|
<< OldType->getDescription() << "], " << (void*)NewType << " ["
|
||||||
<< NewType->getDescription() << "])\n";
|
<< NewType->getDescription() << "])\n";
|
||||||
#endif
|
#endif
|
||||||
|
// Find the type element we are refining...
|
||||||
if (!OldType->isAbstract()) {
|
PATypeHandle<Type> *MatchTy = 0;
|
||||||
if (ResultType == OldType) ResultType.removeUserFromConcrete();
|
if (ResultType == OldType)
|
||||||
for (unsigned i = 0; i < ParamTys.size(); ++i)
|
MatchTy = &ResultType;
|
||||||
if (ParamTys[i] == OldType) ParamTys[i].removeUserFromConcrete();
|
else {
|
||||||
|
unsigned i;
|
||||||
|
for (i = 0; ParamTys[i] != OldType; ++i)
|
||||||
|
assert(i != ParamTys.size());
|
||||||
|
MatchTy = &ParamTys[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OldType != NewType) {
|
if (!OldType->isAbstract())
|
||||||
if (ResultType == OldType) ResultType = NewType;
|
MatchTy->removeUserFromConcrete();
|
||||||
|
|
||||||
for (unsigned i = 0; i < ParamTys.size(); ++i)
|
|
||||||
if (ParamTys[i] == OldType) ParamTys[i] = NewType;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
*MatchTy = NewType;
|
||||||
const FunctionType *MT = FunctionTypes.containsEquivalent(this);
|
const FunctionType *MT = FunctionTypes.containsEquivalent(this);
|
||||||
if (MT && MT != this) {
|
if (MT && MT != this) {
|
||||||
refineAbstractTypeTo(MT); // Different type altogether...
|
refineAbstractTypeTo(MT); // Different type altogether...
|
||||||
@@ -1007,18 +1030,15 @@ void StructType::refineAbstractType(const DerivedType *OldType,
|
|||||||
<< OldType->getDescription() << "], " << (void*)NewType << " ["
|
<< OldType->getDescription() << "], " << (void*)NewType << " ["
|
||||||
<< NewType->getDescription() << "])\n";
|
<< NewType->getDescription() << "])\n";
|
||||||
#endif
|
#endif
|
||||||
if (!OldType->isAbstract()) {
|
unsigned i;
|
||||||
for (unsigned i = 0; i < ETypes.size(); ++i)
|
for (i = 0; ETypes[i] != OldType; ++i)
|
||||||
if (ETypes[i] == OldType)
|
assert(i != ETypes.size() && "OldType not found in this structure!");
|
||||||
ETypes[i].removeUserFromConcrete();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (OldType != NewType) {
|
if (!OldType->isAbstract())
|
||||||
// Update old type to new type in the array...
|
ETypes[i].removeUserFromConcrete();
|
||||||
for (unsigned i = 0; i < ETypes.size(); ++i)
|
|
||||||
if (ETypes[i] == OldType)
|
// Update old type to new type in the array...
|
||||||
ETypes[i] = NewType;
|
ETypes[i] = NewType;
|
||||||
}
|
|
||||||
|
|
||||||
const StructType *ST = StructTypes.containsEquivalent(this);
|
const StructType *ST = StructTypes.containsEquivalent(this);
|
||||||
if (ST && ST != this) {
|
if (ST && ST != this) {
|
||||||
|
Reference in New Issue
Block a user