public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [tuples] Fix GC problems during lowering
@ 2007-08-09 23:55 Diego Novillo
  0 siblings, 0 replies; only message in thread
From: Diego Novillo @ 2007-08-09 23:55 UTC (permalink / raw)
  To: gcc-patches, Aldy Hernandez

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]


This patch fixes the GC problems with the gimple bodies.  The gimple
bodies are now in a GC'd VEC and a separate pointer map is used to
quickly find a body given a FUNCTION_DECL.

While this fixes the GC problem, we still cannot enable lowering because
the unnesting of functions still has not been converted.  So, we can
lower all of compile.exp but fail every test with nested functions.

Aldy, I have not enabled lowering so yet to avoid all the new failures.
I will fix the unnester and enable it.  Probably tomorrow.  I also
haven't included the other changes to GIMPLE_CALL flags.  I kept those
patches for now.

[-- Attachment #2: 20070809-fix-lowering.diff --]
[-- Type: text/x-patch, Size: 7017 bytes --]

2007-08-09  Diego Novillo  <dnovillo@google.com>

	* gimple-low.c: Document conversion to Low GIMPLE.
	* Makefile.in (gimple.o): Add dependency on gt-gimple.h
	(GTFILES): Add gimple.c.
	* gimple.c (gimple_bodies_vec): New.
	(gimple_bodies_map): Rename from gimple_bodies.
	(gss_for_code): Return GSS_ASM for GIMPLE_ASM.
	(walk_tuple_ops): Handle GSS_ASM like GSS_WITH_OPS.
	(set_gimple_body): Push body into gimple_bodies_vec and create
	a mapping to array index in gimple_bodies_map.
	(gimple_body): Corresponding changes to use gimple_bodies_map
	and gimple_bodies_vec.
	* gimple.h: Create VEC templates for gimple_seq.

Index: gimple-low.c
===================================================================
--- gimple-low.c	(revision 127303)
+++ gimple-low.c	(working copy)
@@ -1,4 +1,4 @@
-/* Tree lowering pass.  Lowers GIMPLE into unstructured form.
+/* GIMPLE lowering pass.  Converts High GIMPLE into Low GIMPLE.
 
    Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
@@ -40,16 +40,21 @@ along with GCC; see the file COPYING3.  
 #include "toplev.h"
 #include "tree-pass.h"
 
-/* FIXME tuples: vec.h says:
+/* The differences between High GIMPLE and Low GIMPLE are the
+   following:
 
-   Due to the way GTY works, you must annotate
-   any structures you wish to insert or reference from a vector with a
-   GTY(()) tag.  You need to do this even if you never declare the GC
-   allocated variants.
+   1- Lexical scopes are removed (i.e., GIMPLE_BIND disappears).
 
-   Does this mean we need to GTY mark both struct return_statements_t
-   and struct lower_data.
-   ?? */
+   2- GIMPLE_TRY and GIMPLE_CATCH are converted to abnormal control
+      flow and exception regions are built as an on-the-side region
+      hierarchy (See tree-eh.c:lower_eh_constructs).
+
+   3- Multiple identical return statements are grouped into a single
+      return and gotos to the unique return site.  */
+
+/* Match a return statement with a label.  During lowering, we identify
+   identical return statements and replace duplicates with a jump to
+   the corresponding label.  */
 struct return_statements_t
 {
   tree label;
@@ -78,7 +83,9 @@ static void lower_gimple_bind (gimple_st
 static void lower_gimple_return (gimple_stmt_iterator *, struct lower_data *);
 static void lower_builtin_setjmp (gimple_stmt_iterator *);
 
-/* Lower the body of current_function_decl.  */
+
+/* Lower the body of current_function_decl from High GIMPLE into Low
+   GIMPLE.  */
 
 static unsigned int
 lower_function_body (void)
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 127303)
+++ Makefile.in	(working copy)
@@ -2263,7 +2263,7 @@ tree-gimple.o : tree-gimple.c $(CONFIG_H
    $(RTL_H) $(TREE_GIMPLE_H) $(TM_H) coretypes.h bitmap.h $(GGC_H) \
    output.h $(TREE_FLOW_H)
 gimple.o : gimple.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TREE_H) \
-   $(GGC_H) $(TREE_GIMPLE_H) $(GIMPLE_H) $(DIAGNOSTIC_H)
+   $(GGC_H) $(TREE_GIMPLE_H) $(GIMPLE_H) $(DIAGNOSTIC_H) gt-gimple.h
 gimple-pretty-print.o : gimple-pretty-print.c $(CONFIG_H) $(SYSTEM_H) \
    $(TREE_H) $(DIAGNOSTIC_H) $(REAL_H) $(HASHTAB_H) $(TREE_FLOW_H) \
    $(TM_H) coretypes.h tree-pass.h $(GIMPLE_H)
@@ -3080,7 +3080,7 @@ GTFILES = $(srcdir)/input.h $(srcdir)/co
   $(srcdir)/tree-ssa-structalias.c \
   $(srcdir)/omp-low.c $(srcdir)/varpool.c \
   $(srcdir)/targhooks.c $(out_file) $(srcdir)/passes.c $(srcdir)/cgraphunit.c \
-  $(srcdir)/gimple.h \
+  $(srcdir)/gimple.h $(srcdir)/gimple.c \
   @all_gtfiles@
 
 GTFILES_H = $(subst /,-, $(subst $(srcdir)/,gt-, $(subst .c,.h, \
Index: gimple.c
===================================================================
--- gimple.c	(revision 127303)
+++ gimple.c	(working copy)
@@ -36,11 +36,11 @@ const char *const gimple_code_name[] = {
 };
 #undef DEFGSCODE
 
-/* Pointer map to store the sequence of GIMPLE statements
-   corresponding to each function.  For every FUNCTION_DECL FN, the
-   sequence of GIMPLE statements corresponding to FN are stored in
-   gimple_body (FN).  */
-static struct pointer_map_t *gimple_bodies = NULL;
+/* Keep function bodies in the array GIMPLE_BODIES_VEC and use the
+   pointer map GIMPLE_BODIES_MAP to quickly map a given FUNCTION_DECL
+   to its corresponding position in the array of GIMPLE bodies.  */
+static GTY(()) VEC(gimple_seq,gc) *gimple_bodies_vec;
+static struct pointer_map_t *gimple_bodies_map;
 
 /* Gimple tuple constructors.
    Note: Any constructor taking a ``gimple_seq'' as a parameter, can
@@ -64,12 +64,12 @@ gss_for_code (enum gimple_code code)
     {
     case GIMPLE_ASSIGN:
     case GIMPLE_CALL:
-    case GIMPLE_ASM:
     case GIMPLE_RETURN:		return GSS_WITH_MEM_OPS;
     case GIMPLE_COND:
     case GIMPLE_GOTO:
     case GIMPLE_LABEL:
     case GIMPLE_SWITCH:		return GSS_WITH_OPS;
+    case GIMPLE_ASM:		return GSS_ASM;
     case GIMPLE_BIND:		return GSS_BIND;
     case GIMPLE_CATCH:		return GSS_CATCH;
     case GIMPLE_EH_FILTER:	return GSS_EH_FILTER;
@@ -911,7 +911,7 @@ walk_tuple_ops (gimple gs, walk_tree_fn 
   enum gimple_statement_structure_enum gss;
 
   gss = gimple_statement_structure (gs);
-  if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS)
+  if (gss == GSS_WITH_OPS || gss == GSS_WITH_MEM_OPS || gss == GSS_ASM)
     for (i = 0; i < gimple_num_ops (gs); i++)
       WALKIT (gimple_op (gs, i));
   else
@@ -1001,12 +1001,23 @@ void
 set_gimple_body (tree fn, gimple_seq seq)
 {
   void **slot;
+  size_t index;
 
-  if (gimple_bodies == NULL)
-    gimple_bodies = pointer_map_create ();
+  if (gimple_bodies_map == NULL)
+    gimple_bodies_map = pointer_map_create ();
 
-  slot = pointer_map_insert (gimple_bodies, fn);
-  *slot = (void *) seq;
+  slot = pointer_map_insert (gimple_bodies_map, fn);
+  if (*slot == NULL)
+    {
+      VEC_safe_push (gimple, gc, gimple_bodies_vec, seq);
+      index = VEC_length (gimple, gimple_bodies_vec) - 1;
+      *slot = (void *) index;
+    }
+  else
+    {
+      index = (size_t) *slot;
+      VEC_replace (gimple, gimple_bodies_vec, index, seq);
+    }
 }
   
 
@@ -1016,9 +1027,13 @@ gimple_seq
 gimple_body (tree fn)
 {
   void **slot;
-  
-  if (gimple_bodies && (slot = pointer_map_contains (gimple_bodies, fn)))
-    return (gimple_seq) *slot;
+
+  if (gimple_bodies_map
+      && (slot = pointer_map_contains (gimple_bodies_map, fn)))
+    {
+      size_t ix = (size_t) *slot;
+      return VEC_index (gimple, gimple_bodies_vec, ix);
+    }
   
   return NULL;
 }
@@ -1048,3 +1063,5 @@ gimple_call_flags (gimple stmt)
 
   return flags;
 }
+
+#include "gt-gimple.h"
Index: gimple.h
===================================================================
--- gimple.h	(revision 127303)
+++ gimple.h	(working copy)
@@ -29,6 +29,10 @@ DEF_VEC_P(gimple);
 DEF_VEC_ALLOC_P(gimple,heap);
 DEF_VEC_ALLOC_P(gimple,gc);
 
+DEF_VEC_P(gimple_seq);
+DEF_VEC_ALLOC_P(gimple_seq,gc);
+DEF_VEC_ALLOC_P(gimple_seq,heap);
+
 enum gimple_code {
 #define DEFGSCODE(SYM, STRING)	SYM,
 #include "gimple.def"

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-08-09 23:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-09 23:55 [tuples] Fix GC problems during lowering Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).