Commit 1a65e63
[mlir][ptr] Add ConstantOp with NullAttr and AddressAttr support (#157347)
This patch introduces the `ptr.constant` operation. It also adds the
`NullAttr` and `AddressAttr` for representing null pointers, and integer
raw addresses.
It also implements LLVM IR translation for `ptr.constant` with
`#ptr.null` or `#ptr.address` attributes.
Finally, it extends `FieldParser` to support APInt parsing.
Example:
```mlir
llvm.func @constant_address_op() ->
!llvm.struct<(!ptr.ptr<#llvm.address_space<0>>,
!ptr.ptr<#llvm.address_space<1>>,
!ptr.ptr<#llvm.address_space<2>>)> {
%0 = ptr.constant #ptr.null : !ptr.ptr<#llvm.address_space<0>>
%1 = ptr.constant #ptr.address<0x1000> : !ptr.ptr<#llvm.address_space<1>>
%2 = ptr.constant #ptr.address<3735928559> : !ptr.ptr<#llvm.address_space<2>>
%3 = llvm.mlir.poison : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
%4 = llvm.insertvalue %0, %3[0] : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
%5 = llvm.insertvalue %1, %4[1] : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
%6 = llvm.insertvalue %2, %5[2] : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
llvm.return %6 : !llvm.struct<(!ptr.ptr<#llvm.address_space<0>>, !ptr.ptr<#llvm.address_space<1>>, !ptr.ptr<#llvm.address_space<2>>)>
}
```
Result of translation to LLVM IR:
```llvm
define { ptr, ptr addrspace(1), ptr addrspace(2) } @constant_address_op() {
ret { ptr, ptr addrspace(1), ptr addrspace(2) } { ptr null, ptr addrspace(1) inttoptr (i64 4096 to ptr addrspace(1)), ptr addrspace(2) inttoptr (i64 3735928559 to ptr addrspace(2)) }
}
```
This patch also changes all the `convert*` occurrences in function names
or comments to `translate` in the PtrToLLVM file.
---------
Co-authored-by: Mehdi Amini <[email protected]>1 parent bfedb4a commit 1a65e63
File tree
8 files changed
+262
-66
lines changed- mlir
- include/mlir
- Dialect/Ptr/IR
- IR
- lib
- Dialect/Ptr/IR
- Target/LLVMIR/Dialect/Ptr
- test
- Dialect/Ptr
- Target/LLVMIR
8 files changed
+262
-66
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
25 | 53 | | |
26 | 54 | | |
27 | 55 | | |
| |||
37 | 65 | | |
38 | 66 | | |
39 | 67 | | |
40 | | - | |
| 68 | + | |
41 | 69 | | |
42 | 70 | | |
43 | 71 | | |
44 | | - | |
| 72 | + | |
45 | 73 | | |
46 | 74 | | |
47 | 75 | | |
48 | 76 | | |
49 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
50 | 104 | | |
51 | 105 | | |
52 | 106 | | |
| |||
62 | 116 | | |
63 | 117 | | |
64 | 118 | | |
65 | | - | |
| 119 | + | |
66 | 120 | | |
67 | 121 | | |
68 | 122 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
60 | 85 | | |
61 | 86 | | |
62 | 87 | | |
| |||
81 | 106 | | |
82 | 107 | | |
83 | 108 | | |
84 | | - | |
| 109 | + | |
85 | 110 | | |
86 | 111 | | |
87 | 112 | | |
| |||
361 | 386 | | |
362 | 387 | | |
363 | 388 | | |
364 | | - | |
| 389 | + | |
365 | 390 | | |
366 | 391 | | |
367 | | - | |
| 392 | + | |
368 | 393 | | |
369 | 394 | | |
370 | | - | |
| 395 | + | |
371 | 396 | | |
372 | 397 | | |
373 | 398 | | |
| |||
382 | 407 | | |
383 | 408 | | |
384 | 409 | | |
385 | | - | |
| 410 | + | |
386 | 411 | | |
387 | 412 | | |
388 | 413 | | |
| |||
418 | 443 | | |
419 | 444 | | |
420 | 445 | | |
421 | | - | |
| 446 | + | |
422 | 447 | | |
423 | 448 | | |
424 | 449 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
108 | 109 | | |
109 | | - | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
| |||
0 commit comments