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]

Re: eliminating debug info for symbols/types in unexpanded inlines


On Wed, 2009-05-06 at 19:06 -0700, Jim Wilson wrote:
> At Cisco, it was noticed that when you use an extern variable inside an
> inline function that is optimized away, you still get debug info for

Sorry, I tried to hit Edit/Undo and accidentally hit File/Send which is
right next to it.  Sigh.  Anyways...

I know Cary Coutant is working on a new duplicate header file
elimination scheme, but as far as I know it isn't available yet.  This
patch is a much simpler solution we can use in the meantime.  This patch
has been in use for about a year inside Cisco without any problems so
far, though Cisco is using an older gcc release, so it isn't a complete
proof that this is safe with gcc mainline.

The patch isn't very elegant.  I'm happy to change things like the
option name or variable name if other people think this is useful.

FYI I noticed on mainline that I get two copies of debug info for the
variable bar.  Something is broken on mainline since the gcc-4.4 branch
was made.  Stepping through dwarfout2.c, I see that we have two
different decls for the variable bar, which is why dwarf2out.c emits two
debug entries for it.  I haven't tried to figure out why we have two
decls for one variable yet.

Jim

2009-05-06  James E. Wilson  <wilson@codesourcery.com>

	* doc/invoke.texi (-feliminate-unused-debug-symbols): New.
	* tree.h (struct tree_base): Add used_flag_expand.
	(TREE_USED_EXPAND): New.
	* dwarf2out.c (dwarf2out_decl): Check
	flag_eliminate_unexpanded_debug_symbols.
	* expr.c (expand_expr_real_1, case VAR_DECL): Set TREE_USED_EXPAND.
	* common.opt (feliminate-unexpanded-debug-symbols): New.

Index: doc/invoke.texi
===================================================================
--- doc/invoke.texi	(revision 146849)
+++ doc/invoke.texi	(working copy)
@@ -300,7 +300,8 @@ Objective-C and Objective-C++ Dialects}.
 -fdump-tree-vrp@r{[}-@var{n}@r{]} @gol
 -ftree-vectorizer-verbose=@var{n} @gol
 -fdump-tree-storeccp@r{[}-@var{n}@r{]} @gol
--feliminate-dwarf2-dups -feliminate-unused-debug-types @gol
+-feliminate-dwarf2-dups -feliminate-unexpanded-debug-symbols @gol
+-feliminate-unused-debug-types @gol
 -feliminate-unused-debug-symbols -femit-class-debug-always @gol
 -fmem-report -fpre-ipa-mem-report -fpost-ipa-mem-report -fprofile-arcs @gol
 -frandom-seed=@var{string} -fsched-verbose=@var{n} @gol
@@ -5361,6 +5362,12 @@ not actually used in your program (but i
 however, this results in a significant amount of wasted space.
 With this option, GCC will avoid producing debug symbol output
 for types that are nowhere used in the source file being compiled.
+
+@item -feliminate-unexpanded-debug-symbols
+When producing DWARF2 output, GCC will normally emit debug info for symbols
+referenced in inline functions, even if those functions are unused and
+optimized away.  With this option, GCC will avoid producing debug info
+for such symbols.  This option is on by default.
 @end table
 
 @node Optimize Options
Index: tree.h
===================================================================
--- tree.h	(revision 146849)
+++ tree.h	(working copy)
@@ -362,7 +362,9 @@ struct GTY(()) tree_base {
   unsigned protected_flag : 1;
   unsigned deprecated_flag : 1;
   unsigned saturating_flag : 1;
+
   unsigned default_def_flag : 1;
+  unsigned used_flag_expand : 1;
 
   unsigned lang_flag_0 : 1;
   unsigned lang_flag_1 : 1;
@@ -373,7 +375,7 @@ struct GTY(()) tree_base {
   unsigned lang_flag_6 : 1;
   unsigned visited : 1;
 
-  unsigned spare : 23;
+  unsigned spare : 22;
 
   union tree_ann_d *ann;
 };
@@ -561,6 +563,11 @@ struct GTY(()) tree_common {
            all decls
            IDENTIFIER_NODE
 
+   used_flag_expand:
+
+       TREE_USED_EXPAND in
+           PARM_DECL, VAR_DECL, FUNCTION_DECL, RESULT_DECL
+
    nothrow_flag:
 
        TREE_NOTHROW in
@@ -1285,6 +1292,9 @@ extern void omp_clause_range_check_faile
    In a BLOCK, this means that the block contains variables that are used.  */
 #define TREE_USED(NODE) ((NODE)->base.used_flag)
 
+/* Nonzero in a _DECL if the name is used during RTL expansion.  */
+#define TREE_USED_EXPAND(NODE) ((NODE)->base.used_flag_expand)
+
 /* In a FUNCTION_DECL, nonzero means a call to the function cannot throw
    an exception.  In a CALL_EXPR, nonzero means the call cannot throw.  */
 #define TREE_NOTHROW(NODE) ((NODE)->base.nothrow_flag)
Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 146849)
+++ dwarf2out.c	(working copy)
@@ -15573,7 +15573,10 @@ dwarf2out_decl (tree decl)
 	 block-local extern declarations (whether used or not) because that
 	 would screw-up the debugger's name lookup mechanism and cause it to
 	 miss things which really ought to be in scope at a given point.  */
-      if (DECL_EXTERNAL (decl) && !TREE_USED (decl))
+      if (DECL_EXTERNAL (decl)
+	  && (flag_eliminate_unexpanded_debug_symbols
+	      ? !TREE_USED_EXPAND (decl)
+	      : !TREE_USED (decl)))
 	return;
 
       /* For local statics lookup proper context die.  */
Index: expr.c
===================================================================
--- expr.c	(revision 146849)
+++ expr.c	(working copy)
@@ -7278,6 +7278,8 @@ expand_expr_real_1 (tree exp, rtx target
 	  TREE_USED (exp) = 1;
 	}
 
+      TREE_USED_EXPAND (exp) = 1;
+
       /* Show we haven't gotten RTL for this yet.  */
       temp = 0;
 
Index: common.opt
===================================================================
--- common.opt	(revision 146849)
+++ common.opt	(working copy)
@@ -478,6 +478,10 @@ feliminate-unused-debug-types
 Common Report Var(flag_eliminate_unused_debug_types) Init(1)
 Perform unused type elimination in debug info
 
+feliminate-unexpanded-debug-symbols
+Common Report Var(flag_eliminate_unexpanded_debug_symbols) Init(1)
+Eliminate debug info for symbols referenced in unused inline functions.
+
 femit-class-debug-always
 Common Report Var(flag_emit_class_debug_always) Init(0)
 Do not suppress C++ class debug information.

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