[RFC] gimplefe: expose MULT_HIGHPART_EXPR

Message ID alpine.LNX.2.20.13.1808171557420.2296@monopod.intra.ispras.ru
State New
Headers show
Series
  • [RFC] gimplefe: expose MULT_HIGHPART_EXPR
Related show

Commit Message

Alexander Monakov Aug. 17, 2018, 1:09 p.m.
For testing generic expansion of MULT_HIGHPART_EXPR I chose to expose it
via the GIMPLE FE with the following patch.

"h*" is how tree-pretty-print dumps MULT_HIGHPART_EXPR.

This patch accepts "h<whitespace>*" which ideally shouldn't happen, but
I don't see a simple way to fix that.

Is this desirable for trunk?

Is there general policy for how fancy tree codes should be exposed in
the GIMPLE FE?

	* c/gimple-parser.c (c_parser_gimple_statement): Add "h*" for
	MULT_HIGHPART_EXPR.

Comments

Richard Biener Aug. 20, 2018, 9:43 a.m. | #1
On Fri, Aug 17, 2018 at 3:09 PM Alexander Monakov <amonakov@ispras.ru> wrote:
>

> For testing generic expansion of MULT_HIGHPART_EXPR I chose to expose it

> via the GIMPLE FE with the following patch.

>

> "h*" is how tree-pretty-print dumps MULT_HIGHPART_EXPR.

>

> This patch accepts "h<whitespace>*" which ideally shouldn't happen, but

> I don't see a simple way to fix that.

>

> Is this desirable for trunk?

>

> Is there general policy for how fancy tree codes should be exposed in

> the GIMPLE FE?


We generally use __FOO (__ABS, __ABSU, __MEM), so I'd prefer
__MULT_HIGHPART, though while the existing examples parse
nicely for humans binary operands are somewhat awkward here
and thus a function-style __MULT_HIGHPART would be easier to read.

For example for POINTER_PLUS_EXPR we decide based on the type
context what '+' maps to.  Applying that to '*' and MULT_HIGHPART_EXPR
looks possible as well but I guess it would be non-obvious as well.

I suppose a case that will arise at some point is the need for
EXACT_DIV_EXPR which is also not supported right now and dumped
as '/[ex]' currently.

So if you think

 z = x __MULT_HIGHPART y;

is fine then please go with that instead.  And yes, the GIMPLE FE
should eventually support all of GIMPLE.

Richard.

>         * c/gimple-parser.c (c_parser_gimple_statement): Add "h*" for

>         MULT_HIGHPART_EXPR.

>

> diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c

> index 1be5d14dc2d..cf05c936166 100644

> --- a/gcc/c/gimple-parser.c

> +++ b/gcc/c/gimple-parser.c

> @@ -450,6 +450,7 @@ c_parser_gimple_statement (c_parser *parser, gimple_seq *seq)

>

>     gimple-binary-expression:

>       gimple-unary-expression * gimple-unary-expression

> +     gimple-unary-expression h* gimple-unary-expression

>       gimple-unary-expression / gimple-unary-expression

>       gimple-unary-expression % gimple-unary-expression

>       gimple-unary-expression + gimple-unary-expression

> @@ -544,6 +545,18 @@ c_parser_gimple_binary_expression (c_parser *parser)

>      case CPP_OR_OR:

>        c_parser_error (parser, "%<||%> not valid in GIMPLE");

>        return ret;

> +    case CPP_NAME:

> +       {

> +         tree id = c_parser_peek_token (parser)->value;

> +         if (strcmp (IDENTIFIER_POINTER (id), "h") == 0

> +             && c_parser_peek_2nd_token (parser)->type == CPP_MULT)

> +           {

> +             c_parser_consume_token (parser);

> +             code = MULT_HIGHPART_EXPR;

> +             break;

> +           }

> +       }

> +      /* Fallthru.  */

>      default:

>        /* Not a binary expression.  */

>        return lhs;

Patch

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index 1be5d14dc2d..cf05c936166 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -450,6 +450,7 @@  c_parser_gimple_statement (c_parser *parser, gimple_seq *seq)
 
    gimple-binary-expression:
      gimple-unary-expression * gimple-unary-expression
+     gimple-unary-expression h* gimple-unary-expression
      gimple-unary-expression / gimple-unary-expression
      gimple-unary-expression % gimple-unary-expression
      gimple-unary-expression + gimple-unary-expression
@@ -544,6 +545,18 @@  c_parser_gimple_binary_expression (c_parser *parser)
     case CPP_OR_OR:
       c_parser_error (parser, "%<||%> not valid in GIMPLE");
       return ret;
+    case CPP_NAME:
+	{
+	  tree id = c_parser_peek_token (parser)->value;
+	  if (strcmp (IDENTIFIER_POINTER (id), "h") == 0
+	      && c_parser_peek_2nd_token (parser)->type == CPP_MULT)
+	    {
+	      c_parser_consume_token (parser);
+	      code = MULT_HIGHPART_EXPR;
+	      break;
+	    }
+	}
+      /* Fallthru.  */
     default:
       /* Not a binary expression.  */
       return lhs;