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]

[gcc-ssa mudflap] instrumentation changes for inlining


Hi -

The following patch fixes an inlining-related problem brought on by
the disappearance of the TREE_BOUNDED flag.  The problem was that
inlined functions were in effect instrumented twice, and that's not
m'kay.  This patch reorganizes the way the mudflap instrumentation
pass is called, so that it is done just before rtl expansion.  This
way, DECL_SAVED_TREE trees of functions remain uninstrumented, ripe
for future inlining.  If someone has better advice about how to
separate the abstract inlineable vs concrete instrumented versions
of a function, I'm all ears.

- FChE


+ 2003-06-13  Frank Ch. Eigler  <fche@redhat.com>
+ 
+ 	* tree-mudflap.c (mudflap_c_function): Change calling conventions so
+ 	as to return the instrumented function body rather than changing the
+ 	given fndecl in place.  Gimplify at the very end, for cosmetic
+ 	reasons.
+ 	* tree-mudflap.h, tree-nomudflap.c: Corresponding changes.
+ 	* c-decl.c (c_expand_body_1): Call mudflap_c_function just before
+ 	rtl expansion of function body; don't interfere with inlining.
+ 

+ 2003-06-13  Frank Ch. Eigler  <fche@redhat.com>
+ 
+ 	* semantics.c (expand_body): Call mudflap_c_function just before
+ 	rtl expansion of function body; don't interfere with inlining.
+ 	* optimize.c (optimize_function): Remove mudflap call.
+ 

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.334.2.48
diff -c -p -w -s -r1.334.2.48 c-decl.c
*** c-decl.c	13 Jun 2003 19:00:16 -0000	1.334.2.48
--- c-decl.c	13 Jun 2003 21:04:26 -0000
*************** c_expand_body_1 (fndecl, nested_p)
*** 6394,6399 ****
--- 6394,6401 ----
  {
    const char *saved_input_filename = input_filename;
    int saved_lineno = input_line;
+   tree saved_tree;
+ 
    timevar_push (TV_EXPAND);
  
    if (nested_p)
*************** c_expand_body_1 (fndecl, nested_p)
*** 6433,6442 ****
        /* Invoke the SSA tree optimizer.  */
        if (optimize >= 1 && !flag_disable_tree_ssa)
  	optimize_function_tree (fndecl);
- 
-       /* Add mudflap instrumentation.  */
-       if (flag_mudflap)
- 	mudflap_c_function (fndecl);
      }
  
    timevar_push (TV_EXPAND);
--- 6435,6440 ----
*************** c_expand_body_1 (fndecl, nested_p)
*** 6460,6470 ****
        && DECL_CONTEXT (fndecl) == NULL_TREE)
      expand_main_function ();
  
    /* Generate the RTL for this function.  */
!   if (STATEMENT_CODE_P (TREE_CODE (DECL_SAVED_TREE (fndecl))))
!     expand_stmt (DECL_SAVED_TREE (fndecl));
    else
!     expand_expr_stmt_value (DECL_SAVED_TREE (fndecl), 0, 0);
  
    /* We hard-wired immediate_size_expand to zero above.
       expand_function_end will decrement this variable.  So, we set the
--- 6458,6474 ----
        && DECL_CONTEXT (fndecl) == NULL_TREE)
      expand_main_function ();
  
+   /* Add mudflap instrumentation to a copy of the function body.  */
+   if (flag_mudflap)
+     saved_tree = mudflap_c_function (fndecl);
+   else
+     saved_tree = DECL_SAVED_TREE (fndecl);
+ 
    /* Generate the RTL for this function.  */
!   if (STATEMENT_CODE_P (TREE_CODE (saved_tree)))
!     expand_stmt (saved_tree);
    else
!     expand_expr_stmt_value (saved_tree, 0, 0);
  
    /* We hard-wired immediate_size_expand to zero above.
       expand_function_end will decrement this variable.  So, we set the
Index: tree-mudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.c,v
retrieving revision 1.1.2.46
diff -c -p -w -s -r1.1.2.46 tree-mudflap.c
*** tree-mudflap.c	13 Jun 2003 19:00:18 -0000	1.1.2.46
--- tree-mudflap.c	13 Jun 2003 21:04:26 -0000
*************** mf_marked_p (t)
*** 104,128 ****
  
  
  
! /* Perform the mudflap tree transforms on the given function.  */
   
! void 
  mudflap_c_function (t)
       tree t;
  {
    mf_init_extern_trees ();
  
    /* In multithreaded mode, don't cache the lookup cache parameters.  */
    if (! (flag_mudflap > 1))
!     mf_decl_cache_locals (& DECL_SAVED_TREE (t));
  
!   mf_xform_decls (DECL_SAVED_TREE (t), DECL_ARGUMENTS (t));
!   mf_xform_derefs (DECL_SAVED_TREE (t));
  
!   /* Gimplify mudflap instrumentation.  FIXME  It definitely would be good
!      if mudflap didn't require another gimplification pass.  Gimplification
!      is the single most expensive part of the tree-ssa path! */
    gimplify_function_tree (t);
  
    {
      FILE *dump_file;
--- 104,139 ----
  
  
  
! /* Perform the mudflap tree transforms on the given function.  Return
!    the modified function body.  */
   
! tree
  mudflap_c_function (t)
       tree t;
  {
+   tree original, result;
+ 
    mf_init_extern_trees ();
  
+   result = DECL_SAVED_TREE (t);
+   original = result;
+   walk_tree (& result, mf_mostly_copy_tree_r, NULL, NULL);
+ 
    /* 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;
*************** mudflap_c_function (t)
*** 130,142 ****
      dump_file = dump_begin (TDI_mudflap, &dump_flags);
      if (dump_file)
        {
! 	dump_function (TDI_mudflap, t);
  	dump_end (TDI_mudflap, dump_file);
        }
    }
  
!   if (! (flag_mudflap > 1))
!     mf_decl_clear_locals ();
  }
  
  
--- 141,158 ----
      dump_file = dump_begin (TDI_mudflap, &dump_flags);
      if (dump_file)
        {
! 	fprintf (dump_file, "\n\n;;; Function %s\n", IDENTIFIER_POINTER (DECL_NAME (t)));
! 	print_generic_expr (dump_file, result, 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;
  }
  
  
*************** mx_xfn_indirect_ref (t, continue_p, data
*** 876,884 ****
  	tree value_ptr, check_ptr, check_size;
  	tree check_decls = NULL_TREE;
  
- 	/* Unshare the whole darned tree.  */
- 	walk_tree (t, mf_mostly_copy_tree_r, NULL, NULL);
- 
  	offset_expr = mf_offset_expr_of_array_ref (TREE_OPERAND (*t,0), 
  						   & TREE_OPERAND (*t,1), 
  						   & base_array,
--- 892,897 ----
*************** mx_xfn_indirect_ref (t, continue_p, data
*** 937,943 ****
  	value_ptr = mf_mark (build1 (ADDR_EXPR,
  				     base_ptr_type,
  				     mf_mark (*t)));
- 	walk_tree (& value_ptr, mf_mostly_copy_tree_r, NULL, NULL);
  
  	/* As an optimization, omit checking if the base object is
  	   known to be large enough.  Only certain kinds of
--- 950,955 ----
Index: tree-mudflap.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-mudflap.h,v
retrieving revision 1.1.2.4
diff -c -p -w -s -r1.1.2.4 tree-mudflap.h
*** tree-mudflap.h	5 Jun 2003 17:29:40 -0000	1.1.2.4
--- tree-mudflap.h	13 Jun 2003 21:04:26 -0000
*************** Software Foundation, 59 Temple Place - S
*** 23,29 ****
  #define TREE_MUDFLAP_H
  
  /* Instrumentation. */
! extern void mudflap_c_function PARAMS ((tree));
  extern void mudflap_enqueue_decl PARAMS ((tree, const char *));
  extern void mudflap_enqueue_constant PARAMS ((tree, const char *));
  extern void mudflap_finish_file PARAMS ((void));
--- 23,29 ----
  #define TREE_MUDFLAP_H
  
  /* Instrumentation. */
! extern tree mudflap_c_function PARAMS ((tree));
  extern void mudflap_enqueue_decl PARAMS ((tree, const char *));
  extern void mudflap_enqueue_constant PARAMS ((tree, const char *));
  extern void mudflap_finish_file PARAMS ((void));
Index: tree-nomudflap.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-nomudflap.c,v
retrieving revision 1.1.2.5
diff -c -p -w -s -r1.1.2.5 tree-nomudflap.c
*** tree-nomudflap.c	13 Jan 2003 23:14:44 -0000	1.1.2.5
--- tree-nomudflap.c	13 Jun 2003 21:04:26 -0000
***************
*** 1,5 ****
  /* Mudflap: narrow-pointer bounds-checking by tree rewriting.
!    Copyright (C) 2001, 2002 Free Software Foundation, Inc.
     Contributed by Frank Ch. Eigler <fche@redhat.com>
  
  This file is part of GCC.
--- 1,5 ----
  /* Mudflap: narrow-pointer bounds-checking by tree rewriting.
!    Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
     Contributed by Frank Ch. Eigler <fche@redhat.com>
  
  This file is part of GCC.
*************** Software Foundation, 59 Temple Place - S
*** 45,55 ****
     (e.g. Fortran).  */
  
   
! void 
  mudflap_c_function (t)
       tree t ATTRIBUTE_UNUSED;
  {
    abort ();
  }
  
  
--- 45,56 ----
     (e.g. Fortran).  */
  
   
! tree
  mudflap_c_function (t)
       tree t ATTRIBUTE_UNUSED;
  {
    abort ();
+   return NULL;
  }
  
  
Index: cp/optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/optimize.c,v
retrieving revision 1.81.10.21
diff -c -p -w -s -r1.81.10.21 optimize.c
*** cp/optimize.c	13 Jun 2003 19:00:22 -0000	1.81.10.21
--- cp/optimize.c	13 Jun 2003 21:04:26 -0000
***************
*** 1,5 ****
  /* Perform optimizations on tree structure.
!    Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
     Written by Mark Michell (mark@codesourcery.com).
  
  This file is part of GCC.
--- 1,5 ----
  /* Perform optimizations on tree structure.
!    Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
     Written by Mark Michell (mark@codesourcery.com).
  
  This file is part of GCC.
*************** Software Foundation, 59 Temple Place - S
*** 35,41 ****
  #include "hashtab.h"
  #include "debug.h"
  #include "tree-inline.h"
- #include "tree-mudflap.h"
  #include "flags.h"
  #include "langhooks.h"
  #include "diagnostic.h"
--- 35,40 ----
*************** optimize_function (tree fn)
*** 87,102 ****
      {
        /* Debugging dump after gimplification.  */
        dump_function (TDI_gimple, fn);
- 
-       if (flag_mudflap)
- 	{
- 	  mudflap_c_function (fn);
- 
- 	  /* Gimplify mudflap instrumentation.  FIXME  Long term: Would it
- 	     be better for mudflap to gimplify each tree as it generates
- 	     them?  */
- 	  gimplify_function_tree (fn);
- 	}
  
        /* Invoke the SSA tree optimizer.  */
        if (optimize >= 1)
--- 86,91 ----
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.264.2.29
diff -c -p -w -s -r1.264.2.29 semantics.c
*** cp/semantics.c	13 Jun 2003 19:00:23 -0000	1.264.2.29
--- cp/semantics.c	13 Jun 2003 21:04:27 -0000
***************
*** 32,37 ****
--- 32,38 ----
  #include "tree.h"
  #include "cp-tree.h"
  #include "tree-inline.h"
+ #include "tree-mudflap.h"
  #include "except.h"
  #include "lex.h"
  #include "toplev.h"
*************** expand_body (fn)
*** 2379,2384 ****
--- 2380,2386 ----
  {
    location_t saved_loc;
    tree saved_function;
+   tree saved_tree;
  
    /* When the parser calls us after finishing the body of a template
       function, we don't really want to expand the body.  When we're
*************** expand_body (fn)
*** 2482,2497 ****
    genrtl_start_function (fn);
    current_function_is_thunk = DECL_THUNK_P (fn);
  
    /* Expand the body.  */
!   if (STATEMENT_CODE_P (TREE_CODE (DECL_SAVED_TREE (fn))))
      {
        if (flag_disable_gimple)
! 	expand_stmt (DECL_SAVED_TREE (fn));
        else
  	abort ();
      }
    else
!     expand_expr_stmt_value (DECL_SAVED_TREE (fn), 0, 0);
  
    /* Statements should always be full-expressions at the outermost set
       of curly braces for a function.  */
--- 2484,2506 ----
    genrtl_start_function (fn);
    current_function_is_thunk = DECL_THUNK_P (fn);
  
+ 
+   /* Add mudflap instrumentation to a copy of the function body.  */
+   if (flag_mudflap)
+     saved_tree = mudflap_c_function (fn);
+   else
+     saved_tree = DECL_SAVED_TREE (fn);
+ 
    /* Expand the body.  */
!   if (STATEMENT_CODE_P (TREE_CODE (saved_tree)))
      {
        if (flag_disable_gimple)
! 	expand_stmt (saved_tree);
        else
  	abort ();
      }
    else
!     expand_expr_stmt_value (saved_tree, 0, 0);
  
    /* Statements should always be full-expressions at the outermost set
       of curly braces for a function.  */


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