[PATCH, Pointer Bounds Checker 14/x] Passes [8/n] Remove useless builtin calls

Richard Biener richard.guenther@gmail.com
Fri Oct 10 07:59:00 GMT 2014


On Wed, Oct 8, 2014 at 9:08 PM, Ilya Enkovich <enkovich.gnu@gmail.com> wrote:
> Hi,
>
> This patch adds removal of user calls to chkp builtins which become useless after instrumentation.
>
> Thanks,
> Ilya
> --
> 2014-10-08  Ilya Enkovich  <ilya.enkovich@intel.com>
>
>         * tree-chkp.c (chkp_remove_useless_builtins): New.
>         (chkp_execute): Remove useless calls to Pointer Bounds
>         Checker builtins.
>
>
> diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
> index 5443950..b424af8 100644
> --- a/gcc/tree-chkp.c
> +++ b/gcc/tree-chkp.c
> @@ -3805,6 +3805,49 @@ chkp_instrument_function (void)
>         }
>  }
>
> +/* Find init/null/copy_ptr_bounds calls and replace them
> +   with assignments.  It should allow better code
> +   optimization.  */
> +
> +static void
> +chkp_remove_useless_builtins ()
> +{
> +  basic_block bb, next;
> +  gimple_stmt_iterator gsi;
> +
> +  bb = ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb;
> +  do
> +    {
> +      next = bb->next_bb;

Please don't use ->next_bb but instead use FOR_EACH_BB_FN (cfun, bb)
instead.

> +      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
> +        {
> +          gimple stmt = gsi_stmt (gsi);
> +         tree fndecl;
> +         enum built_in_function fcode;
> +
> +         /* Find builtins returning first arg and replace
> +            them with assignments.  */
> +         if (gimple_code (stmt) == GIMPLE_CALL
> +             && (fndecl = gimple_call_fndecl (stmt))
> +             && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
> +             && (fcode = DECL_FUNCTION_CODE (fndecl))
> +             && (fcode == BUILT_IN_CHKP_INIT_PTR_BOUNDS
> +                 || fcode == BUILT_IN_CHKP_NULL_PTR_BOUNDS
> +                 || fcode == BUILT_IN_CHKP_COPY_PTR_BOUNDS
> +                 || fcode == BUILT_IN_CHKP_SET_PTR_BOUNDS))
> +           {
> +             tree res = gimple_call_arg (stmt, 0);
> +             if (!update_call_from_tree (&gsi, res))
> +               gimplify_and_update_call_from_tree (&gsi, res);

update_call_from_tree should always succeed with res being a call argument.

Richard.

> +             stmt = gsi_stmt (gsi);
> +             update_stmt (stmt);
> +           }
> +        }
> +      bb = next;
> +    }
> +  while (bb);
> +}
> +
>  /* Initialize pass.  */
>  static void
>  chkp_init (void)
> @@ -3872,6 +3915,8 @@ chkp_execute (void)
>
>    chkp_instrument_function ();
>
> +  chkp_remove_useless_builtins ();
> +
>    chkp_function_mark_instrumented (cfun->decl);
>
>    chkp_fix_cfg ();



More information about the Gcc-patches mailing list