Commit 6d094a0
authored
[mono] Use SROA-friendly struct type declarations (dotnet#59007)
LLVM's SROA can decompose loads and stores of aggregate type into a
sequence of aggregate-element-typed loads and stores. Before this
change, Mono translated .NET-level value types into LLVM IR-level
structs containing nothing but `i8` elements.
When a value type field has reference type, and a value of this value
type is copied using a `memcpy` intrinsic or an LLVM IR load followed by
a store, LLVM will emit code that loads managed references in multiple
byte-sized fragments before reconstructing the original pointer using a
sequence of ALU ops. This causes sgen to fail to pin the referent.
This change works around this by translating value types to LLVM IR
structs with pointer-sized fields. Packed value types with non-standard
alignment will be translated into LLVM IR structs containing
alignment-sized fields.
Note that this does not completely guarantee that the code we generate
will respect sgen's requirements. No specific guarantees are provided
about the translation of non-atomic LLVM IR loads and stores to machine
code. And we'll need some alternative means (perhaps a special
`gc_copy_unaligned` runtime call or similar) to copy packed or
misaligned value types that contain managed references. For stronger
LLVM IR-level guarantees, we'll want to make use of unordered atomic
loads and stores and unordered atomic memcpy, but that work is out of
scope for this change.
Fixes dotnet#58062, but see the previous paragraph for caveats.
See:
- https://github.com/dotnet/llvm-project/blob/release/11.x/llvm/lib/Transforms/Scalar/SROA.cpp#L3371-L3388
- https://github.com/dotnet/llvm-project/blob/release/11.x/llvm/lib/Transforms/Scalar/SROA.cpp#L3327-L33401 parent 17221d1 commit 6d094a0
2 files changed
+25
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
530 | 530 | | |
531 | 531 | | |
532 | 532 | | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
533 | 538 | | |
534 | 539 | | |
535 | 540 | | |
536 | 541 | | |
537 | 542 | | |
538 | | - | |
539 | | - | |
| 543 | + | |
| 544 | + | |
540 | 545 | | |
541 | | - | |
542 | | - | |
543 | | - | |
| 546 | + | |
| 547 | + | |
544 | 548 | | |
545 | 549 | | |
546 | 550 | | |
547 | 551 | | |
548 | | - | |
549 | | - | |
| 552 | + | |
| 553 | + | |
550 | 554 | | |
551 | 555 | | |
552 | 556 | | |
| |||
681 | 685 | | |
682 | 686 | | |
683 | 687 | | |
684 | | - | |
685 | | - | |
686 | | - | |
687 | | - | |
688 | | - | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
689 | 699 | | |
690 | 700 | | |
691 | 701 | | |
| |||
2672 | 2682 | | |
2673 | 2683 | | |
2674 | 2684 | | |
2675 | | - | |
| 2685 | + | |
2676 | 2686 | | |
2677 | 2687 | | |
2678 | 2688 | | |
2679 | | - | |
| 2689 | + | |
2680 | 2690 | | |
2681 | 2691 | | |
2682 | 2692 | | |
| |||
7342 | 7352 | | |
7343 | 7353 | | |
7344 | 7354 | | |
7345 | | - | |
| 7355 | + | |
7346 | 7356 | | |
7347 | 7357 | | |
7348 | 7358 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2317 | 2317 | | |
2318 | 2318 | | |
2319 | 2319 | | |
2320 | | - | |
2321 | | - | |
2322 | | - | |
2323 | 2320 | | |
2324 | 2321 | | |
2325 | 2322 | | |
| |||
0 commit comments