This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[lto] PATCH: CALL_EXPR changes to gcc/tree-object-size.c


Already committed as "obvious".

-Sandra
2006-07-12  Sandra Loosemore  <sandra@codesourcery.com>

	* gcc/tree-object-size.c (alloc_object_size):  Use build_call_expr
	and simplify logic to avoid having to iterate over arguments.

Index: gcc/tree-object-size.c
===================================================================
*** gcc/tree-object-size.c	(revision 115346)
--- gcc/tree-object-size.c	(working copy)
*************** addr_object_size (tree ptr, int object_s
*** 227,275 ****
  static unsigned HOST_WIDE_INT
  alloc_object_size (tree call, int object_size_type)
  {
!   tree callee, arglist, a, bytes = NULL_TREE;
!   unsigned int arg_mask = 0;
  
    gcc_assert (TREE_CODE (call) == CALL_EXPR);
  
    callee = get_callee_fndecl (call);
-   arglist = TREE_OPERAND (call, 1);
    if (callee
        && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
      switch (DECL_FUNCTION_CODE (callee))
        {
        case BUILT_IN_MALLOC:
        case BUILT_IN_ALLOCA:
! 	arg_mask = 1;
  	break;
        /*
        case BUILT_IN_REALLOC:
! 	arg_mask = 2;
  	break;
  	*/
        case BUILT_IN_CALLOC:
! 	arg_mask = 3;
  	break;
        default:
  	break;
        }
  
!   for (a = arglist; arg_mask && a; arg_mask >>= 1, a = TREE_CHAIN (a))
!     if (arg_mask & 1)
!       {
! 	tree arg = TREE_VALUE (a);
! 
! 	if (TREE_CODE (arg) != INTEGER_CST)
! 	  break;
! 
! 	if (! bytes)
! 	  bytes = fold_convert (sizetype, arg);
! 	else
! 	  bytes = size_binop (MULT_EXPR, bytes,
! 			      fold_convert (sizetype, arg));
!       }
! 
!   if (! arg_mask && bytes && host_integerp (bytes, 1))
      return tree_low_cst (bytes, 1);
  
    return unknown[object_size_type];
--- 227,267 ----
  static unsigned HOST_WIDE_INT
  alloc_object_size (tree call, int object_size_type)
  {
!   tree callee, bytes = NULL_TREE;
  
    gcc_assert (TREE_CODE (call) == CALL_EXPR);
  
    callee = get_callee_fndecl (call);
    if (callee
        && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
      switch (DECL_FUNCTION_CODE (callee))
        {
        case BUILT_IN_MALLOC:
        case BUILT_IN_ALLOCA:
! 	if (call_expr_nargs (call) == 1
! 	    && TREE_CODE (CALL_EXPR_ARG0 (call)) == INTEGER_CST)
! 	  bytes = fold_convert (sizetype, CALL_EXPR_ARG0 (call));
  	break;
        /*
        case BUILT_IN_REALLOC:
! 	if (call_expr_nargs (call) == 2
! 	    && TREE_CODE (CALL_EXPR_ARG1 (call)) == INTEGER_CST)
! 	  bytes = fold_convert (sizetype, CALL_EXPR_ARG1 (call));
  	break;
  	*/
        case BUILT_IN_CALLOC:
! 	if (call_expr_nargs (call) == 2
! 	    && TREE_CODE (CALL_EXPR_ARG0 (call)) == INTEGER_CST
! 	    && TREE_CODE (CALL_EXPR_ARG1 (call)) == INTEGER_CST)
! 	  bytes = size_binop (MULT_EXPR,
! 			      fold_convert (sizetype, CALL_EXPR_ARG0 (call)),
! 			      fold_convert (sizetype, CALL_EXPR_ARG1 (call)));
  	break;
        default:
  	break;
        }
  
!   if (bytes && host_integerp (bytes, 1))
      return tree_low_cst (bytes, 1);
  
    return unknown[object_size_type];
*************** static tree
*** 284,290 ****
  pass_through_call (tree call)
  {
    tree callee = get_callee_fndecl (call);
-   tree arglist = TREE_OPERAND (call, 1);
  
    if (callee
        && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL)
--- 276,281 ----
*************** pass_through_call (tree call)
*** 304,311 ****
        case BUILT_IN_STRNCPY_CHK:
        case BUILT_IN_STRCAT_CHK:
        case BUILT_IN_STRNCAT_CHK:
! 	if (arglist)
! 	  return TREE_VALUE (arglist);
  	break;
        default:
  	break;
--- 295,302 ----
        case BUILT_IN_STRNCPY_CHK:
        case BUILT_IN_STRCAT_CHK:
        case BUILT_IN_STRNCAT_CHK:
! 	if (call_expr_nargs (call) >= 1)
! 	  return CALL_EXPR_ARG0 (call);
  	break;
        default:
  	break;
*************** compute_object_sizes (void)
*** 1008,1021 ****
  	  result = fold_call_expr (call, false);
  	  if (!result)
  	    {
! 	      tree arglist = TREE_OPERAND (call, 1);
! 
! 	      if (arglist != NULL
! 		  && POINTER_TYPE_P (TREE_TYPE (TREE_VALUE (arglist)))
! 		  && TREE_CHAIN (arglist) != NULL
! 		  && TREE_CHAIN (TREE_CHAIN (arglist)) == NULL)
  		{
! 		  tree ost = TREE_VALUE (TREE_CHAIN (arglist));
  
  		  if (host_integerp (ost, 1))
  		    {
--- 999,1008 ----
  	  result = fold_call_expr (call, false);
  	  if (!result)
  	    {
! 	      if (call_expr_nargs (call) == 2
! 		  && POINTER_TYPE_P (TREE_TYPE (CALL_EXPR_ARG0 (call))))
  		{
! 		  tree ost = CALL_EXPR_ARG1 (call);
  
  		  if (host_integerp (ost, 1))
  		    {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]