This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[vta] don't expand strings just because of debug info
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 03 Jan 2008 05:24:06 -0200
- Subject: [vta] don't expand strings just because of debug info
On ppc64, strings used in initializers of automatic variables take up
constant pool entries. When constant pool entries go out of sync
between debug and non-debug compilations, we output different code (or
at least different data).
This patch works by deferring the decision on whether to emit a string
constant to the end of the expansion of a function. It handles
scenarios like this:
# DEBUG var = &"somestring"[0]
printf (&"something"[0], otherargs);
If the string was completely optimized away, then we can't emit debug
info for it, but we still emit the CONST_STRING in the debug insn, in
case it is indexed to obtain a constant char or some such. However,
if the same string is expanded elsewhere, then we'll use the same RTX
in debug insns.
I'm checking this in the vta branch.
for gcc/ChangeLog.vta
from Alexandre Oliva <aoliva@redhat.com>
* cfgexpand.c (adjust_debug_string_constant): New.
(debug_string_constants_p): New.
(adjust_debug_string_constants): New.
(expand_debug_expr): Don't expand STRING_CSTs unless we know
we're actually going to need them.
(tree_expand_cfg): Replace placeholders with a final decision.
Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c.orig 2007-12-25 07:00:52.000000000 -0200
+++ gcc/cfgexpand.c 2007-12-25 07:34:09.000000000 -0200
@@ -1544,6 +1544,58 @@ round_udiv_adjust (enum machine_mode mod
const1_rtx, const0_rtx);
}
+/* for_each_rtx function that adjusts VAR_LOCATION placeholders for
+ debug string constants. */
+
+static int
+adjust_debug_string_constant (rtx *x, void *nothing ATTRIBUTE_UNUSED)
+{
+ rtx rtstr, cst;
+ tree exp;
+
+ if (GET_CODE (*x) != VAR_LOCATION)
+ return 0;
+
+ exp = PAT_VAR_LOCATION_DECL (*x);
+ rtstr = PAT_VAR_LOCATION_LOC (*x);
+
+ gcc_assert (TREE_CODE (exp) == STRING_CST && GET_CODE (rtstr) == CONST_STRING
+ && TREE_STRING_POINTER (exp) == XSTR (rtstr, 0));
+
+ cst = lookup_constant_def (exp);
+ if (cst && MEM_P (cst))
+ *x = XEXP (cst, 0);
+ else
+ *x = rtstr;
+
+ return -1;
+}
+
+/* Set to true when a debug string constant is expanded as a
+ VAR_LOCATION placeholder rather than as regular rtl. */
+
+static bool debug_string_constants_p = false;
+
+/* Adjust any debug string constants expanded as VAR_LOCATION
+ placeholders (see how STRING_CST is handled in expand_debug_expr)
+ to regular rtx or debug-only CONST_STRINGs. */
+
+static void
+adjust_debug_string_constants (void)
+{
+ rtx insn;
+
+ if (!debug_string_constants_p)
+ return;
+
+ for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
+ if (DEBUG_INSN_P (insn))
+ for_each_rtx (&INSN_VAR_LOCATION_LOC (insn),
+ adjust_debug_string_constant, NULL);
+
+ debug_string_constants_p = false;
+}
+
/* Return an RTX equivalent to the value of the tree expression
EXP. */
@@ -1626,14 +1678,24 @@ expand_debug_expr (tree exp)
return DECL_RTL (exp);
+ case STRING_CST:
+ if (!lookup_constant_def (exp))
+ {
+ op0 = gen_rtx_CONST_STRING (mode, TREE_STRING_POINTER (exp));
+ op0 = gen_rtx_VAR_LOCATION (mode, exp, op0, 0);
+ op0 = gen_rtx_MEM (mode, op0);
+ debug_string_constants_p = true;
+ return op0;
+ }
+ /* Fall through... */
+
case INTEGER_CST:
case REAL_CST:
case FIXED_CST:
case COMPLEX_CST:
- case STRING_CST:
op0 = expand_expr (exp, NULL_RTX, mode, EXPAND_INITIALIZER);
if (op0 && GET_MODE (op0) == VOIDmode && mode != VOIDmode)
- return op0 = gen_rtx_CONST (mode, op0);
+ op0 = gen_rtx_CONST (mode, op0);
return op0;
case NOP_EXPR:
@@ -2562,6 +2624,8 @@ tree_expand_cfg (void)
bb = expand_gimple_basic_block (bb);
pointer_map_destroy (lab_rtx_for_bb);
+ adjust_debug_string_constants ();
+
construct_exit_block ();
set_curr_insn_block (DECL_INITIAL (current_function_decl));
insn_locators_finalize ();
Index: gcc/print-rtl.c
===================================================================
--- gcc/print-rtl.c.orig 2007-11-23 18:05:53.000000000 -0200
+++ gcc/print-rtl.c 2007-12-25 07:40:23.000000000 -0200
@@ -211,7 +211,10 @@ print_rtx (const_rtx in_rtx)
#ifndef GENERATOR_FILE
if (GET_CODE (in_rtx) == VAR_LOCATION)
{
- print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
+ if (TREE_CODE (PAT_VAR_LOCATION_DECL (in_rtx)) == STRING_CST)
+ fputs (" <debug string placeholder>", outfile);
+ else
+ print_mem_expr (outfile, PAT_VAR_LOCATION_DECL (in_rtx));
fputc (' ', outfile);
print_rtx (PAT_VAR_LOCATION_LOC (in_rtx));
if (PAT_VAR_LOCATION_STATUS (in_rtx)
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
FSF Latin America Board Member http://www.fsfla.org/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}