This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: struct-reorg optimization


Jan Hubicka <hubicka@ucw.cz> wrote on 18/08/2007 01:24:44:

> Hi,
> I don't think I can approve the patch under the cgraph maintainer rule,
> but at least couple of comments.  Overall the patch looks fine to me,
> the changes outside struct-reorg.c are fine.
> I would perhaps call it ipa-struct-reorg.c to stay consistent with file
> naming of ipa passes (we really need to move from flat directory
> structure).
>

ok.

> You are missing a number of comments in front of functions that are
> required by coding standards, also documenting arguments at least in
> case there are couple of those would be nice (like
> is_complicated_indirect_ref)

sure, I'll add it.

>
>       if (TREE_CODE (type) == RECORD_TYPE)
>    {
>      return true;
>    }
>       else
>    return false;
> is better as:
>       return (TREE_CODE (type) == RECORD_TYPE);

sure.

>
> /* Print structure type.  */
> static void
> print_struct_type (tree new_type, char * indent)
>
> How this facility differ from what we already have in pretty-print.c?

In general, print_generic_expr does this work, but it prints struct name,
if
it exists and decl of struct otherwise, i.e. in tree-pretty-print.c:

    case RECORD_TYPE:
      ...
      if (TYPE_NAME (node))
        dump_generic_node (buffer, TYPE_NAME (node), spc, flags, false);
      else
        print_struct_decl (buffer, node, spc, flags);
      break;

and I would want to see both.
Is there any other function that can be used?

>
> /* This function is a hack to overcome the types problem.
>    When number of compilation units are compiled together
>    under -combine flag, the TYPE_MAIN_VARIANT cannot
>    be structed. First we comparing names,  but they do not
>    also appear, like for example, in stmts. Only then we
>    are going inside structures.
> */
> static bool
> is_equal_types (tree type1, tree type2)
>
> In longer term I definitly would like to have type merging done
> separately,

agree with you.

> but I guess it is resonable short term hack (or in initial
> implementation just require types to match pesimizing -combine case)

I got to this function due to number of reasons:

1. types cannot be compared as trees (type1 == type2) for multiple units,
i.e.
type1 != type2 for the same type where type1 represents type in unit1
and type2 represent type in unit2

2. TYPE_MAIN_VARIANTs cannot be compared as trees
 (TYPE_MAIN_VARIAN (type1) == TYPE_MAIN_VARIANT (type2))
for multiple units, i.e. TYPE_MAIN_VARIANT of the same type are different
for different compilation units

3. TYPE_MAIN_VARIAN keeps no name of the type.

4. the name of type is not always preserved, as for example,
in array_refs of arrays of structures. (I suppose it just uses
TYPE_MAIN_VARIAN of the structure type here.)

>
>   name1 = get_type_name (type1);
>   name2 = get_type_name (type2);
>
>   if (name1 && name2 && !strcmp (name1, name2))
>     return true;
>
>   if (name1 && name2 && strcmp (name1, name2))
>     return false;
>
> What happens if the two units declare type with same name and completely
> different layout and use it for different variables?
> (ie in completely legal way).  Will we every get into this matching
> predicate?

We have two corner cases here: structs with the same name and different
bodies,
and structs with same body and different names. So I think theoretically
structs are equal if they have the same name and the same body. But we cut
the name in many cases (like in TYPE_MAIN_VARIAN), so there is no good
solution
for now.

>
> /* Check whether the indirect_ref is of the form we can deal with.  */
> static bool
> is_complicated_indirect_ref (tree str_decl, tree ref, tree * num_p,
> tree * offset_p,
>              tree * base_p, tree * ref_def_stmt_p, tree * cast_stmt_p)
>
> Comment on operands here.  Perhaps would be better if packed into some
> descriptor structure a-la ifcvt.c.  Also it seems bit weird for me to
> have predicae returning true but setting the _p variables only when
> returning false.  Perhaps decompose_indirect_ref_acces would be better
> name, then one can return 0 as error and 1 when _p values was computed.

ok with me.

>
> /* Helper for walk_tree called from collect_accesses_in_bb function.  */
> static tree
> get_stmt_accesses (tree *tp, int *walk_subtrees, void *data)
> {
>   tree stmt = (tree) data;
>   tree t = *tp;
>
>   if (!t)
>     return NULL;
>
>   switch (TREE_CODE (t))
>     {
>     case BIT_FIELD_REF:
>      ...
>       break;
>     case GIMPLE_MODIFY_STMT:
>
> On GIMPLE we would probably benefit from organizing this on dealing with
> statement codes first (ie GIMPLE_MODIFY_STMT) having separate function
> looking for stmt accesses in the GIMPLE operands (ie _REFs and frineds)
> walking via handled refs.

yes, agree.

>
> The walk_tree uses should probably mostly go away for tupleification
> benefits anyway.
>     case COMPONENT_REF:
>       {
>    tree ref = TREE_OPERAND (t, 0);
>    tree field_decl = TREE_OPERAND (t, 1);
>
>
>    if ((TREE_CODE (ref) == INDIRECT_REF
>         || TREE_CODE (ref) == ARRAY_REF
>         || TREE_CODE (ref) == VAR_DECL)
>        && TREE_CODE (field_decl) == FIELD_DECL)
>
> What would happen with, for instance, COMPONENT_REF containing
> VIEW_CONVERT_EXPR, REALPART_EXPR or IMAGPART_EXPR?

any example of source code that can bring to these cases
would be very helpful.

>
> /* Generate new structure name.  */
> static inline char *
> gen_cluster_name (tree decl, int clust_num, int str_num)
>
> Can't we use here the facility for generating names of nested functions
> and local statics?  It has one global counter so you probably won't need
> to check if the name was already taken (assuming we don't have other
> sources of basename.id type of names that we probably should not).

which function do you mean?

>
> static void
> finish_var_creation (tree new_decl)
> {
>   if (!var_ann (new_decl))
>     create_var_ann (new_decl);
> add_referenced_var will create one for you.

ok.

> I am not sure why you need gimple_referenced_vars predicate - you are
> always seeing SSA functions and thus it should be always up.
>
>   if (is_global_var (new_decl))
>     mark_call_clobbered (new_decl, ESCAPE_UNKNOWN);
>
>
>   mark_sym_for_renaming (new_decl);
>   if (gimple_referenced_vars (cfun))
>     add_referenced_var (new_decl);
> }

agree.

>
> static char *
> gen_var_name (tree orig_decl, int i, tree * id_node)
>
> Similarly the facility for producing local statics should help here.
>
> /* This function copy attributes form ORIG_DECL to NEW_DECL.  */
> static inline void
> copy_decl_attributes (tree new_decl, tree orig_decl)
>
> This seems like you want something similar to copy_decl_no_change in
> tree-inline.c For C++ I am quite convinced it is neccesary to use the
> langhook still :(
>

I see. Working to test C++ patterns.

>
> struct type_wrapper
>
> Some explanation of what are the wrappers for?

it is used to generate new type when structure is wrapped
by pointers and arrays. I'll add an explanations there.

>
> /* For each SSA_NAME or VAR_DECL local variable of structure
>    type relevant for transformation in current function (cfun)
>    this function generate new variable(s) to replace it.  */
> static void
> create_new_local_vars (void)
> {
>   unsigned i;
>   tree var_list;
>
>   if (gimple_in_ssa_p (cfun))
>
> You probably want just require all functions in SSA form so you don't
> need to do analysis for SSA and non-SSA bodies...

yes, true.

>           if (is_malloc_of_struct (stmt, &str_node))
>             {
>          d_str str = str_node->struct_data;
>
>          /* We support only malloc now.  */
> C++ new operator is probably good idea to add, but you are probably
> aware of that ;)

yes.

>          if (DECL_FUNCTION_CODE (decl) == BUILT_IN_MALLOC)
>              add_call_to_malloc_list (node->decl, stmt, str);
>          else
>            remove_struct_from_data_struct_list (str_node);
>
>
>       if (TREE_CODE (rhs) == MULT_EXPR)
>    {
>      tree arg0 = TREE_OPERAND (rhs, 0);
>      tree arg1 = TREE_OPERAND (rhs, 1);
>
>      if (operand_equal_p (arg0, struct_size, OEP_ONLY_CONST))
> From canonicality you probably can expect the constant to be in arg1.
> Don't you want to also handle constantly size allocations?

yes, it requires extensions; it's partly prepared in
gen_num_of_structs_in_malloc.

>
> /* Do transformation for a function represented by NODE.  */
> static void
> do_reorg_for_func (struct cgraph_node *node)
> {
>   create_new_local_vars ();
>
>   create_new_mallocs_for_func (node);
>   create_new_accesses_for_func ();
>   update_ssa (TODO_update_ssa);
>   cleanup_tree_cfg ();
>
> You should probably use function local cfun->todo lists. You care above
> to update cgraph edges, however ding update_ssa/cleanup_tree_cfg is
> going to disturb cgraph anyway, so you probably just want to add TODO
> flag for rebuilding cgraph edges as well.

ok.

>
> Nice work and sorry for delays with the review!

I am working to incorporate your comments now.

Thank you a lot for reviewing this patch!

Olga

> Honza


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]