Commit 1fbf33c
[OpenMP][Clang] Use
This adds support for using `ATTACH` map-type for proper
pointer-attachment when mapping list-items that have base-pointers.
For example, for the following:
```c
int *p;
#pragma omp target enter data map(p[1:10])
```
The following maps are now emitted by clang:
```
(A)
&p[0], &p[1], 10 * sizeof(p[1]), TO | FROM
&p, &p[1], sizeof(p), ATTACH
```
Previously, the two possible maps emitted by clang were:
```
(B)
&p[0], &p[1], 10 * sizeof(p[1]), TO | FROM
(C)
&p, &p[1], 10 * sizeof(p[1]), TO | FROM | PTR_AND_OBJ
````
(B) does not perform any pointer attachment, while (C) also maps the
pointer p, both of which are incorrect.
-----
With this change, we are using ATTACH-style maps, like `(A)`, for cases
where the expression has a base-pointer. For example:
```cpp
int *p, **pp;
S *ps, **pps;
... map(p[0])
... map(p[10:20])
... map(*p)
... map(([20])p)
... map(ps->a)
... map(pps->p->a)
... map(pp[0][0])
... map(*(pp + 10)[0])
```
#### Grouping of maps based on attach base-pointers
We also group mapping of clauses with the same base decl in the order of
the increasing complexity of their base-pointers, e.g. for something
like:
```
S **spp;
map(spp[0][0], spp[0][0].a), // attach-ptr: spp[0]
map(spp[0]), // attach-ptr: spp
map(spp), // attach-ptr: N/A
```
We first map `spp`, then `spp[0]` then `spp[0][0]` and `spp[0][0].a`.
This allows us to also group "struct" allocation based on their attach
pointers. This resolves the issues of us always mapping everything from
the beginning of the symbol `spp`. Each group is mapped independently,
and at the same level, like `spp[0][0]` and its member `spp[0][0].a`, we
still get map them together as part of the same contiguous struct
`spp[0][0]`. This resolves issue llvm#141042.
#### use_device_ptr/addr fixes
The handling of `use_device_ptr/addr` was updated to use the attach-ptr
information, and works for many cases that were failing before. It has
to be done as part of this series because otherwise, the switch from
ptr_to_obj to attach-style mapping would have caused regressions in
existing use_device_ptr/addr tests.
#### Handling of attach-pointers that are members of implicitly mapped
structs:
* When a struct member-pointer, like `p` below, is a base-pointer in a
`map` clause on a target construct (like `map(p[0:1])`, and the base of
that struct is either the `this` pointer (implicitly or explicitly), or
a struct that is implicitly mapped on that construct, we add an implicit
`map(p)` so that we don't implicitly map the full struct.
```c
struct S { int *p;
void f1() {
#pragma omp target map(p[0:1]) // Implicitly map this->p, to ensure
// that the implicit map of `this[:]` does
// not map the full struct
printf("%p %p\n", &p, p);
}
```
#### Scope for improvement:
* We may be able to compute attach-ptr expr while collecting
component-lists in Sema.
* But we cache the computation results already, and `findAttachPtrExpr`
is fairly simple, and fast.
* There may be a better way to implement semantic expr comparison.
#### Needs future work:
* Attach-style maps not yet emitted for declare mappers.
* Mapping of class member references: We are still using PTR_AND_OBJ
maps for them. We will likely need to change that to handle
`ref_ptr/ref_ptee`, and `attach` map-type-modifier on them.
* Implicit capturing of "this" needs to map the full `this[0:1]` unless
there is an explicit map on one of the members, or a map with a member
as its base-pointer.
* Implicit map added for capturing a class member pointer needs to also
add a zero-length-array-section map.
* `use_device_addr` on array-sections-on-pointers need further
improvements (documented using FIXMEs)
#### Why a large PR
While it's unfortunate that this PR has gotten large and difficult to
review, the issue is that all the functional changes have to be made
together, to prevent regressions from partially implemented changes.
For example, the changes to capturing were previously done separately
(llvm#145454), but they would still cause stability issues in absence of
full attach-mapping. And attach-mapping needs those changes to be able
to launch kernels.
We extracted the utilities and functions, like those for finding
attach-ptrs, or comparing exprs, out as a separate NFC PR that doesn't
call those functions, just adds them (llvm#155625). Maybe the change that
adds a new error message for use_device_addr on array-sections with
non-var base-pointers could have been extracted out too (but that would
have had to be a follow-up change in that case, and we would get
comp-fails with this PR when the erroneous case was not
caught/diagnosed).
---------
Co-authored-by: Alex Duran <[email protected]>ATTACH map-type for list-items with base-pointers. (llvm#153683)1 parent 8af59b2 commit 1fbf33c
File tree
71 files changed
+5457
-3970
lines changed- clang
- docs
- include/clang/Basic
- lib
- CodeGen
- Sema
- test/OpenMP
- llvm/lib/Frontend/OpenMP
- offload/test
- mapping
- use_device_addr
- use_device_ptr
- offloading
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
71 files changed
+5457
-3970
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
843 | 843 | | |
844 | 844 | | |
845 | 845 | | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
846 | 858 | | |
847 | 859 | | |
848 | 860 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11805 | 11805 | | |
11806 | 11806 | | |
11807 | 11807 | | |
| 11808 | + | |
| 11809 | + | |
| 11810 | + | |
11808 | 11811 | | |
11809 | 11812 | | |
11810 | 11813 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2206 | 2206 | | |
2207 | 2207 | | |
2208 | 2208 | | |
| 2209 | + | |
2209 | 2210 | | |
2210 | 2211 | | |
2211 | 2212 | | |
| |||
2231 | 2232 | | |
2232 | 2233 | | |
2233 | 2234 | | |
| 2235 | + | |
| 2236 | + | |
2234 | 2237 | | |
2235 | 2238 | | |
2236 | 2239 | | |
2237 | 2240 | | |
2238 | | - | |
2239 | | - | |
2240 | | - | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
2241 | 2244 | | |
| 2245 | + | |
2242 | 2246 | | |
2243 | 2247 | | |
2244 | 2248 | | |
2245 | 2249 | | |
| 2250 | + | |
2246 | 2251 | | |
2247 | 2252 | | |
2248 | 2253 | | |
| |||
2258 | 2263 | | |
2259 | 2264 | | |
2260 | 2265 | | |
2261 | | - | |
2262 | | - | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
2263 | 2279 | | |
2264 | 2280 | | |
2265 | 2281 | | |
| |||
2273 | 2289 | | |
2274 | 2290 | | |
2275 | 2291 | | |
2276 | | - | |
2277 | | - | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
2278 | 2296 | | |
2279 | 2297 | | |
2280 | 2298 | | |
| |||
2283 | 2301 | | |
2284 | 2302 | | |
2285 | 2303 | | |
2286 | | - | |
2287 | | - | |
| 2304 | + | |
| 2305 | + | |
| 2306 | + | |
| 2307 | + | |
| 2308 | + | |
| 2309 | + | |
| 2310 | + | |
| 2311 | + | |
| 2312 | + | |
| 2313 | + | |
| 2314 | + | |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
| 2318 | + | |
| 2319 | + | |
| 2320 | + | |
2288 | 2321 | | |
2289 | 2322 | | |
2290 | 2323 | | |
| |||
22944 | 22977 | | |
22945 | 22978 | | |
22946 | 22979 | | |
22947 | | - | |
22948 | | - | |
| 22980 | + | |
| 22981 | + | |
| 22982 | + | |
| 22983 | + | |
22949 | 22984 | | |
22950 | 22985 | | |
22951 | 22986 | | |
| |||
24659 | 24694 | | |
24660 | 24695 | | |
24661 | 24696 | | |
24662 | | - | |
24663 | | - | |
24664 | | - | |
24665 | | - | |
24666 | | - | |
24667 | | - | |
24668 | | - | |
24669 | | - | |
24670 | | - | |
24671 | | - | |
24672 | | - | |
| 24697 | + | |
| 24698 | + | |
| 24699 | + | |
| 24700 | + | |
| 24701 | + | |
| 24702 | + | |
| 24703 | + | |
| 24704 | + | |
| 24705 | + | |
| 24706 | + | |
| 24707 | + | |
| 24708 | + | |
| 24709 | + | |
| 24710 | + | |
| 24711 | + | |
| 24712 | + | |
| 24713 | + | |
| 24714 | + | |
| 24715 | + | |
| 24716 | + | |
| 24717 | + | |
| 24718 | + | |
| 24719 | + | |
| 24720 | + | |
| 24721 | + | |
| 24722 | + | |
| 24723 | + | |
| 24724 | + | |
| 24725 | + | |
| 24726 | + | |
| 24727 | + | |
| 24728 | + | |
| 24729 | + | |
| 24730 | + | |
| 24731 | + | |
| 24732 | + | |
| 24733 | + | |
| 24734 | + | |
| 24735 | + | |
| 24736 | + | |
| 24737 | + | |
| 24738 | + | |
| 24739 | + | |
| 24740 | + | |
| 24741 | + | |
| 24742 | + | |
| 24743 | + | |
| 24744 | + | |
| 24745 | + | |
| 24746 | + | |
| 24747 | + | |
| 24748 | + | |
| 24749 | + | |
| 24750 | + | |
| 24751 | + | |
| 24752 | + | |
| 24753 | + | |
| 24754 | + | |
| 24755 | + | |
| 24756 | + | |
| 24757 | + | |
24673 | 24758 | | |
24674 | 24759 | | |
24675 | 24760 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
0 commit comments