This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] don't consume all memory in pprinter
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 17 Sep 2003 13:38:13 -0700
- Subject: [tree-ssa] don't consume all memory in pprinter
Dumping gimple from g++.dg/eh/cleanup1.C generates a 1.3GB file.
We shouldn't need 1.3GB of ram to create this file.
Written by Diego, tested by me.
r~
* pretty-print.c (pp_write_text_to_stream): Export.
* pretty-print.h (pp_write_text_to_stream): Declare.
* tree-pretty-print.c (print_generic_stmt): Flush to file.
(dump_generic_node): Call pp_write_text_to_stream.
(maybe_init_pretty_print): Take file argument; associate the
stream with the buffer.
Index: pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/pretty-print.c,v
retrieving revision 2.5.2.1
diff -d -u -p -r2.5.2.1 pretty-print.c
--- pretty-print.c 20 Aug 2003 20:44:26 -0000 2.5.2.1
+++ pretty-print.c 17 Sep 2003 19:25:53 -0000
@@ -91,7 +91,7 @@ pp_clear_state (pretty_printer *pp)
}
/* Flush the formatted text of PRETTY-PRINTER onto the attached stream. */
-static inline void
+void
pp_write_text_to_stream (pretty_printer *pp)
{
const char *text = pp_formatted_text (pp);
Index: pretty-print.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/pretty-print.h,v
retrieving revision 1.4.2.4
diff -d -u -p -r1.4.2.4 pretty-print.h
--- pretty-print.h 20 Aug 2003 20:44:26 -0000 1.4.2.4
+++ pretty-print.h 17 Sep 2003 19:25:53 -0000
@@ -255,5 +255,6 @@ extern void pp_base_indent (pretty_print
extern void pp_base_newline (pretty_printer *);
extern void pp_base_character (pretty_printer *, int);
extern void pp_base_string (pretty_printer *, const char *);
+extern void pp_write_text_to_stream (pretty_printer *pp);
#endif /* GCC_PRETTY_PRINT_H */
Index: tree-pretty-print.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-pretty-print.c,v
retrieving revision 1.1.2.41
diff -d -u -p -r1.1.2.41 tree-pretty-print.c
--- tree-pretty-print.c 10 Sep 2003 13:26:35 -0000 1.1.2.41
+++ tree-pretty-print.c 17 Sep 2003 19:25:53 -0000
@@ -38,7 +38,7 @@ static const char *op_symbol (tree);
static void pretty_print_string (pretty_printer *, const char*);
static void print_call_name (pretty_printer *, tree);
static void newline_and_indent (pretty_printer *, int);
-static void maybe_init_pretty_print (void);
+static void maybe_init_pretty_print (FILE *);
static void print_declaration (pretty_printer *, tree, int, int);
static void print_struct_decl (pretty_printer *, tree, int);
static void dump_block_info (pretty_printer *, basic_block, int);
@@ -105,11 +105,10 @@ debug_generic_stmt (tree t)
void
print_generic_stmt (FILE *file, tree t, int flags)
{
- maybe_init_pretty_print ();
+ maybe_init_pretty_print (file);
dumping_stmts = true;
dump_generic_node (&buffer, t, 0, flags);
- fprintf (file, "%s", pp_base_formatted_text (&buffer));
- pp_clear_output_area (&buffer);
+ pp_flush (&buffer);
}
@@ -119,11 +118,9 @@ print_generic_stmt (FILE *file, tree t,
void
print_generic_expr (FILE *file, tree t, int flags)
{
- maybe_init_pretty_print ();
+ maybe_init_pretty_print (file);
dumping_stmts = false;
dump_generic_node (&buffer, t, 0, flags);
- fprintf (file, "%s", pp_base_formatted_text (&buffer));
- pp_clear_output_area (&buffer);
}
@@ -1368,6 +1365,8 @@ dump_generic_node (pretty_printer *buffe
NIY;
}
+ pp_write_text_to_stream (buffer);
+
return spc;
}
@@ -1911,15 +1910,18 @@ pretty_print_string (pretty_printer *buf
}
static void
-maybe_init_pretty_print (void)
+maybe_init_pretty_print (FILE *file)
{
last_bb = NULL;
if (!initialized)
{
pp_construct (&buffer, /* prefix */NULL, /* line-width */0);
+ pp_needs_newline (&buffer) = true;
initialized = 1;
}
+
+ buffer.buffer->stream = file;
}
static void