[PATCH] D122758: DataLayout::getPointerSize() should always return a power of 2 (#89)

Stephen Neuendorffer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 12:34:56 PDT 2022


stephenneuendorffer created this revision.
Herald added subscribers: dexonsmith, hiraditya.
Herald added a project: All.
stephenneuendorffer requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Previously, we expanded the behavior of DataLayout to allow representing
pointer sizes with an arbitrary number of bits, with the expectation
that most users would migrate to the getPointerSizeInBits API.  We
implemented some backward compatibility for the getPointerSize() API to
return the minimum number of bytes needed to contain a poitner.  However
it appears that there are some APIs, in particular, uses around Dwarf
Debug information where the pointer model is more constrained and
are expected to be a power 2.

This patch updates getPointerSize() in these cases return a power of
2 number of bytes.  NFC for in-tree code since these architectures
already have a pointer size that is a power of 2.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D122758

Files:
  llvm/include/llvm/IR/DataLayout.h
  llvm/lib/IR/DataLayout.cpp


Index: llvm/lib/IR/DataLayout.cpp
===================================================================
--- llvm/lib/IR/DataLayout.cpp
+++ llvm/lib/IR/DataLayout.cpp
@@ -706,7 +706,7 @@
 }
 
 unsigned DataLayout::getPointerSize(unsigned AS) const {
-  return divideCeil(getPointerAlignElem(AS).TypeBitWidth, 8);
+  return PowerOf2Ceil(divideCeil(getPointerAlignElem(AS).TypeBitWidth, 8));
 }
 
 unsigned DataLayout::getMaxIndexSize() const {
Index: llvm/include/llvm/IR/DataLayout.h
===================================================================
--- llvm/include/llvm/IR/DataLayout.h
+++ llvm/include/llvm/IR/DataLayout.h
@@ -373,7 +373,7 @@
   /// the backends/clients are updated.
   Align getPointerPrefAlignment(unsigned AS = 0) const;
 
-  /// Layout pointer size in bytes, rounded up to a whole
+  /// Layout pointer size in bytes, rounded up to a power of 2
   /// number of bytes.
   /// FIXME: The defaults need to be removed once all of
   /// the backends/clients are updated.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122758.419246.patch
Type: text/x-patch
Size: 991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220330/15f15c0e/attachment.bin>


More information about the llvm-commits mailing list