I've committed the cut-down version of the gimple statement subclasses
work to svn trunk [specifically the gimple-classes-v2-option-3 git
branch, having bootstrapped&regrested it on x86_64-unknown-linux-gnu
(Fedora 20)].

This is the the 89-patch kit from 
  https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01148.html
with various fixups, reviewed by Jeff and Richi.

This strengthens the type requirements on numerous places in the middle
end.  For example, the callgraph now works on gcall * rather than plain
gimple, capturing the GIMPLE_CALL requirement and checking that at
compile-time.  This gives us earlier failures when bugs occur, closer to
the failure point, and (I hope) more readable code (since the
assumptions made become clearer).

It converts about half of the gimple_foo_ accessors, so that they take a
gimple subclass pointer.  [In theory we could add a gimple-compat.h that
adds back overloads for these if you have out-of-tree code that uses the
accessors with a plain "gimple"].

I've dropped about 80 followup patches where I attempted to convert the
rest of the accessors, which led to contorted and overly-verbose C++isms
in the code.

Discussion on IRC indicates unhappiness with the cut-down version, a
feeling that it's still too verbose.

I'm sorry about that.  There may be ways of shortening the API (if
that's acceptable at this dev stage).

Two common patterns relating to gimple_statement_iterator:

(A) after detecting a particular kind of statement currently visited by
a gsi, call some function, passing it the gsi, where the callee has
something like this (in what I merged):

-  gimple stmt = gsi_stmt (*gsi);
+  greturn *stmt = as_a <greturn *> (gsi_stmt (*gsi));

i.e. where we then rely on it being a GIMPLE_RETURN in the callee.

Would it be useful to have a less verbose spelling of, say:

   as_a <greturn *> (gsi_stmt (*gsi));

?

(B) a check for a particular gimple code on the gsi_stmt e.g. like this
in what I merged:

-  if (gimple_code (stmt) != GIMPLE_CALL)
+  stmt = dyn_cast <gcall *> (gsi_stmt (*gsi));
+  if (!stmt)
     return;

Should we add a less verbose spelling of:

  dyn_cast <gcall *> (gsi_stmt (*gsi));

?

It's important to have a clear distinction between the as_a<> and
dyn_cast<> cases: the former is a simple cast in a release build,
whereas the latter is a conditional that could return NULL (in both
debug and release builds).

If we're going for minimal typing, then a method is shorter than a
function, since we wouldn't need to spell out the "gsi" twice e.g.:

(A) could become:

  greturn *stmt = gsi->as_a_greturn ();

(B) could become:

  stmt = gsi->dyn_cast <gcall *> ();
  if (!stmt)

or:

  stmt = gsi->dyn_cast_gcall ();
  if (!stmt)

or maybe:

  stmt = gsi->is_a_gcall ();
  if (!stmt)

An earlier version of my patches had casting methods within the
gimple_statement_base class, which were rejected; the above proposals
would instead put them within gimple_stmt_iterator.


Dave

Reply via email to