[all-commits] [llvm/llvm-project] efda12: [DataLayout] Introduce sentinel pointer value
Ryotaro Kasuga via All-commits
all-commits at lists.llvm.org
Mon Mar 17 10:51:35 PDT 2025
Branch: refs/heads/users/shiltian/data-layout-sentinel-pointer
Home: https://github.com/llvm/llvm-project
Commit: efda127ecd06ea966df89425d10bd837c0cafe4e
https://github.com/llvm/llvm-project/commit/efda127ecd06ea966df89425d10bd837c0cafe4e
Author: Ryotaro Kasuga <kasuga.ryotaro at fujitsu.com>
Date: 2025-03-17 (Mon, 17 Mar 2025)
Changed paths:
M clang/lib/Basic/Targets/AMDGPU.cpp
M clang/test/CodeGen/target-data.c
M clang/test/CodeGenOpenCL/amdgpu-env-amdgcn.cl
M llvm/docs/LangRef.rst
M llvm/include/llvm/IR/DataLayout.h
M llvm/lib/IR/DataLayout.cpp
M llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.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