Kill {save,restore}_stmt_status.

Bernd Schmidt bernds@cygnus.co.uk
Sat Jul 31 10:24:00 GMT 1999


The next part of the GC backport diffs.  This one converts stmt.c.  All the
information is now private to stmt.c, so some small helper functions had to
be introduced for cases where other files tried to access the now private
variables.

A slightly earlier version of this was tested by make check without new
failures; I'm currently running another test with this one.  Provided that
doesn't show any failures, can I check this in?

Bernd

For gcc:
	
	* stmt.c (emit_filename, emit_lineno, expr_stmts_for_value,
	last_expr_type, last_expr_value, block_start_count, block_stack,
	stack_block_stack, cond_stack, loop_stack, case_stack, nesting_stack,
	nesting_depth, goto_fixup_chain): Delete global	vars; now allocated
	dynamically in stmt elt of struct function for each function.
	(struct nesting): Rename function_call_count elt to n_function_calls,
	target_temp_slot_level to block_target_temp_slot_level.  All users
	changed.
	(struct stmt_status): New structure definition.
	Add many accessor macros for stmt_status elements which previously
	were global variables.
	(init_stmt_for_function): Allocate stmt elt for current_function.
	Reflect that block_start_count was renamed to
	current_block_start_count.
	(save_stmt_status, restore_stmt_status): Delete functions.
	(preserve_subexpressions_p): Don't access loop_stack when outside
	a function.
	(expand_start_bindings): Reflect that block_start_count was renamed to
	current_block_start_count.
	(expand_fixup): Likewise.
	(expand_decl): Don't access block_stack when outside a function.
	(expand_decl_cleanup): Likewise.
	(expand_dcc_cleanup): Likewise.
	(expand_dhc_cleanup): Likewise.
	(expand_anon_union_decl): Likewise.
	(set_file_and_line_for_stmt): New function.
	(in_control_zone_p): New function.

	* function.h (struct function): Add new elt stmt.
	Delete elts block_stack, stack_block_stack, cond_stack, loop_stack,
	case_stack, nesting_stack, nesting_depth, block_start_count,
	last_expr_type, last_expr_value, expr_stmts_for_value, emit_filename,
	emit_lineno, goto_fixup_chain.
	(save_eh_status, restore_eh_status, save_stmt_status,
	restore_stmt_status): Delete declarations.
	* function.c (push_function_context_to): Don't call save_stmt_status.
	(pop_function_context_to): Don't call restore_stmt_status.
	* tree.h (in_control_zone_p): Declare.
	* rtl.h (set_file_and_line_for_stmt): Declare.

	* emit-rtl.c (emit_line_note): Don't set emit_filename/emit_lineno;
	call set_file_and_line_for_stmt.

For gcc/cp:
	* decl.c (finish_stmt): Don't declare and test cond_stack, loop_stack,
	case_stack; use in_control_zone_p.
	* typeck.c (c_expand_return): Likewise.

Index: stmt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/stmt.c,v
retrieving revision 1.75
diff -u -p -r1.75 stmt.c
--- stmt.c	1999/07/31 12:46:44	1.75
+++ stmt.c	1999/07/31 17:12:01
@@ -62,32 +62,12 @@ struct obstack stmt_obstack;
 #define CASE_VECTOR_PC_RELATIVE 0
 #endif
 
-/* Filename and line number of last line-number note,
-   whether we actually emitted it or not.  */
-char *emit_filename;
-int emit_lineno;
-
-/* Nonzero if within a ({...}) grouping, in which case we must
-   always compute a value for each expr-stmt in case it is the last one.  */
-
-int expr_stmts_for_value;
-
-/* Each time we expand an expression-statement,
-   record the expr's type and its RTL value here.  */
-
-static tree last_expr_type;
-static rtx last_expr_value;
-
 /* Each time we expand the end of a binding contour (in `expand_end_bindings')
    and we emit a new NOTE_INSN_BLOCK_END note, we save a pointer to it here.
    This is used by the `remember_end_note' function to record the endpoint
    of each generated block in its associated BLOCK node.  */
 
 static rtx last_block_end_note;
-
-/* Number of binding contours started so far in this function.  */
-
-int block_start_count;
 
 /* Functions and data structures for expanding case statements.  */
 
@@ -223,7 +203,7 @@ struct nesting
 	     For contours that have stack levels or cleanups.  */
 	  struct label_chain *label_chain;
 	  /* Number of function calls seen, as of start of this block.  */
-	  int function_call_count;
+	  int n_function_calls;
 	  /* Nonzero if this is associated with a EH region.  */
 	  int exception_region;
 	  /* The saved target_temp_slot_level from our outer block.
@@ -231,7 +211,7 @@ struct nesting
 	     this block, if that is done, target_temp_slot_level
 	     reverts to the saved target_temp_slot_level at the very
 	     end of the block.  */
-	  int target_temp_slot_level;
+	  int block_target_temp_slot_level;
 	  /* True if we are currently emitting insns in an area of
 	     output code that is controlled by a conditional
 	     expression.  This is used by the cleanup handling code to
@@ -276,31 +256,6 @@ struct nesting
     } data;
 };
 
-/* Chain of all pending binding contours.  */
-struct nesting *block_stack;
-
-/* If any new stacks are added here, add them to POPSTACKS too.  */
-
-/* Chain of all pending binding contours that restore stack levels
-   or have cleanups.  */
-struct nesting *stack_block_stack;
-
-/* Chain of all pending conditional statements.  */
-struct nesting *cond_stack;
-
-/* Chain of all pending loops.  */
-struct nesting *loop_stack;
-
-/* Chain of all pending case or switch statements.  */
-struct nesting *case_stack;
-
-/* Separate chain including all of the above,
-   chained through the `all' field.  */
-struct nesting *nesting_stack;
-
-/* Number of entries on nesting_stack now.  */
-int nesting_depth;
-
 /* Allocate and return a new `struct nesting'.  */
 
 #define ALLOC_NESTING() \
@@ -369,8 +324,6 @@ struct goto_fixup
   tree cleanup_list_list;
 };
 
-static struct goto_fixup *goto_fixup_chain;
-
 /* Within any binding contour that must restore a stack level,
    all labels are recorded with a chain of these structures.  */
 
@@ -381,6 +334,67 @@ struct label_chain
   tree label;
 };
 
+struct stmt_status
+{
+  /* Chain of all pending binding contours.  */
+  struct nesting *x_block_stack;
+
+  /* If any new stacks are added here, add them to POPSTACKS too.  */
+
+  /* Chain of all pending binding contours that restore stack levels
+     or have cleanups.  */
+  struct nesting *x_stack_block_stack;
+
+  /* Chain of all pending conditional statements.  */
+  struct nesting *x_cond_stack;
+
+  /* Chain of all pending loops.  */
+  struct nesting *x_loop_stack;
+
+  /* Chain of all pending case or switch statements.  */
+  struct nesting *x_case_stack;
+
+  /* Separate chain including all of the above,
+     chained through the `all' field.  */
+  struct nesting *x_nesting_stack;
+
+  /* Number of entries on nesting_stack now.  */
+  int x_nesting_depth;
+
+  /* Number of binding contours started so far in this function.  */
+  int x_block_start_count;
+
+  /* Each time we expand an expression-statement,
+     record the expr's type and its RTL value here.  */
+  tree x_last_expr_type;
+  rtx x_last_expr_value;
+
+  /* Nonzero if within a ({...}) grouping, in which case we must
+     always compute a value for each expr-stmt in case it is the last one.  */
+  int x_expr_stmts_for_value;
+
+  /* Filename and line number of last line-number note,
+     whether we actually emitted it or not.  */
+  char *x_emit_filename;
+  int x_emit_lineno;
+
+  struct goto_fixup *x_goto_fixup_chain;
+};
+
+#define block_stack (current_function->stmt->x_block_stack)
+#define stack_block_stack (current_function->stmt->x_stack_block_stack)
+#define cond_stack (current_function->stmt->x_cond_stack)
+#define loop_stack (current_function->stmt->x_loop_stack)
+#define case_stack (current_function->stmt->x_case_stack)
+#define nesting_stack (current_function->stmt->x_nesting_stack)
+#define nesting_depth (current_function->stmt->x_nesting_depth)
+#define current_block_start_count (current_function->stmt->x_block_start_count)
+#define last_expr_type (current_function->stmt->x_last_expr_type)
+#define last_expr_value (current_function->stmt->x_last_expr_value)
+#define expr_stmts_for_value (current_function->stmt->x_expr_stmts_for_value)
+#define emit_filename (current_function->stmt->x_emit_filename)
+#define emit_lineno (current_function->stmt->x_emit_lineno)
+#define goto_fixup_chain (current_function->stmt->x_goto_fixup_chain)
 
 /* Non-zero if we are using EH to handle cleanus.  */
 static int using_eh_for_cleanups_p = 0;
@@ -428,6 +442,9 @@ init_stmt ()
 void
 init_stmt_for_function ()
 {
+  current_function->stmt
+    = (struct stmt_status *) xmalloc (sizeof (struct stmt_status));
+
   /* We are not currently within any block, conditional, loop or case.  */
   block_stack = 0;
   stack_block_stack = 0;
@@ -437,7 +454,7 @@ init_stmt_for_function ()
   nesting_stack = 0;
   nesting_depth = 0;
 
-  block_start_count = 0;
+  current_block_start_count = 0;
 
   /* No gotos have been expanded yet.  */
   goto_fixup_chain = 0;
@@ -448,47 +465,25 @@ init_stmt_for_function ()
 
   init_eh_for_function ();
 }
-
-void
-save_stmt_status (p)
-     struct function *p;
+
+/* Return nonzero if anything is pushed on the loop, condition, or case
+   stack.  */
+int
+in_control_zone_p ()
 {
-  p->block_stack = block_stack;
-  p->stack_block_stack = stack_block_stack;
-  p->cond_stack = cond_stack;
-  p->loop_stack = loop_stack;
-  p->case_stack = case_stack;
-  p->nesting_stack = nesting_stack;
-  p->nesting_depth = nesting_depth;
-  p->block_start_count = block_start_count;
-  p->last_expr_type = last_expr_type;
-  p->last_expr_value = last_expr_value;
-  p->expr_stmts_for_value = expr_stmts_for_value;
-  p->emit_filename = emit_filename;
-  p->emit_lineno = emit_lineno;
-  p->goto_fixup_chain = goto_fixup_chain;
+  return cond_stack || loop_stack || case_stack;
 }
 
+/* Record the current file and line.  Called from emit_line_note.  */
 void
-restore_stmt_status (p)
-     struct function *p;
-{
-  block_stack = p->block_stack;
-  stack_block_stack = p->stack_block_stack;
-  cond_stack = p->cond_stack;
-  loop_stack = p->loop_stack;
-  case_stack = p->case_stack;
-  nesting_stack = p->nesting_stack;
-  nesting_depth = p->nesting_depth;
-  block_start_count = p->block_start_count;
-  last_expr_type = p->last_expr_type;
-  last_expr_value = p->last_expr_value;
-  expr_stmts_for_value = p->expr_stmts_for_value;
-  emit_filename = p->emit_filename;
-  emit_lineno = p->emit_lineno;
-  goto_fixup_chain = p->goto_fixup_chain;
+set_file_and_line_for_stmt (file, line)
+     char *file;
+     int line;
+{
+  emit_filename = file;
+  emit_lineno = line;
 }
-
+
 /* Emit a no-op instruction.  */
 
 void
@@ -878,7 +873,7 @@ expand_fixup (tree_label, rtl_label, las
         emit_insns_after (start, original_before_jump);
       }
 
-      fixup->block_start_count = block_start_count;
+      fixup->block_start_count = current_block_start_count;
       fixup->stack_level = 0;
       fixup->cleanup_list_list
 	= ((block->data.block.outer_cleanups
@@ -2437,7 +2432,7 @@ preserve_subexpressions_p ()
   if (flag_expensive_optimizations)
     return 1;
 
-  if (optimize == 0 || loop_stack == 0)
+  if (optimize == 0 || current_function == 0 || loop_stack == 0)
     return 0;
 
   insn = get_last_insn_anywhere ();
@@ -3019,9 +3014,9 @@ expand_start_bindings (exit_flag)
   thisblock->depth = ++nesting_depth;
   thisblock->data.block.stack_level = 0;
   thisblock->data.block.cleanups = 0;
-  thisblock->data.block.function_call_count = 0;
+  thisblock->data.block.n_function_calls = 0;
   thisblock->data.block.exception_region = 0;
-  thisblock->data.block.target_temp_slot_level = target_temp_slot_level;
+  thisblock->data.block.block_target_temp_slot_level = target_temp_slot_level;
 
   thisblock->data.block.conditional_code = 0;
   thisblock->data.block.last_unconditional_cleanup = note;
@@ -3038,7 +3033,7 @@ expand_start_bindings (exit_flag)
   thisblock->data.block.label_chain = 0;
   thisblock->data.block.innermost_stack_block = stack_block_stack;
   thisblock->data.block.first_insn = note;
-  thisblock->data.block.block_start_count = ++block_start_count;
+  thisblock->data.block.block_start_count = ++current_block_start_count;
   thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
   block_stack = thisblock;
   nesting_stack = thisblock;
@@ -3365,7 +3360,7 @@ expand_end_bindings (vars, mark_ends, do
 
   /* If necessary, make handlers for nonlocal gotos taking
      place in the function calls in this block.  */
-  if (function_call_count != thisblock->data.block.function_call_count
+  if (function_call_count != thisblock->data.block.n_function_calls
       && nonlocal_labels
       /* Make handler for outermost block
 	 if there were any nonlocal gotos to this function.  */
@@ -3462,7 +3457,7 @@ expand_end_bindings (vars, mark_ends, do
 	use_variable (DECL_RTL (decl));
 
   /* Restore the temporary level of TARGET_EXPRs.  */
-  target_temp_slot_level = thisblock->data.block.target_temp_slot_level;
+  target_temp_slot_level = thisblock->data.block.block_target_temp_slot_level;
 
   /* Restore block_stack level for containing block.  */
 
@@ -3480,7 +3475,7 @@ void
 expand_decl (decl)
      register tree decl;
 {
-  struct nesting *thisblock = block_stack;
+  struct nesting *thisblock;
   tree type;
 
   type = TREE_TYPE (decl);
@@ -3496,6 +3491,8 @@ expand_decl (decl)
   if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
     return;
 
+  thisblock = block_stack;
+
   /* Create the RTL representation for the variable.  */
 
   if (type == error_mark_node)
@@ -3722,12 +3719,14 @@ int
 expand_decl_cleanup (decl, cleanup)
      tree decl, cleanup;
 {
-  struct nesting *thisblock = block_stack;
+  struct nesting *thisblock;
 
   /* Error if we are not in any block.  */
-  if (thisblock == 0)
+  if (current_function == 0 || block_stack == 0)
     return 0;
 
+  thisblock = block_stack;
+
   /* Record the cleanup if there is one.  */
 
   if (cleanup != 0)
@@ -3851,12 +3850,13 @@ int
 expand_dcc_cleanup (decl)
      tree decl;
 {
-  struct nesting *thisblock = block_stack;
+  struct nesting *thisblock;
   tree cleanup;
 
   /* Error if we are not in any block.  */
-  if (thisblock == 0)
+  if (current_function == 0 || block_stack == 0)
     return 0;
+  thisblock = block_stack;
 
   /* Record the cleanup for the dynamic handler chain.  */
 
@@ -3892,12 +3892,13 @@ int
 expand_dhc_cleanup (decl)
      tree decl;
 {
-  struct nesting *thisblock = block_stack;
+  struct nesting *thisblock;
   tree cleanup;
 
   /* Error if we are not in any block.  */
-  if (thisblock == 0)
+  if (current_function == 0 || block_stack == 0)
     return 0;
+  thisblock = block_stack;
 
   /* Record the cleanup for the dynamic handler chain.  */
 
@@ -3924,7 +3925,7 @@ void
 expand_anon_union_decl (decl, cleanup, decl_elts)
      tree decl, cleanup, decl_elts;
 {
-  struct nesting *thisblock = block_stack;
+  struct nesting *thisblock = current_function == 0 ? 0 : block_stack;
   rtx x;
 
   expand_decl (decl);
Index: function.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/function.c,v
retrieving revision 1.92
diff -u -p -r1.92 function.c
--- function.c	1999/07/31 12:46:43	1.92
+++ function.c	1999/07/31 17:12:03
@@ -626,7 +626,6 @@ push_function_context_to (context)
   save_storage_status (p);
   save_emit_status (p);
   save_expr_status (p);
-  save_stmt_status (p);
   save_varasm_status (p, context);
   if (save_machine_status)
     (*save_machine_status) (p);
@@ -715,7 +714,6 @@ pop_function_context_from (context)
   restore_storage_status (p);
   restore_expr_status (p);
   restore_emit_status (p);
-  restore_stmt_status (p);
   restore_varasm_status (p);
 
   if (restore_machine_status)
Index: function.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/function.h,v
retrieving revision 1.21
diff -u -p -r1.21 function.h
--- function.h	1999/07/31 12:46:44	1.21
+++ function.h	1999/07/31 17:12:03
@@ -68,6 +68,7 @@ struct function
   struct function *next;
 
   struct eh_status *eh;
+  struct stmt_status *stmt;
 
   /* For function.c.  */
   char *name;
@@ -124,22 +125,6 @@ struct function
   struct var_refs_queue *fixup_var_refs_queue;
   CUMULATIVE_ARGS args_info;
 
-  /* For stmt.c  */
-  struct nesting *block_stack;
-  struct nesting *stack_block_stack;
-  struct nesting *cond_stack;
-  struct nesting *loop_stack;
-  struct nesting *case_stack;
-  struct nesting *nesting_stack;
-  int nesting_depth;
-  int block_start_count;
-  tree last_expr_type;
-  rtx last_expr_value;
-  int expr_stmts_for_value;
-  char *emit_filename;
-  int emit_lineno;
-  struct goto_fixup *goto_fixup_chain;
-
   /* For expr.c.  */
   rtx pending_chain;
   int pending_stack_adjust;
@@ -278,10 +263,6 @@ extern void save_tree_status		PROTO((str
 extern void restore_tree_status		PROTO((struct function *, tree));
 extern void save_varasm_status		PROTO((struct function *, tree));
 extern void restore_varasm_status	PROTO((struct function *));
-extern void save_eh_status		PROTO((struct function *));
-extern void restore_eh_status		PROTO((struct function *));
-extern void save_stmt_status		PROTO((struct function *));
-extern void restore_stmt_status		PROTO((struct function *));
 extern void save_expr_status		PROTO((struct function *));
 extern void restore_expr_status		PROTO((struct function *));
 extern void save_emit_status		PROTO((struct function *));
Index: tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/tree.h,v
retrieving revision 1.72
diff -u -p -r1.72 tree.h
--- tree.h	1999/07/26 01:21:03	1.72
+++ tree.h	1999/07/31 17:12:04
@@ -1929,6 +1929,7 @@ extern int (*lang_get_alias_set)        
 
 /* In stmt.c */
 
+extern int in_control_zone_p			PROTO((void));
 extern void expand_fixups			PROTO((struct rtx_def *));
 extern tree expand_start_stmt_expr		PROTO((void));
 extern tree expand_end_stmt_expr		PROTO((tree));
Index: rtl.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/rtl.h,v
retrieving revision 1.106
diff -u -p -r1.106 rtl.h
--- rtl.h	1999/07/23 01:21:31	1.106
+++ rtl.h	1999/07/31 17:12:05
@@ rtl.h		PROTO ((rtx
 extern int safe_from_earlyclobber	PROTO ((rtx, rtx));
 
 /* In stmt.c */
+extern void set_file_and_line_for_stmt	PROTO ((char *, int));
 extern void expand_null_return		PROTO((void));
 extern void emit_jump			PROTO ((rtx));
 extern int preserve_subexpressions_p	PROTO ((void));
Index: emit-rtl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/emit-rtl.c,v
retrieving revision 1.65
diff -u -p -r1.65 emit-rtl.c
--- emit-rtl.c	1999/07/31 12:46:43	1.65
+++ emit-rtl.c	1999/07/31 17:12:06
@@ -3167,8 +3167,7 @@ emit_line_note (file, line)
      char *file;
      int line;
 {
-  emit_filename = file;
-  emit_lineno = line;
+  set_file_and_line_for_stmt (file, line);
 
 #if 0
   if (no_line_numbers)
Index: cp/decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.384
diff -u -p -r1.384 decl.c
--- cp/decl.c	1999/07/26 08:18:13	1.384
+++ cp/decl.c	1999/07/31 17:12:10
@@ -14509,9 +14509,6 @@ cplus_expand_expr_stmt (exp)
 void
 finish_stmt ()
 {
-  extern struct nesting *cond_stack, *loop_stack, *case_stack;
-
-  
   if (current_function_assigns_this
       || ! current_function_just_assigned_this)
     return;
@@ -14519,7 +14516,7 @@ finish_stmt ()
     {
       /* Constructors must wait until we are out of control
 	 zones before calling base constructors.  */
-      if (cond_stack || loop_stack || case_stack)
+      if (in_control_zone_p ())
 	return;
       expand_expr_stmt (base_init_expr);
       check_base_init (current_class_type);
Index: cp/typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/typeck.c,v
retrieving revision 1.179
diff -u -p -r1.179 typeck.c
--- cp/typeck.c	1999/07/28 00:45:12	1.179
+++ cp/typeck.c	1999/07/31 17:12:12
@@ -6735,7 +6735,6 @@ void
 c_expand_return (retval)
      tree retval;
 {
-  extern struct nesting *cond_stack, *loop_stack, *case_stack;
   extern tree dtor_label, ctor_label;
   tree result = DECL_RESULT (current_function_decl);
   tree valtype = TREE_TYPE (result);
@@ -6925,7 +6924,7 @@ c_expand_return (retval)
 
   if (retval != NULL_TREE
       && TREE_CODE_CLASS (TREE_CODE (retval)) == 'd'
-      && cond_stack == 0 && loop_stack == 0 && case_stack == 0)
+      && ! in_control_zone_p ())
     current_function_return_value = retval;
 
   if (ctor_label && TREE_CODE (ctor_label) != ERROR_MARK)



More information about the Gcc-patches mailing list