Commit c966236
committed
[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.1 parent 4fde8c3 commit c966236
File tree
5 files changed
+78
-21
lines changed- clang/lib/Basic/Targets
- llvm
- docs
- include/llvm/IR
- lib/IR
- unittests/IR
5 files changed
+78
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3134 | 3134 | | |
3135 | 3135 | | |
3136 | 3136 | | |
3137 | | - | |
| 3137 | + | |
3138 | 3138 | | |
3139 | 3139 | | |
3140 | 3140 | | |
| |||
3143 | 3143 | | |
3144 | 3144 | | |
3145 | 3145 | | |
3146 | | - | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
3147 | 3150 | | |
3148 | 3151 | | |
3149 | 3152 | | |
| |||
13045 | 13048 | | |
13046 | 13049 | | |
13047 | 13050 | | |
13048 | | - | |
| 13051 | + | |
13049 | 13052 | | |
13050 | | - | |
| 13053 | + | |
13051 | 13054 | | |
13052 | 13055 | | |
13053 | 13056 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
151 | | - | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| |||
552 | 553 | | |
553 | 554 | | |
554 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
555 | 561 | | |
556 | 562 | | |
557 | 563 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | | - | |
210 | | - | |
211 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
| |||
296 | 297 | | |
297 | 298 | | |
298 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
299 | 316 | | |
300 | 317 | | |
301 | 318 | | |
| |||
409 | 426 | | |
410 | 427 | | |
411 | 428 | | |
412 | | - | |
| 429 | + | |
413 | 430 | | |
414 | 431 | | |
415 | 432 | | |
416 | 433 | | |
417 | | - | |
418 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
419 | 437 | | |
420 | 438 | | |
421 | 439 | | |
| |||
454 | 472 | | |
455 | 473 | | |
456 | 474 | | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
457 | 481 | | |
458 | | - | |
| 482 | + | |
459 | 483 | | |
460 | 484 | | |
461 | 485 | | |
| |||
631 | 655 | | |
632 | 656 | | |
633 | 657 | | |
634 | | - | |
| 658 | + | |
635 | 659 | | |
636 | 660 | | |
637 | 661 | | |
| |||
679 | 703 | | |
680 | 704 | | |
681 | 705 | | |
682 | | - | |
| 706 | + | |
| 707 | + | |
683 | 708 | | |
684 | 709 | | |
685 | 710 | | |
686 | | - | |
| 711 | + | |
| 712 | + | |
687 | 713 | | |
688 | 714 | | |
689 | 715 | | |
690 | 716 | | |
691 | 717 | | |
| 718 | + | |
692 | 719 | | |
693 | 720 | | |
694 | 721 | | |
| |||
1020 | 1047 | | |
1021 | 1048 | | |
1022 | 1049 | | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | | - | |
320 | | - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
| |||
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
404 | 418 | | |
405 | 419 | | |
406 | 420 | | |
| |||
0 commit comments