mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-30 22:37:28 +00:00
[opaque pointer type] Track explicit GEP pointee type through in-memory IR
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
4def1cbf5d
commit
a67d5abd53
@ -801,6 +801,8 @@ inline Type *checkGEPType(Type *Ty) {
|
|||||||
/// access elements of arrays and structs
|
/// access elements of arrays and structs
|
||||||
///
|
///
|
||||||
class GetElementPtrInst : public Instruction {
|
class GetElementPtrInst : public Instruction {
|
||||||
|
Type *SourceElementType;
|
||||||
|
|
||||||
GetElementPtrInst(const GetElementPtrInst &GEPI);
|
GetElementPtrInst(const GetElementPtrInst &GEPI);
|
||||||
void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
|
void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
|
||||||
|
|
||||||
@ -823,6 +825,13 @@ public:
|
|||||||
const Twine &NameStr = "",
|
const Twine &NameStr = "",
|
||||||
Instruction *InsertBefore = nullptr) {
|
Instruction *InsertBefore = nullptr) {
|
||||||
unsigned Values = 1 + unsigned(IdxList.size());
|
unsigned Values = 1 + unsigned(IdxList.size());
|
||||||
|
if (!PointeeType)
|
||||||
|
PointeeType =
|
||||||
|
cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
|
||||||
|
else
|
||||||
|
assert(
|
||||||
|
PointeeType ==
|
||||||
|
cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
|
||||||
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
|
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
|
||||||
NameStr, InsertBefore);
|
NameStr, InsertBefore);
|
||||||
}
|
}
|
||||||
@ -831,6 +840,13 @@ public:
|
|||||||
const Twine &NameStr,
|
const Twine &NameStr,
|
||||||
BasicBlock *InsertAtEnd) {
|
BasicBlock *InsertAtEnd) {
|
||||||
unsigned Values = 1 + unsigned(IdxList.size());
|
unsigned Values = 1 + unsigned(IdxList.size());
|
||||||
|
if (!PointeeType)
|
||||||
|
PointeeType =
|
||||||
|
cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
|
||||||
|
else
|
||||||
|
assert(
|
||||||
|
PointeeType ==
|
||||||
|
cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
|
||||||
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
|
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
|
||||||
NameStr, InsertAtEnd);
|
NameStr, InsertAtEnd);
|
||||||
}
|
}
|
||||||
@ -876,10 +892,9 @@ public:
|
|||||||
return cast<SequentialType>(Instruction::getType());
|
return cast<SequentialType>(Instruction::getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
Type *getSourceElementType() const {
|
Type *getSourceElementType() const { return SourceElementType; }
|
||||||
return cast<SequentialType>(getPointerOperandType()->getScalarType())
|
|
||||||
->getElementType();
|
void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
|
||||||
}
|
|
||||||
|
|
||||||
Type *getResultElementType() const {
|
Type *getResultElementType() const {
|
||||||
return cast<PointerType>(getType()->getScalarType())->getElementType();
|
return cast<PointerType>(getType()->getScalarType())->getElementType();
|
||||||
@ -1002,23 +1017,21 @@ GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
|
|||||||
ArrayRef<Value *> IdxList, unsigned Values,
|
ArrayRef<Value *> IdxList, unsigned Values,
|
||||||
const Twine &NameStr,
|
const Twine &NameStr,
|
||||||
Instruction *InsertBefore)
|
Instruction *InsertBefore)
|
||||||
: Instruction(PointeeType ? getGEPReturnType(PointeeType, Ptr, IdxList)
|
: Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
|
||||||
: getGEPReturnType(Ptr, IdxList),
|
|
||||||
GetElementPtr,
|
|
||||||
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
||||||
Values, InsertBefore) {
|
Values, InsertBefore),
|
||||||
|
SourceElementType(PointeeType) {
|
||||||
init(Ptr, IdxList, NameStr);
|
init(Ptr, IdxList, NameStr);
|
||||||
assert(!PointeeType || PointeeType == getSourceElementType());
|
|
||||||
}
|
}
|
||||||
GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
|
GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
|
||||||
ArrayRef<Value *> IdxList, unsigned Values,
|
ArrayRef<Value *> IdxList, unsigned Values,
|
||||||
const Twine &NameStr,
|
const Twine &NameStr,
|
||||||
BasicBlock *InsertAtEnd)
|
BasicBlock *InsertAtEnd)
|
||||||
: Instruction(getGEPReturnType(Ptr, IdxList), GetElementPtr,
|
: Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
|
||||||
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
OperandTraits<GetElementPtrInst>::op_end(this) - Values,
|
||||||
Values, InsertAtEnd) {
|
Values, InsertAtEnd),
|
||||||
|
SourceElementType(PointeeType) {
|
||||||
init(Ptr, IdxList, NameStr);
|
init(Ptr, IdxList, NameStr);
|
||||||
assert(!PointeeType || PointeeType == getSourceElementType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1243,10 +1243,11 @@ void GetElementPtrInst::init(Value *Ptr, ArrayRef<Value *> IdxList,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
|
GetElementPtrInst::GetElementPtrInst(const GetElementPtrInst &GEPI)
|
||||||
: Instruction(GEPI.getType(), GetElementPtr,
|
: Instruction(GEPI.getType(), GetElementPtr,
|
||||||
OperandTraits<GetElementPtrInst>::op_end(this)
|
OperandTraits<GetElementPtrInst>::op_end(this) -
|
||||||
- GEPI.getNumOperands(),
|
GEPI.getNumOperands(),
|
||||||
GEPI.getNumOperands()) {
|
GEPI.getNumOperands()),
|
||||||
|
SourceElementType(GEPI.SourceElementType) {
|
||||||
std::copy(GEPI.op_begin(), GEPI.op_end(), op_begin());
|
std::copy(GEPI.op_begin(), GEPI.op_end(), op_begin());
|
||||||
SubclassOptionalData = GEPI.SubclassOptionalData;
|
SubclassOptionalData = GEPI.SubclassOptionalData;
|
||||||
}
|
}
|
||||||
|
@ -1602,6 +1602,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
// is a leading zero) we can fold the cast into this GEP.
|
// is a leading zero) we can fold the cast into this GEP.
|
||||||
if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace()) {
|
if (StrippedPtrTy->getAddressSpace() == GEP.getAddressSpace()) {
|
||||||
GEP.setOperand(0, StrippedPtr);
|
GEP.setOperand(0, StrippedPtr);
|
||||||
|
GEP.setSourceElementType(XATy);
|
||||||
return &GEP;
|
return &GEP;
|
||||||
}
|
}
|
||||||
// Cannot replace the base pointer directly because StrippedPtr's
|
// Cannot replace the base pointer directly because StrippedPtr's
|
||||||
|
@ -400,5 +400,8 @@ void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap,
|
|||||||
}
|
}
|
||||||
if (auto *AI = dyn_cast<AllocaInst>(I))
|
if (auto *AI = dyn_cast<AllocaInst>(I))
|
||||||
AI->setAllocatedType(TypeMapper->remapType(AI->getAllocatedType()));
|
AI->setAllocatedType(TypeMapper->remapType(AI->getAllocatedType()));
|
||||||
|
if (auto *GEP = dyn_cast<GetElementPtrInst>(I))
|
||||||
|
GEP->setSourceElementType(
|
||||||
|
TypeMapper->remapType(GEP->getSourceElementType()));
|
||||||
I->mutateType(TypeMapper->remapType(I->getType()));
|
I->mutateType(TypeMapper->remapType(I->getType()));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user