LTO remapping/deduction of machine modes of types/decls
Alexander Monakov
amonakov@ispras.ru
Fri Dec 30 18:37:00 GMT 2016
Hello, Richard, Jakub, community,
May I join/restart the old discussion about machine mode remapping at LTO
stream-in time. To recap, when offloading to NVPTX was introduced, there
was a problem due to differences in the set of supported modes (e.g. there
was no 'XFmode' on NVPTX that would correspond to 'long double' tree type
node in GIMPLE LTO streams produced by x86 host compiler).
The current solution in GCC is to additionally stream a 'mode table' and use it
to remap numeric mode identifiers during LTO stream-in in all trees that have
modes. This is the solution initially outlined by Jakub in the message
https://gcc.gnu.org/ml/gcc-patches/2015-02/msg00226.html . In response to that,
Richard said,
> I think (also communicated that on IRC) we should instead try not streaming
> machine-modes at all but generating them at stream-in time via layout_type
> or layout_decl.
and later in the thread also:
> I'm just looking for a way to make this less of a hack (and the LTO IL
> less target dependent). Not for GCC 5 for which something like your
> patch is probably ok, but for the future.
Now that we're in the future, I've asked Vlad Ivanishin (Cc'ed) to try and
implement Richard's approach. The motivation is enhancing LTO for offloaded
code, in particular to expose library code for inlining. In that scenario,
the current scheme has a problem that WPA can arbitrarily mix LTO sections
coming from libraries (where the modes don't need remapping) and LTO sections
produced by the host compiler. Thus, mode_table would need to be only
selectively applied during stream-in, based on the origin of the section. And,
we'd need to ensure that WPA duplicates mode tables across all ltrans units.
In light of that, I felt that trying Richard's approach would be proper.
Actually, I don't know why gimple/tree representation carries machine modes in
the first place; it seems to be redundant information deducible from type
information.
Vlad's current patch is adding mode deduction for types and decls, matches the
deduced mode against the streamed-in mode, and ICEs in case of mismatch. To be
clear, he's checking this for native LTO via lto-bootstrap, but nevertheless
it's a nice way of giving confidence that mode inference works as intended.
This seems to be fine for C, but in C++ we are seeing some hard-to-explain cases
where the deduced BLKmode for 7-byte-sized/4-byte-aligned base-class decl is
mismatching against deduced DImode. The DImode would be obviously correct for
8-byte-sized decl of the corresponding type, but the base class decl does not
have 1 byte of padding in the tail. What's worse, the issue is just for the
mode of the decl: the mode of the type is BLKmode, as we'd expect.
Unfortunately, just adjusting the C++ frontend to place BLKmode on the decl too
doesn't lead to immediate success, because decl modes have implications for
debug info generation, and the compiler starts ICE'ing there instead.
So we're hitting under-documented places in the compiler here, and personally
I don't have the confidence to judge how they're intended to work.
Basically for now my questions are:
1. Is there an intended invariant that decl modes should match type modes? It
appears that if there was, the above situation with C++ base objects would be a
violation.
2. Do you think we should continue digging in this direction?
I'm not sure how much it'd help a discussion, but for completeness Vlad's
current patchset is provided as attachments. Patch 1/3 adds mode inference for
types (only), patch 2 just reverts Jakub's additions of mode_table handling,
and finally patch 3 adds mode inference for decls, adds checking against
streamed-in modes, and shows where the attempted adjustments in the C++ frontend
and debug info generation were. There are a few coding style violations; sorry;
I hope they are not too distracting.
Thanks.
Alexander
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Infer-modes-from-types-after-LTO-streaming-in.patch
Type: text/x-diff
Size: 6632 bytes
Desc:
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20161230/6437894d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Revert-passes.c-ipa_write_summaries_1-Call-lto_outpu.patch
Type: text/x-diff
Size: 34138 bytes
Desc:
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20161230/6437894d/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Infer-modes-for-decls.patch
Type: text/x-diff
Size: 6812 bytes
Desc:
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20161230/6437894d/attachment-0002.bin>
More information about the Gcc
mailing list