mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-10 16:24:04 +00:00
Fix PR7658, a problem where type refinement can trigger
constant replacement which was botching its handling of types. Use of getType() instead of getRawType() was causing the type map in constant folding to be updated wrong. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108610 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
21444efae0
commit
93604b6de2
@ -956,14 +956,14 @@ ConstantAggregateZero* ConstantAggregateZero::get(const Type* Ty) {
|
|||||||
/// destroyConstant - Remove the constant from the constant table...
|
/// destroyConstant - Remove the constant from the constant table...
|
||||||
///
|
///
|
||||||
void ConstantAggregateZero::destroyConstant() {
|
void ConstantAggregateZero::destroyConstant() {
|
||||||
getType()->getContext().pImpl->AggZeroConstants.remove(this);
|
getRawType()->getContext().pImpl->AggZeroConstants.remove(this);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// destroyConstant - Remove the constant from the constant table...
|
/// destroyConstant - Remove the constant from the constant table...
|
||||||
///
|
///
|
||||||
void ConstantArray::destroyConstant() {
|
void ConstantArray::destroyConstant() {
|
||||||
getType()->getContext().pImpl->ArrayConstants.remove(this);
|
getRawType()->getContext().pImpl->ArrayConstants.remove(this);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1027,21 +1027,21 @@ namespace llvm {
|
|||||||
// destroyConstant - Remove the constant from the constant table...
|
// destroyConstant - Remove the constant from the constant table...
|
||||||
//
|
//
|
||||||
void ConstantStruct::destroyConstant() {
|
void ConstantStruct::destroyConstant() {
|
||||||
getType()->getContext().pImpl->StructConstants.remove(this);
|
getRawType()->getContext().pImpl->StructConstants.remove(this);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
// destroyConstant - Remove the constant from the constant table...
|
// destroyConstant - Remove the constant from the constant table...
|
||||||
//
|
//
|
||||||
void ConstantUnion::destroyConstant() {
|
void ConstantUnion::destroyConstant() {
|
||||||
getType()->getContext().pImpl->UnionConstants.remove(this);
|
getRawType()->getContext().pImpl->UnionConstants.remove(this);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
// destroyConstant - Remove the constant from the constant table...
|
// destroyConstant - Remove the constant from the constant table...
|
||||||
//
|
//
|
||||||
void ConstantVector::destroyConstant() {
|
void ConstantVector::destroyConstant() {
|
||||||
getType()->getContext().pImpl->VectorConstants.remove(this);
|
getRawType()->getContext().pImpl->VectorConstants.remove(this);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1082,7 +1082,7 @@ ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) {
|
|||||||
// destroyConstant - Remove the constant from the constant table...
|
// destroyConstant - Remove the constant from the constant table...
|
||||||
//
|
//
|
||||||
void ConstantPointerNull::destroyConstant() {
|
void ConstantPointerNull::destroyConstant() {
|
||||||
getType()->getContext().pImpl->NullPtrConstants.remove(this);
|
getRawType()->getContext().pImpl->NullPtrConstants.remove(this);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1097,7 +1097,7 @@ UndefValue *UndefValue::get(const Type *Ty) {
|
|||||||
// destroyConstant - Remove the constant from the constant table.
|
// destroyConstant - Remove the constant from the constant table.
|
||||||
//
|
//
|
||||||
void UndefValue::destroyConstant() {
|
void UndefValue::destroyConstant() {
|
||||||
getType()->getContext().pImpl->UndefValueConstants.remove(this);
|
getRawType()->getContext().pImpl->UndefValueConstants.remove(this);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1131,7 +1131,7 @@ BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
|
|||||||
// destroyConstant - Remove the constant from the constant table.
|
// destroyConstant - Remove the constant from the constant table.
|
||||||
//
|
//
|
||||||
void BlockAddress::destroyConstant() {
|
void BlockAddress::destroyConstant() {
|
||||||
getFunction()->getType()->getContext().pImpl
|
getFunction()->getRawType()->getContext().pImpl
|
||||||
->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock()));
|
->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock()));
|
||||||
getBasicBlock()->AdjustBlockAddressRefCount(-1);
|
getBasicBlock()->AdjustBlockAddressRefCount(-1);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
@ -1930,7 +1930,7 @@ Constant* ConstantExpr::getAShr(Constant* C1, Constant* C2) {
|
|||||||
// destroyConstant - Remove the constant from the constant table...
|
// destroyConstant - Remove the constant from the constant table...
|
||||||
//
|
//
|
||||||
void ConstantExpr::destroyConstant() {
|
void ConstantExpr::destroyConstant() {
|
||||||
getType()->getContext().pImpl->ExprConstants.remove(this);
|
getRawType()->getContext().pImpl->ExprConstants.remove(this);
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1971,11 +1971,10 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
|
||||||
Constant *ToC = cast<Constant>(To);
|
Constant *ToC = cast<Constant>(To);
|
||||||
|
|
||||||
LLVMContext &Context = getType()->getContext();
|
LLVMContextImpl *pImpl = getRawType()->getContext().pImpl;
|
||||||
LLVMContextImpl *pImpl = Context.pImpl;
|
|
||||||
|
|
||||||
std::pair<LLVMContextImpl::ArrayConstantsTy::MapKey, ConstantArray*> Lookup;
|
std::pair<LLVMContextImpl::ArrayConstantsTy::MapKey, ConstantArray*> Lookup;
|
||||||
Lookup.first.first = getType();
|
Lookup.first.first = cast<ArrayType>(getRawType());
|
||||||
Lookup.second = this;
|
Lookup.second = this;
|
||||||
|
|
||||||
std::vector<Constant*> &Values = Lookup.first.second;
|
std::vector<Constant*> &Values = Lookup.first.second;
|
||||||
@ -2009,7 +2008,7 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
|
|
||||||
Constant *Replacement = 0;
|
Constant *Replacement = 0;
|
||||||
if (isAllZeros) {
|
if (isAllZeros) {
|
||||||
Replacement = ConstantAggregateZero::get(getType());
|
Replacement = ConstantAggregateZero::get(getRawType());
|
||||||
} else {
|
} else {
|
||||||
// Check to see if we have this array type already.
|
// Check to see if we have this array type already.
|
||||||
bool Exists;
|
bool Exists;
|
||||||
@ -2060,7 +2059,7 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
assert(getOperand(OperandToUpdate) == From && "ReplaceAllUsesWith broken!");
|
assert(getOperand(OperandToUpdate) == From && "ReplaceAllUsesWith broken!");
|
||||||
|
|
||||||
std::pair<LLVMContextImpl::StructConstantsTy::MapKey, ConstantStruct*> Lookup;
|
std::pair<LLVMContextImpl::StructConstantsTy::MapKey, ConstantStruct*> Lookup;
|
||||||
Lookup.first.first = getType();
|
Lookup.first.first = cast<StructType>(getRawType());
|
||||||
Lookup.second = this;
|
Lookup.second = this;
|
||||||
std::vector<Constant*> &Values = Lookup.first.second;
|
std::vector<Constant*> &Values = Lookup.first.second;
|
||||||
Values.reserve(getNumOperands()); // Build replacement struct.
|
Values.reserve(getNumOperands()); // Build replacement struct.
|
||||||
@ -2082,14 +2081,13 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
}
|
}
|
||||||
Values[OperandToUpdate] = ToC;
|
Values[OperandToUpdate] = ToC;
|
||||||
|
|
||||||
LLVMContext &Context = getType()->getContext();
|
LLVMContextImpl *pImpl = getRawType()->getContext().pImpl;
|
||||||
LLVMContextImpl *pImpl = Context.pImpl;
|
|
||||||
|
|
||||||
Constant *Replacement = 0;
|
Constant *Replacement = 0;
|
||||||
if (isAllZeros) {
|
if (isAllZeros) {
|
||||||
Replacement = ConstantAggregateZero::get(getType());
|
Replacement = ConstantAggregateZero::get(getRawType());
|
||||||
} else {
|
} else {
|
||||||
// Check to see if we have this array type already.
|
// Check to see if we have this struct type already.
|
||||||
bool Exists;
|
bool Exists;
|
||||||
LLVMContextImpl::StructConstantsTy::MapTy::iterator I =
|
LLVMContextImpl::StructConstantsTy::MapTy::iterator I =
|
||||||
pImpl->StructConstants.InsertOrGetItem(Lookup, Exists);
|
pImpl->StructConstants.InsertOrGetItem(Lookup, Exists);
|
||||||
@ -2128,16 +2126,15 @@ void ConstantUnion::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
assert(getOperand(0) == From && "ReplaceAllUsesWith broken!");
|
assert(getOperand(0) == From && "ReplaceAllUsesWith broken!");
|
||||||
|
|
||||||
std::pair<LLVMContextImpl::UnionConstantsTy::MapKey, ConstantUnion*> Lookup;
|
std::pair<LLVMContextImpl::UnionConstantsTy::MapKey, ConstantUnion*> Lookup;
|
||||||
Lookup.first.first = getType();
|
Lookup.first.first = cast<UnionType>(getRawType());
|
||||||
Lookup.second = this;
|
Lookup.second = this;
|
||||||
Lookup.first.second = ToC;
|
Lookup.first.second = ToC;
|
||||||
|
|
||||||
LLVMContext &Context = getType()->getContext();
|
LLVMContextImpl *pImpl = getRawType()->getContext().pImpl;
|
||||||
LLVMContextImpl *pImpl = Context.pImpl;
|
|
||||||
|
|
||||||
Constant *Replacement = 0;
|
Constant *Replacement = 0;
|
||||||
if (ToC->isNullValue()) {
|
if (ToC->isNullValue()) {
|
||||||
Replacement = ConstantAggregateZero::get(getType());
|
Replacement = ConstantAggregateZero::get(getRawType());
|
||||||
} else {
|
} else {
|
||||||
// Check to see if we have this union type already.
|
// Check to see if we have this union type already.
|
||||||
bool Exists;
|
bool Exists;
|
||||||
@ -2180,7 +2177,7 @@ void ConstantVector::replaceUsesOfWithOnConstant(Value *From, Value *To,
|
|||||||
Values.push_back(Val);
|
Values.push_back(Val);
|
||||||
}
|
}
|
||||||
|
|
||||||
Constant *Replacement = get(getType(), Values);
|
Constant *Replacement = get(cast<VectorType>(getRawType()), Values);
|
||||||
assert(Replacement != this && "I didn't contain From!");
|
assert(Replacement != this && "I didn't contain From!");
|
||||||
|
|
||||||
// Everyone using this now uses the replacement.
|
// Everyone using this now uses the replacement.
|
||||||
@ -2227,7 +2224,7 @@ void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV,
|
|||||||
&Indices[0], Indices.size());
|
&Indices[0], Indices.size());
|
||||||
} else if (isCast()) {
|
} else if (isCast()) {
|
||||||
assert(getOperand(0) == From && "Cast only has one use!");
|
assert(getOperand(0) == From && "Cast only has one use!");
|
||||||
Replacement = ConstantExpr::getCast(getOpcode(), To, getType());
|
Replacement = ConstantExpr::getCast(getOpcode(), To, getRawType());
|
||||||
} else if (getOpcode() == Instruction::Select) {
|
} else if (getOpcode() == Instruction::Select) {
|
||||||
Constant *C1 = getOperand(0);
|
Constant *C1 = getOperand(0);
|
||||||
Constant *C2 = getOperand(1);
|
Constant *C2 = getOperand(1);
|
||||||
|
@ -757,9 +757,13 @@ public:
|
|||||||
|
|
||||||
// If this constant is the representative element for its abstract type,
|
// If this constant is the representative element for its abstract type,
|
||||||
// update the AbstractTypeMap so that the representative element is I.
|
// update the AbstractTypeMap so that the representative element is I.
|
||||||
if (C->getType()->isAbstract()) {
|
//
|
||||||
|
// This must use getRawType() because if the type is under refinement, we
|
||||||
|
// will get the refineAbstractType callback below, and we don't want to
|
||||||
|
// kick union find in on the constant.
|
||||||
|
if (C->getRawType()->isAbstract()) {
|
||||||
typename AbstractTypeMapTy::iterator ATI =
|
typename AbstractTypeMapTy::iterator ATI =
|
||||||
AbstractTypeMap.find(C->getType());
|
AbstractTypeMap.find(cast<DerivedType>(C->getRawType()));
|
||||||
assert(ATI != AbstractTypeMap.end() &&
|
assert(ATI != AbstractTypeMap.end() &&
|
||||||
"Abstract type not in AbstractTypeMap?");
|
"Abstract type not in AbstractTypeMap?");
|
||||||
if (ATI->second == OldI)
|
if (ATI->second == OldI)
|
||||||
|
Loading…
Reference in New Issue
Block a user