mmix: support -fstack-usage

Message ID alpine.BSF.2.20.16.2007201918060.72168@arjuna.pair.com
State New
Headers show
Series
  • mmix: support -fstack-usage
Related show

Commit Message

Hans-Peter Nilsson July 20, 2020, 11:18 p.m.
MMIX has two stacks; the regular one using register $254 as a
convention and the register-stack, pushed and popped by call
instructions (usually).  The decision to only report the stack usage
of the regular stack (and not of the register stack) may be updated,
perhaps the sum is better.  This initial decision is helped a little
bit by the order of passes: the size of the register-stack is
calculated only later (in the machine-dependent reorg pass), long
after finalization of the stack-usage info (in the prologue/epilogue
pass).  No regressions for mmix-knuth-mmixware (but a whole lot more
PASSes), committed.

gcc:
	* config/mmix/mmix.c (mmix_expand_prologue): Calculate the total
	allocated size and set current_function_static_stack_size, if
	flag_stack_usage_info.

Patch

--- gcc/gcc/config/mmix/mmix.c.orig	Mon Jan 13 22:30:46 2020
+++ gcc/gcc/config/mmix/mmix.c	Mon Jul 20 05:44:05 2020
@@ -1987,6 +1987,7 @@  mmix_expand_prologue (void)
        + crtl->args.pretend_args_size
        + locals_size + 7) & ~7;
   HOST_WIDE_INT offset = -8;
+  HOST_WIDE_INT total_allocated_stack_space = 0;

   /* Add room needed to save global non-register-stack registers.  */
   for (regno = 255;
@@ -2036,6 +2037,8 @@  mmix_expand_prologue (void)
 		? (256 - 8) : stack_space_to_allocate;

 	      mmix_emit_sp_add (-stack_chunk);
+	      total_allocated_stack_space += stack_chunk;
+
 	      offset += stack_chunk;
 	      stack_space_to_allocate -= stack_chunk;
 	    }
@@ -2064,6 +2067,7 @@  mmix_expand_prologue (void)
 	    ? (256 - 8 - 8) : stack_space_to_allocate;

 	  mmix_emit_sp_add (-stack_chunk);
+	  total_allocated_stack_space += stack_chunk;

 	  offset += stack_chunk;
 	  stack_space_to_allocate -= stack_chunk;
@@ -2099,6 +2103,7 @@  mmix_expand_prologue (void)
 	    ? (256 - 8 - 8) : stack_space_to_allocate;

 	  mmix_emit_sp_add (-stack_chunk);
+	  total_allocated_stack_space += stack_chunk;

 	  offset += stack_chunk;
 	  stack_space_to_allocate -= stack_chunk;
@@ -2143,6 +2148,7 @@  mmix_expand_prologue (void)
 	    ? (256 - 8 - 8) : stack_space_to_allocate;

 	  mmix_emit_sp_add (-stack_chunk);
+	  total_allocated_stack_space += stack_chunk;

 	  offset += stack_chunk;
 	  stack_space_to_allocate -= stack_chunk;
@@ -2193,6 +2199,8 @@  mmix_expand_prologue (void)
 		 ? (256 - offset - 8) : stack_space_to_allocate);

 	    mmix_emit_sp_add (-stack_chunk);
+	    total_allocated_stack_space += stack_chunk;
+
 	    offset += stack_chunk;
 	    stack_space_to_allocate -= stack_chunk;
 	  }
@@ -2210,6 +2218,14 @@  mmix_expand_prologue (void)
      wasn't allocated above.  */
   if (stack_space_to_allocate)
     mmix_emit_sp_add (-stack_space_to_allocate);
+  total_allocated_stack_space += stack_space_to_allocate;
+
+  /* Let's assume that reporting the usage of the regular stack on its
+     own, is more useful than either not supporting -fstack-usage or
+     reporting the sum of the usages of the regular stack and the
+     register stack.  */
+  if (flag_stack_usage_info)
+    current_function_static_stack_size = total_allocated_stack_space;
 }

 /* Expands the function epilogue into RTX.  */