PR13376

Steven Bosscher s.bosscher@student.tudelft.nl
Sun Jan 11 21:50:00 GMT 2004


Hi Roger, all,

Another attempt to fix the current_function_name issue.  Roger, I
don't like your suggestion to make current_function_name a define
for lang_hooks.printable_name, because it would require including
langhooks.h in more places just for being able to dump RTL, or to
do really stupid things in some of the files in config/*.  I can
still do so if you prefer that, but this patch seems cleaner to me.

So I made it a function in function.c.

Bootstrapped on i686-pc-linux-gnu, and verified that it fixes the
bug.  I don't have access to any of the other affected platforms.

Gr.
Steven

	* function.h (struct function): Kill `name' field.
	(current_function_name): Make it an extern function.
	* function.c (current_function_name): New function.
	* graph.c: Update all uses of current_function_name.
	* gcse.c: Likewise.
	* config/alpha/alpha.c, config/avr/avr.c, config/c4x/c4x.c,
	config/mips/mips.c, config/pdp11/pdp11.c: Likewise.
	* config/ip2k/ip2k.c (function_prologue): Use MAIN_NAME_P
	instead of a strcmp with "main".

Index: function.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.c,v
retrieving revision 1.482
diff -c -3 -p -r1.482 function.c
*** function.c	3 Jan 2004 19:58:39 -0000	1.482
--- function.c	11 Jan 2004 12:41:13 -0000
*************** allocate_struct_function (tree fndecl)
*** 6408,6415 ****
    DECL_SAVED_INSNS (fndecl) = cfun;
    cfun->decl = fndecl;
  
-   current_function_name = (*lang_hooks.decl_printable_name) (fndecl, 2);
- 
    result = DECL_RESULT (fndecl);
    if (aggregate_value_p (result, fndecl))
      {
--- 6408,6413 ----
*************** init_function_once (void)
*** 8068,8073 ****
--- 8066,8078 ----
    VARRAY_INT_INIT (prologue, 0, "prologue");
    VARRAY_INT_INIT (epilogue, 0, "epilogue");
    VARRAY_INT_INIT (sibcall_epilogue, 0, "sibcall_epilogue");
+ }
+ 
+ /* Returns the name of the current function.  */
+ const char *
+ current_function_name (void)
+ {
+   return (*lang_hooks.decl_printable_name) (cfun->decl, 2);
  }
  
  #include "gt-function.h"
Index: function.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/function.h,v
retrieving revision 1.107
diff -c -3 -p -r1.107 function.h
*** function.h	3 Jan 2004 19:58:39 -0000	1.107
--- function.h	11 Jan 2004 12:41:14 -0000
*************** struct function GTY(())
*** 183,191 ****
  
    /* For function.c.  */
  
-   /* Name of this function.  */
-   const char *name;
- 
    /* Points to the FUNCTION_DECL of this function.  */
    tree decl;
  
--- 183,188 ----
*************** extern int virtuals_instantiated;
*** 534,540 ****
  extern int trampolines_created;
  
  /* For backward compatibility... eventually these should all go away.  */
- #define current_function_name (cfun->name)
  #define current_function_pops_args (cfun->pops_args)
  #define current_function_returns_struct (cfun->returns_struct)
  #define current_function_returns_pcc_struct (cfun->returns_pcc_struct)
--- 531,536 ----
*************** extern void use_return_register (void);
*** 637,642 ****
--- 633,641 ----
  extern rtx get_arg_pointer_save_area (struct function *);
  
  extern void init_virtual_regs (struct emit_status *);
+ 
+ /* Returns the name of the current function.  */
+ extern const char *current_function_name (void);
  
  /* Called once, at initialization, to initialize function.c.  */
  extern void init_function_once (void);
Index: gcse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcse.c,v
retrieving revision 1.286
diff -c -3 -p -r1.286 gcse.c
*** gcse.c	6 Jan 2004 16:51:13 -0000	1.286
--- gcse.c	11 Jan 2004 12:41:28 -0000
*************** gcse_main (rtx f, FILE *file)
*** 855,861 ****
    if (file)
      {
        fprintf (file, "GCSE of %s: %d basic blocks, ",
! 	       current_function_name, n_basic_blocks);
        fprintf (file, "%d pass%s, %d bytes\n\n",
  	       pass, pass > 1 ? "es" : "", max_pass_bytes);
      }
--- 855,861 ----
    if (file)
      {
        fprintf (file, "GCSE of %s: %d basic blocks, ",
! 	       current_function_name (), n_basic_blocks);
        fprintf (file, "%d pass%s, %d bytes\n\n",
  	       pass, pass > 1 ? "es" : "", max_pass_bytes);
      }
*************** one_classic_gcse_pass (int pass)
*** 3614,3620 ****
      {
        fprintf (gcse_file, "\n");
        fprintf (gcse_file, "GCSE of %s, pass %d: %d bytes needed, %d substs,",
! 	       current_function_name, pass, bytes_used, gcse_subst_count);
        fprintf (gcse_file, "%d insns created\n", gcse_create_count);
      }
  
--- 3614,3620 ----
      {
        fprintf (gcse_file, "\n");
        fprintf (gcse_file, "GCSE of %s, pass %d: %d bytes needed, %d substs,",
! 	       current_function_name (), pass, bytes_used, gcse_subst_count);
        fprintf (gcse_file, "%d insns created\n", gcse_create_count);
      }
  
*************** one_cprop_pass (int pass, int cprop_jump
*** 4686,4692 ****
    if (gcse_file)
      {
        fprintf (gcse_file, "CPROP of %s, pass %d: %d bytes needed, ",
! 	       current_function_name, pass, bytes_used);
        fprintf (gcse_file, "%d const props, %d copy props\n\n",
  	       const_prop_count, copy_prop_count);
      }
--- 4686,4692 ----
    if (gcse_file)
      {
        fprintf (gcse_file, "CPROP of %s, pass %d: %d bytes needed, ",
! 	       current_function_name (), pass, bytes_used);
        fprintf (gcse_file, "%d const props, %d copy props\n\n",
  	       const_prop_count, copy_prop_count);
      }
*************** one_pre_gcse_pass (int pass)
*** 5788,5794 ****
    if (gcse_file)
      {
        fprintf (gcse_file, "\nPRE GCSE of %s, pass %d: %d bytes needed, ",
! 	       current_function_name, pass, bytes_used);
        fprintf (gcse_file, "%d substs, %d insns created\n",
  	       gcse_subst_count, gcse_create_count);
      }
--- 5788,5794 ----
    if (gcse_file)
      {
        fprintf (gcse_file, "\nPRE GCSE of %s, pass %d: %d bytes needed, ",
! 	       current_function_name (), pass, bytes_used);
        fprintf (gcse_file, "%d substs, %d insns created\n",
  	       gcse_subst_count, gcse_create_count);
      }
*************** bypass_jumps (FILE *file)
*** 8017,8023 ****
    if (file)
      {
        fprintf (file, "BYPASS of %s: %d basic blocks, ",
! 	       current_function_name, n_basic_blocks);
        fprintf (file, "%d bytes\n\n", bytes_used);
      }
  
--- 8017,8023 ----
    if (file)
      {
        fprintf (file, "BYPASS of %s: %d basic blocks, ",
! 	       current_function_name (), n_basic_blocks);
        fprintf (file, "%d bytes\n\n", bytes_used);
      }
  
Index: graph.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/graph.c,v
retrieving revision 1.30
diff -c -3 -p -r1.30 graph.c
*** graph.c	3 Jan 2004 19:58:40 -0000	1.30
--- graph.c	11 Jan 2004 12:41:29 -0000
*************** start_fct (FILE *fp)
*** 55,61 ****
      case vcg:
        fprintf (fp, "\
  graph: { title: \"%s\"\nfolding: 1\nhidden: 2\nnode: { title: \"%s.0\" }\n",
! 	       current_function_name, current_function_name);
        break;
      case no_graph:
        break;
--- 55,61 ----
      case vcg:
        fprintf (fp, "\
  graph: { title: \"%s\"\nfolding: 1\nhidden: 2\nnode: { title: \"%s.0\" }\n",
! 	       current_function_name (), current_function_name ());
        break;
      case no_graph:
        break;
*************** start_bb (FILE *fp, int bb)
*** 71,77 ****
        fprintf (fp, "\
  graph: {\ntitle: \"%s.BB%d\"\nfolding: 1\ncolor: lightblue\n\
  label: \"basic block %d",
! 	       current_function_name, bb, bb);
        break;
      case no_graph:
        break;
--- 71,77 ----
        fprintf (fp, "\
  graph: {\ntitle: \"%s.BB%d\"\nfolding: 1\ncolor: lightblue\n\
  label: \"basic block %d",
! 	       current_function_name (), bb, bb);
        break;
      case no_graph:
        break;
*************** node_data (FILE *fp, rtx tmp_rtx)
*** 113,120 ****
  	case vcg:
  	  fprintf (fp, "\
  edge: { sourcename: \"%s.0\" targetname: \"%s.%d\" }\n",
! 		   current_function_name,
! 		   current_function_name, XINT (tmp_rtx, 0));
  	  break;
  	case no_graph:
  	  break;
--- 113,120 ----
  	case vcg:
  	  fprintf (fp, "\
  edge: { sourcename: \"%s.0\" targetname: \"%s.%d\" }\n",
! 		   current_function_name (),
! 		   current_function_name (), XINT (tmp_rtx, 0));
  	  break;
  	case no_graph:
  	  break;
*************** edge: { sourcename: \"%s.0\" targetname:
*** 126,132 ****
      case vcg:
        fprintf (fp, "node: {\n  title: \"%s.%d\"\n  color: %s\n  \
  label: \"%s %d\n",
! 	       current_function_name, XINT (tmp_rtx, 0),
  	       GET_CODE (tmp_rtx) == NOTE ? "lightgrey"
  	       : GET_CODE (tmp_rtx) == INSN ? "green"
  	       : GET_CODE (tmp_rtx) == JUMP_INSN ? "darkgreen"
--- 126,132 ----
      case vcg:
        fprintf (fp, "node: {\n  title: \"%s.%d\"\n  color: %s\n  \
  label: \"%s %d\n",
! 	       current_function_name (), XINT (tmp_rtx, 0),
  	       GET_CODE (tmp_rtx) == NOTE ? "lightgrey"
  	       : GET_CODE (tmp_rtx) == INSN ? "green"
  	       : GET_CODE (tmp_rtx) == JUMP_INSN ? "darkgreen"
*************** draw_edge (FILE *fp, int from, int to, i
*** 178,185 ****
  	color = "color: green ";
        fprintf (fp,
  	       "edge: { sourcename: \"%s.%d\" targetname: \"%s.%d\" %s",
! 	       current_function_name, from,
! 	       current_function_name, to, color);
        if (class)
  	fprintf (fp, "class: %d ", class);
        fputs ("}\n", fp);
--- 178,185 ----
  	color = "color: green ";
        fprintf (fp,
  	       "edge: { sourcename: \"%s.%d\" targetname: \"%s.%d\" %s",
! 	       current_function_name (), from,
! 	       current_function_name (), to, color);
        if (class)
  	fprintf (fp, "class: %d ", class);
        fputs ("}\n", fp);
*************** end_fct (FILE *fp)
*** 209,215 ****
      {
      case vcg:
        fprintf (fp, "node: { title: \"%s.999999\" label: \"END\" }\n}\n",
! 	       current_function_name);
        break;
      case no_graph:
        break;
--- 209,215 ----
      {
      case vcg:
        fprintf (fp, "node: { title: \"%s.999999\" label: \"END\" }\n}\n",
! 	       current_function_name ());
        break;
      case no_graph:
        break;
Index: config/alpha/alpha.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/alpha/alpha.c,v
retrieving revision 1.341
diff -c -3 -p -r1.341 alpha.c
*** config/alpha/alpha.c	25 Dec 2003 15:17:34 -0000	1.341
--- config/alpha/alpha.c	11 Jan 2004 12:41:59 -0000
*************** unicosmk_add_call_info_word (rtx x)
*** 9739,9745 ****
    ++machine->ciw_count;
  
    return GEN_INT (machine->ciw_count
! 		  + strlen (current_function_name)/8 + 5);
  }
  
  static char unicosmk_section_buf[100];
--- 9739,9745 ----
    ++machine->ciw_count;
  
    return GEN_INT (machine->ciw_count
! 		  + strlen (current_function_name ())/8 + 5);
  }
  
  static char unicosmk_section_buf[100];
Index: config/avr/avr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/avr/avr.c,v
retrieving revision 1.107
diff -c -3 -p -r1.107 avr.c
*** config/avr/avr.c	5 Jan 2004 17:26:30 -0000	1.107
--- config/avr/avr.c	11 Jan 2004 12:42:07 -0000
*************** avr_output_function_prologue (FILE *file
*** 662,674 ****
      }
    else if (minimize && (frame_pointer_needed || live_seq > 6)) 
      {
        fprintf (file, ("\t"
  		      AS1 (ldi, r26) ",lo8(" HOST_WIDE_INT_PRINT_DEC ")" CR_TAB
  		      AS1 (ldi, r27) ",hi8(" HOST_WIDE_INT_PRINT_DEC ")" CR_TAB), size, size);
  
        fprintf (file, (AS2 (ldi, r30, pm_lo8(.L_%s_body)) CR_TAB
! 		      AS2 (ldi, r31, pm_hi8(.L_%s_body)) CR_TAB)
! 	       ,current_function_name, current_function_name);
        
        prologue_size += 4;
        
--- 662,675 ----
      }
    else if (minimize && (frame_pointer_needed || live_seq > 6)) 
      {
+       const char *cfun_name = current_function_name ();
        fprintf (file, ("\t"
  		      AS1 (ldi, r26) ",lo8(" HOST_WIDE_INT_PRINT_DEC ")" CR_TAB
  		      AS1 (ldi, r27) ",hi8(" HOST_WIDE_INT_PRINT_DEC ")" CR_TAB), size, size);
  
        fprintf (file, (AS2 (ldi, r30, pm_lo8(.L_%s_body)) CR_TAB
! 		      AS2 (ldi, r31, pm_hi8(.L_%s_body)) CR_TAB),
! 	       cfun_name, cfun_name);
        
        prologue_size += 4;
        
*************** avr_output_function_prologue (FILE *file
*** 684,690 ****
  		   (18 - live_seq) * 2);
  	  ++prologue_size;
  	}
!       fprintf (file, ".L_%s_body:\n", current_function_name);
      }
    else
      {
--- 685,691 ----
  		   (18 - live_seq) * 2);
  	  ++prologue_size;
  	}
!       fprintf (file, ".L_%s_body:\n", cfun_name);
      }
    else
      {
*************** avr_output_function_epilogue (FILE *file
*** 871,877 ****
  
   out:
    fprintf (file, "/* epilogue end (size=%d) */\n", epilogue_size);
!   fprintf (file, "/* function %s size %d (%d) */\n", current_function_name,
  	   prologue_size + function_size + epilogue_size, function_size);
    commands_in_file += prologue_size + function_size + epilogue_size;
    commands_in_prologues += prologue_size;
--- 872,878 ----
  
   out:
    fprintf (file, "/* epilogue end (size=%d) */\n", epilogue_size);
!   fprintf (file, "/* function %s size %d (%d) */\n", current_function_name (),
  	   prologue_size + function_size + epilogue_size, function_size);
    commands_in_file += prologue_size + function_size + epilogue_size;
    commands_in_prologues += prologue_size;
Index: config/c4x/c4x.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/c4x/c4x.c,v
retrieving revision 1.135
diff -c -3 -p -r1.135 c4x.c
*** config/c4x/c4x.c	13 Dec 2003 04:44:03 -0000	1.135
--- config/c4x/c4x.c	11 Jan 2004 12:42:15 -0000
*************** c4x_naked_function_p (void)
*** 791,808 ****
  int
  c4x_interrupt_function_p (void)
  {
    if (lookup_attribute ("interrupt",
  			TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
      return 1;
  
    /* Look for TI style c_intnn.  */
!   return current_function_name[0] == 'c'
!     && current_function_name[1] == '_'
!     && current_function_name[2] == 'i'
!     && current_function_name[3] == 'n' 
!     && current_function_name[4] == 't'
!     && ISDIGIT (current_function_name[5])
!     && ISDIGIT (current_function_name[6]);
  }
  
  void
--- 791,810 ----
  int
  c4x_interrupt_function_p (void)
  {
+   const char *cfun_name;
    if (lookup_attribute ("interrupt",
  			TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))
      return 1;
  
    /* Look for TI style c_intnn.  */
!   cfun_name = current_function_name ();
!   return cfun_name[0] == 'c'
!     && cfun_name[1] == '_'
!     && cfun_name[2] == 'i'
!     && cfun_name[3] == 'n' 
!     && cfun_name[4] == 't'
!     && ISDIGIT (cfun_name[5])
!     && ISDIGIT (cfun_name[6]);
  }
  
  void
*************** c4x_expand_prologue (void)
*** 846,852 ****
  	     storage!  */
  	  if (size > 32767)
  	    error ("ISR %s requires %d words of local vars, max is 32767",
! 		   current_function_name, size);
  
  	  insn = emit_insn (gen_addqi3 (gen_rtx_REG (QImode, SP_REGNO),
  				        gen_rtx_REG (QImode, SP_REGNO),
--- 848,854 ----
  	     storage!  */
  	  if (size > 32767)
  	    error ("ISR %s requires %d words of local vars, max is 32767",
! 		   current_function_name (), size);
  
  	  insn = emit_insn (gen_addqi3 (gen_rtx_REG (QImode, SP_REGNO),
  				        gen_rtx_REG (QImode, SP_REGNO),
Index: config/ip2k/ip2k.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/ip2k/ip2k.c,v
retrieving revision 1.28
diff -c -3 -p -r1.28 ip2k.c
*** config/ip2k/ip2k.c	21 Dec 2003 18:40:48 -0000	1.28
--- config/ip2k/ip2k.c	11 Jan 2004 12:42:25 -0000
*************** function_prologue (FILE *file, HOST_WIDE
*** 202,208 ****
      }
  
    leaf_func_p = leaf_function_p ();
!   main_p = ! strcmp ("main", current_function_name);
  
    /* For now, we compute all these facts about the function, but don't
       take any action based on the information.  */
--- 202,208 ----
      }
  
    leaf_func_p = leaf_function_p ();
!   main_p = MAIN_NAME_P (DECL_NAME (current_function_decl));
  
    /* For now, we compute all these facts about the function, but don't
       take any action based on the information.  */
Index: config/mips/mips.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.c,v
retrieving revision 1.359
diff -c -3 -p -r1.359 mips.c
*** config/mips/mips.c	5 Jan 2004 09:59:41 -0000	1.359
--- config/mips/mips.c	11 Jan 2004 12:42:42 -0000
*************** build_mips16_function_stub (FILE *file)
*** 7659,7665 ****
  			 build_function_type (void_type_node, NULL_TREE));
    DECL_SECTION_NAME (stubdecl) = build_string (strlen (secname), secname);
  
!   fprintf (file, "\t# Stub function for %s (", current_function_name);
    need_comma = 0;
    for (f = (unsigned int) current_function_args_info.fp_code; f != 0; f >>= 2)
      {
--- 7659,7665 ----
  			 build_function_type (void_type_node, NULL_TREE));
    DECL_SECTION_NAME (stubdecl) = build_string (strlen (secname), secname);
  
!   fprintf (file, "\t# Stub function for %s (", current_function_name ());
    need_comma = 0;
    for (f = (unsigned int) current_function_args_info.fp_code; f != 0; f >>= 2)
      {
Index: config/pdp11/pdp11.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/pdp11/pdp11.c,v
retrieving revision 1.31
diff -c -3 -p -r1.31 pdp11.c
*** config/pdp11/pdp11.c	28 Sep 2003 12:09:07 -0000	1.31
--- config/pdp11/pdp11.c	11 Jan 2004 12:42:45 -0000
*************** pdp11_output_function_prologue (FILE *st
*** 148,154 ****
      int via_ac = -1;
  
      fprintf (stream,
! 	     "\n\t;	/* function prologue %s*/\n", current_function_name);
  
      /* if we are outputting code for main, 
         the switch FPU to right mode if TARGET_FPU */
--- 148,155 ----
      int via_ac = -1;
  
      fprintf (stream,
! 	     "\n\t;	/* function prologue %s*/\n",
! 	     current_function_name ());
  
      /* if we are outputting code for main, 
         the switch FPU to right mode if TARGET_FPU */



More information about the Gcc-patches mailing list