[PATCH] Clean up gcc_asserts in inline functions

Richard Guenther rguenther@suse.de
Wed Jan 6 23:55:00 GMT 2010


The following patch removes asserts where they are unnecessary
(or duplicate work done by the IL verifiers) or wrap them inside
ENABLE_CHECKING where they are similar to other tree or
bounds checking in the compiler.  In general we shouldn't
inline checking code for release-checking.

It also removes FOR_EACH_REFERENCED_VARS_SAFE as it is 1) unused,
2) wrong after we no longer have stable UIDs for -g vs. -g0
code equivalence.

A checking enabled cc1 is about 0.2% smaller, the simulated
compile-time effect is insignificant.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2010-01-07  Richard Guenther  <rguenther@suse.de>

	* gimple.h (gss_for_code): Wrap gcc_assert in ENABLE_CHECKING.
	(gimple_op): Likewise.
	(gimple_op_ptr): Likewise.
	(gimple_assign_set_lhs): Remove gcc_assert.
	(gimple_assign_set_rhs1): Likewise.
	(gimple_assign_set_rhs2): Likewise.
	(gimple_call_set_lhs): Likewise.
	(gimple_call_set_fn): Likewise.
	(gimple_call_set_fndecl): Likewise.
	(gimple_call_fndecl): Likewise.
	(gimple_call_return_type): Likewise.
	(gimple_call_set_chain): Likewise.
	(gimple_call_num_args): Likewise.
	(gimple_call_set_arg): Likewise.
	(gimple_cond_set_code): Likewise.
	(gimple_cond_set_lhs): Likewise.
	(gimple_cond_set_rhs): Likewise.
	(gimple_cond_set_true_label): Likewise.
	(gimple_cond_set_false_label): Likewise.
	(gimple_label_set_label): Likewise.
	(gimple_goto_set_dest): Likewise.
	(gimple_debug_bind_get_var): Wrap gcc_assert in ENABLE_CHECKING.
	(gimple_debug_bind_get_value): Likewise.
	(gimple_debug_bind_get_value_ptr): Likewise.
	(gimple_debug_bind_set_var): Likewise.
	(gimple_debug_bind_set_value): Likewise.
	(gimple_debug_bind_reset_value): Likewise.
	(gimple_debug_bind_has_value_p): Likewise.
	(gimple_return_retval_ptr): Remove gcc_assert.
	(gimple_return_retval): Likewise.
	(gimple_return_set_retval): Likewise.
	* tree-flow.h (struct gimple_df): Remove nonlocal_all member.
	(safe_referenced_var_iterator): Remove.
	(FOR_EACH_REFERENCED_VAR_SAFE): Likewise.
	* tree-flow-inline.h (gimple_nonlocal_all): Remove.
	(fill_referenced_var_vec): Remove.
	(first_readonly_imm_use): Remove redundant gcc_assert.
	(phi_arg_index_from_use): Combine gcc_asserts.
	(move_use_after_head): Wrap gcc_assert in ENABLE_CHECKING.
	(first_imm_use_stmt): Remove redundant gcc_assert.

Index: gcc/gimple.h
===================================================================
*** gcc/gimple.h	(revision 155678)
--- gcc/gimple.h	(working copy)
*************** gimple_code (const_gimple g)
*** 1061,1067 ****
--- 1061,1069 ----
  static inline enum gimple_statement_structure_enum
  gss_for_code (enum gimple_code code)
  {
+ #ifdef ENABLE_CHECKING
    gcc_assert ((unsigned int)code < LAST_AND_UNUSED_GIMPLE_CODE);
+ #endif
    return gss_for_code_[code];
  }
  
*************** gimple_op (const_gimple gs, unsigned i)
*** 1628,1634 ****
--- 1630,1638 ----
  {
    if (gimple_has_ops (gs))
      {
+ #ifdef ENABLE_CHECKING
        gcc_assert (i < gimple_num_ops (gs));
+ #endif
        return gimple_ops (CONST_CAST_GIMPLE (gs))[i];
      }
    else
*************** gimple_op_ptr (const_gimple gs, unsigned
*** 1642,1648 ****
--- 1646,1654 ----
  {
    if (gimple_has_ops (gs))
      {
+ #ifdef ENABLE_CHECKING
        gcc_assert (i < gimple_num_ops (gs));
+ #endif
        return gimple_ops (CONST_CAST_GIMPLE (gs)) + i;
      }
    else
*************** static inline void
*** 1706,1712 ****
  gimple_assign_set_lhs (gimple gs, tree lhs)
  {
    GIMPLE_CHECK (gs, GIMPLE_ASSIGN);
-   gcc_assert (is_gimple_operand (lhs));
    gimple_set_op (gs, 0, lhs);
  
    if (lhs && TREE_CODE (lhs) == SSA_NAME)
--- 1712,1717 ----
*************** gimple_assign_set_rhs1 (gimple gs, tree 
*** 1741,1753 ****
  {
    GIMPLE_CHECK (gs, GIMPLE_ASSIGN);
  
-   /* If there are 3 or more operands, the 2 operands on the RHS must be
-      GIMPLE values.  */
-   if (gimple_num_ops (gs) >= 3)
-     gcc_assert (is_gimple_val (rhs));
-   else
-     gcc_assert (is_gimple_operand (rhs));
- 
    gimple_set_op (gs, 1, rhs);
  }
  
--- 1746,1751 ----
*************** gimple_assign_set_rhs2 (gimple gs, tree 
*** 1785,1793 ****
  {
    GIMPLE_CHECK (gs, GIMPLE_ASSIGN);
  
-   /* The 2 operands on the RHS must be GIMPLE values.  */
-   gcc_assert (is_gimple_val (rhs));
- 
    gimple_set_op (gs, 2, rhs);
  }
  
--- 1783,1788 ----
*************** static inline void
*** 1901,1907 ****
  gimple_call_set_lhs (gimple gs, tree lhs)
  {
    GIMPLE_CHECK (gs, GIMPLE_CALL);
-   gcc_assert (!lhs || is_gimple_operand (lhs));
    gimple_set_op (gs, 0, lhs);
    if (lhs && TREE_CODE (lhs) == SSA_NAME)
      SSA_NAME_DEF_STMT (lhs) = gs;
--- 1896,1901 ----
*************** static inline void
*** 1936,1942 ****
  gimple_call_set_fn (gimple gs, tree fn)
  {
    GIMPLE_CHECK (gs, GIMPLE_CALL);
-   gcc_assert (is_gimple_operand (fn));
    gimple_set_op (gs, 1, fn);
  }
  
--- 1930,1935 ----
*************** static inline void
*** 1947,1953 ****
  gimple_call_set_fndecl (gimple gs, tree decl)
  {
    GIMPLE_CHECK (gs, GIMPLE_CALL);
-   gcc_assert (TREE_CODE (decl) == FUNCTION_DECL);
    gimple_set_op (gs, 1, build_fold_addr_expr_loc (gimple_location (gs), decl));
  }
  
--- 1940,1945 ----
*************** gimple_call_fndecl (const_gimple gs)
*** 1961,1970 ****
  {
    tree addr = gimple_call_fn (gs);
    if (TREE_CODE (addr) == ADDR_EXPR)
!     {
!       gcc_assert (TREE_CODE (TREE_OPERAND (addr, 0)) == FUNCTION_DECL);
!       return TREE_OPERAND (addr, 0);
!     }
    return NULL_TREE;
  }
  
--- 1953,1959 ----
  {
    tree addr = gimple_call_fn (gs);
    if (TREE_CODE (addr) == ADDR_EXPR)
!     return TREE_OPERAND (addr, 0);
    return NULL_TREE;
  }
  
*************** gimple_call_return_type (const_gimple gs
*** 1978,1989 ****
    tree type = TREE_TYPE (fn);
  
    /* See through the pointer.  */
-   gcc_assert (POINTER_TYPE_P (type));
    type = TREE_TYPE (type);
  
-   gcc_assert (TREE_CODE (type) == FUNCTION_TYPE
- 	      || TREE_CODE (type) == METHOD_TYPE);
- 
    /* The type returned by a FUNCTION_DECL is the type of its
       function type.  */
    return TREE_TYPE (type);
--- 1967,1974 ----
*************** static inline void
*** 2015,2023 ****
  gimple_call_set_chain (gimple gs, tree chain)
  {
    GIMPLE_CHECK (gs, GIMPLE_CALL);
!   gcc_assert (chain == NULL
!               || TREE_CODE (chain) == ADDR_EXPR
!               || SSA_VAR_P (chain));
    gimple_set_op (gs, 2, chain);
  }
  
--- 2000,2006 ----
  gimple_call_set_chain (gimple gs, tree chain)
  {
    GIMPLE_CHECK (gs, GIMPLE_CALL);
! 
    gimple_set_op (gs, 2, chain);
  }
  
*************** gimple_call_num_args (const_gimple gs)
*** 2030,2036 ****
    unsigned num_ops;
    GIMPLE_CHECK (gs, GIMPLE_CALL);
    num_ops = gimple_num_ops (gs);
-   gcc_assert (num_ops >= 3);
    return num_ops - 3;
  }
  
--- 2013,2018 ----
*************** static inline void
*** 2062,2068 ****
  gimple_call_set_arg (gimple gs, unsigned index, tree arg)
  {
    GIMPLE_CHECK (gs, GIMPLE_CALL);
-   gcc_assert (is_gimple_operand (arg));
    gimple_set_op (gs, index + 3, arg);
  }
  
--- 2044,2049 ----
*************** static inline void
*** 2248,2254 ****
  gimple_cond_set_code (gimple gs, enum tree_code code)
  {
    GIMPLE_CHECK (gs, GIMPLE_COND);
-   gcc_assert (TREE_CODE_CLASS (code) == tcc_comparison);
    gs->gsbase.subcode = code;
  }
  
--- 2229,2234 ----
*************** static inline void
*** 2279,2285 ****
  gimple_cond_set_lhs (gimple gs, tree lhs)
  {
    GIMPLE_CHECK (gs, GIMPLE_COND);
-   gcc_assert (is_gimple_operand (lhs));
    gimple_set_op (gs, 0, lhs);
  }
  
--- 2259,2264 ----
*************** static inline void
*** 2311,2317 ****
  gimple_cond_set_rhs (gimple gs, tree rhs)
  {
    GIMPLE_CHECK (gs, GIMPLE_COND);
-   gcc_assert (is_gimple_operand (rhs));
    gimple_set_op (gs, 1, rhs);
  }
  
--- 2290,2295 ----
*************** static inline void
*** 2334,2340 ****
  gimple_cond_set_true_label (gimple gs, tree label)
  {
    GIMPLE_CHECK (gs, GIMPLE_COND);
-   gcc_assert (!label || TREE_CODE (label) == LABEL_DECL);
    gimple_set_op (gs, 2, label);
  }
  
--- 2312,2317 ----
*************** static inline void
*** 2346,2352 ****
  gimple_cond_set_false_label (gimple gs, tree label)
  {
    GIMPLE_CHECK (gs, GIMPLE_COND);
-   gcc_assert (!label || TREE_CODE (label) == LABEL_DECL);
    gimple_set_op (gs, 3, label);
  }
  
--- 2323,2328 ----
*************** static inline void
*** 2477,2483 ****
  gimple_label_set_label (gimple gs, tree label)
  {
    GIMPLE_CHECK (gs, GIMPLE_LABEL);
-   gcc_assert (TREE_CODE (label) == LABEL_DECL);
    gimple_set_op (gs, 0, label);
  }
  
--- 2453,2458 ----
*************** static inline void
*** 2498,2504 ****
  gimple_goto_set_dest (gimple gs, tree dest)
  {
    GIMPLE_CHECK (gs, GIMPLE_GOTO);
-   gcc_assert (is_gimple_operand (dest));
    gimple_set_op (gs, 0, dest);
  }
  
--- 2473,2478 ----
*************** static inline tree
*** 3292,3298 ****
--- 3266,3274 ----
  gimple_debug_bind_get_var (gimple dbg)
  {
    GIMPLE_CHECK (dbg, GIMPLE_DEBUG);
+ #ifdef ENABLE_CHECKING
    gcc_assert (gimple_debug_bind_p (dbg));
+ #endif
    return gimple_op (dbg, 0);
  }
  
*************** static inline tree
*** 3303,3309 ****
--- 3279,3287 ----
  gimple_debug_bind_get_value (gimple dbg)
  {
    GIMPLE_CHECK (dbg, GIMPLE_DEBUG);
+ #ifdef ENABLE_CHECKING
    gcc_assert (gimple_debug_bind_p (dbg));
+ #endif
    return gimple_op (dbg, 1);
  }
  
*************** static inline tree *
*** 3314,3320 ****
--- 3292,3300 ----
  gimple_debug_bind_get_value_ptr (gimple dbg)
  {
    GIMPLE_CHECK (dbg, GIMPLE_DEBUG);
+ #ifdef ENABLE_CHECKING
    gcc_assert (gimple_debug_bind_p (dbg));
+ #endif
    return gimple_op_ptr (dbg, 1);
  }
  
*************** static inline void
*** 3324,3330 ****
--- 3304,3312 ----
  gimple_debug_bind_set_var (gimple dbg, tree var)
  {
    GIMPLE_CHECK (dbg, GIMPLE_DEBUG);
+ #ifdef ENABLE_CHECKING
    gcc_assert (gimple_debug_bind_p (dbg));
+ #endif
    gimple_set_op (dbg, 0, var);
  }
  
*************** static inline void
*** 3335,3341 ****
--- 3317,3325 ----
  gimple_debug_bind_set_value (gimple dbg, tree value)
  {
    GIMPLE_CHECK (dbg, GIMPLE_DEBUG);
+ #ifdef ENABLE_CHECKING
    gcc_assert (gimple_debug_bind_p (dbg));
+ #endif
    gimple_set_op (dbg, 1, value);
  }
  
*************** static inline void
*** 3350,3356 ****
--- 3334,3342 ----
  gimple_debug_bind_reset_value (gimple dbg)
  {
    GIMPLE_CHECK (dbg, GIMPLE_DEBUG);
+ #ifdef ENABLE_CHECKING
    gcc_assert (gimple_debug_bind_p (dbg));
+ #endif
    gimple_set_op (dbg, 1, GIMPLE_DEBUG_BIND_NOVALUE);
  }
  
*************** static inline bool
*** 3361,3367 ****
--- 3347,3355 ----
  gimple_debug_bind_has_value_p (gimple dbg)
  {
    GIMPLE_CHECK (dbg, GIMPLE_DEBUG);
+ #ifdef ENABLE_CHECKING
    gcc_assert (gimple_debug_bind_p (dbg));
+ #endif
    return gimple_op (dbg, 1) != GIMPLE_DEBUG_BIND_NOVALUE;
  }
  
*************** static inline tree *
*** 4254,4260 ****
  gimple_return_retval_ptr (const_gimple gs)
  {
    GIMPLE_CHECK (gs, GIMPLE_RETURN);
-   gcc_assert (gimple_num_ops (gs) == 1);
    return gimple_op_ptr (gs, 0);
  }
  
--- 4242,4247 ----
*************** static inline tree
*** 4264,4270 ****
  gimple_return_retval (const_gimple gs)
  {
    GIMPLE_CHECK (gs, GIMPLE_RETURN);
-   gcc_assert (gimple_num_ops (gs) == 1);
    return gimple_op (gs, 0);
  }
  
--- 4251,4256 ----
*************** static inline void
*** 4275,4284 ****
  gimple_return_set_retval (gimple gs, tree retval)
  {
    GIMPLE_CHECK (gs, GIMPLE_RETURN);
-   gcc_assert (gimple_num_ops (gs) == 1);
-   gcc_assert (retval == NULL_TREE
-               || TREE_CODE (retval) == RESULT_DECL
- 	      || is_gimple_val (retval));
    gimple_set_op (gs, 0, retval);
  }
  
--- 4261,4266 ----
Index: gcc/tree-flow.h
===================================================================
*** gcc/tree-flow.h	(revision 155678)
--- gcc/tree-flow.h	(working copy)
*************** struct GTY(()) gimple_df {
*** 53,62 ****
    /* Artificial variable used for the virtual operand FUD chain.  */
    tree vop;
  
-   /* Artificial variable used to model the effects of nonlocal
-      variables.  */
-   tree nonlocal_all;
- 
    /* The PTA solution for the ESCAPED artificial variable.  */
    struct pt_solution escaped;
  
--- 53,58 ----
*************** typedef struct
*** 339,345 ****
    htab_iterator hti;
  } referenced_var_iterator;
  
- 
  /* This macro loops over all the referenced vars, one at a time, putting the
     current var in VAR.  Note:  You are not allowed to add referenced variables
     to the hashtable while using this macro.  Doing so may cause it to behave
--- 335,340 ----
*************** typedef struct
*** 350,374 ****
         !end_referenced_vars_p (&(ITER)); \
         (VAR) = next_referenced_var (&(ITER)))
  
- 
- typedef struct
- {
-   int i;
- } safe_referenced_var_iterator;
- 
- /* This macro loops over all the referenced vars, one at a time, putting the
-    current var in VAR.  You are allowed to add referenced variables during the
-    execution of this macro, however, the macro will not iterate over them.  It
-    requires a temporary vector of trees, VEC, whose lifetime is controlled by
-    the caller.  The purpose of the vector is to temporarily store the
-    referenced_variables hashtable so that adding referenced variables does not
-    affect the hashtable.  */
- 
- #define FOR_EACH_REFERENCED_VAR_SAFE(VAR, VEC, ITER) \
-   for ((ITER).i = 0, fill_referenced_var_vec (&(VEC)); \
-        VEC_iterate (tree, (VEC), (ITER).i, (VAR)); \
-        (ITER).i++)
- 
  extern tree referenced_var_lookup (unsigned int);
  extern bool referenced_var_check_and_insert (tree);
  #define num_referenced_vars htab_elements (gimple_referenced_vars (cfun))
--- 345,350 ----
Index: gcc/tree-flow-inline.h
===================================================================
*** gcc/tree-flow-inline.h	(revision 155678)
--- gcc/tree-flow-inline.h	(working copy)
*************** gimple_referenced_vars (const struct fun
*** 44,58 ****
    return fun->gimple_df->referenced_vars;
  }
  
- /* Artificial variable used to model the effects of nonlocal
-    variables.  */
- static inline tree
- gimple_nonlocal_all (const struct function *fun)
- {
-   gcc_assert (fun && fun->gimple_df);
-   return fun->gimple_df->nonlocal_all;
- }
- 
  /* Artificial variable used for the virtual operand FUD chain.  */
  static inline tree
  gimple_vop (const struct function *fun)
--- 44,49 ----
*************** next_referenced_var (referenced_var_iter
*** 135,152 ****
    return (tree) next_htab_element (&iter->hti);
  }
  
- /* Fill up VEC with the variables in the referenced vars hashtable.  */
- 
- static inline void
- fill_referenced_var_vec (VEC (tree, heap) **vec)
- {
-   referenced_var_iterator rvi;
-   tree var;
-   *vec = NULL;
-   FOR_EACH_REFERENCED_VAR (var, rvi)
-     VEC_safe_push (tree, heap, *vec, var);
- }
- 
  /* Return the variable annotation for T, which must be a _DECL node.
     Return NULL if the variable annotation doesn't already exist.  */
  static inline var_ann_t
--- 126,131 ----
*************** end_readonly_imm_use_p (const imm_use_it
*** 312,319 ****
  static inline use_operand_p
  first_readonly_imm_use (imm_use_iterator *imm, tree var)
  {
-   gcc_assert (TREE_CODE (var) == SSA_NAME);
- 
    imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
    imm->imm_use = imm->end_p->next;
  #ifdef ENABLE_CHECKING
--- 291,296 ----
*************** phi_arg_index_from_use (use_operand_p us
*** 573,581 ****
  #ifdef ENABLE_CHECKING
    /* Make sure the calculation doesn't have any leftover bytes.  If it does,
       then imm_use is likely not the first element in phi_arg_d.  */
!   gcc_assert (
! 	  (((char *)element - (char *)root) % sizeof (struct phi_arg_d)) == 0);
!   gcc_assert (index < gimple_phi_capacity (phi));
  #endif
  
   return index;
--- 550,558 ----
  #ifdef ENABLE_CHECKING
    /* Make sure the calculation doesn't have any leftover bytes.  If it does,
       then imm_use is likely not the first element in phi_arg_d.  */
!   gcc_assert ((((char *)element - (char *)root)
! 	       % sizeof (struct phi_arg_d)) == 0
! 	      && index < gimple_phi_capacity (phi));
  #endif
  
   return index;
*************** static inline use_operand_p
*** 1013,1019 ****
--- 990,998 ----
  move_use_after_head (use_operand_p use_p, use_operand_p head,
  		      use_operand_p last_p)
  {
+ #ifdef ENABLE_CHECKING
    gcc_assert (USE_FROM_PTR (use_p) == USE_FROM_PTR (head));
+ #endif
    /* Skip head when we find it.  */
    if (use_p != head)
      {
*************** link_use_stmts_after (use_operand_p head
*** 1078,1085 ****
  static inline gimple
  first_imm_use_stmt (imm_use_iterator *imm, tree var)
  {
-   gcc_assert (TREE_CODE (var) == SSA_NAME);
- 
    imm->end_p = &(SSA_NAME_IMM_USE_NODE (var));
    imm->imm_use = imm->end_p->next;
    imm->next_imm_name = NULL_USE_OPERAND_P;
--- 1057,1062 ----



More information about the Gcc-patches mailing list