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]

tidy creation of struct function


Things are now split up so that 

  - allocate_struct_function allocates and initializes struct function,
    sets cfun, and does nothing else.

  - prepare_function_start calls allocate_struct_function, if needed,
    and also initializes other rtl state variables not present in
    struct function.

  - init_function_start calls prepare_function_start and then starts
    emitting actual rtl, such as notes.

I have a use for allocate_struct_function shortly...


r~


        * function.c (allocate_struct_function): New, split out of ...
        (prepare_function_start, init_function_start): ... here.
        * expr.c (init_expr): Use ggc_alloc_cleared.
        * stmt.c (init_stmt_for_function): Likewise.
        * tree.h (allocate_struct_function): Declare.

Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.579
diff -u -p -r1.579 expr.c
--- expr.c	26 Aug 2003 08:51:27 -0000	1.579
+++ expr.c	29 Aug 2003 22:00:52 -0000
@@ -338,15 +338,7 @@ init_expr_once (void)
 void
 init_expr (void)
 {
-  cfun->expr = ggc_alloc (sizeof (struct expr_status));
-
-  pending_chain = 0;
-  pending_stack_adjust = 0;
-  stack_pointer_delta = 0;
-  inhibit_defer_pop = 0;
-  saveregs_value = 0;
-  apply_args_value = 0;
-  forced_labels = 0;
+  cfun->expr = ggc_alloc_cleared (sizeof (struct expr_status));
 }
 
 /* Small sanity check that the queue is empty at the end of a function.  */
Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.451
diff -u -p -r1.451 function.c
--- function.c	27 Aug 2003 07:05:16 -0000	1.451
+++ function.c	29 Aug 2003 22:00:58 -0000
@@ -284,7 +284,7 @@ static hashval_t insns_for_mem_hash (con
 static int insns_for_mem_comp (const void *, const void *);
 static int insns_for_mem_walk (rtx *, void *);
 static void compute_insns_for_mem (rtx, rtx, htab_t);
-static void prepare_function_start (void);
+static void prepare_function_start (tree);
 static void do_clobber_return_reg (rtx, void *);
 static void do_use_return_reg (rtx, void *);
 static void instantiate_virtual_regs_lossage (rtx);
@@ -6246,103 +6246,77 @@ debug_find_var_in_block_tree (tree var, 
   return NULL_TREE;
 }
 
-/* Allocate a function structure and reset its contents to the defaults.  */
+/* Allocate a function structure for FNDECL and set its contents
+   to the defaults.  */
 
-static void
-prepare_function_start (void)
+void
+allocate_struct_function (tree fndecl)
 {
-  cfun = ggc_alloc_cleared (sizeof (struct function));
-
-  init_stmt_for_function ();
-  init_eh_for_function ();
-
-  cse_not_expected = ! optimize;
-
-  /* Caller save not needed yet.  */
-  caller_save_needed = 0;
-
-  /* No stack slots have been made yet.  */
-  stack_slot_list = 0;
+  tree result;
 
-  current_function_has_nonlocal_label = 0;
-  current_function_has_nonlocal_goto = 0;
+  cfun = ggc_alloc_cleared (sizeof (struct function));
 
-  /* There is no stack slot for handling nonlocal gotos.  */
-  nonlocal_goto_handler_slots = 0;
-  nonlocal_goto_stack_level = 0;
+  max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
 
-  /* No labels have been declared for nonlocal use.  */
-  nonlocal_labels = 0;
-  nonlocal_goto_handler_labels = 0;
+  cfun->stack_alignment_needed = STACK_BOUNDARY;
+  cfun->preferred_stack_boundary = STACK_BOUNDARY;
 
-  /* No function calls so far in this function.  */
-  function_call_count = 0;
+  current_function_funcdef_no = funcdef_no++;
 
-  /* No parm regs have been allocated.
-     (This is important for output_inline_function.)  */
-  max_parm_reg = LAST_VIRTUAL_REGISTER + 1;
+  cfun->function_frequency = FUNCTION_FREQUENCY_NORMAL;
 
-  /* Initialize the RTL mechanism.  */
+  init_stmt_for_function ();
+  init_eh_for_function ();
   init_emit ();
-
-  /* Initialize the queue of pending postincrement and postdecrements,
-     and some other info in expr.c.  */
   init_expr ();
+  init_varasm_status (cfun);
 
-  /* We haven't done register allocation yet.  */
-  reg_renumber = 0;
+  (*lang_hooks.function.init) (cfun);
+  if (init_machine_status)
+    cfun->machine = (*init_machine_status) ();
 
-  init_varasm_status (cfun);
+  if (fndecl == NULL)
+    return;
 
-  /* Clear out data used for inlining.  */
-  cfun->inlinable = 0;
-  cfun->original_decl_initial = 0;
-  cfun->original_arg_vector = 0;
+  DECL_SAVED_INSNS (fndecl) = cfun;
+  cfun->decl = fndecl;
 
-  cfun->stack_alignment_needed = STACK_BOUNDARY;
-  cfun->preferred_stack_boundary = STACK_BOUNDARY;
+  current_function_name = (*lang_hooks.decl_printable_name) (fndecl, 2);
 
-  /* Set if a call to setjmp is seen.  */
-  current_function_calls_setjmp = 0;
+  result = DECL_RESULT (fndecl);
+  if (aggregate_value_p (result))
+    {
+#ifdef PCC_STATIC_STRUCT_RETURN
+      current_function_returns_pcc_struct = 1;
+#endif
+      current_function_returns_struct = 1;
+    }
 
-  /* Set if a call to longjmp is seen.  */
-  current_function_calls_longjmp = 0;
+  current_function_returns_pointer = POINTER_TYPE_P (TREE_TYPE (result));
 
-  current_function_calls_alloca = 0;
-  current_function_calls_eh_return = 0;
-  current_function_calls_constant_p = 0;
-  current_function_contains_functions = 0;
-  current_function_is_leaf = 0;
-  current_function_nothrow = 0;
-  current_function_sp_is_unchanging = 0;
-  current_function_uses_only_leaf_regs = 0;
-  current_function_has_computed_jump = 0;
-  current_function_is_thunk = 0;
-
-  current_function_returns_pcc_struct = 0;
-  current_function_returns_struct = 0;
-  current_function_epilogue_delay_list = 0;
-  current_function_uses_const_pool = 0;
-  current_function_uses_pic_offset_table = 0;
-  current_function_cannot_inline = 0;
-
-  /* We have not yet needed to make a label to jump to for tail-recursion.  */
-  tail_recursion_label = 0;
-
-  /* We haven't had a need to make a save area for ap yet.  */
-  arg_pointer_save_area = 0;
-
-  /* No stack slots allocated yet.  */
-  frame_offset = 0;
+  current_function_needs_context
+    = (decl_function_context (current_function_decl) != 0
+       && ! DECL_NO_STATIC_CHAIN (current_function_decl));
+}
+
+/* Reset cfun, and other non-struct-function variables to defaults as
+   appropriate for emiiting rtl at the start of a function.  */
+
+static void
+prepare_function_start (tree fndecl)
+{
+  if (fndecl && DECL_SAVED_INSNS (fndecl))
+    cfun = DECL_SAVED_INSNS (fndecl);
+  else
+    allocate_struct_function (fndecl);
 
-  /* No SAVE_EXPRs in this function yet.  */
-  save_expr_regs = 0;
+  cse_not_expected = ! optimize;
 
-  /* No RTL_EXPRs in this function yet.  */
-  rtl_expr_chain = 0;
+  /* Caller save not needed yet.  */
+  caller_save_needed = 0;
 
-  /* Set up to allocate temporaries.  */
-  init_temp_slots ();
+  /* We haven't done register allocation yet.  */
+  reg_renumber = 0;
 
   /* Indicate that we need to distinguish between the return value of the
      present function and the return value of a function being called.  */
@@ -6356,27 +6330,6 @@ prepare_function_start (void)
 
   /* Indicate we have no need of a frame pointer yet.  */
   frame_pointer_needed = 0;
-
-  /* By default assume not stdarg.  */
-  current_function_stdarg = 0;
-
-  /* We haven't made any trampolines for this function yet.  */
-  trampoline_list = 0;
-
-  init_pending_stack_adjust ();
-  inhibit_defer_pop = 0;
-
-  current_function_outgoing_args_size = 0;
-
-  current_function_funcdef_no = funcdef_no++;
-
-  cfun->function_frequency = FUNCTION_FREQUENCY_NORMAL;
-
-  cfun->max_jumptable_ents = 0;
-
-  (*lang_hooks.function.init) (cfun);
-  if (init_machine_status)
-    cfun->machine = (*init_machine_status) ();
 }
 
 /* Initialize the rtl expansion mechanism so that we can do simple things
@@ -6385,7 +6338,7 @@ prepare_function_start (void)
 void
 init_dummy_function_start (void)
 {
-  prepare_function_start ();
+  prepare_function_start (NULL);
 }
 
 /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
@@ -6395,16 +6348,7 @@ init_dummy_function_start (void)
 void
 init_function_start (tree subr)
 {
-  prepare_function_start ();
-
-  current_function_name = (*lang_hooks.decl_printable_name) (subr, 2);
-  cfun->decl = subr;
-
-  /* Nonzero if this is a nested function that uses a static chain.  */
-
-  current_function_needs_context
-    = (decl_function_context (current_function_decl) != 0
-       && ! DECL_NO_STATIC_CHAIN (current_function_decl));
+  prepare_function_start (subr);
 
   /* Within function body, compute a type's size as soon it is laid out.  */
   immediate_size_expand++;
@@ -6421,23 +6365,11 @@ init_function_start (tree subr)
      Also, final expects a note to appear there.  */
   emit_note (NOTE_INSN_DELETED);
 
-  /* Set flags used by final.c.  */
-  if (aggregate_value_p (DECL_RESULT (subr)))
-    {
-#ifdef PCC_STATIC_STRUCT_RETURN
-      current_function_returns_pcc_struct = 1;
-#endif
-      current_function_returns_struct = 1;
-    }
-
   /* Warn if this value is an aggregate type,
      regardless of which calling convention we are using for it.  */
   if (warn_aggregate_return
       && AGGREGATE_TYPE_P (TREE_TYPE (DECL_RESULT (subr))))
     warning ("function returns an aggregate");
-
-  current_function_returns_pointer
-    = POINTER_TYPE_P (TREE_TYPE (DECL_RESULT (subr)));
 }
 
 /* Make sure all values used by the optimization passes have sane
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.325
diff -u -p -r1.325 stmt.c
--- stmt.c	16 Aug 2003 13:32:03 -0000	1.325
+++ stmt.c	29 Aug 2003 22:01:09 -0000
@@ -433,25 +433,7 @@ using_eh_for_cleanups (void)
 void
 init_stmt_for_function (void)
 {
-  cfun->stmt =ggc_alloc (sizeof (struct stmt_status));
-
-  /* We are not currently within any block, conditional, loop or case.  */
-  block_stack = 0;
-  stack_block_stack = 0;
-  loop_stack = 0;
-  case_stack = 0;
-  cond_stack = 0;
-  nesting_stack = 0;
-  nesting_depth = 0;
-
-  current_block_start_count = 0;
-
-  /* No gotos have been expanded yet.  */
-  goto_fixup_chain = 0;
-
-  /* We are not processing a ({...}) grouping.  */
-  expr_stmts_for_value = 0;
-  clear_last_expr ();
+  cfun->stmt = ggc_alloc_cleared (sizeof (struct stmt_status));
 }
 
 /* Record the current file and line.  Called from emit_line_note.  */
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.442
diff -u -p -r1.442 tree.h
--- tree.h	29 Aug 2003 21:57:05 -0000	1.442
+++ tree.h	29 Aug 2003 22:01:17 -0000
@@ -2856,6 +2856,7 @@ extern void expand_main_function (void);
 extern void init_dummy_function_start (void);
 extern void expand_dummy_function_end (void);
 extern void init_function_for_compilation (void);
+extern void allocate_struct_function (tree);
 extern void init_function_start (tree);
 extern void assign_parms (tree);
 extern void put_var_into_stack (tree, int);


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