forked from OSchip/llvm-project
[CodeGen] Store ElementType in LValue
Store the pointer element type inside LValue so that we can preserve it when converting it back into an Address. Storing the pointer element type might not be strictly required here in that we could probably re-derive it from the QualType (which would require CGF access though), but storing it seems like the simpler solution. The global register case is special and does not store an element type, as the value is not a pointer type in that case and it's not possible to create an Address from it. This is the main remaining part from D103465. Differential Revision: https://reviews.llvm.org/D115791
This commit is contained in:
parent
c209b7e3d5
commit
6bca9a428e
|
@ -175,6 +175,7 @@ class LValue {
|
||||||
} LVType;
|
} LVType;
|
||||||
|
|
||||||
llvm::Value *V;
|
llvm::Value *V;
|
||||||
|
llvm::Type *ElementType;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
// Index into a vector subscript: V[i]
|
// Index into a vector subscript: V[i]
|
||||||
|
@ -230,6 +231,13 @@ private:
|
||||||
LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
|
LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
|
||||||
assert((!Alignment.isZero() || Type->isIncompleteType()) &&
|
assert((!Alignment.isZero() || Type->isIncompleteType()) &&
|
||||||
"initializing l-value with zero alignment!");
|
"initializing l-value with zero alignment!");
|
||||||
|
if (isGlobalReg())
|
||||||
|
assert(ElementType == nullptr && "Global reg does not store elem type");
|
||||||
|
else
|
||||||
|
assert(llvm::cast<llvm::PointerType>(V->getType())
|
||||||
|
->isOpaqueOrPointeeTypeMatches(ElementType) &&
|
||||||
|
"Pointer element type mismatch");
|
||||||
|
|
||||||
this->Type = Type;
|
this->Type = Type;
|
||||||
this->Quals = Quals;
|
this->Quals = Quals;
|
||||||
const unsigned MaxAlign = 1U << 31;
|
const unsigned MaxAlign = 1U << 31;
|
||||||
|
@ -327,17 +335,18 @@ public:
|
||||||
return V;
|
return V;
|
||||||
}
|
}
|
||||||
Address getAddress(CodeGenFunction &CGF) const {
|
Address getAddress(CodeGenFunction &CGF) const {
|
||||||
return Address(getPointer(CGF), getAlignment());
|
return Address(getPointer(CGF), ElementType, getAlignment());
|
||||||
}
|
}
|
||||||
void setAddress(Address address) {
|
void setAddress(Address address) {
|
||||||
assert(isSimple());
|
assert(isSimple());
|
||||||
V = address.getPointer();
|
V = address.getPointer();
|
||||||
|
ElementType = address.getElementType();
|
||||||
Alignment = address.getAlignment().getQuantity();
|
Alignment = address.getAlignment().getQuantity();
|
||||||
}
|
}
|
||||||
|
|
||||||
// vector elt lvalue
|
// vector elt lvalue
|
||||||
Address getVectorAddress() const {
|
Address getVectorAddress() const {
|
||||||
return Address(getVectorPointer(), getAlignment());
|
return Address(getVectorPointer(), ElementType, getAlignment());
|
||||||
}
|
}
|
||||||
llvm::Value *getVectorPointer() const {
|
llvm::Value *getVectorPointer() const {
|
||||||
assert(isVectorElt());
|
assert(isVectorElt());
|
||||||
|
@ -349,7 +358,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Address getMatrixAddress() const {
|
Address getMatrixAddress() const {
|
||||||
return Address(getMatrixPointer(), getAlignment());
|
return Address(getMatrixPointer(), ElementType, getAlignment());
|
||||||
}
|
}
|
||||||
llvm::Value *getMatrixPointer() const {
|
llvm::Value *getMatrixPointer() const {
|
||||||
assert(isMatrixElt());
|
assert(isMatrixElt());
|
||||||
|
@ -362,7 +371,7 @@ public:
|
||||||
|
|
||||||
// extended vector elements.
|
// extended vector elements.
|
||||||
Address getExtVectorAddress() const {
|
Address getExtVectorAddress() const {
|
||||||
return Address(getExtVectorPointer(), getAlignment());
|
return Address(getExtVectorPointer(), ElementType, getAlignment());
|
||||||
}
|
}
|
||||||
llvm::Value *getExtVectorPointer() const {
|
llvm::Value *getExtVectorPointer() const {
|
||||||
assert(isExtVectorElt());
|
assert(isExtVectorElt());
|
||||||
|
@ -375,7 +384,7 @@ public:
|
||||||
|
|
||||||
// bitfield lvalue
|
// bitfield lvalue
|
||||||
Address getBitFieldAddress() const {
|
Address getBitFieldAddress() const {
|
||||||
return Address(getBitFieldPointer(), getAlignment());
|
return Address(getBitFieldPointer(), ElementType, getAlignment());
|
||||||
}
|
}
|
||||||
llvm::Value *getBitFieldPointer() const { assert(isBitField()); return V; }
|
llvm::Value *getBitFieldPointer() const { assert(isBitField()); return V; }
|
||||||
const CGBitFieldInfo &getBitFieldInfo() const {
|
const CGBitFieldInfo &getBitFieldInfo() const {
|
||||||
|
@ -395,6 +404,7 @@ public:
|
||||||
R.LVType = Simple;
|
R.LVType = Simple;
|
||||||
assert(address.getPointer()->getType()->isPointerTy());
|
assert(address.getPointer()->getType()->isPointerTy());
|
||||||
R.V = address.getPointer();
|
R.V = address.getPointer();
|
||||||
|
R.ElementType = address.getElementType();
|
||||||
R.Initialize(type, qs, address.getAlignment(), BaseInfo, TBAAInfo);
|
R.Initialize(type, qs, address.getAlignment(), BaseInfo, TBAAInfo);
|
||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
@ -405,6 +415,7 @@ public:
|
||||||
LValue R;
|
LValue R;
|
||||||
R.LVType = VectorElt;
|
R.LVType = VectorElt;
|
||||||
R.V = vecAddress.getPointer();
|
R.V = vecAddress.getPointer();
|
||||||
|
R.ElementType = vecAddress.getElementType();
|
||||||
R.VectorIdx = Idx;
|
R.VectorIdx = Idx;
|
||||||
R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
|
R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
|
||||||
BaseInfo, TBAAInfo);
|
BaseInfo, TBAAInfo);
|
||||||
|
@ -417,6 +428,7 @@ public:
|
||||||
LValue R;
|
LValue R;
|
||||||
R.LVType = ExtVectorElt;
|
R.LVType = ExtVectorElt;
|
||||||
R.V = vecAddress.getPointer();
|
R.V = vecAddress.getPointer();
|
||||||
|
R.ElementType = vecAddress.getElementType();
|
||||||
R.VectorElts = Elts;
|
R.VectorElts = Elts;
|
||||||
R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
|
R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
|
||||||
BaseInfo, TBAAInfo);
|
BaseInfo, TBAAInfo);
|
||||||
|
@ -435,6 +447,7 @@ public:
|
||||||
LValue R;
|
LValue R;
|
||||||
R.LVType = BitField;
|
R.LVType = BitField;
|
||||||
R.V = Addr.getPointer();
|
R.V = Addr.getPointer();
|
||||||
|
R.ElementType = Addr.getElementType();
|
||||||
R.BitFieldInfo = &Info;
|
R.BitFieldInfo = &Info;
|
||||||
R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo,
|
R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo,
|
||||||
TBAAInfo);
|
TBAAInfo);
|
||||||
|
@ -446,6 +459,7 @@ public:
|
||||||
LValue R;
|
LValue R;
|
||||||
R.LVType = GlobalReg;
|
R.LVType = GlobalReg;
|
||||||
R.V = V;
|
R.V = V;
|
||||||
|
R.ElementType = nullptr;
|
||||||
R.Initialize(type, type.getQualifiers(), alignment,
|
R.Initialize(type, type.getQualifiers(), alignment,
|
||||||
LValueBaseInfo(AlignmentSource::Decl), TBAAAccessInfo());
|
LValueBaseInfo(AlignmentSource::Decl), TBAAAccessInfo());
|
||||||
return R;
|
return R;
|
||||||
|
@ -457,6 +471,7 @@ public:
|
||||||
LValue R;
|
LValue R;
|
||||||
R.LVType = MatrixElt;
|
R.LVType = MatrixElt;
|
||||||
R.V = matAddress.getPointer();
|
R.V = matAddress.getPointer();
|
||||||
|
R.ElementType = matAddress.getElementType();
|
||||||
R.VectorIdx = Idx;
|
R.VectorIdx = Idx;
|
||||||
R.Initialize(type, type.getQualifiers(), matAddress.getAlignment(),
|
R.Initialize(type, type.getQualifiers(), matAddress.getAlignment(),
|
||||||
BaseInfo, TBAAInfo);
|
BaseInfo, TBAAInfo);
|
||||||
|
|
Loading…
Reference in New Issue