Re: [patch] Call free_after_parsing earlier

2012-07-16 Thread Richard Guenther
On Fri, Jul 13, 2012 at 4:33 PM, Steven Bosscher stevenb@gmail.com wrote:
 On Thu, Jul 12, 2012 at 9:21 AM, Richard Guenther
 richard.guent...@gmail.com wrote:
 On Wed, Jul 11, 2012 at 9:39 PM, Steven Bosscher stevenb@gmail.com 
 wrote:
 Hello,

 GCC calls free_after_parsing in rest_of_clean_state.
 That's way too late, it can be done in free_lang_data_in_cgraph instead.

 But that's only called with -flto ... I think it should be called in
 cgraph_finalize_function instead (being optimistic here - heh).

 Quite optimistic, indeed...

;)

Btw, the

* final.c (final): Don't loop to find max_uid.

part is ok if you want to commit it separately.

 I choose for free_lang_data_in_cgraph (which, BTW, doesn't belong in
 tree.c, but that aside) because I thought the C++ front end might need
 its function-language after cgraph_finalize_function. And indeed
 so...

Ok, so how about doing it at the end of cgraph_analyze_function?

Thanks,
Richard.

 Ciao!
 Steven


 $ cat t.C
 #line 14971 configure
 struct S { ~S(); };
 void bar();
 void foo()
 {
   S s;
   bar();
 }

 $ gdb --args ./cc1plus t.C
 GNU gdb 6.8-debian
 Copyright (C) 2008 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.  Type show copying
 and show warranty for details.
 This GDB was configured as x86_64-linux-gnu...
 Breakpoint 1 at 0x38a80b5: file ../../trunk/gcc/diagnostic.c, line 1011.
 Breakpoint 2 at 0x38a7ed6: file ../../trunk/gcc/diagnostic.c, line 955.
 Function exit not defined.
 Make breakpoint pending on future shared library load? (y or [n])
 [answered N; input not from terminal]
 Function abort not defined.
 Make breakpoint pending on future shared library load? (y or [n])
 [answered N; input not from terminal]
 (gdb) run
 Starting program: /home/stevenb/devel/build-test/gcc/cc1plus t.C
  void foo()
 Analyzing compilation unit

 Program received signal SIGSEGV, Segmentation fault.
 0x0096b93a in stmts_are_full_exprs_p () at
 ../../trunk/gcc/cp/semantics.c:370
 370   return current_stmt_tree ()-stmts_are_full_exprs_p;
 (gdb) bt
 #0  0x0096b93a in stmts_are_full_exprs_p () at
 ../../trunk/gcc/cp/semantics.c:370
 #1  0x00b1f294 in cp_gimplify_expr (expr_p=0x77232a20,
 pre_p=0x7fff97a8, post_p=0x7fff8ba8) at
 ../../trunk/gcc/cp/cp-gimplify.c:530
 #2  0x0156fb44 in gimplify_expr (expr_p=0x77232a20,
 pre_p=0x7fff97a8, post_p=0x7fff8ba8, gimple_test_f=0x155d16c
 is_gimple_stmt, fallback=0)
 at ../../trunk/gcc/gimplify.c:7064
 #3  0x01563bb7 in gimplify_stmt (stmt_p=0x77232a20,
 seq_p=0x7fff97a8) at ../../trunk/gcc/gimplify.c:5678
 #4  0x01562d43 in gimplify_cleanup_point_expr
 (expr_p=0x77245ad8, pre_p=0x7fffb3b0) at
 ../../trunk/gcc/gimplify.c:5455
 #5  0x01572c33 in gimplify_expr (expr_p=0x77245ad8,
 pre_p=0x7fffb3b0, post_p=0x7fff9998, gimple_test_f=0x155d16c
 is_gimple_stmt, fallback=0)
 at ../../trunk/gcc/gimplify.c:7479
 #6  0x01563bb7 in gimplify_stmt (stmt_p=0x77245ad8,
 seq_p=0x7fffb3b0) at ../../trunk/gcc/gimplify.c:5678
 #7  0x01543e69 in gimplify_statement_list
 (expr_p=0x7fffb288, pre_p=0x7fffb3b0) at
 ../../trunk/gcc/gimplify.c:1527
 #8  0x0157352f in gimplify_expr (expr_p=0x7fffb288,
 pre_p=0x7fffb3b0, post_p=0x7fffa6e8, gimple_test_f=0x155d16c
 is_gimple_stmt, fallback=0)
 at ../../trunk/gcc/gimplify.c:7531
 #9  0x01563bb7 in gimplify_stmt (stmt_p=0x7fffb288,
 seq_p=0x7fffb3b0) at ../../trunk/gcc/gimplify.c:5678
 #10 0x0153eb49 in gimplify_and_add (t=0x77247600,
 seq_p=0x7fffb3b0) at ../../trunk/gcc/gimplify.c:358
 #11 0x01572a22 in gimplify_expr (expr_p=0x77245ac0,
 pre_p=0x7fffcd40, post_p=0x7fffb3f8, gimple_test_f=0x155d16c
 is_gimple_stmt, fallback=0)
 at ../../trunk/gcc/gimplify.c:7457
 #12 0x01563bb7 in gimplify_stmt (stmt_p=0x77245ac0,
 seq_p=0x7fffcd40) at ../../trunk/gcc/gimplify.c:5678
 #13 0x01543e69 in gimplify_statement_list
 (expr_p=0x7724c098, pre_p=0x7fffcd40) at
 ../../trunk/gcc/gimplify.c:1527
 #14 0x0157352f in gimplify_expr (expr_p=0x7724c098,
 pre_p=0x7fffcd40, post_p=0x7fffc148, gimple_test_f=0x155d16c
 is_gimple_stmt, fallback=0)
 at ../../trunk/gcc/gimplify.c:7531
 #15 0x01563bb7 in gimplify_stmt (stmt_p=0x7724c098,
 seq_p=0x7fffcd40) at ../../trunk/gcc/gimplify.c:5678
 #16 0x01542106 in gimplify_bind_expr (expr_p=0x7723c898,
 pre_p=0x7fffdc80) at ../../trunk/gcc/gimplify.c:1220
 #17 0x01571446 in gimplify_expr (expr_p=0x7723c898,
 pre_p=0x7fffdc80, post_p=0x7fffd068, gimple_test_f=0x155d16c
 is_gimple_stmt, fallback=0)
 at ../../trunk/gcc/gimplify.c:7316
 #18 0x01563bb7 in 

Re: [patch] Call free_after_parsing earlier

2012-07-13 Thread Steven Bosscher
On Thu, Jul 12, 2012 at 9:21 AM, Richard Guenther
richard.guent...@gmail.com wrote:
 On Wed, Jul 11, 2012 at 9:39 PM, Steven Bosscher stevenb@gmail.com 
 wrote:
 Hello,

 GCC calls free_after_parsing in rest_of_clean_state.
 That's way too late, it can be done in free_lang_data_in_cgraph instead.

 But that's only called with -flto ... I think it should be called in
 cgraph_finalize_function instead (being optimistic here - heh).

Quite optimistic, indeed...

I choose for free_lang_data_in_cgraph (which, BTW, doesn't belong in
tree.c, but that aside) because I thought the C++ front end might need
its function-language after cgraph_finalize_function. And indeed
so...

Ciao!
Steven


$ cat t.C
#line 14971 configure
struct S { ~S(); };
void bar();
void foo()
{
  S s;
  bar();
}

$ gdb --args ./cc1plus t.C
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type show copying
and show warranty for details.
This GDB was configured as x86_64-linux-gnu...
Breakpoint 1 at 0x38a80b5: file ../../trunk/gcc/diagnostic.c, line 1011.
Breakpoint 2 at 0x38a7ed6: file ../../trunk/gcc/diagnostic.c, line 955.
Function exit not defined.
Make breakpoint pending on future shared library load? (y or [n])
[answered N; input not from terminal]
Function abort not defined.
Make breakpoint pending on future shared library load? (y or [n])
[answered N; input not from terminal]
(gdb) run
Starting program: /home/stevenb/devel/build-test/gcc/cc1plus t.C
 void foo()
Analyzing compilation unit

Program received signal SIGSEGV, Segmentation fault.
0x0096b93a in stmts_are_full_exprs_p () at
../../trunk/gcc/cp/semantics.c:370
370   return current_stmt_tree ()-stmts_are_full_exprs_p;
(gdb) bt
#0  0x0096b93a in stmts_are_full_exprs_p () at
../../trunk/gcc/cp/semantics.c:370
#1  0x00b1f294 in cp_gimplify_expr (expr_p=0x77232a20,
pre_p=0x7fff97a8, post_p=0x7fff8ba8) at
../../trunk/gcc/cp/cp-gimplify.c:530
#2  0x0156fb44 in gimplify_expr (expr_p=0x77232a20,
pre_p=0x7fff97a8, post_p=0x7fff8ba8, gimple_test_f=0x155d16c
is_gimple_stmt, fallback=0)
at ../../trunk/gcc/gimplify.c:7064
#3  0x01563bb7 in gimplify_stmt (stmt_p=0x77232a20,
seq_p=0x7fff97a8) at ../../trunk/gcc/gimplify.c:5678
#4  0x01562d43 in gimplify_cleanup_point_expr
(expr_p=0x77245ad8, pre_p=0x7fffb3b0) at
../../trunk/gcc/gimplify.c:5455
#5  0x01572c33 in gimplify_expr (expr_p=0x77245ad8,
pre_p=0x7fffb3b0, post_p=0x7fff9998, gimple_test_f=0x155d16c
is_gimple_stmt, fallback=0)
at ../../trunk/gcc/gimplify.c:7479
#6  0x01563bb7 in gimplify_stmt (stmt_p=0x77245ad8,
seq_p=0x7fffb3b0) at ../../trunk/gcc/gimplify.c:5678
#7  0x01543e69 in gimplify_statement_list
(expr_p=0x7fffb288, pre_p=0x7fffb3b0) at
../../trunk/gcc/gimplify.c:1527
#8  0x0157352f in gimplify_expr (expr_p=0x7fffb288,
pre_p=0x7fffb3b0, post_p=0x7fffa6e8, gimple_test_f=0x155d16c
is_gimple_stmt, fallback=0)
at ../../trunk/gcc/gimplify.c:7531
#9  0x01563bb7 in gimplify_stmt (stmt_p=0x7fffb288,
seq_p=0x7fffb3b0) at ../../trunk/gcc/gimplify.c:5678
#10 0x0153eb49 in gimplify_and_add (t=0x77247600,
seq_p=0x7fffb3b0) at ../../trunk/gcc/gimplify.c:358
#11 0x01572a22 in gimplify_expr (expr_p=0x77245ac0,
pre_p=0x7fffcd40, post_p=0x7fffb3f8, gimple_test_f=0x155d16c
is_gimple_stmt, fallback=0)
at ../../trunk/gcc/gimplify.c:7457
#12 0x01563bb7 in gimplify_stmt (stmt_p=0x77245ac0,
seq_p=0x7fffcd40) at ../../trunk/gcc/gimplify.c:5678
#13 0x01543e69 in gimplify_statement_list
(expr_p=0x7724c098, pre_p=0x7fffcd40) at
../../trunk/gcc/gimplify.c:1527
#14 0x0157352f in gimplify_expr (expr_p=0x7724c098,
pre_p=0x7fffcd40, post_p=0x7fffc148, gimple_test_f=0x155d16c
is_gimple_stmt, fallback=0)
at ../../trunk/gcc/gimplify.c:7531
#15 0x01563bb7 in gimplify_stmt (stmt_p=0x7724c098,
seq_p=0x7fffcd40) at ../../trunk/gcc/gimplify.c:5678
#16 0x01542106 in gimplify_bind_expr (expr_p=0x7723c898,
pre_p=0x7fffdc80) at ../../trunk/gcc/gimplify.c:1220
#17 0x01571446 in gimplify_expr (expr_p=0x7723c898,
pre_p=0x7fffdc80, post_p=0x7fffd068, gimple_test_f=0x155d16c
is_gimple_stmt, fallback=0)
at ../../trunk/gcc/gimplify.c:7316
#18 0x01563bb7 in gimplify_stmt (stmt_p=0x7723c898,
seq_p=0x7fffdc80) at ../../trunk/gcc/gimplify.c:5678
#19 0x01577766 in gimplify_body (fndecl=0x7723c800,
do_parms=1 '\001') at ../../trunk/gcc/gimplify.c:8177
#20 0x01578d36 in gimplify_function_tree
(fndecl=0x7723c800) at ../../trunk/gcc/gimplify.c:8311
#21 0x00fc490c in cgraph_analyze_function

Re: [patch] Call free_after_parsing earlier

2012-07-12 Thread Richard Guenther
On Wed, Jul 11, 2012 at 9:39 PM, Steven Bosscher stevenb@gmail.com wrote:
 Hello,

 GCC calls free_after_parsing in rest_of_clean_state.
 That's way too late, it can be done in free_lang_data_in_cgraph instead.

But that's only called with -flto ... I think it should be called in
cgraph_finalize_function instead (being optimistic here - heh).

Richard.

 While there, I noticed a silly loop in final.c, and cleaned that up too.

 Bootstrappedtested on x86_64-unknown-linux-gnu. OK for trunk?

 Ciao!
 Steven

 * final.c (final): Don't loop to find max_uid.
 (rest_of_clean_state): Don't call free_after_parsing here.
 * tree.c (free_lang_data_in_cgraph): Call free_after_parsing here.

 Index: final.c
 ===
 --- final.c (revision 189423)
 +++ final.c (working copy)
 @@ -1826,7 +1826,6 @@ void
  final (rtx first, FILE *file, int optimize_p)
  {
rtx insn, next;
 -  int max_uid = 0;
int seen = 0;

/* Used for -dA dump.  */
 @@ -1837,11 +1836,9 @@ final (rtx first, FILE *file, int optimi

last_ignored_compare = 0;

 +#ifdef HAVE_cc0
for (insn = first; insn; insn = NEXT_INSN (insn))
  {
 -  if (INSN_UID (insn)  max_uid)   /* Find largest UID.  */
 -   max_uid = INSN_UID (insn);
 -#ifdef HAVE_cc0
/* If CC tracking across branches is enabled, record the insn which
  jumps to each branch only reached from one place.  */
if (optimize_p  JUMP_P (insn))
 @@ -1852,8 +1849,8 @@ final (rtx first, FILE *file, int optimi
   LABEL_REFS (lab) = insn;
 }
 }
 -#endif
  }
 +#endif

init_recog ();

 @@ -4500,7 +4497,6 @@ rest_of_clean_state (void)
init_recog_no_volatile ();

/* We're done with this function.  Free up memory if we can.  */
 -  free_after_parsing (cfun);
free_after_compilation (cfun);
return 0;
  }
 Index: tree.c
 ===
 --- tree.c  (revision 189423)
 +++ tree.c  (working copy)
 @@ -5167,16 +5167,19 @@ assign_assembler_name_if_neeeded (tree t


  /* Free language specific information for every operand and expression
 -   in every node of the call graph.  This process operates in three stages:
 +   in every node of the call graph.  This process operates in four stages:

 -   1- Every callgraph node and varpool node is traversed looking for
 +   1- Every function is traversed to free any front-end specific
 +  data hung from the function's struct function-language.
 +
 +   2- Every callgraph node and varpool node is traversed looking for
decls and types embedded in them.  This is a more exhaustive
search than that done by find_referenced_vars, because it will
also collect individual fields, decls embedded in types, etc.

 -   2- All the decls found are sent to free_lang_data_in_decl.
 +   3- All the decls found are sent to free_lang_data_in_decl.

 -   3- All the types found are sent to free_lang_data_in_type.
 +   4- All the types found are sent to free_lang_data_in_type.

 The ordering between decls and types is important because
 free_lang_data_in_decl sets assembler names, which includes
 @@ -5193,6 +5196,10 @@ free_lang_data_in_cgraph (void)
unsigned i;
alias_pair *p;

 +  /* Clear out function-language.  */
 +  FOR_EACH_FUNCTION (n)
 +free_after_parsing (DECL_STRUCT_FUNCTION (n-symbol.decl));
 +
/* Initialize sets and arrays to store referenced decls and types.  */
fld.pset = pointer_set_create ();
fld.worklist = NULL;


[patch] Call free_after_parsing earlier

2012-07-11 Thread Steven Bosscher
Hello,

GCC calls free_after_parsing in rest_of_clean_state.
That's way too late, it can be done in free_lang_data_in_cgraph instead.

While there, I noticed a silly loop in final.c, and cleaned that up too.

Bootstrappedtested on x86_64-unknown-linux-gnu. OK for trunk?

Ciao!
Steven

* final.c (final): Don't loop to find max_uid.
(rest_of_clean_state): Don't call free_after_parsing here.
* tree.c (free_lang_data_in_cgraph): Call free_after_parsing here.

Index: final.c
===
--- final.c (revision 189423)
+++ final.c (working copy)
@@ -1826,7 +1826,6 @@ void
 final (rtx first, FILE *file, int optimize_p)
 {
   rtx insn, next;
-  int max_uid = 0;
   int seen = 0;

   /* Used for -dA dump.  */
@@ -1837,11 +1836,9 @@ final (rtx first, FILE *file, int optimi

   last_ignored_compare = 0;

+#ifdef HAVE_cc0
   for (insn = first; insn; insn = NEXT_INSN (insn))
 {
-  if (INSN_UID (insn)  max_uid)   /* Find largest UID.  */
-   max_uid = INSN_UID (insn);
-#ifdef HAVE_cc0
   /* If CC tracking across branches is enabled, record the insn which
 jumps to each branch only reached from one place.  */
   if (optimize_p  JUMP_P (insn))
@@ -1852,8 +1849,8 @@ final (rtx first, FILE *file, int optimi
  LABEL_REFS (lab) = insn;
}
}
-#endif
 }
+#endif

   init_recog ();

@@ -4500,7 +4497,6 @@ rest_of_clean_state (void)
   init_recog_no_volatile ();

   /* We're done with this function.  Free up memory if we can.  */
-  free_after_parsing (cfun);
   free_after_compilation (cfun);
   return 0;
 }
Index: tree.c
===
--- tree.c  (revision 189423)
+++ tree.c  (working copy)
@@ -5167,16 +5167,19 @@ assign_assembler_name_if_neeeded (tree t


 /* Free language specific information for every operand and expression
-   in every node of the call graph.  This process operates in three stages:
+   in every node of the call graph.  This process operates in four stages:

-   1- Every callgraph node and varpool node is traversed looking for
+   1- Every function is traversed to free any front-end specific
+  data hung from the function's struct function-language.
+
+   2- Every callgraph node and varpool node is traversed looking for
   decls and types embedded in them.  This is a more exhaustive
   search than that done by find_referenced_vars, because it will
   also collect individual fields, decls embedded in types, etc.

-   2- All the decls found are sent to free_lang_data_in_decl.
+   3- All the decls found are sent to free_lang_data_in_decl.

-   3- All the types found are sent to free_lang_data_in_type.
+   4- All the types found are sent to free_lang_data_in_type.

The ordering between decls and types is important because
free_lang_data_in_decl sets assembler names, which includes
@@ -5193,6 +5196,10 @@ free_lang_data_in_cgraph (void)
   unsigned i;
   alias_pair *p;

+  /* Clear out function-language.  */
+  FOR_EACH_FUNCTION (n)
+free_after_parsing (DECL_STRUCT_FUNCTION (n-symbol.decl));
+
   /* Initialize sets and arrays to store referenced decls and types.  */
   fld.pset = pointer_set_create ();
   fld.worklist = NULL;