This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH][GIMPLEFE] Simplify/fix call stmt building
On Tue, 7 Feb 2017, Prathamesh Kulkarni wrote:
> On 7 February 2017 at 14:10, Richard Biener <rguenther@suse.de> wrote:
> >
> > This avoids the C machinery when building CALL_EXPRs (folding and argument
> > promotion).
> >
> > Bootstrap and regtest in progress on x86_64-unknown-linux-gnu.
> Hi Richard,
> IIUC, __builtin_abs(a) would now get built as a call instead of
> abs_expr<a> with the patch ?
Yes, you are writing a call and thus you should get one.
> Should we be then having explicit representation for operators like
> abs_expr, fma_expr etc. in gimple-fe ?
Yes, all tree.def operators that are not currently handled need
an explicit representation (see what I did for __MEM for example).
Thanks,
Richard.
>
> Thanks,
> Prathamesh
> >
> > Richard.
> >
> > 2017-02-07 Richard Biener <rguenther@suse.de>
> >
> > c/
> > * gimple-parser.c (c_parser_gimple_expr_list): Simplify.
> > (c_parser_gimple_postfix_expression_after_primary):
> > Do not use c_build_function_call_vec to avoid folding and promotion.
> > Simplify.
> >
> > * gcc.dg/gimplefe-23.c: New testcase.
> > * gcc.dg/gimplefe-24.c: Likewise.
> >
> > Index: gcc/c/gimple-parser.c
> > ===================================================================
> > --- gcc/c/gimple-parser.c (revision 245240)
> > +++ gcc/c/gimple-parser.c (working copy)
> > @@ -73,8 +73,7 @@ static void c_parser_gimple_switch_stmt
> > static void c_parser_gimple_return_stmt (c_parser *, gimple_seq *);
> > static void c_finish_gimple_return (location_t, tree);
> > static tree c_parser_gimple_paren_condition (c_parser *);
> > -static vec<tree, va_gc> *c_parser_gimple_expr_list (c_parser *,
> > - vec<tree, va_gc> **, vec<location_t> *);
> > +static void c_parser_gimple_expr_list (c_parser *, vec<tree> *);
> >
> >
> > /* Parse the body of a function declaration marked with "__GIMPLE". */
> > @@ -898,10 +897,6 @@ c_parser_gimple_postfix_expression_after
> > location_t expr_loc,
> > struct c_expr expr)
> > {
> > - struct c_expr orig_expr;
> > - vec<tree, va_gc> *exprlist;
> > - vec<tree, va_gc> *origtypes = NULL;
> > - vec<location_t> arg_loc = vNULL;
> > location_t start;
> > location_t finish;
> > tree ident;
> > @@ -936,34 +931,16 @@ c_parser_gimple_postfix_expression_after
> > {
> > /* Function call. */
> > c_parser_consume_token (parser);
> > - if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
> > - exprlist = NULL;
> > - else
> > - exprlist = c_parser_gimple_expr_list (parser, &origtypes,
> > - &arg_loc);
> > + auto_vec<tree> exprlist;
> > + if (! c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
> > + c_parser_gimple_expr_list (parser, &exprlist);
> > c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
> > "expected %<)%>");
> > - orig_expr = expr;
> > - start = expr.get_start ();
> > - finish = c_parser_tokens_buf (parser, 0)->get_finish ();
> > - expr.value = c_build_function_call_vec (expr_loc, arg_loc,
> > - expr.value,
> > - exprlist, origtypes);
> > - set_c_expr_source_range (&expr, start, finish);
> > -
> > + expr.value = build_call_array_loc
> > + (expr_loc, TREE_TYPE (TREE_TYPE (expr.value)),
> > + expr.value, exprlist.length (), exprlist.address ());
> > expr.original_code = ERROR_MARK;
> > - if (TREE_CODE (expr.value) == INTEGER_CST
> > - && TREE_CODE (orig_expr.value) == FUNCTION_DECL
> > - && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL
> > - && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P)
> > - expr.original_code = C_MAYBE_CONST_EXPR;
> > expr.original_type = NULL;
> > - if (exprlist)
> > - {
> > - release_tree_vector (exprlist);
> > - release_tree_vector (origtypes);
> > - }
> > - arg_loc.release ();
> > break;
> > }
> > case CPP_DOT:
> > @@ -1058,41 +1035,19 @@ c_parser_gimple_postfix_expression_after
> >
> > */
> >
> > -static vec<tree, va_gc> *
> > -c_parser_gimple_expr_list (c_parser *parser, vec<tree, va_gc> **p_orig_types,
> > - vec<location_t> *locations)
> > +static void
> > +c_parser_gimple_expr_list (c_parser *parser, vec<tree> *ret)
> > {
> > - vec<tree, va_gc> *ret;
> > - vec<tree, va_gc> *orig_types;
> > struct c_expr expr;
> > - location_t loc = c_parser_peek_token (parser)->location;
> > -
> > - ret = make_tree_vector ();
> > - if (p_orig_types == NULL)
> > - orig_types = NULL;
> > - else
> > - orig_types = make_tree_vector ();
> >
> > expr = c_parser_gimple_unary_expression (parser);
> > - vec_safe_push (ret, expr.value);
> > - if (orig_types)
> > - vec_safe_push (orig_types, expr.original_type);
> > - if (locations)
> > - locations->safe_push (loc);
> > + ret->safe_push (expr.value);
> > while (c_parser_next_token_is (parser, CPP_COMMA))
> > {
> > c_parser_consume_token (parser);
> > - loc = c_parser_peek_token (parser)->location;
> > expr = c_parser_gimple_unary_expression (parser);
> > - vec_safe_push (ret, expr.value);
> > - if (orig_types)
> > - vec_safe_push (orig_types, expr.original_type);
> > - if (locations)
> > - locations->safe_push (loc);
> > + ret->safe_push (expr.value);
> > }
> > - if (orig_types)
> > - *p_orig_types = orig_types;
> > - return ret;
> > }
> >
> > /* Parse gimple label.
> > Index: gcc/testsuite/gcc.dg/gimplefe-23.c
> > ===================================================================
> > --- gcc/testsuite/gcc.dg/gimplefe-23.c (nonexistent)
> > +++ gcc/testsuite/gcc.dg/gimplefe-23.c (working copy)
> > @@ -0,0 +1,33 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-fgimple" } */
> > +
> > +short int __GIMPLE ()
> > +foo (short int s)
> > +{
> > + short int D_1803;
> > +
> > +bb_2:
> > + D_1803 = s;
> > +
> > +L0:
> > + return D_1803;
> > +
> > +}
> > +
> > +int __GIMPLE ()
> > +main (int argc, char * * argv)
> > +{
> > + short int s;
> > + int D_1805;
> > + int _1;
> > + short _2;
> > +
> > +bb_2:
> > + s = (short int) argc;
> > + _1 = (int) s;
> > + _2 = foo (_1);
> > + D_1805 = (int) _2;
> > +
> > +L0:
> > + return D_1805;
> > +}
> > Index: gcc/testsuite/gcc.dg/gimplefe-24.c
> > ===================================================================
> > --- gcc/testsuite/gcc.dg/gimplefe-24.c (nonexistent)
> > +++ gcc/testsuite/gcc.dg/gimplefe-24.c (working copy)
> > @@ -0,0 +1,9 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-fgimple" } */
> > +
> > +int __GIMPLE foo(int a)
> > +{
> > + int t1;
> > + t1_1 = __builtin_abs (a);
> > + return t1_1;
> > +}
>
>
--
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)