Skip to content

Commit

Permalink
DataLayout: Fix latent issues with getMaxIndexSizeInBits
Browse files Browse the repository at this point in the history
Because it was implemented in terms of getMaxIndexSize, it was always
rounding the values up to a multiple of 8. Additionally, it was using
the PointerSpec's BitWidth rather than its IndexBitWidth, which was
self-evidently incorrect.

Since getMaxIndexSize was only used by getMaxIndexSizeInBits, and its
name and function seem niche and somewhat confusing, go ahead and remove
it until a concrete need for it arises.
  • Loading branch information
resistor committed Dec 5, 2024
1 parent df43af4 commit e590d58
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 1 addition & 6 deletions llvm/include/llvm/IR/DataLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,6 @@ class DataLayout {
/// the backends/clients are updated.
unsigned getPointerSize(unsigned AS = 0) const;

/// Returns the maximum index size over all address spaces.
unsigned getMaxIndexSize() const;

// Index size in bytes used for address calculation,
/// rounded up to a whole number of bytes.
unsigned getIndexSize(unsigned AS) const;
Expand Down Expand Up @@ -369,9 +366,7 @@ class DataLayout {
}

/// Returns the maximum index size over all address spaces.
unsigned getMaxIndexSizeInBits() const {
return getMaxIndexSize() * 8;
}
unsigned getMaxIndexSizeInBits() const;

/// Size in bits of index used for address calculation in getelementptr.
unsigned getIndexSizeInBits(unsigned AS) const {
Expand Down
6 changes: 2 additions & 4 deletions llvm/lib/IR/DataLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,12 +740,10 @@ unsigned DataLayout::getPointerSize(unsigned AS) const {
return divideCeil(getPointerSpec(AS).BitWidth, 8);
}

unsigned DataLayout::getMaxIndexSize() const {
unsigned DataLayout::getMaxIndexSizeInBits() const {
unsigned MaxIndexSize = 0;
for (const PointerSpec &Spec : PointerSpecs)
MaxIndexSize =
std::max(MaxIndexSize, (unsigned)divideCeil(Spec.BitWidth, 8));

MaxIndexSize =std::max(MaxIndexSize, Spec.IndexBitWidth);
return MaxIndexSize;
}

Expand Down

0 comments on commit e590d58

Please sign in to comment.