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]

Eliminate some of more expensive gcc_asserts


Hi,
this patch change most of asserts that collect over 500 samples in my
oprofile to gcc_checking_assert.  I tried to double check that they
are not terribly important.
In bitmap.c they are all bitmap internal checks, I kept those checking
that things are used correctly.

Bootstrapped/regtested x86_64-linux, OK?

	* bitmap.c (bitmap_and, bitmap_and_into, bitmap_and_compl,
	bitmap_and_compl_into, bitmap_compl_and_into, bitmap_ior,
	bitmap_ior_into, bitmap_xor, bitmap_xor_into,
	bitmap_ior_and_compl, bitmap_ior_and_compl): Turn internal datastructure
	checks into checking asserts.
	* rtlanal.c (find_reg_note): Use gcc_checking_assert.
	* tree-ssa-sccvn.c (VN_INFO): Likewise.
	* df-scan.c (df_reorganize_refs_by_reg_by_reg, df_install_ref,
	df_ref_create_structure): Likewise.
	* alloc-pool.c (create_alloc_pool, empty_alloc_pool, pool_alloc,
	pool_free): Use gcc_checking_assert.
	* alias.c (get_alias_set): Likewise.
	* var-tracking.c (variable_htab_free, shared_hash_copy,
	canonicalize_values_mark, variable_merge_over_cur): Likewise.
	* lto-streamer.c (bp_unpack_value): Likewise.
Index: bitmap.c
===================================================================
--- bitmap.c	(revision 160516)
+++ bitmap.c	(working copy)
@@ -927,7 +927,7 @@ bitmap_and (bitmap dst, const_bitmap a,
   /* Ensure that dst->current is valid.  */
   dst->current = dst->first;
   bitmap_elt_clear_from (dst, dst_elt);
-  gcc_assert (!dst->current == !dst->first);
+  gcc_checking_assert (!dst->current == !dst->first);
   if (dst->current)
     dst->indx = dst->current->indx;
 }
@@ -975,8 +975,8 @@ bitmap_and_into (bitmap a, const_bitmap
 	}
     }
   bitmap_elt_clear_from (a, a_elt);
-  gcc_assert (!a->current == !a->first
-	      && (!a->current || a->indx == a->current->indx));
+  gcc_checking_assert (!a->current == !a->first
+		       && (!a->current || a->indx == a->current->indx));
 }
 
 
@@ -1119,7 +1119,7 @@ bitmap_and_compl (bitmap dst, const_bitm
       changed = true;
       bitmap_elt_clear_from (dst, dst_elt);
     }
-  gcc_assert (!dst->current == !dst->first);
+  gcc_checking_assert (!dst->current == !dst->first);
   if (dst->current)
     dst->indx = dst->current->indx;
 
@@ -1175,8 +1177,8 @@ bitmap_and_compl_into (bitmap a, const_b
 	  b_elt = b_elt->next;
 	}
     }
-  gcc_assert (!a->current == !a->first
-	      && (!a->current || a->indx == a->current->indx));
+  gcc_checking_assert (!a->current == !a->first
+		       && (!a->current || a->indx == a->current->indx));
   return changed != 0;
 }
 
@@ -1470,8 +1472,8 @@ bitmap_compl_and_into (bitmap a, const_b
 	  b_elt = b_elt->next;
 	}
     }
-  gcc_assert (!a->current == !a->first
-	      && (!a->current || a->indx == a->current->indx));
+  gcc_checking_assert (!a->current == !a->first
+		       && (!a->current || a->indx == a->current->indx));
   return;
 }
 
@@ -1576,7 +1577,7 @@ bitmap_ior (bitmap dst, const_bitmap a,
       changed = true;
       bitmap_elt_clear_from (dst, dst_elt);
     }
-  gcc_assert (!dst->current == !dst->first);
+  gcc_checking_assert (!dst->current == !dst->first);
   if (dst->current)
     dst->indx = dst->current->indx;
   return changed;
@@ -1615,7 +1616,7 @@ bitmap_ior_into (bitmap a, const_bitmap
       a_elt = *a_prev_pnext;
     }
 
-  gcc_assert (!a->current == !a->first);
+  gcc_checking_assert (!a->current == !a->first);
   if (a->current)
     a->indx = a->current->indx;
   return changed;
@@ -1693,7 +1694,7 @@ bitmap_xor (bitmap dst, const_bitmap a,
   /* Ensure that dst->current is valid.  */
   dst->current = dst->first;
   bitmap_elt_clear_from (dst, dst_elt);
-  gcc_assert (!dst->current == !dst->first);
+  gcc_checking_assert (!dst->current == !dst->first);
   if (dst->current)
     dst->indx = dst->current->indx;
 }
@@ -1750,7 +1751,7 @@ bitmap_xor_into (bitmap a, const_bitmap
 	  a_elt = next;
 	}
     }
-  gcc_assert (!a->current == !a->first);
+  gcc_checking_assert (!a->current == !a->first);
   if (a->current)
     a->indx = a->current->indx;
 }
@@ -1932,7 +1933,7 @@ bitmap_ior_and_compl (bitmap dst, const_
       changed = true;
       bitmap_elt_clear_from (dst, dst_elt);
     }
-  gcc_assert (!dst->current == !dst->first);
+  gcc_checking_assert (!dst->current == !dst->first);
   if (dst->current)
     dst->indx = dst->current->indx;
 
@@ -2028,7 +2029,7 @@ bitmap_ior_and_into (bitmap a, const_bit
     }
 
  done:
-  gcc_assert (!a->current == !a->first);
+  gcc_checking_assert (!a->current == !a->first);
   if (a->current)
     a->indx = a->current->indx;
   return changed;
Index: rtlanal.c
===================================================================
--- rtlanal.c	(revision 160516)
+++ rtlanal.c	(working copy)
@@ -1694,7 +1694,7 @@ find_reg_note (const_rtx insn, enum reg_
 {
   rtx link;
 
-  gcc_assert (insn);
+  gcc_checking_assert (insn);
 
   /* Ignore anything that is not an INSN, JUMP_INSN or CALL_INSN.  */
   if (! INSN_P (insn))
Index: tree-ssa-sccvn.c
===================================================================
--- tree-ssa-sccvn.c	(revision 160516)
+++ tree-ssa-sccvn.c	(working copy)
@@ -176,7 +176,7 @@ VN_INFO (tree name)
 {
   vn_ssa_aux_t res = VEC_index (vn_ssa_aux_t, vn_ssa_aux_table,
 				SSA_NAME_VERSION (name));
-  gcc_assert (res);
+  gcc_checking_assert (res);
   return res;
 }
 
Index: df-scan.c
===================================================================
--- df-scan.c	(revision 160516)
+++ df-scan.c	(working copy)
@@ -1571,7 +1554,7 @@ df_reorganize_refs_by_reg_by_reg (struct
 	      DF_REF_ID (ref) = offset++;
 	      count++;
 	      ref = DF_REF_NEXT_REG (ref);
-	      gcc_assert (offset < ref_info->refs_size);
+	      gcc_checking_assert (offset < ref_info->refs_size);
 	    }
 	}
       if (include_uses)
@@ -1583,7 +1566,7 @@ df_reorganize_refs_by_reg_by_reg (struct
 	      DF_REF_ID (ref) = offset++;
 	      count++;
 	      ref = DF_REF_NEXT_REG (ref);
-	      gcc_assert (offset < ref_info->refs_size);
+	      gcc_checking_assert (offset < ref_info->refs_size);
 	    }
 	}
       if (include_eq_uses)
@@ -1595,7 +1578,7 @@ df_reorganize_refs_by_reg_by_reg (struct
 	      DF_REF_ID (ref) = offset++;
 	      count++;
 	      ref = DF_REF_NEXT_REG (ref);
-	      gcc_assert (offset < ref_info->refs_size);
+	      gcc_checking_assert (offset < ref_info->refs_size);
 	    }
 	}
       ref_info->count[regno] = count;
@@ -2610,8 +2593,8 @@ df_install_ref (df_ref this_ref,
       df->hard_regs_live_count[regno]++;
     }
 
-  gcc_assert (DF_REF_NEXT_REG (this_ref) == NULL
-	      && DF_REF_PREV_REG (this_ref) == NULL);
+  gcc_checking_assert (DF_REF_NEXT_REG (this_ref) == NULL
+		       && DF_REF_PREV_REG (this_ref) == NULL);
 
   DF_REF_NEXT_REG (this_ref) = head;
 
@@ -2806,19 +2789,19 @@ df_ref_create_structure (enum df_ref_cla
     {
     case DF_REF_BASE:
       this_ref = (df_ref) pool_alloc (problem_data->ref_base_pool);
-      gcc_assert (loc == NULL);
+      gcc_checking_assert (loc == NULL);
       break;
 
     case DF_REF_ARTIFICIAL:
       this_ref = (df_ref) pool_alloc (problem_data->ref_artificial_pool);
       this_ref->artificial_ref.bb = bb;
-      gcc_assert (loc == NULL);
+      gcc_checking_assert (loc == NULL);
       break;
 
     case DF_REF_REGULAR:
       this_ref = (df_ref) pool_alloc (problem_data->ref_regular_pool);
       this_ref->regular_ref.loc = loc;
-      gcc_assert (loc);
+      gcc_checking_assert (loc);
       break;
 
     case DF_REF_EXTRACT:
@@ -2827,7 +2810,7 @@ df_ref_create_structure (enum df_ref_cla
       DF_REF_EXTRACT_OFFSET (this_ref) = offset;
       DF_REF_EXTRACT_MODE (this_ref) = mode;
       this_ref->regular_ref.loc = loc;
-      gcc_assert (loc);
+      gcc_checking_assert (loc);
       break;
     }
 
@@ -2897,7 +2880,7 @@ df_ref_record (enum df_ref_class cl,
 {
   unsigned int regno;
 
-  gcc_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
+  gcc_checking_assert (REG_P (reg) || GET_CODE (reg) == SUBREG);
 
   regno = REGNO (GET_CODE (reg) == SUBREG ? SUBREG_REG (reg) : reg);
   if (regno < FIRST_PSEUDO_REGISTER)
Index: alloc-pool.c
===================================================================
--- alloc-pool.c	(revision 160516)
+++ alloc-pool.c	(working copy)
@@ -137,7 +137,7 @@ create_alloc_pool (const char *name, siz
   struct alloc_pool_descriptor *desc;
 #endif
 
-  gcc_assert (name);
+  gcc_checking_assert (name);
 
   /* Make size large enough to store the list header.  */
   if (size < sizeof (alloc_pool_list))
@@ -152,7 +152,7 @@ create_alloc_pool (const char *name, siz
 #endif
 
   /* Um, we can't really allocate 0 elements per block.  */
-  gcc_assert (num);
+  gcc_checking_assert (num);
 
   /* Allocate memory for the pool structure.  */
   pool = XNEW (struct alloc_pool_def);
@@ -201,7 +201,7 @@ empty_alloc_pool (alloc_pool pool)
   struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
 #endif
 
-  gcc_assert (pool);
+  gcc_checking_assert (pool);
 
   /* Free each block allocated to the pool.  */
   for (block = pool->block_list; block != NULL; block = next_block)
@@ -260,7 +260,7 @@ pool_alloc (alloc_pool pool)
     desc->peak = desc->current;
 #endif
 
-  gcc_assert (pool);
+  gcc_checking_assert (pool);
 
   /* If there are no more free elements, make some more!.  */
   if (!pool->returned_free_list)
@@ -328,19 +328,19 @@ pool_free (alloc_pool pool, void *ptr)
   struct alloc_pool_descriptor *desc = alloc_pool_descriptor (pool->name);
 #endif
 
-  gcc_assert (ptr);
 
 #ifdef ENABLE_CHECKING
-  /* Check whether the PTR was allocated from POOL.  */
-  gcc_assert (pool->id == ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id);
+  gcc_assert (ptr
+	      /* Check if we free more than we allocated, which is Bad (TM).  */
+	      && pool->elts_free < pool->elts_allocated
+	      /* Check whether the PTR was allocated from POOL.  */
+	      && pool->id == ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id);
 
   memset (ptr, 0xaf, pool->elt_size - offsetof (allocation_object, u.data));
 
   /* Mark the element to be free.  */
   ALLOCATION_OBJECT_PTR_FROM_USER_PTR (ptr)->id = 0;
 #else
-  /* Check if we free more than we allocated, which is Bad (TM).  */
-  gcc_assert (pool->elts_free < pool->elts_allocated);
 #endif
 
   header = (alloc_pool_list) ptr;
Index: alias.c
===================================================================
--- alias.c	(revision 160516)
+++ alias.c	(working copy)
@@ -713,7 +713,7 @@ get_alias_set (tree t)
   t = TYPE_CANONICAL (t);
   /* Canonical types shouldn't form a tree nor should the canonical
      type require structural equality checks.  */
-  gcc_assert (!TYPE_STRUCTURAL_EQUALITY_P (t) && TYPE_CANONICAL (t) == t);
+  gcc_checking_assert (!TYPE_STRUCTURAL_EQUALITY_P (t) && TYPE_CANONICAL (t) == t);
 
   /* If this is a type with a known alias set, return it.  */
   if (TYPE_ALIAS_SET_KNOWN_P (t))
@@ -1136,7 +1136,7 @@ record_set (rtx dest, const_rtx set, voi
 
   regno = REGNO (dest);
 
-  gcc_assert (regno < VEC_length (rtx, reg_base_value));
+  gcc_checking_assert (regno < VEC_length (rtx, reg_base_value));
 
   /* If this spans multiple hard registers, then we must indicate that every
      register has an unusable value.  */
Index: var-tracking.c
===================================================================
--- var-tracking.c	(revision 160516)
+++ var-tracking.c	(working copy)
@@ -1167,7 +1167,7 @@ variable_htab_free (void *elem)
   variable var = (variable) elem;
   location_chain node, next;
 
-  gcc_assert (var->refcount > 0);
+  gcc_checking_assert (var->refcount > 0);
 
   var->refcount--;
   if (var->refcount > 0)
@@ -1370,7 +1370,7 @@ shared_hash_copy (shared_hash vars)
 static void
 shared_hash_destroy (shared_hash vars)
 {
-  gcc_assert (vars->refcount > 0);
+  gcc_checking_assert (vars->refcount > 0);
   if (--vars->refcount == 0)
     {
       htab_delete (vars->htab);
@@ -3110,7 +3110,7 @@ canonicalize_values_mark (void **slot, v
   if (!dv_is_value_p (dv))
     return 1;
 
-  gcc_assert (var->n_var_parts == 1);
+  gcc_checking_assert (var->n_var_parts == 1);
 
   val = dv_as_value (dv);
 
@@ -3153,7 +3153,7 @@ canonicalize_values_star (void **slot, v
   if (!dv_onepart_p (dv))
     return 1;
 
-  gcc_assert (var->n_var_parts == 1);
+  gcc_checking_assert (var->n_var_parts == 1);
 
   if (dv_is_value_p (dv))
     {
@@ -3343,8 +3343,8 @@ canonicalize_values_star (void **slot, v
 
   /* Variable may have been unshared.  */
   var = (variable)*slot;
-  gcc_assert (var->n_var_parts && var->var_part[0].loc_chain->loc == cval
-	      && var->var_part[0].loc_chain->next == NULL);
+  gcc_checking_assert (var->n_var_parts && var->var_part[0].loc_chain->loc == cval
+		       && var->var_part[0].loc_chain->next == NULL);
 
   if (VALUE_RECURSED_INTO (cval))
     goto restart_with_cval;
@@ -3433,14 +3433,14 @@ variable_merge_over_cur (variable s1var,
   /* If the incoming onepart variable has an empty location list, then
      the intersection will be just as empty.  For other variables,
      it's always union.  */
-  gcc_assert (s1var->n_var_parts
-	      && s1var->var_part[0].loc_chain);
+  gcc_checking_assert (s1var->n_var_parts
+		       && s1var->var_part[0].loc_chain);
 
   if (!onepart)
     return variable_union (s1var, dst);
 
-  gcc_assert (s1var->n_var_parts == 1
-	      && s1var->var_part[0].offset == 0);
+  gcc_checking_assert (s1var->n_var_parts == 1
+		       && s1var->var_part[0].offset == 0);
 
   dvhash = dv_htab_hash (dv);
   if (dv_is_value_p (dv))
Index: lto-streamer.c
===================================================================
--- lto-streamer.c	(revision 160516)
+++ lto-streamer.c	(working copy)
@@ -382,7 +382,7 @@ bp_unpack_value (struct bitpack_d *bp, u
   unsigned ix;
 
   /* We cannot decode more bits than BITS_PER_BITPACK_WORD.  */
-  gcc_assert (nbits > 0 && nbits <= BITS_PER_BITPACK_WORD);
+  gcc_checking_assert (nbits > 0 && nbits <= BITS_PER_BITPACK_WORD);
 
   /* Compute which word contains the next NBITS.  */
   ix = bp_get_next_word (bp, nbits);


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