public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: Mikhail Maltsev <maltsevm@gmail.com>, gcc-patches <gcc-patches@gnu.org>
Subject: Re: [PATCH 1/2] C++-ify dominance.c
Date: Fri, 14 Aug 2015 18:25:00 -0000	[thread overview]
Message-ID: <55CE3162.5030400@redhat.com> (raw)
In-Reply-To: <55CD3C87.40101@gmail.com>

On 08/13/2015 06:55 PM, Mikhail Maltsev wrote:
> Hi all.
>
> These two patches are refactoring of dominator-related code.
>
> The comment in dominance.c says: "We work in a poor-mans object oriented
> fashion, and carry an instance of this structure through all our 'methods'". So,
> the first patch converts the mentioned structure (dom_info) into a class with
> proper encapsulation. It also adds a new member - m_fn (the function currently
> being compiled) to this structure and replaces some uses of cfun with m_fn. It
> also contains some fixes, related to current coding standards: move variable
> declarations to place of first use, replace elaborated type specifiers (i.e.
> "struct/enum foo") by simple ones (i.e., just "foo") in function prototypes.
>
> Bootstrapped and regtested on x86_64-linux. Tested build of config-list.mk.
>
> gcc/ChangeLog:
>
> 2015-08-14  Mikhail Maltsev<maltsevm@gmail.com>
>
>          * (ENABLE_CHECKING): Define as 0 by default.
>          dominance.c (new_zero_array): Define.
>          (dom_info): Define as class instead of struct.
>          (dom_info::dom_info, ~dom_info): Define.  Use new/delete for memory
>          allocations/deallocations.  Pass function as parameter (instead of
>          using cfun).
>          (dom_info::get_idom): Define accessor method.
>          (dom_info::calc_dfs_tree_nonrec, calc_dfs_tree, compress, eval,
>          link_roots, calc_idoms): Redefine as class members.  Use m_fn instead
>          of cfun.
>          (init_dom_info, free_dom_info): Remove (use dom_info ctor/dtor).
>          (dom_convert_dir_to_idx): Fix prototype.
>          (assign_dfs_numbers): Move variable declarations to their first uses.
>          (calculate_dominance_info): Remove conditional compilation, move
>          variables.
>          (free_dominance_info, get_immediate_dominator, set_immediate_dominator,
>          get_dominated_b, get_dominated_by_region, get_dominated_to_depth,
>          redirect_immediate_dominators, nearest_common_dominator_for_set,
>          dominated_by_p, bb_dom_dfs_in, bb_dom_dfs_out, verify_dominators,
>          determine_dominators_for_sons, iterate_fix_dominators, first_dom_son,
>          next_dom_son, debug_dominance_info, debug_dominance_tree_1): Adjust to
>          use class dom_info. Move variable declarations to the place of first
>          use. Fix prototypes (remove struct/enum).
>          * dominance.h: Fix prototypes (remove struct/enum).
>
> -- Regards, Mikhail Maltsev
>
It looks like your patch is primarily concerned with converting all the 
internal stuff into a C++ style and not exposing a class to the users of 
dominance.h. Correct?

As a whole I don't see anything objectionable here, but I also don't see 
that it really takes us forward in a real significant way.  I guess 
there's some value in having dominance.c brought up to current 
standards, but my recollection was we weren't going to do through the 
entire source base and do things like move variable declarations to 
their initial use and more generally c++-ify the code base en-masse.

Similarly losing the elaborated type specifiers doesn't really gain us 
anything, except perhaps one less token when people parse the code. 
Again, not objectionable, but also not a big gain.

I could argue that those kind of changes are independent of turning 
dom_info into a real class and if they're going to go forward, they 
would have to stand alone on their merits and go in independently if 
turning dom_info into a class (which AFIACT is the meat of this patch).



> refactor_dom1.patch
>
>
> diff --git a/gcc/dominance.c b/gcc/dominance.c
> index d8d87ca..3c4f228 100644
> --- a/gcc/dominance.c
> +++ b/gcc/dominance.c
> @@ -44,6 +44,10 @@
>   #include "timevar.h"
>   #include "graphds.h"
>
> +#ifndef ENABLE_CHECKING
> +# define ENABLE_CHECKING 0
> +#endif
Umm, isn't ENABLE_CHECKING defined in auto-host.h (as set up by 
configure?)  What's the reason for this change?

Is the issue that auto-host.h won't define checking at all for 
--disable-checking?

I think that the ENABLE_CHECKING conversion from #ifdef testing to 
testing for a value should probably be done separately.  It also 
probably has higher value than this refactoring.


> +
> +  /* The function being processed.  */
> +  function *m_fn;
So presumably the idea here is to avoid explicitly hitting cfun which in 
theory we could recompute the dominance tree for another function. But 
is that really all that useful?

I'm a bit torn here.  Richi mentioned the idea of stuffing away a 
pointer to cfun looked backwards to him and he'd pretty stuffing away 
the entry, exit & # blocks and perhaps take us a step towards the 
ability to compute dominance on sub-graphs.

The problem I see with Richi's idea now that I think about it more is 
keeping that information up-to-date.  Ie, if we've stuffed away those 
pointers, what happens if (for example) a block gets deleted from the 
graph.  What if that block happens to be the exit block we've recorded?

So I guess I'm starting to lean towards saving away the cfun  like as is 
done in this patch.


>> +  int *son      = new int[n + 1],
> +      *brother  = new int[n + 1],
> +      *parent   = new int[n + 1];
ICK.  Don't do this.  Make each initialization a separate statement. 
There's nothing really to be gained by avoiding the "int" here.

So ultimately the question is whether or not we're gaining much with 
this patch to justify the churn it creates.  I think I'll hold off on 
yes/no to the patch to give other folks an opportunity to chime in.


Jeff

  parent reply	other threads:[~2015-08-14 18:20 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-14  1:05 Mikhail Maltsev
2015-08-14  1:25 ` [PATCH 2/2] Get rid of global state accesses in dominance.c Mikhail Maltsev
2015-08-14  8:17   ` Richard Biener
2015-08-14 18:28     ` Jeff Law
2015-08-14 20:24       ` David Malcolm
2015-08-15  6:13     ` Mikhail Maltsev
2015-08-18 10:13       ` Richard Biener
2015-08-14  7:54 ` [PATCH 1/2] C++-ify dominance.c Richard Biener
2015-08-14 17:26   ` Jeff Law
2015-08-15  6:05   ` Mikhail Maltsev
2015-08-18 19:23     ` Jeff Law
2015-08-22  7:01       ` Mikhail Maltsev
2015-08-14 18:25 ` Jeff Law [this message]
2015-08-15  7:59   ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55CE3162.5030400@redhat.com \
    --to=law@redhat.com \
    --cc=gcc-patches@gnu.org \
    --cc=maltsevm@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).