Skip to content

Commit 3648cc7

Browse files
authored
[IRGen] NFC: Repack TypeInfo and FixedTypeInfo bits (#16241)
This saves eight bytes per FixedTypeInfo node.
1 parent 57183ae commit 3648cc7

File tree

7 files changed

+140
-99
lines changed

7 files changed

+140
-99
lines changed

lib/IRGen/FixedTypeInfo.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ namespace irgen {
3535
/// implementing a type that has a statically known layout.
3636
class FixedTypeInfo : public TypeInfo {
3737
private:
38-
/// The storage size of this type in bytes. This may be zero even
39-
/// for well-formed and complete types, such as a trivial enum or
40-
/// tuple.
41-
Size StorageSize;
42-
4338
/// The spare bit mask for this type. SpareBits[0] is the LSB of the first
4439
/// byte. This may be empty if the type has no spare bits.
4540
SpareBitVector SpareBits;
@@ -49,22 +44,26 @@ class FixedTypeInfo : public TypeInfo {
4944
const SpareBitVector &spareBits,
5045
Alignment align, IsPOD_t pod, IsBitwiseTakable_t bt,
5146
IsFixedSize_t alwaysFixedSize,
52-
SpecialTypeInfoKind stik = STIK_Fixed)
47+
SpecialTypeInfoKind stik = SpecialTypeInfoKind::Fixed)
5348
: TypeInfo(type, align, pod, bt, alwaysFixedSize, stik),
54-
StorageSize(size), SpareBits(spareBits) {
49+
SpareBits(spareBits) {
5550
assert(SpareBits.size() == size.getValueInBits());
5651
assert(isFixedSize());
52+
Bits.FixedTypeInfo.Size = size.getValue();
53+
assert(Bits.FixedTypeInfo.Size == size.getValue() && "truncation");
5754
}
5855

5956
FixedTypeInfo(llvm::Type *type, Size size,
6057
SpareBitVector &&spareBits,
6158
Alignment align, IsPOD_t pod, IsBitwiseTakable_t bt,
6259
IsFixedSize_t alwaysFixedSize,
63-
SpecialTypeInfoKind stik = STIK_Fixed)
60+
SpecialTypeInfoKind stik = SpecialTypeInfoKind::Fixed)
6461
: TypeInfo(type, align, pod, bt, alwaysFixedSize, stik),
65-
StorageSize(size), SpareBits(std::move(spareBits)) {
62+
SpareBits(std::move(spareBits)) {
6663
assert(SpareBits.size() == size.getValueInBits());
6764
assert(isFixedSize());
65+
Bits.FixedTypeInfo.Size = size.getValue();
66+
assert(Bits.FixedTypeInfo.Size == size.getValue() && "truncation");
6867
}
6968

7069
public:
@@ -73,7 +72,7 @@ class FixedTypeInfo : public TypeInfo {
7372

7473
/// Whether this type is known to be empty.
7574
bool isKnownEmpty(ResilienceExpansion expansion) const {
76-
return (isFixedSize(expansion) && StorageSize.isZero());
75+
return (isFixedSize(expansion) && getFixedSize().isZero());
7776
}
7877

7978
StackAddress allocateStack(IRGenFunction &IGF, SILType T,
@@ -99,7 +98,8 @@ class FixedTypeInfo : public TypeInfo {
9998
llvm::Constant *getStaticStride(IRGenModule &IGM) const override;
10099

101100
void completeFixed(Size size, Alignment alignment) {
102-
StorageSize = size;
101+
Bits.FixedTypeInfo.Size = size.getValue();
102+
assert(Bits.FixedTypeInfo.Size == size.getValue() && "truncation");
103103
setStorageAlignment(alignment);
104104
}
105105

@@ -110,7 +110,7 @@ class FixedTypeInfo : public TypeInfo {
110110

111111
/// Returns the known, fixed size required to store a value of this type.
112112
Size getFixedSize() const {
113-
return StorageSize;
113+
return Size(Bits.FixedTypeInfo.Size);
114114
}
115115

116116
/// Returns the (assumed fixed) stride of the storage for this
@@ -120,7 +120,7 @@ class FixedTypeInfo : public TypeInfo {
120120
/// The stride is at least one, even for zero-sized types, like the empty
121121
/// tuple.
122122
Size getFixedStride() const {
123-
Size s = StorageSize.roundUpToAlignment(getFixedAlignment());
123+
Size s = getFixedSize().roundUpToAlignment(getFixedAlignment());
124124
if (s.isZero())
125125
s = Size(1);
126126
return s;

lib/IRGen/GenType.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ TypeInfo::~TypeInfo() {
102102

103103
Address TypeInfo::getAddressForPointer(llvm::Value *ptr) const {
104104
assert(ptr->getType()->getPointerElementType() == StorageType);
105-
return Address(ptr, StorageAlignment);
105+
return Address(ptr, getBestKnownAlignment());
106106
}
107107

108108
Address TypeInfo::getUndefAddress() const {
109109
return Address(llvm::UndefValue::get(getStorageType()->getPointerTo(0)),
110-
StorageAlignment);
110+
getBestKnownAlignment());
111111
}
112112

113113
/// Whether this type is known to be empty.
@@ -239,12 +239,12 @@ unsigned FixedTypeInfo::getSpareBitExtraInhabitantCount() const {
239239
return 0;
240240
// The runtime supports a max of 0x7FFFFFFF extra inhabitants, which ought
241241
// to be enough for anybody.
242-
if (StorageSize.getValue() >= 4)
242+
if (getFixedSize().getValue() >= 4)
243243
return 0x7FFFFFFF;
244244
unsigned spareBitCount = SpareBits.count();
245-
assert(spareBitCount <= StorageSize.getValueInBits()
245+
assert(spareBitCount <= getFixedSize().getValueInBits()
246246
&& "more spare bits than storage bits?!");
247-
unsigned inhabitedBitCount = StorageSize.getValueInBits() - spareBitCount;
247+
unsigned inhabitedBitCount = getFixedSize().getValueInBits() - spareBitCount;
248248
return ((1U << spareBitCount) - 1U) << inhabitedBitCount;
249249
}
250250

@@ -304,7 +304,7 @@ FixedTypeInfo::getSpareBitExtraInhabitantIndex(IRGenFunction &IGF,
304304
auto &C = IGF.IGM.getLLVMContext();
305305

306306
// Load the value.
307-
auto payloadTy = llvm::IntegerType::get(C, StorageSize.getValueInBits());
307+
auto payloadTy = llvm::IntegerType::get(C, getFixedSize().getValueInBits());
308308
src = IGF.Builder.CreateBitCast(src, payloadTy->getPointerTo());
309309
auto val = IGF.Builder.CreateLoad(src);
310310

@@ -331,7 +331,7 @@ FixedTypeInfo::getSpareBitExtraInhabitantIndex(IRGenFunction &IGF,
331331

332332
// See if spare bits fit into the 31 bits of the index.
333333
unsigned numSpareBits = SpareBits.count();
334-
unsigned numOccupiedBits = StorageSize.getValueInBits() - numSpareBits;
334+
unsigned numOccupiedBits = getFixedSize().getValueInBits() - numSpareBits;
335335
if (numOccupiedBits < 31) {
336336
// Gather the spare bits.
337337
llvm::Value *spareIdx
@@ -756,7 +756,7 @@ FixedTypeInfo::storeSpareBitExtraInhabitant(IRGenFunction &IGF,
756756

757757
auto &C = IGF.IGM.getLLVMContext();
758758

759-
auto payloadTy = llvm::IntegerType::get(C, StorageSize.getValueInBits());
759+
auto payloadTy = llvm::IntegerType::get(C, getFixedSize().getValueInBits());
760760

761761
unsigned spareBitCount = SpareBits.count();
762762
unsigned occupiedBitCount = SpareBits.size() - spareBitCount;

lib/IRGen/LoadableTypeInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class LoadableTypeInfo : public FixedTypeInfo {
5757
const SpareBitVector &spareBits,
5858
Alignment align,
5959
IsPOD_t pod, IsFixedSize_t alwaysFixedSize,
60-
SpecialTypeInfoKind stik = STIK_Loadable)
60+
SpecialTypeInfoKind stik = SpecialTypeInfoKind::Loadable)
6161
: FixedTypeInfo(type, size, spareBits, align, pod,
6262
// All currently implemented loadable types are bitwise-takable.
6363
IsBitwiseTakable, alwaysFixedSize, stik) {
@@ -68,7 +68,7 @@ class LoadableTypeInfo : public FixedTypeInfo {
6868
SpareBitVector &&spareBits,
6969
Alignment align,
7070
IsPOD_t pod, IsFixedSize_t alwaysFixedSize,
71-
SpecialTypeInfoKind stik = STIK_Loadable)
71+
SpecialTypeInfoKind stik = SpecialTypeInfoKind::Loadable)
7272
: FixedTypeInfo(type, size, std::move(spareBits), align, pod,
7373
// All currently implemented loadable types are bitwise-takable.
7474
IsBitwiseTakable, alwaysFixedSize, stik) {

lib/IRGen/NonFixedTypeInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class WitnessSizedTypeInfo : public IndirectTypeInfo<Impl, TypeInfo> {
5353

5454
WitnessSizedTypeInfo(llvm::Type *type, Alignment align, IsPOD_t pod,
5555
IsBitwiseTakable_t bt)
56-
: super(type, align, pod, bt, IsNotFixedSize, TypeInfo::STIK_None) {}
56+
: super(type, align, pod, bt, IsNotFixedSize, SpecialTypeInfoKind::None) {}
5757

5858
private:
5959
/// Bit-cast the given pointer to the right type and assume it as an

lib/IRGen/ReferenceTypeInfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class ReferenceTypeInfo : public LoadableTypeInfo {
3535
ReferenceTypeInfo(llvm::Type *type, Size size, SpareBitVector spareBits,
3636
Alignment align, IsPOD_t pod = IsNotPOD)
3737
: LoadableTypeInfo(type, size, spareBits, align, pod,
38-
IsFixedSize, STIK_Reference)
38+
IsFixedSize, SpecialTypeInfoKind::Reference)
3939
{}
4040

4141
public:
@@ -102,7 +102,7 @@ class ReferenceTypeInfo : public LoadableTypeInfo {
102102

103103
static bool classof(const ReferenceTypeInfo *type) { return true; }
104104
static bool classof(const TypeInfo *type) {
105-
return type->getSpecialTypeInfoKind() == STIK_Reference;
105+
return type->getSpecialTypeInfoKind() == SpecialTypeInfoKind::Reference;
106106
}
107107
};
108108

0 commit comments

Comments
 (0)