Makefile.in (c-lang.o): Depend on $(VARRAY_H).
authorAlexandre Oliva <aoliva@redhat.com>
Mon, 12 Nov 2001 00:02:36 +0000 (00:02 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Mon, 12 Nov 2001 00:02:36 +0000 (00:02 +0000)
* Makefile.in (c-lang.o): Depend on $(VARRAY_H).
* c-decl.c (c_expand_body): Take argument can_defer_p.  Use it
to decide whether to defer a function.
(finish_function): Adjust.
(c_expand_deferred_function): New function.
* c-lang.c (deferred_fns): New variable.
(c_init): Initialize it, and mark it as a root.
(defer_fn): New function.
(finish_file): Expand all deferred functions.
* c-tree.h (defer_fn): Declare.
(c_expand_deferred_function): Likewise.
* objc/Make-lang.in (objc-act.o): Depend on $(VARRAY_H).
* objc-act.c (deferred_fns): New variable.
(objc_init): Initialize it, and mark it as a root.
(defer_fn): New function.
(finish_file): Expand all deferred functions.

From-SVN: r46933

gcc/ChangeLog
gcc/Makefile.in
gcc/c-decl.c
gcc/c-lang.c
gcc/c-tree.h
gcc/objc/Make-lang.in
gcc/objc/objc-act.c

index 70d51f37ea527da173a1f8bb3db3062f78a2ce91..675e489b3890a5b488d88ea7555450cd8708b4cf 100644 (file)
@@ -1,3 +1,22 @@
+2001-11-11  Alexandre Oliva  <aoliva@redhat.com>
+
+       * Makefile.in (c-lang.o): Depend on $(VARRAY_H).
+       * c-decl.c (c_expand_body): Take argument can_defer_p.  Use it
+       to decide whether to defer a function.
+       (finish_function): Adjust.
+       (c_expand_deferred_function): New function.
+       * c-lang.c (deferred_fns): New variable.
+       (c_init): Initialize it, and mark it as a root.
+       (defer_fn): New function.
+       (finish_file): Expand all deferred functions.
+       * c-tree.h (defer_fn): Declare.
+       (c_expand_deferred_function): Likewise.
+       * objc/Make-lang.in (objc-act.o): Depend on $(VARRAY_H).
+       * objc-act.c (deferred_fns): New variable.
+       (objc_init): Initialize it, and mark it as a root.
+       (defer_fn): New function.
+       (finish_file): Expand all deferred functions.
+
 2001-11-11  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * alpha.c (unicosmk_special_name): Prototype.
index 2112a0734df2d3429dfbce5fa5cef0b3118af69b..c75dcd88da38e67e968a5a29900a182706e5141a 100644 (file)
@@ -1169,7 +1169,7 @@ c-decl.o : c-decl.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) $(C_TREE_H) \
 c-typeck.o : c-typeck.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
     $(TARGET_H) flags.h intl.h output.h $(EXPR_H) $(RTL_H) toplev.h $(TM_P_H)
 c-lang.o : c-lang.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
-    $(GGC_H)  c-lex.h toplev.h diagnostic.h output.h function.h \
+    $(GGC_H) c-lex.h toplev.h diagnostic.h output.h function.h $(VARRAY_H) \
     $(RTL_H) $(EXPR_H) tree-inline.h insn-config.h integrate.h langhooks.h \
     langhooks-def.h
 c-lex.o : c-lex.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(RTL_H) c-lex.h \
index 8f8edf4e98c3f9da6585693ce52ab018e9b93103..0e4cf0c6b52322fd3789fde7f459c1b151b832ef 100644 (file)
@@ -279,7 +279,7 @@ static tree grokdeclarator          PARAMS ((tree, tree, enum decl_context,
 static tree grokparms                  PARAMS ((tree, int));
 static void layout_array_type          PARAMS ((tree));
 static tree c_make_fname_decl           PARAMS ((tree, int));
-static void c_expand_body               PARAMS ((tree, int));
+static void c_expand_body               PARAMS ((tree, int, int));
 \f
 /* C-specific option variables.  */
 
@@ -6748,7 +6748,7 @@ finish_function (nested)
   if (! nested)
     {
       /* Generate RTL for the body of this function.  */
-      c_expand_body (fndecl, nested);
+      c_expand_body (fndecl, nested, 1);
       /* Let the error reporting routines know that we're outside a
         function.  For a nested function, this value is used in
         pop_c_function_context and then reset via pop_function_context.  */
@@ -6756,14 +6756,25 @@ finish_function (nested)
     }
 }
 
+/* Generate the RTL for a deferred function FNDECL.  */
+
+void
+c_expand_deferred_function (fndecl)
+     tree fndecl;
+{
+  c_expand_body (fndecl, 0, 0);
+  current_function_decl = NULL;
+}
+
 /* Generate the RTL for the body of FNDECL.  If NESTED_P is non-zero,
    then we are already in the process of generating RTL for another
-   function.  */
+   function.  If can_defer_p is zero, we won't attempt to defer the
+   generation of RTL.  */
 
 static void
-c_expand_body (fndecl, nested_p)
+c_expand_body (fndecl, nested_p, can_defer_p)
      tree fndecl;
-     int nested_p;
+     int nested_p, can_defer_p;
 {
   int uninlinable = 1;
 
@@ -6781,6 +6792,17 @@ c_expand_body (fndecl, nested_p)
          function completely.  */
       uninlinable = ! tree_inlinable_function_p (fndecl);
       
+      if (! uninlinable && can_defer_p
+         /* Save function tree for inlining.  Should return 0 if the
+             language does not support function deferring or the
+             function could not be deferred.  */
+         && defer_fn (fndecl))
+       {
+         /* Let the back-end know that this funtion exists.  */
+         (*debug_hooks->deferred_inline_function) (fndecl);
+         return;
+       }
+      
       /* Then, inline any functions called in it.  */
       optimize_inline_calls (fndecl);
     }
@@ -7202,7 +7224,7 @@ c_expand_decl_stmt (t)
   if (TREE_CODE (decl) == FUNCTION_DECL
       && DECL_CONTEXT (decl) == current_function_decl
       && DECL_SAVED_TREE (decl))
-    c_expand_body (decl, /*nested_p=*/1);
+    c_expand_body (decl, /*nested_p=*/1, /*can_defer_p=*/0);
 }
 
 /* Return the IDENTIFIER_GLOBAL_VALUE of T, for use in common code, since
index 67c860b790025f4f1fac0cd4f3b362cd073fe2fa..d6644582fba9138a915170d6394905e036892201 100644 (file)
@@ -38,6 +38,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "cpplib.h"
 #include "insn-config.h"
 #include "integrate.h"
+#include "varray.h"
 #include "langhooks.h"
 #include "langhooks-def.h"
 
@@ -79,6 +80,8 @@ static int c_cannot_inline_tree_fn PARAMS ((tree *));
 /* Each front end provides its own.  */
 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
 
+static varray_type deferred_fns;
+
 /* Post-switch processing.  */
 static void
 c_post_options ()
@@ -136,6 +139,9 @@ c_init ()
   lang_missing_noreturn_ok_p = &c_missing_noreturn_ok_p;
 
   c_parse_init ();
+
+  VARRAY_TREE_INIT (deferred_fns, 32, "deferred_fns");
+  ggc_add_tree_varray_root (&deferred_fns, 1);
 }
 
 /* Used by c-lex.c, but only for objc.  */
@@ -242,11 +248,33 @@ finish_cdtor (body)
 }
 #endif
 
+/* Register a function tree, so that its optimization and conversion
+   to RTL is only done at the end of the compilation.  */
+
+int
+defer_fn (fn)
+     tree fn;
+{
+  VARRAY_PUSH_TREE (deferred_fns, fn);
+
+  return 1;
+}
+
 /* Called at end of parsing, but before end-of-file processing.  */
 
 void
 finish_file ()
 {
+  int i;
+
+  for (i = 0; i < VARRAY_ACTIVE_SIZE (deferred_fns); i++)
+    /* Don't output the same function twice.  We may run into such
+       situations when an extern inline function is later given a
+       non-extern-inline definition.  */
+    if (! TREE_ASM_WRITTEN (VARRAY_TREE (deferred_fns, i)))
+      c_expand_deferred_function (VARRAY_TREE (deferred_fns, i));
+  VARRAY_FREE (deferred_fns);
+
 #ifndef ASM_OUTPUT_CONSTRUCTOR
   if (static_ctors)
     {
index acde94ec2c50149539aa56d98dd29a38320cc7db..19e5b03a79e76d7b32289196298074b5002ddc1a 100644 (file)
@@ -152,6 +152,8 @@ extern int maybe_objc_comptypes                 PARAMS ((tree, tree, int));
 extern tree maybe_building_objc_message_expr    PARAMS ((void));
 extern int recognize_objc_keyword              PARAMS ((void));
 extern tree lookup_objc_ivar                   PARAMS ((tree));
+/* in c-lang.c and objc/objc-act.c */
+extern int defer_fn                            PARAMS ((tree));
 \f
 /* in c-parse.in */
 extern void c_parse_init                       PARAMS ((void));
@@ -219,6 +221,7 @@ extern tree start_struct                        PARAMS ((enum tree_code, tree));
 extern void store_parm_decls                    PARAMS ((void));
 extern tree xref_tag                            PARAMS ((enum tree_code, tree));
 extern tree c_begin_compound_stmt               PARAMS ((void));
+extern void c_expand_deferred_function          PARAMS ((tree));
 extern void c_expand_decl_stmt                  PARAMS ((tree));
 
 /* in c-typeck.c */
index 9b777d4289da9fb78182721a84fc5da6f113afc0..5fec773a994dab69f07c08e94fc88f292d5e86de 100644 (file)
@@ -78,7 +78,7 @@ $(srcdir)/objc/objc-parse.y: $(srcdir)/c-parse.in
 
 objc-act.o : $(srcdir)/objc/objc-act.c \
    $(CONFIG_H) $(TREE_H) $(RTL_H) $(SYSTEM_H) $(EXPR_H) $(TARGET_H) \
-   $(srcdir)/c-tree.h $(srcdir)/c-common.h $(srcdir)/c-lex.h \
+   $(srcdir)/c-tree.h $(srcdir)/c-common.h $(srcdir)/c-lex.h $(VARRAY_H) \
    $(srcdir)/toplev.h $(srcdir)/flags.h $(srcdir)/objc/objc-act.h \
    $(srcdir)/input.h $(srcdir)/function.h $(srcdir)/output.h $(srcdir)/debug.h \
    $(srcdir)/langhooks.h $(srcdir)/langhooks-def.h
index fa2842eda6e96525f3268016cc7352fa52ab3c7c..2d345882c2de6cb7902febf22a0742a5e7ea31ba 100644 (file)
@@ -58,6 +58,7 @@ Boston, MA 02111-1307, USA.  */
 #include "cpplib.h"
 #include "debug.h"
 #include "target.h"
+#include "varray.h"
 #include "langhooks.h"
 #include "langhooks-def.h"
 
@@ -469,6 +470,8 @@ static int print_struct_values = 0;
 /* Each front end provides its own.  */
 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
 
+static varray_type deferred_fns;
+
 /* Post-switch processing.  */
 static void
 objc_post_options ()
@@ -593,11 +596,36 @@ objc_init ()
 
   objc_act_parse_init ();
   c_parse_init ();
+
+  VARRAY_TREE_INIT (deferred_fns, 32, "deferred_fns");
+  ggc_add_tree_varray_root (&deferred_fns, 1);
+}
+
+/* Register a function tree, so that its optimization and conversion
+   to RTL is only done at the end of the compilation.  */
+
+int
+defer_fn (fn)
+     tree fn;
+{
+  VARRAY_PUSH_TREE (deferred_fns, fn);
+
+  return 1;
 }
 
 void
 finish_file ()
 {
+  int i;
+
+  for (i = 0; i < VARRAY_ACTIVE_SIZE (deferred_fns); i++)
+    /* Don't output the same function twice.  We may run into such
+       situations when an extern inline function is later given a
+       non-extern-inline definition.  */
+    if (! TREE_ASM_WRITTEN (VARRAY_TREE (deferred_fns, i)))
+      c_expand_deferred_function (VARRAY_TREE (deferred_fns, i));
+  VARRAY_FREE (deferred_fns);
+
   finish_objc ();              /* Objective-C finalization */
 
   if (gen_declaration_file)