Skip to content

Commit

Permalink
[CodeGen] Store element type in RValue
Browse files Browse the repository at this point in the history
For aggregates, we need to store the element type to be able to
reconstruct the aggregate Address. This increases the size of this
packed structure (as the second value is already used for alignment
in this case), but I did not observe any compile-time or memory
usage regression from this change.
  • Loading branch information
nikic committed Dec 17, 2021
1 parent 65777ad commit ba31cb4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/lib/CodeGen/CGValue.h
Expand Up @@ -47,6 +47,8 @@ class RValue {
llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1;
// Stores second value and volatility.
llvm::PointerIntPair<llvm::Value *, 1, bool> V2;
// Stores element type for aggregate values.
llvm::Type *ElementType;

public:
bool isScalar() const { return V1.getInt() == Scalar; }
Expand All @@ -71,7 +73,8 @@ class RValue {
Address getAggregateAddress() const {
assert(isAggregate() && "Not an aggregate!");
auto align = reinterpret_cast<uintptr_t>(V2.getPointer()) >> AggAlignShift;
return Address(V1.getPointer(), CharUnits::fromQuantity(align));
return Address(
V1.getPointer(), ElementType, CharUnits::fromQuantity(align));
}
llvm::Value *getAggregatePointer() const {
assert(isAggregate() && "Not an aggregate!");
Expand Down Expand Up @@ -108,6 +111,7 @@ class RValue {
RValue ER;
ER.V1.setPointer(addr.getPointer());
ER.V1.setInt(Aggregate);
ER.ElementType = addr.getElementType();

auto align = static_cast<uintptr_t>(addr.getAlignment().getQuantity());
ER.V2.setPointer(reinterpret_cast<llvm::Value*>(align << AggAlignShift));
Expand Down

0 comments on commit ba31cb4

Please sign in to comment.