[llvm-dev] RFC: Representing unions in TBAA
Daniel Berlin via llvm-dev
llvm-dev at lists.llvm.org
Sun May 14 09:06:42 PDT 2017
On Sun, May 14, 2017 at 8:37 AM, Hal Finkel <hfinkel at anl.gov> wrote:
>
> On 03/01/2017 05:30 PM, Daniel Berlin via llvm-dev wrote:
>
> So, https://bugs.llvm.org/show_bug.cgi?id=32056 is an example showing our
> current TBAA tree for union generation is definitely irretrievably broken.
> I'll be honest here. I'm pretty sure your proposal doesn't go far enough.
> But truthfully, I would rather see us come closer to a representation we
> know works, which is GCC's.
> Let me try to simplify what you are suggesting, and what we have.
> Our current representation is basically inverted from GCC, but we don't
> allow things that would enable it to work.
>
> Given
> union {int a, short b};
>
> GCC's will be:
>
> union
> / \
> short int
>
>
> Everything is implicitly a subset of alias set 0 (which for C/C++ is char)
> just to avoid representing it.
>
> Our metadata has no child links, and only a single parent link.
>
> You can't represent the above form because you can't make a single short
> node a child of every union/struct it needs to be (lack of multiple
> parents means you can't just frob them all to offset zero).
>
> Your suggestion is to invert this as a struct
>
> short int
> | /
> union
>
> We don't allow multiple parents, however.
> Because of that, you suggest we follow all nodes for unions, special
> casing union-type nodes somehow
>
>
> Now that I've spent a bunch of time looking at this, I'd like to voice
> support for Steven's original proposal. In the context of what we have, it
> makes sense, seems sound, and should fix the representational mapping
> problem we currently have.
>
Except you can't easily differentiate it from the current one, and if we
are going to have to upgrade/break compatibility, why not just do it once
right, a way we know works, instead of risk screwing it up again, and
playing with a representation we aren't actually sure we can make efficient
for this case?
> Something completely different (e.g. closer to what GCC uses) can work
> too, but this seems unnecessary (the proposed extension to the current
> semantics seem equivalently expressive).
>
Yes, they are equivalently expressive.
>
> What you call "special casing of union-type nodes" does not actually seem
> all that special. The rule seems quite simple: if you some across
> duplicate offsets, then search all of them.
>
Which means you have to know they exist, for starters, which means keeping
it in some sorted order and checking, or some other mechanism.
This should not be difficult to implement or use, and seems no less
> efficient than any other way of encoding the concept of disjunction in the
> hierarchy.
>
> It is, in actuality, less efficient.
For starters, in the inverted representation, you don't have to explicitly
represent the things that are children of alias set zero (char in C++'s
case), which is quite common.
It's also trivial to generate transitive closures of parts of the graph in
the inverted representation, and be able to use them, if you need to.
It turns out to be much trickier the other way.
Those are just trivial examples.
Now, how often this matters, don't know.
But i'm suggesting what i believe to be the most practical route:
Given a situation where our representation has been broken for years, take
an approach that is battle tested and we know works and is efficient,
instead of trying to patch our representation and hope we've thought it
through well enough :)
Does this mean the original proposal won't work?
Nope. It may in fact work. But i'd still do the thing i knew already
worked well. Because like i said, you are going to break compatibility
anyway, so ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170514/5dce33e9/attachment.html>
More information about the llvm-dev
mailing list