Skip to content

IRGen: simplify getSpareBitsForType #23442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions lib/IRGen/GenType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2182,32 +2182,27 @@ SpareBitVector IRGenModule::getSpareBitsForType(llvm::Type *scalarTy, Size size)
if (it != SpareBitsForTypes.end())
return it->second;

assert(DataLayout.getTypeAllocSizeInBits(scalarTy) <= size.getValueInBits() &&
assert(!isa<llvm::StructType>(scalarTy));

unsigned allocBits = size.getValueInBits();
assert(allocBits >= DataLayout.getTypeAllocSizeInBits(scalarTy) &&
"using a size that's smaller than LLVM's alloc size?");

{
// FIXME: Currently we only implement spare bits for primitive integer
// types.
assert(!isa<llvm::StructType>(scalarTy));

auto *intTy = dyn_cast<llvm::IntegerType>(scalarTy);
if (!intTy)
goto no_spare_bits;

// Round Integer-Of-Unusual-Size types up to their allocation size.
unsigned allocBits = size.getValueInBits();
assert(allocBits >= intTy->getBitWidth());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped this assertion since llvm::APInt::getBitsSetFrom already asserts this and the earlier DataLayout assertion will catch it first anyway probably.


// FIXME: Endianness.
SpareBitVector &result = SpareBitsForTypes[scalarTy];
result.appendClearBits(intTy->getBitWidth());
result.extendWithSetBits(allocBits);

// Allocate a new cache entry.
SpareBitVector &result = SpareBitsForTypes[scalarTy];

// FIXME: Currently we only implement spare bits for primitive integer
// types.
if (auto *intTy = dyn_cast<llvm::IntegerType>(scalarTy)) {
// Pad integers with spare bits up to their allocation size.
auto v = llvm::APInt::getBitsSetFrom(allocBits, intTy->getBitWidth());
// FIXME: byte swap v on big-endian platforms.
result = SpareBitVector::fromAPInt(v);
return result;
}

no_spare_bits:
SpareBitVector &result = SpareBitsForTypes[scalarTy];
result.appendClearBits(size.getValueInBits());

// No spare bits.
result = SpareBitVector::getConstant(allocBits, false);
return result;
}

Expand Down