[all-commits] [llvm/llvm-project] c96623: [DataLayout] Introduce sentinel pointer value
Shilei Tian via All-commits
all-commits at lists.llvm.org
Sun Mar 16 20:44:35 PDT 2025
Branch: refs/heads/users/shiltian/data-layout-sentinel-pointer
Home: https://github.com/llvm/llvm-project
Commit: c966236e1ec99fbd45063e0363873c8d8abe4c50
https://github.com/llvm/llvm-project/commit/c966236e1ec99fbd45063e0363873c8d8abe4c50
Author: Shilei Tian <i at tianshilei.me>
Date: 2025-03-16 (Sun, 16 Mar 2025)
Changed paths:
M clang/lib/Basic/Targets/AMDGPU.cpp
M llvm/docs/LangRef.rst
M llvm/include/llvm/IR/DataLayout.h
M llvm/lib/IR/DataLayout.cpp
M llvm/unittests/IR/DataLayoutTest.cpp
Log Message:
-----------
[DataLayout] Introduce sentinel pointer value
The value of a null pointer is not always `0`. For example, on AMDGPU, the null
pointer in address spaces 3 and 5 is `0xffffffff`. Currently, there is no
target-independent way to get this information, making it difficult and
error-prone to handle null pointers in target-agnostic code.
We do have `ConstantPointerNull`, but it might be a little confusing and
misleading. It represents a pointer with an all-zero value rather than
necessarily a real `nullptr`.
This PR introduces the concept of a *sentinel pointer value* to `DataLayout`,
representing the actual `nullptr` value for a given address space. The changes
include:
- A new interface function:
```
APInt getSentinelPointerValue(unsigned AS)
```
This function returns an `APInt` representing the sentinel pointer value for
the given address space `AS`. An `APInt` is used instead of a literal integer
to support cases where pointers are wider than 64 bits (e.g., AMDGPU’s address
space 8).
- An extension to the data layout string format:
```
p[n]:<size>:<abi>[:<pref>[:<idx>[:<sentinel>]]]
```
The new `<sentinel>` component specifies the sentinel value for the
corresponding pointer. It currently supports two values:
- `0` for an all-zero value
- `f` for a full-bit set value
These two values are the most common representations of `nullptr`. It is
unlikely that any target would define `nullptr` as a random value.
A follow-up patch series will introduce an equivalent of `ConstantPointerNull`
that represents the actual `nullptr`, built on top of this PR.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list