[tree-ssa mudflap] unbreaking after gimple changes

Frank Ch. Eigler fche@redhat.com
Thu Nov 20 20:36:00 GMT 2003


Hi -

The recent batch of tree-ssa representation and processing changes
have required some surgery on mudflap in order to work again.  The
transform had to be broken into two passes, one running before and
the other after all the tree-ssa stuff.  Callgraph related changes
also made it necessary in the C++ mudflap support.  (An aside: does
someone understand why the timing of callgraph final expansion vs.
static ctor/dtor expansion differs between C and C++?  Compare
c_objc_common_finish_file() to cp/decl2.c's finish_file().)

- FChE


+2003-11-20  Frank Ch. Eigler  <fche@redhat.com>
+ 
+	* tree-inline.c (copy_tree_r): Propagate mf_marked-ness.
+	* tree-mudflap.c (mudflap_c_function): Break into new
+	_decls and _ops functions.
+	(mudflap_c_function_decls): Avoid unnecessary tree copying.
+	(mudflap_c_function_ops): Ditto.  Gimplify explicitly only for
+	tree dumping.
+	* tree-nomudflap.c: Add new stub functions.  Simplify error
+	message emission throughout.
+	* tree-mudflap.h: Corresponding changes.
+	* tree-optimize.c (tree_rest_of_compilation): Call the _decl
+	instrumentation before gimplification and ssa optimizations;
+	call the _ops instrumentation after ssa optimizations.

+2003-11-20  Frank Ch. Eigler  <fche@redhat.com>
+
+	* cp-mudflap.c (mflang_flush_calls): Adapt to direct expansion of
+	synthetic function, bypassing callgraph code.
+	* cp-decl2.c (finish_file): Call mudflap after callgraph-based
+	expansion.

Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.26.2.62
diff -u -w -s -p -r1.26.2.62 tree-inline.c
--- tree-inline.c	17 Nov 2003 00:31:00 -0000	1.26.2.62
+++ tree-inline.c	20 Nov 2003 20:26:00 -0000
@@ -39,6 +39,7 @@ Boston, MA 02111-1307, USA.  */
 #include "langhooks.h"
 #include "cgraph.h"
 #include "intl.h"
+#include "tree-mudflap.h"
 
 
 /* I'm not real happy about this, but we need to handle gimple and
@@ -2065,9 +2066,16 @@ copy_tree_r (tree *tp, int *walk_subtree
       /* Because the chain gets clobbered when we make a copy, we save it
 	 here.  */
       tree chain = TREE_CHAIN (*tp);
+      tree new;
 
       /* Copy the node.  */
-      *tp = copy_node (*tp);
+      new = copy_node (*tp);
+
+      /* Propagate mudflap marked-ness.  */
+      if (flag_mudflap && mf_marked_p (new))
+        mf_mark (new);
+
+      *tp = new;
 
       /* Now, restore the chain, if appropriate.  That will cause
 	 walk_tree to walk into the chain as well.  */
Index: tree-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.c,v
retrieving revision 1.1.2.57
diff -u -w -s -p -r1.1.2.57 tree-mudflap.c
--- tree-mudflap.c	12 Nov 2003 22:06:26 -0000	1.1.2.57
+++ tree-mudflap.c	20 Nov 2003 20:26:00 -0000
@@ -102,54 +102,66 @@ mf_marked_p (tree t)
 
 
 
-/* Perform the mudflap tree transforms on the given function.  Return
-   the modified function body.  */
+/* Perform the declaration-related mudflap tree transforms on the
+   given function.  Update its DECL_SAVED_TREE.  */
 
-tree
-mudflap_c_function (tree t)
+void
+mudflap_c_function_decls (tree t)
 {
-  tree original, result;
+  tree result = DECL_SAVED_TREE (t);
 
   mf_init_extern_trees ();
 
-  result = DECL_SAVED_TREE (t);
-  original = result;
-  walk_tree (& result, mf_mostly_copy_tree_r, NULL, NULL);
+  mf_xform_decls (result, DECL_ARGUMENTS (t));
+
+  DECL_SAVED_TREE (t) = result;
+  gimplify_function_tree (t); /* XXX: necessary? */
+}
+
+
+/* Same as above, for the indirection-related transforms.  */
+void
+mudflap_c_function_ops (tree t)
+{
+  tree result = DECL_SAVED_TREE (t);
 
   /* In multithreaded mode, don't cache the lookup cache parameters.  */
   if (! (flag_mudflap > 1))
     mf_decl_cache_locals (& result);
 
-  mf_xform_decls (result, DECL_ARGUMENTS (t));
   mf_xform_derefs (result);
 
   if (! (flag_mudflap > 1))
     mf_decl_clear_locals ();
 
-  /* Gimplify the resulting function, mainly so that tree
-     pretty-printing works.  It's expensive though.  */
-  DECL_SAVED_TREE (t) = result;
-  gimplify_function_tree (t);
-  result = DECL_SAVED_TREE (t);
-
   {
     FILE *dump_file;
     int dump_flags;
     dump_file = dump_begin (TDI_mudflap, &dump_flags);
     if (dump_file)
       {
+        tree copy = result;
+        tree original;
+	
+        /* Gimplify the function body for dumping purposes only.  */
+
+        walk_tree (& copy, mf_mostly_copy_tree_r, NULL, NULL);
+
+        original = DECL_SAVED_TREE (t);
+        DECL_SAVED_TREE (t) = copy;
+        gimplify_function_tree (t);
+
 	fprintf (dump_file, "\n\n;;; Function %s\n", IDENTIFIER_POINTER (DECL_NAME (t)));
-	print_generic_expr (dump_file, result, 0);
+        print_generic_stmt (dump_file, DECL_SAVED_TREE (t), 0);
 	fprintf (dump_file, "\n");
 	dump_end (TDI_mudflap, dump_file);
-      }
-  }
 
-  /* Restore original tree to function body, in case it is used
-     for inlining later.  */
   DECL_SAVED_TREE (t) = original;
+      }
+  }
 
-  return result;
+  DECL_SAVED_TREE (t) = result;
+  /* gimplify_function_tree (t); */
 }
 
 
Index: tree-mudflap.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.h,v
retrieving revision 1.1.2.6
diff -u -w -s -p -r1.1.2.6 tree-mudflap.h
--- tree-mudflap.h	15 Jul 2003 03:13:40 -0000	1.1.2.6
+++ tree-mudflap.h	20 Nov 2003 20:26:00 -0000
@@ -23,7 +23,8 @@ Software Foundation, 59 Temple Place - S
 #define TREE_MUDFLAP_H
 
 /* Instrumentation. */
-extern tree mudflap_c_function (tree);
+extern void mudflap_c_function_decls (tree);
+extern void mudflap_c_function_ops (tree);
 extern void mudflap_enqueue_decl (tree, const char *);
 extern void mudflap_enqueue_constant (tree, const char *);
 extern void mudflap_finish_file (void);
Index: tree-nomudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-nomudflap.c,v
retrieving revision 1.1.2.9
diff -u -w -s -p -r1.1.2.9 tree-nomudflap.c
--- tree-nomudflap.c	15 Jul 2003 05:53:16 -0000	1.1.2.9
+++ tree-nomudflap.c	20 Nov 2003 20:26:00 -0000
@@ -45,11 +45,24 @@ Software Foundation, 59 Temple Place - S
    (e.g. Fortran).  */
 
 
-tree
-mudflap_c_function (tree t ATTRIBUTE_UNUSED)
+static void
+nogo ()
 {
   internal_error ("mudflap: this language is not supported");
-  return NULL;
+}
+
+
+void
+mudflap_c_function_decls (tree t ATTRIBUTE_UNUSED)
+{
+  nogo ();
+}
+
+
+void
+mudflap_c_function_ops (tree t ATTRIBUTE_UNUSED)
+{
+  nogo ();
 }
 
 
@@ -57,7 +70,7 @@ void
 mudflap_enqueue_decl (tree obj ATTRIBUTE_UNUSED,
 		      const char *label ATTRIBUTE_UNUSED)
 {
-  internal_error ("mudflap: this language is not supported");
+  nogo ();
 }
 
 
@@ -65,30 +78,31 @@ void
 mudflap_enqueue_constant (tree obj ATTRIBUTE_UNUSED,
 			  const char *label ATTRIBUTE_UNUSED)
 {
-  internal_error ("mudflap: this language is not supported");
+  nogo ();
 }
 
 
-
 /* Emit file-wide instrumentation.  */
 
 void
 mudflap_finish_file (void)
 {
-  internal_error ("mudflap: this language is not supported");
+  nogo ();
 }
 
 
 int
 mf_marked_p (tree t ATTRIBUTE_UNUSED)
 {
-  internal_error ("mudflap: this language is not supported");
+  nogo ();
+  return 0;
 }
 
+
 tree
 mf_mark (tree t ATTRIBUTE_UNUSED)
 {
-  internal_error ("mudflap: this language is not supported");
+  nogo ();
   return NULL;
 }
 
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 1.1.4.76
diff -u -w -s -p -r1.1.4.76 tree-optimize.c
--- tree-optimize.c	20 Nov 2003 18:23:56 -0000	1.1.4.76
+++ tree-optimize.c	20 Nov 2003 20:26:00 -0000
@@ -288,6 +288,10 @@ tree_rest_of_compilation (tree fndecl, b
       nested_p = true;
     }
 
+  /* Mudflap-instrument any relevant declarations.  */
+  if (flag_mudflap)
+    mudflap_c_function_decls (fndecl);
+
   /* If the function has not already been gimplified, do so now.  */
   if (!lang_hooks.gimple_before_inlining)
     gimplify_function_tree (fndecl);
@@ -321,6 +325,10 @@ tree_rest_of_compilation (tree fndecl, b
   DECL_SAVED_TREE (fndecl) = build (BIND_EXPR, void_type_node,
 				    NULL_TREE, chain, NULL_TREE);
 
+  /* Mudflap-instrument any relevant operations.  */
+  if (flag_mudflap)
+    mudflap_c_function_ops (fndecl);
+
   /* If the function has a variably modified type, there may be
      SAVE_EXPRs in the parameter types.  Their context must be set to
      refer to this function; they cannot be expanded in the containing
@@ -345,10 +353,6 @@ tree_rest_of_compilation (tree fndecl, b
       && MAIN_NAME_P (DECL_NAME (fndecl))
       && DECL_FILE_SCOPE_P (fndecl))
     expand_main_function ();
-
-  /* Add mudflap instrumentation to a copy of the function body.  */
-  if (flag_mudflap)
-    DECL_SAVED_TREE (fndecl) = mudflap_c_function (fndecl);
 
   /* Generate the RTL for this function.  */
   (*lang_hooks.rtl_expand.stmt) (DECL_SAVED_TREE (fndecl));


Index: cp/cp-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/Attic/cp-mudflap.c,v
retrieving revision 1.1.2.9
diff -u -w -s -p -r1.1.2.9 cp-mudflap.c
--- cp/cp-mudflap.c	28 Sep 2003 06:07:22 -0000	1.1.2.9
+++ cp/cp-mudflap.c	20 Nov 2003 20:26:00 -0000
@@ -140,7 +140,16 @@ mflang_flush_calls (tree enqueued_call_s
 
   finish_compound_stmt (body);
   fndecl = finish_function (0);
-  expand_or_defer_fn (fndecl);
 
-  static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
+  /* NB: We cannot call expand_or_defer_fn here, since that goes through
+     the callgraph queue.  This queue will have already been processed by the
+     time this function is running.  */
+  expand_body (fndecl);
+  if (targetm.have_ctors_dtors)
+    (* targetm.asm_out.constructor) (XEXP (DECL_RTL (fndecl), 0),
+                                     DEFAULT_INIT_PRIORITY);
+  else
+    /* By this time, it's too late to do this:
+       static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors); */
+    abort ();
 }
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.540.2.40
diff -u -w -s -p -r1.540.2.40 decl2.c
--- cp/decl2.c	28 Oct 2003 14:58:02 -0000	1.540.2.40
+++ cp/decl2.c	20 Nov 2003 20:26:01 -0000
@@ -2833,10 +2833,6 @@ finish_file (void)
       
     }
   
-  /* Emit mudflap static registration function.  */
-  if (flag_mudflap)
-    mudflap_finish_file ();
-
   /* We give C linkage to static constructors and destructors.  */
   push_lang_context (lang_name_c);
 
@@ -2870,6 +2866,11 @@ finish_file (void)
       cgraph_finalize_compilation_unit ();
       cgraph_optimize ();
     }
+
+  /* Emit mudflap static registration function.  This must be done
+     after all the user functions have been expanded.  */
+  if (flag_mudflap)
+    mudflap_finish_file ();
 
   /* Now, issue warnings about static, but not defined, functions,
      etc., and emit debugging information.  */



More information about the Gcc-patches mailing list