Problems with changing the type of an ssa name

Richard Biener richard.guenther@gmail.com
Mon Jul 27 07:25:02 GMT 2020


On Sun, Jul 26, 2020 at 10:31 PM Gary Oblock <gary@amperecomputing.com> wrote:
>
> Richard,
>
> As you know I'm working on a structure reorganization optimization.
> The particular one I'm working on is called instance interleaving.
> For the particular case I'm working on now, there is a single array
> of structures being transformed, a pointer to an element of the
> array is transformed into an index into what is now a structure
> of arrays. Note, I did share my HL design document with you so
> there are more details in there if you need them. So what all this
> means is for this example
>
> typedef struct fu fu_t;
> struct fu {
>   char     x;
>   int        y;
>   double z;
> };
>   :
>   :
>   fu_t *fubar = (fu_t*)malloc(...);
>   fu_t *baz;
>
> That fubar and baz no longer are pointer types and need to be
> transformed into some integer type (say _index_fu_t.) Thus if
> I encounter an ssa_name of type "fu_t *", I'll need to modify its
> type be _index_fu_t. This is of course equivalent to replacing
> that ssa name with a new one of type _index_fu_t.
>
> Now, how do I actually do either of these? My attempts at
> former all failed and the  later seems equally difficult for
> the default defs. Note, prefer modifying them to replacing
> them because it seems more reasonable and it also seems
> to work except for the default defs.
>
> I really need some help with this Richard.

OK, so modifying the SSA name in-place is really bad here
since you _have_ to adjust all uses and defs anyway.  Thus
please create a new SSA name here.

The default-def case you run into is either an uninitialized
value which can easily appear with conditionally initialized
pointers or the SSA name associated with the value of
a function argument.

Once you have to deal with a default def you have to create
a new underlying VAR_DECL (or PARM_DECL if it was a
parameter) with the new type and for the SSA replacement
create its default def (get_or_create_ssa_default_def).

Now for parameters this of course means you have to
adjust function signatures and calls.  For the function
boundary case you'll likely need to pass a pointer to
the structure as well which means you'll have to add
parameters.

As for "replacing" uses you can use immediate uses
to walk them:

 FOR_EACH_IMM_USE_STMT (...)
    FOR_EACH_IMM_USE_ON_STMT (..)
        ...

also the SSA definition statement after your transform
cannot be the same so you have to create another
stmt anyway, no?

Richard.

> Thanks,
>
> Gary
> ________________________________
> From: Richard Biener <richard.guenther@gmail.com>
> Sent: Saturday, July 25, 2020 10:48 PM
> To: Gary Oblock <gary@amperecomputing.com>; gcc@gcc.gnu.org <gcc@gcc.gnu.org>
> Subject: Re: Problems with changing the type of an ssa name
>
> [EXTERNAL EMAIL NOTICE: This email originated from an external sender. Please be mindful of safe email handling and proprietary information protection practices.]
>
>
> On July 25, 2020 10:47:59 PM GMT+02:00, Gary Oblock <gary@amperecomputing.com> wrote:
> >Richard,
> >
> >I suppose that might be doable but aren't there any ramifications
> >from the fact that the problematic ssa_names are the default defs?
> >I can imagine easily replacing all the ssa names except those that
> >are default defs.
>
> Well, just changing the SSA names doesn't make it less ramifications. You have to know what you are doing.
>
> So - what's the reason you need to change those SSA name types?
>
> Richard.
>
> >Gary
> >________________________________
> >From: Richard Biener <richard.guenther@gmail.com>
> >Sent: Friday, July 24, 2020 11:16 PM
> >To: Gary Oblock <gary@amperecomputing.com>; Gary Oblock via Gcc
> ><gcc@gcc.gnu.org>; gcc@gcc.gnu.org <gcc@gcc.gnu.org>
> >Subject: Re: Problems with changing the type of an ssa name
> >
> >[EXTERNAL EMAIL NOTICE: This email originated from an external sender.
> >Please be mindful of safe email handling and proprietary information
> >protection practices.]
> >
> >
> >On July 25, 2020 7:30:48 AM GMT+02:00, Gary Oblock via Gcc
> ><gcc@gcc.gnu.org> wrote:
> >>If you've followed what I've been up to via my questions
> >>on the mailing list, I finally traced my latest big problem
> >>back to to my own code. In a nut shell here is what
> >>I'm doing.
> >>
> >>I'm creating a new type exaactly like this:
> >>
> >>    tree pointer_rep =
> >>      make_signed_type ( TYPE_PRECISION ( pointer_sized_int_node));
> >>    TYPE_MAIN_VARIANT ( pointer_rep) =
> >>      TYPE_MAIN_VARIANT ( pointer_sized_int_node);
> >>    const char *gcc_name =
> >>identifier_to_locale ( IDENTIFIER_POINTER ( TYPE_NAME (
> >>ri->gcc_type)));
> >>    size_t len =
> >>      strlen ( REORG_SP_PTR_PREFIX) + strlen ( gcc_name);
> >>    char *name = ( char *)alloca(len + 1);
> >>    strcpy ( name, REORG_SP_PTR_PREFIX);
> >>    strcat ( name, gcc_name);
> >>    TYPE_NAME ( pointer_rep) = get_identifier ( name);
> >>
> >>I detect an ssa_name that I want to change to have this type
> >>and change it thusly. Note, this particular ssa_name is a
> >>default def which I seems to be very pertinent (since it's
> >>the only case that fails.)
> >>
> >>    modify_ssa_name_type ( an_ssa_name, pointer_rep);
> >>
> >>void
> >>modify_ssa_name_type ( tree ssa_name, tree type)
> >>{
> >>  // This rips off the code in make_ssa_name_fn with a
> >>  // modification or two.
> >>
> >>  if ( TYPE_P ( type) )
> >>    {
> >>       TREE_TYPE ( ssa_name) = TYPE_MAIN_VARIANT ( type);
> >>       if ( ssa_defined_default_def_p ( ssa_name) )
> >>          {
> >>             // I guessing which I know is a terrible thing to do...
> >> SET_SSA_NAME_VAR_OR_IDENTIFIER ( ssa_name, TYPE_MAIN_VARIANT (
> >type));
> >>           }
> >>         else
> >>           {
> >>           // The following breaks defaults defs hence the check
> >above.
> >>             SET_SSA_NAME_VAR_OR_IDENTIFIER ( ssa_name, NULL_TREE);
> >>           }
> >>        }
> >>     else
> >>        {
> >>          TREE_TYPE ( ssa_name) = TREE_TYPE ( type);
> >>          SET_SSA_NAME_VAR_OR_IDENTIFIER ( ssa_name, type);
> >>        }
> >>}
> >>
> >>After this it dies when trying to call print_generic_expr with the ssa
> >>name.
> >>
> >>Here's the bottom most complaint from the internal error:
> >>
> >>tree check: expected tree that contains ‘decl minimal’ structure, have
> >>‘integer_type’ in dump_generic_node, at tree-pretty-print.c:3154
> >>
> >>Can anybody tell what I'm doing wrong?
> >
> >Do not modify existing SSA names, instead create a new one and replace
> >uses of the old.
> >
> >Richard.
> >
> >>Thank,
> >>
> >>Gary
> >>
> >>
> >>
> >>
> >>CONFIDENTIALITY NOTICE: This e-mail message, including any
> >attachments,
> >>is for the sole use of the intended recipient(s) and contains
> >>information that is confidential and proprietary to Ampere Computing
> >or
> >>its subsidiaries. It is to be used solely for the purpose of
> >furthering
> >>the parties' business relationship. Any review, copying, or
> >>distribution of this email (or any attachments thereto) is strictly
> >>prohibited. If you are not the intended recipient, please contact the
> >>sender immediately and permanently delete the original and any copies
> >>of this email and any attachments thereto.
>


More information about the Gcc mailing list