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]

[incremental] Patch: FYI: more work on delayed gimplification


I'm checking this in on the incremental-compiler branch.

This fixes the other front ends for delayed gimplification.  I tried
out c++, java, and fortran -- but not ada or treelang.  (As usual,
don't worry about this kind of thing.  All will be well before a
merge.)

In the new scheme, cgraph_finalize_compilation_unit and
cgraph_optimize are pushed into the write_global_declarations lang hook.
This is a bit goofy, but calling 2 langhooks in a row also seemed weird.
And, the languages that override this hook are already calling
these functions there.

Also, the goal is for only tree_lowering_passes to call
gimplify_function_tree.  But doing this uncovered a few oddities.
Like C, the fortran front end has a pass that needs gimple.  This
looks easy to fix.

In the C++ FE, the AGGR_INIT_EXPR lowering code also wants gimple.  I
hacked around this.  I will investigate it more deeply later.

The tree.c change is also somewhat hacky.  Another cleanup required.
I'm not exactly sure what I want to do here yet.  Maybe we really will
need some kind of "forwarding decl" idea; I was hoping to avoid that.
I can explain the problem if you want to understand it.

Anyway, now we're back to some semblance of order: we can build
libstdc++ (aside from a PCH bug), libgfortran, and libjava.

Tom

ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* c-gimplify.c (c_genericize): Don't dump generic function.
	* tree-optimize.c (tree_lowering_passes): Dump generic function.
	* gimplify.c (gimplify_function_tree): Exit early if function
	already gimplified.
	* tree.c (staticp): Handle VIEW_CONVERT_EXPR.
	* debug.h: (dwarf2out_ensure_output_file_set): Declare.
	* dwarf2out.c (dwarf2out_ensure_output_file_set): New function.
	* toplev.c (compile_file): Don't call
	cgraph_finalize_compilation_unit.
	(lang_dependent_init): Call dwarf2out_ensure_output_file_set.
	(compile_file): Likewise.
	* langhooks.c (write_global_declarations): Call
	cgraph_finalize_compilation_unit and cgraph_optimize.
	Include cgraph.h.

java/ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* java-gimplify.c (java_genericize): Don't call
	gimplify_function_tree.
	* jcf-parse.c (java_parse_file): Don't call cgraph_optimize or
	cgraph_finalize_compilation_unit.

cp/ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* semantics.c (expand_or_defer_fn): Call gimplify_function_tree.
	* decl.c (finish_function): Don't call c_warn_unused_result.

ada/ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* utils.c (gnat_gimplify_function): Don't call
	gimplify_function_tree.
	* misc.c (gnat_parse_file): Don't call
	cgraph_finalize_compilation_unit.

fortran/ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* trans-decl.c (gfc_gimplify_function): Don't call
	gimplify_function_tree.
	* f95-lang.c (gfc_be_parse_file): Don't call cgraph_optimize or
	cgraph_finalize_compilation_unit.

treelang/ChangeLog:
2007-12-04  Tom Tromey  <tromey@redhat.com>

	* treetree.c (tree_code_create_function_wrapup): Don't call
	gimplify_function_tree.
	* tree1.c (treelang_parse_file): Don't call cgraph_optimize or
	cgraph_finalize_compilation_unit.

Index: java/java-gimplify.c
===================================================================
--- java/java-gimplify.c	(revision 130053)
+++ java/java-gimplify.c	(working copy)
@@ -43,11 +43,6 @@
 java_genericize (tree fndecl)
 {
   dump_java_tree (TDI_original, fndecl);
-
-  /* Genericize with the gimplifier.  */
-  gimplify_function_tree (fndecl);
-
-  dump_function (TDI_generic, fndecl);
 }
 
 /* Gimplify a Java tree.  */
Index: java/jcf-parse.c
===================================================================
--- java/jcf-parse.c	(revision 130546)
+++ java/jcf-parse.c	(working copy)
@@ -1989,11 +1989,6 @@
  finish:
   /* Arrange for any necessary initialization to happen.  */
   java_emit_static_constructor ();
-
-  /* Only finalize the compilation unit after we've told cgraph which
-     functions have their addresses stored.  */
-  cgraph_finalize_compilation_unit ();
-  cgraph_optimize ();
 }
 
 
Index: tree.c
===================================================================
--- tree.c	(revision 130454)
+++ tree.c	(working copy)
@@ -2070,6 +2070,12 @@
       else
 	return false;
 
+      /* FIXME: this is needed for the decl-non-smashing code in the C
+	 FE.  But we should find a different way of handling this
+	 case.  */
+    case VIEW_CONVERT_EXPR:
+      return staticp (TREE_OPERAND (arg, 0));
+
     default:
       if ((unsigned int) TREE_CODE (arg)
 	  >= (unsigned int) LAST_AND_UNUSED_TREE_CODE)
Index: toplev.c
===================================================================
--- toplev.c	(revision 130473)
+++ toplev.c	(working copy)
@@ -1122,10 +1122,18 @@
       init_asm_output (main_input_filename);
     }
   if (flag_unit_at_a_time)
-    (*debug_hooks->set_output_file) (asm_out_file);
+    {
+      (*debug_hooks->set_output_file) (asm_out_file);
+      /* FIXME: this is lame.  */
+#if defined (DWARF2_UNWIND_INFO) || defined (TARGET_UNWIND_INFO)
+      if (write_symbols != DWARF2_DEBUG
+	  && write_symbols != VMS_AND_DWARF2_DEBUG)
+	dwarf2out_ensure_output_file_set (asm_out_file);
+#endif
+    }
 
-  cgraph_finalize_compilation_unit ();
-
+  /* This must also call cgraph_finalize_compilation_unit and
+     cgraph_optimize.  */
   lang_hooks.decls.final_write_globals ();
 
   if (errorcount || sorrycount)
@@ -2151,7 +2159,15 @@
   (*debug_hooks->init) (name);
   dw2_initialize ();
   if (!flag_unit_at_a_time)
-    (*debug_hooks->set_output_file) (asm_out_file);
+    {
+      (*debug_hooks->set_output_file) (asm_out_file);
+      /* FIXME: this is lame.  */
+#if defined (DWARF2_UNWIND_INFO) || defined (TARGET_UNWIND_INFO)
+      if (write_symbols != DWARF2_DEBUG
+	  && write_symbols != VMS_AND_DWARF2_DEBUG)
+	dwarf2out_ensure_output_file_set (asm_out_file);
+#endif
+    }
 
   timevar_pop (TV_SYMOUT);
 
Index: debug.h
===================================================================
--- debug.h	(revision 130053)
+++ debug.h	(working copy)
@@ -158,6 +158,7 @@
 
 /* Dwarf2 frame information.  */
 
+extern void dwarf2out_ensure_output_file_set (FILE *);
 extern void dwarf2out_begin_prologue (unsigned int, const char *);
 extern void dwarf2out_end_epilogue (unsigned int, const char *);
 extern void dwarf2out_frame_init (void);
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 130518)
+++ cp/decl.c	(working copy)
@@ -11629,7 +11629,8 @@
       f->extern_decl_map = NULL;
 
       /* Handle attribute((warn_unused_result)).  Relies on gimple input.  */
-      c_warn_unused_result (&DECL_SAVED_TREE (fndecl));
+      /* FIXME: do this elsewhere.  */
+/*       c_warn_unused_result (&DECL_SAVED_TREE (fndecl)); */
     }
   /* Clear out the bits we don't need.  */
   local_names = NULL;
Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 130518)
+++ cp/semantics.c	(working copy)
@@ -3184,6 +3184,11 @@
       return;
     }
 
+  /* FIXME: we don't want this here -- we want to delay gimplification
+     until tree_lowering_passes.  However, replacing the
+     AGGR_INIT_EXPRs requires gimple.  */
+  gimplify_function_tree (fn);
+
   /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs.  */
   cp_walk_tree_without_duplicates (&DECL_SAVED_TREE (fn),
 				   simplify_aggr_init_exprs_r,
Index: dwarf2out.c
===================================================================
--- dwarf2out.c	(revision 130506)
+++ dwarf2out.c	(working copy)
@@ -14457,6 +14457,13 @@
   seen_decls = htab_create_ggc (20, htab_hash_pointer, htab_eq_pointer, NULL);
 }
 
+void
+dwarf2out_ensure_output_file_set (FILE *out)
+{
+  gcc_assert (!dw_asm_out_file);
+  dw_asm_out_file = out;
+}
+
 /* Set the output file and prepare for writing.  */
 static void
 dwarf2out_set_output_file (FILE *out)
Index: ada/utils.c
===================================================================
--- ada/utils.c	(revision 130518)
+++ ada/utils.c	(working copy)
@@ -2154,8 +2154,6 @@
   struct cgraph_node *cgn;
 
   dump_function (TDI_original, fndecl);
-  gimplify_function_tree (fndecl);
-  dump_function (TDI_generic, fndecl);
 
   /* Convert all nested functions to GIMPLE now.  We do things in this order
      so that items like VLA sizes are expanded properly in the context of the
Index: ada/misc.c
===================================================================
--- ada/misc.c	(revision 130518)
+++ ada/misc.c	(working copy)
@@ -240,9 +240,6 @@
 
   /* Call the front end.  */
   _ada_gnat1drv ();
-
-  /* We always have a single compilation unit in Ada.  */
-  cgraph_finalize_compilation_unit ();
 }
 
 /* Decode all the language specific options that cannot be decoded by GCC.
Index: fortran/f95-lang.c
===================================================================
--- fortran/f95-lang.c	(revision 130546)
+++ fortran/f95-lang.c	(working copy)
@@ -303,9 +303,6 @@
   gfc_parse_file ();
   gfc_generate_constructors ();
 
-  cgraph_finalize_compilation_unit ();
-  cgraph_optimize ();
-
   /* Tell the frontent about any errors.  */
   gfc_get_errors (&warnings, &errors);
   errorcount += errors;
Index: fortran/trans-decl.c
===================================================================
--- fortran/trans-decl.c	(revision 130518)
+++ fortran/trans-decl.c	(working copy)
@@ -1543,6 +1543,7 @@
 {
   struct cgraph_node *cgn;
 
+#if 0
   gimplify_function_tree (fndecl);
   dump_function (TDI_generic, fndecl);
 
@@ -1550,6 +1551,7 @@
   /* ??? Could be done as part of resolve_labels.  */
   if (flag_openmp)
     diagnose_omp_structured_block_errors (fndecl);
+#endif
 
   /* Convert all nested functions to GIMPLE now.  We do things in this order
      so that items like VLA sizes are expanded properly in the context of the
Index: langhooks.c
===================================================================
--- langhooks.c	(revision 130053)
+++ langhooks.c	(working copy)
@@ -37,6 +37,7 @@
 #include "langhooks-def.h"
 #include "ggc.h"
 #include "diagnostic.h"
+#include "cgraph.h"
 
 /* Do nothing; in many cases the default hook.  */
 
@@ -362,15 +363,21 @@
 void
 write_global_declarations (void)
 {
+  tree globals, decl, *vec;
+  int len, i;
+
+  /* This lang hook is dual-purposed, and also finalizes the
+     compilation unit.  */
+  cgraph_finalize_compilation_unit ();
+  cgraph_optimize ();
+
   /* Really define vars that have had only a tentative definition.
      Really output inline functions that must actually be callable
      and have not been output so far.  */
 
-  tree globals = lang_hooks.decls.getdecls ();
-  int len = list_length (globals);
-  tree *vec = XNEWVEC (tree, len);
-  int i;
-  tree decl;
+  globals = lang_hooks.decls.getdecls ();
+  len = list_length (globals);
+  vec = XNEWVEC (tree, len);
 
   /* Process the decls in reverse order--earliest first.
      Put them into VEC from back to front, then take out from front.  */
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 130053)
+++ gimplify.c	(working copy)
@@ -6465,10 +6465,14 @@
 gimplify_function_tree (tree fndecl)
 {
   tree oldfn, parm, ret;
+  struct function *fun;
 
+  fun = DECL_STRUCT_FUNCTION (fndecl);
+  if (fun && fun->gimplified)
+    return;
   oldfn = current_function_decl;
   current_function_decl = fndecl;
-  cfun = DECL_STRUCT_FUNCTION (fndecl);
+  cfun = fun;
   if (cfun == NULL)
     allocate_struct_function (fndecl);
 
Index: treelang/treetree.c
===================================================================
--- treelang/treetree.c	(revision 130518)
+++ treelang/treetree.c	(working copy)
@@ -470,10 +470,6 @@
   /* Dump the original tree to a file.  */
   dump_function (TDI_original, fn_decl);
 
-  /* Convert current function to GIMPLE for the middle end.  */
-  gimplify_function_tree (fn_decl);
-  dump_function (TDI_generic, fn_decl);
-
   /* We are not inside of any scope now.  */
   current_function_decl = NULL_TREE;
   cfun = NULL;
Index: treelang/tree1.c
===================================================================
--- treelang/tree1.c	(revision 130546)
+++ treelang/tree1.c	(working copy)
@@ -199,11 +199,9 @@
 
   treelang_debug ();
   yyparse ();
-  cgraph_finalize_compilation_unit ();
 #ifdef USE_MAPPED_LOCATION
   linemap_add (&line_table, LC_LEAVE, false, false, NULL, 0);
 #endif
-  cgraph_optimize ();
 }
 
 /* Allocate SIZE bytes and clear them.  Not to be used for strings
Index: tree-optimize.c
===================================================================
--- tree-optimize.c	(revision 130053)
+++ tree-optimize.c	(working copy)
@@ -355,7 +355,10 @@
   current_function_decl = fn;
   push_cfun (DECL_STRUCT_FUNCTION (fn));
   tree_register_cfg_hooks ();
+
   gimplify_function_tree (fn);
+  dump_function (TDI_generic, fn);
+
   bitmap_obstack_initialize (NULL);
   execute_pass_list (all_lowering_passes);
   if (optimize && cgraph_global_info_ready)
Index: c-gimplify.c
===================================================================
--- c-gimplify.c	(revision 130053)
+++ c-gimplify.c	(working copy)
@@ -101,9 +101,6 @@
       dump_end (TDI_original, dump_orig);
     }
 
-  /* Dump the genericized tree IR.  */
-  dump_function (TDI_generic, fndecl);
-
   /* Genericize all nested functions now.  We do things in this order so
      that items like VLA sizes are expanded properly in the context of
      the correct function.  */


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