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]

[tree-ssa mudflap] instrumentation tweak


Hi -

The following patch includes the first attempt to omit
unnecessary instrumentation.  It lets some array accesses go
unchecked when they are known to be in bounds at compile time.
Any more insightful elision of instrumentation will need more
data, likely in the form of prior tree/ssa optimization passes.

- FChE


Index: ChangeLog.tree-ssa
+2002-10-03  Frank Ch. Eigler  <fche@redhat.com>
+
+	* tree-mudflap.c (mf_offset_expr_of_array_ref): Don't emit
+	intermediate variables for constant index values.
+	(mx_xfn_indirect_ref): For constant valid index values and
+	known valid array sizes, omit bounds checks.

Index: tree-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.c,v
retrieving revision 1.1.2.15
diff -p -u -w -s -r1.1.2.15 tree-mudflap.c
--- tree-mudflap.c	1 Oct 2002 20:40:55 -0000	1.1.2.15
+++ tree-mudflap.c	3 Oct 2002 20:40:07 -0000
@@ -572,8 +572,9 @@ mf_offset_expr_of_array_ref (t, offset, 
   /* Replace the array index operand [1] with a temporary variable.
      This is meant to emulate SAVE_EXPRs that are sometimes screwed up
      by other parts of gcc.  */
-  if (TREE_CODE (t) == ARRAY_REF ||
-      TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
+  if ((TREE_CODE (t) == ARRAY_REF ||
+       TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE) &&
+      ! really_constant_p (*offset))
     {
       static unsigned declindex;
       char declname[20];
@@ -878,7 +879,6 @@ mx_xfn_indirect_ref (t, continue_p, data
 	tree base_array, base_obj_type, base_ptr_type;
 	tree offset_expr;
 	tree value_ptr, check_ptr, check_size;
-	tree tmp;
 	tree check_decls = NULL_TREE;
 
 	/* Unshare the whole darned tree.  */
@@ -918,6 +918,31 @@ mx_xfn_indirect_ref (t, continue_p, data
 					       integer_one_node,
 					       offset_expr))));
 
+	/* As an optimization, omit checking if the base object is
+	   known to be large enough.  Only certain kinds of
+	   declarations and indexes/sizes are trustworthy.  */
+	if (TREE_CODE (check_size) == INTEGER_CST && /* constant offset */
+	    TREE_CODE (base_array) == VAR_DECL && /* not a PARM_DECL */
+	    ! DECL_EXTERNAL (base_array) && /* has known size */
+	    TREE_CODE (TREE_TYPE (base_array)) == ARRAY_TYPE && /* an array */
+	    (int_size_in_bytes (TREE_TYPE (base_array)) >= TREE_INT_CST_LOW (check_size) &&
+	     TREE_INT_CST_HIGH (check_size) == 0)) /* offset within bounds */
+	  {
+#if 0
+	    warning ("mudflap is omitting array bounds checks");
+	    fprintf (stderr, "  for expression: ");
+	    print_c_tree (stderr, *t);
+	    fprintf (stderr, " array-size=%u", int_size_in_bytes (TREE_TYPE (base_array)));
+	    fprintf (stderr, " check-size=%u", TREE_INT_CST_LOW (check_size));
+	    fprintf (stderr, "\n");
+#endif
+	    if (check_decls != NULL_TREE) abort();
+	    break;
+	  }
+	else
+	  {
+	    tree tmp;
+
 	/* In case we're instrumenting an expression like a[b[c]], the
 	   following call is meant to eliminate the
 	   redundant/recursive check of the outer size=b[c] check. */
@@ -928,6 +953,7 @@ mx_xfn_indirect_ref (t, continue_p, data
 					    check_decls,
 					    last_filename, last_lineno);
 	*t = mx_flag (build1 (INDIRECT_REF, base_obj_type, tmp));
+	  }
       }
       break;
       


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