@@ -2182,32 +2182,27 @@ SpareBitVector IRGenModule::getSpareBitsForType(llvm::Type *scalarTy, Size size)
2182
2182
if (it != SpareBitsForTypes.end ())
2183
2183
return it->second ;
2184
2184
2185
- assert (DataLayout.getTypeAllocSizeInBits (scalarTy) <= size.getValueInBits () &&
2185
+ assert (!isa<llvm::StructType>(scalarTy));
2186
+
2187
+ unsigned allocBits = size.getValueInBits ();
2188
+ assert (allocBits >= DataLayout.getTypeAllocSizeInBits (scalarTy) &&
2186
2189
" using a size that's smaller than LLVM's alloc size?" );
2187
-
2188
- {
2189
- // FIXME: Currently we only implement spare bits for primitive integer
2190
- // types.
2191
- assert (!isa<llvm::StructType>(scalarTy));
2192
-
2193
- auto *intTy = dyn_cast<llvm::IntegerType>(scalarTy);
2194
- if (!intTy)
2195
- goto no_spare_bits;
2196
-
2197
- // Round Integer-Of-Unusual-Size types up to their allocation size.
2198
- unsigned allocBits = size.getValueInBits ();
2199
- assert (allocBits >= intTy->getBitWidth ());
2200
-
2201
- // FIXME: Endianness.
2202
- SpareBitVector &result = SpareBitsForTypes[scalarTy];
2203
- result.appendClearBits (intTy->getBitWidth ());
2204
- result.extendWithSetBits (allocBits);
2190
+
2191
+ // Allocate a new cache entry.
2192
+ SpareBitVector &result = SpareBitsForTypes[scalarTy];
2193
+
2194
+ // FIXME: Currently we only implement spare bits for primitive integer
2195
+ // types.
2196
+ if (auto *intTy = dyn_cast<llvm::IntegerType>(scalarTy)) {
2197
+ // Pad integers with spare bits up to their allocation size.
2198
+ auto v = llvm::APInt::getBitsSetFrom (allocBits, intTy->getBitWidth ());
2199
+ // FIXME: byte swap v on big-endian platforms.
2200
+ result = SpareBitVector::fromAPInt (v);
2205
2201
return result;
2206
2202
}
2207
-
2208
- no_spare_bits:
2209
- SpareBitVector &result = SpareBitsForTypes[scalarTy];
2210
- result.appendClearBits (size.getValueInBits ());
2203
+
2204
+ // No spare bits.
2205
+ result = SpareBitVector::getConstant (allocBits, false );
2211
2206
return result;
2212
2207
}
2213
2208
0 commit comments