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] ignore-reads speedup, bug fixes


Hi -

The following patch does several things.  The biggest is adding
a "don't instrument reads" suboption to the compiler, which basically
tells it not to instrument pointer *reads*.  For some baby benchmarks,
this change can speed up a fully instrumented program by a factor of two,
making it "only" a factor of two slower than an uninstrumented one.
This option is activated by "-fmudflap -fmudflapir" (ir = ignore reads).
I intend to improve this notation somehow, though it needs to mesh well
with the specs-dependent "-fmudflapth" (th = threads) suboption also.

Other minor cleanups involve eliminating some command-line option handling
duplication, the removal of some inappropriate run-time compiler warnings
about the synthetic static constructor function being unused, and some
test suite tweaks.

- FChE


--- ChangeLog.tree-ssa	30 Jan 2004 19:17:12 -0000	1.1.2.1142
+++ ChangeLog.tree-ssa	30 Jan 2004 20:55:28 -0000
@@ -1,3 +1,14 @@
+2004-01-30  Frank Ch. Eigler  <fche@redhat.com>
+
+	* common.opt: Add support for -fmudflapth, -fmudflapir.
+	* opts.c: Ditto.
+	* flags.h: Add new flags flag_mudflap_threads, _ignorereads.
+	* toplev.c: Initialize new flags.  Remove redundant code from
+	lang_independent_options[].
+	* tree-mudflap.c (*): Support new flag_mudflap_threads encoding.
+	(mf_xform_derefs_1): Support flag_mudflap_ignorereads option.
+	* c-mudflap.c (mflang_flush_calls): Mark static ctor TREE_USED.
+

Index: c-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-mudflap.c,v
retrieving revision 1.1.2.10
diff -u -p -s -r1.1.2.10 c-mudflap.c
--- c-mudflap.c	8 Jan 2004 20:08:57 -0000	1.1.2.10
+++ c-mudflap.c	30 Jan 2004 20:55:28 -0000
@@ -81,6 +81,7 @@ mflang_flush_calls (tree enqueued_call_s
 
   DECL_STATIC_CONSTRUCTOR (current_function_decl) = 1;
   TREE_PUBLIC (current_function_decl) = 0;
+  TREE_USED (current_function_decl) = 1;
   mf_mark (current_function_decl);
 
   body = c_begin_compound_stmt ();
Index: common.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/common.opt,v
retrieving revision 1.14.2.16
diff -u -p -s -r1.14.2.16 common.opt
--- common.opt	7 Jan 2004 23:44:14 -0000	1.14.2.16
+++ common.opt	30 Jan 2004 20:55:28 -0000
@@ -455,7 +455,15 @@ Force all loop invariant computations ou
 
 fmudflap
 Common RejectNegative
-Add mudflap bounds-checking instrumentation (-fmudflapth includes multithreading support)
+Add mudflap bounds-checking instrumentation for single-threaded program.
+
+fmudflapth
+Common RejectNegative
+Add mudflap bounds-checking instrumentation for multi-threaded program.
+
+fmudflapir
+Common RejectNegative
+Ignore read operations when inserting mudflap instrumentation.
 
 fnew-ra
 Common
Index: flags.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/flags.h,v
retrieving revision 1.86.2.43
diff -u -p -s -r1.86.2.43 flags.h
--- flags.h	7 Jan 2004 23:44:14 -0000	1.86.2.43
+++ flags.h	30 Jan 2004 20:55:28 -0000
@@ -1,6 +1,6 @@
 /* Compilation switch flag definitions for GCC.
    Copyright (C) 1987, 1988, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002,
-   2003
+   2003, 2004
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -708,6 +708,8 @@ extern int flag_non_call_exceptions;
 /* Nonzero means enable mudflap bounds-checking transforms;
    >1 means also to include multithreading locks.  */
 extern int flag_mudflap;
+extern int flag_mudflap_threads;
+extern int flag_mudflap_ignore_reads;
 
 /* Disable SSA optimizations on trees.  */
 extern int flag_disable_tree_ssa;
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.31.2.24
diff -u -p -s -r1.31.2.24 opts.c
--- opts.c	7 Jan 2004 23:44:14 -0000	1.31.2.24
+++ opts.c	30 Jan 2004 20:55:28 -0000
@@ -1130,6 +1130,15 @@ common_handle_option (size_t scode, cons
       flag_mudflap = value;
       break;
 
+    case OPT_fmudflapth:
+      flag_mudflap = value;
+      flag_mudflap_threads = value;
+      break;
+
+    case OPT_fmudflapir:
+      flag_mudflap_ignore_reads = value;
+      break;
+
     case OPT_fnew_ra:
       flag_new_regalloc = value;
       break;
Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.654.2.91
diff -u -p -s -r1.654.2.91 toplev.c
--- toplev.c	30 Jan 2004 13:14:16 -0000	1.654.2.91
+++ toplev.c	30 Jan 2004 20:55:29 -0000
@@ -940,6 +940,8 @@ int flag_bounds_check = 0;
 
 /* Mudflap bounds-checking transform.  */
 int flag_mudflap = 0;
+int flag_mudflap_threads = 0;
+int flag_mudflap_ignore_reads = 0;
 
 /* This will attempt to merge constant section constants, if 1 only
    string constants and constants from constant pool, if 2 also constant
@@ -1174,8 +1176,6 @@ static const lang_independent_options f_
   { "trapv", &flag_trapv, 1 },
   { "wrapv", &flag_wrapv, 1 },
   { "new-ra", &flag_new_regalloc, 1 },
-  { "mudflap", &flag_mudflap, 1 },
-  { "mudflapth", &flag_mudflap, 2 },
   { "disable-tree-ssa", &flag_disable_tree_ssa, 1 },
   { "tree-gvn", &flag_tree_gvn, 1 },
   { "tree-pre", &flag_tree_pre, 1 },
Index: tree-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.c,v
retrieving revision 1.1.2.70
diff -u -p -s -r1.1.2.70 tree-mudflap.c
--- tree-mudflap.c	27 Jan 2004 22:49:08 -0000	1.1.2.70
+++ tree-mudflap.c	30 Jan 2004 20:55:29 -0000
@@ -158,12 +158,12 @@ mudflap_function_ops (void)
   push_gimplify_context ();
 
   /* In multithreaded mode, don't cache the lookup cache parameters.  */
-  if (! (flag_mudflap > 1))
+  if (! flag_mudflap_threads)
     mf_decl_cache_locals (&DECL_SAVED_TREE (current_function_decl));
 
   mf_xform_derefs (DECL_SAVED_TREE (current_function_decl));
 
-  if (! (flag_mudflap > 1))
+  if (! flag_mudflap_threads)
     mf_decl_clear_locals ();
 
   pop_gimplify_context (NULL);
@@ -465,9 +465,9 @@ mf_build_check_statement_for (tree addr,
   /* Build: __mf_elem = &__mf_lookup_cache [(__mf_base >> __mf_shift)
                                             & __mf_mask].  */
   t = build (RSHIFT_EXPR, mf_uintptr_type, mf_base,
-             (flag_mudflap > 1 ? mf_cache_shift_decl : mf_cache_shift_decl_l));
+             (flag_mudflap_threads ? mf_cache_shift_decl : mf_cache_shift_decl_l));
   t = build (BIT_AND_EXPR, mf_uintptr_type, t,
-             (flag_mudflap > 1 ? mf_cache_mask_decl : mf_cache_mask_decl_l));
+             (flag_mudflap_threads ? mf_cache_mask_decl : mf_cache_mask_decl_l));
   t = build (ARRAY_REF,
              TREE_TYPE (TREE_TYPE (mf_cache_array_decl)),
              mf_cache_array_decl, t);
@@ -526,7 +526,7 @@ mf_build_check_statement_for (tree addr,
   t = build_function_call_expr (mf_check_fndecl, u);
   append_to_statement_list (t, &stmt);
 
-  if (! (flag_mudflap > 1))
+  if (! flag_mudflap_threads)
     {
       t = build (MODIFY_EXPR, void_type_node,
                  mf_cache_shift_decl_l, mf_cache_shift_decl);
@@ -551,6 +551,10 @@ mf_xform_derefs_1 (tree_stmt_iterator *i
 {
   tree type, ptr_type, addr, size, t;
 
+  /* Don't instrument read operations.  */
+  if (dirflag == integer_zero_node && flag_mudflap_ignore_reads)
+    return;
+
   t = *tp;
   type = TREE_TYPE (t);
   size = TYPE_SIZE_UNIT (type);
@@ -743,7 +747,7 @@ mx_register_decls (tree decl, tree *stmt
           (! mf_marked_p (decl)) && /* not already processed */
           (TREE_ADDRESSABLE (decl))) /* has address taken */
         {
-          tree size, variable_name;
+          tree size = NULL_TREE, variable_name;
           tree unregister_fncall, unregister_fncall_params;
           tree register_fncall, register_fncall_params;
 
+2004-01-30  Frank Ch. Eigler  <fche@redhat.com>
+
+	* cp-mudflap.c (mflang_flush_calls): Mark static ctor as TREE_USED.
+

Index: cp/cp-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Attic/cp-mudflap.c,v
retrieving revision 1.1.2.12
diff -u -p -s -r1.1.2.12 cp-mudflap.c
--- cp/cp-mudflap.c	8 Jan 2004 20:08:57 -0000	1.1.2.12
+++ cp/cp-mudflap.c	30 Jan 2004 20:55:31 -0000
@@ -77,6 +77,7 @@ mflang_flush_calls (tree enqueued_call_s
 		  NULL_TREE, SF_DEFAULT);
 
   TREE_PUBLIC (current_function_decl) = 0;
+  TREE_USED (current_function_decl) = 1;
   DECL_ARTIFICIAL (current_function_decl) = 1;
   mf_mark (current_function_decl);
 
--- ChangeLog	27 Jan 2004 22:51:03 -0000	1.1.2.83
+++ ChangeLog	30 Jan 2004 20:48:08 -0000
@@ -1,3 +1,12 @@
+2004-01-30  Frank Ch. Eigler  <fche@redhat.com>
+
+	* testsuite/libmudflap.c/pass36-frag.c: Add missing free() call.
+	* testsuite/libmudflap.c/pass46-frag.c: New test for -fmudflapri.
+	* testsuite/libmudflap.cth/cthfrags.exp: Add -DSTATIC to compiler
+	flags for static linking permutation.
+	* testsuite/libmudflap.cth/pass40-frag.c: When -DSTATIC, avoid
+	some pthreads code that croaks on linux glibc tls.

Index: testsuite/libmudflap.c/pass36-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/testsuite/libmudflap.c/Attic/pass36-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -s -r1.1.2.1 pass36-frag.c
--- testsuite/libmudflap.c/pass36-frag.c	28 Mar 2003 22:33:26 -0000	1.1.2.1
+++ testsuite/libmudflap.c/pass36-frag.c	30 Jan 2004 20:48:08 -0000
@@ -9,6 +9,7 @@ char *k;
 __mf_set_options ("-sigusr1-report -print-leaks");
 k = (char *) malloc (100);
 raise (SIGUSR1);
+free (k);
 return 0;
 }
 /* { dg-output "Leaked object.*name=.malloc region.*objects: 1" } */
Index: testsuite/libmudflap.c/pass46-frag.c
===================================================================
RCS file: testsuite/libmudflap.c/pass46-frag.c
diff -N testsuite/libmudflap.c/pass46-frag.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/libmudflap.c/pass46-frag.c	30 Jan 2004 20:48:08 -0000
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int foo (int *u, int i)
+{
+   return u[i];  /* this dereference should not be instrumented */
+}
+
+int main ()
+{
+  int *k = malloc (6);
+ int l = foo (k, 8);
+ int boo [8];
+ int m = boo [l % 2 + 12]; /* should not be instrumented */
+ return m & strlen (""); /* a fancy way of saying "0" */
+}
+/* { dg-options "-fmudflap -fmudflapir -Wall" } */
Index: testsuite/libmudflap.cth/cthfrags.exp
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/testsuite/libmudflap.cth/Attic/cthfrags.exp,v
retrieving revision 1.1.2.2
diff -u -p -s -r1.1.2.2 cthfrags.exp
--- testsuite/libmudflap.cth/cthfrags.exp	23 Jul 2003 21:21:10 -0000	1.1.2.2
+++ testsuite/libmudflap.cth/cthfrags.exp	30 Jan 2004 20:48:08 -0000
@@ -4,7 +4,7 @@ libmudflap-init [find_gcc]
 dg-init
 
 global srcdir
-foreach flags [list {} {-static} {-O2} {-O3}] {
+foreach flags [list {} {-static -DSTATIC} {-O2} {-O3}] {
     foreach srcfile [lsort [glob -nocomplain ${srcdir}/libmudflap.cth/*.c]] {
 	set bsrc [file tail $srcfile]
 	setenv MUDFLAP_OPTIONS "-viol-segv"
Index: testsuite/libmudflap.cth/pass40-frag.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/testsuite/libmudflap.cth/Attic/pass40-frag.c,v
retrieving revision 1.1.2.1
diff -u -p -s -r1.1.2.1 pass40-frag.c
--- testsuite/libmudflap.cth/pass40-frag.c	23 Jul 2003 21:21:10 -0000	1.1.2.1
+++ testsuite/libmudflap.cth/pass40-frag.c	30 Jan 2004 20:48:08 -0000
@@ -21,8 +21,10 @@ test (void)
         for (i = 1; i <= 10000; ++i) {
                 if (i%100 == 0) fprintf (stderr, "%i ", i);
                 if (i%1000 == 0) fprintf (stderr, "\n");
+#ifndef STATIC 
+	  /* Some glibc versions don't like static multithreaded programs doing this. */
                 if (i==5000) __mf_set_options ("-thread-stack=192");
-
+#endif
                 rc = pthread_create (&h, &my_pthread_attr,
                         func, NULL);
                 if (rc)


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