Patchwork [4/27] Use target structures for init_emit_regs

login
register
mail settings
Submitter Richard Sandiford
Date July 4, 2010, 10:05 p.m.
Message ID <87vd8unbry.fsf_-_@firetop.home>
Download mbox | patch
Permalink /patch/57853/
State New
Headers show

Comments

Richard Sandiford - July 4, 2010, 10:05 p.m.
This patch deals with all the variables initialized by init_emit_regs
itself.  I renamed static_regno_reg_rtx to initial_regno_reg_rtx
since it's no longer static in the C sense.

Richard


gcc/
	* Makefile.in (target-globals.o): Depend on $(RTL_H).
	* rtl.h: (target_rtl): New structure.
	(default_target_rtl): Declare.
	(this_target_rtl): Declare as a variable or define as a macro.
	(global_rtl, pic_offset_table_rtx, return_address_pointer_rtx):
	Redefine as macros.
	* emit-rtl.c (default_target_rtl): New variable.
	(this_target_rtl): New conditional variable.
	(global_rtl, static_regno_reg_rtx, pic_offset_table_rtx)
	(return_address_pointer_rtx): Delete.
	(initial_regno_reg_rtx): New macro.
	(init_emit): Use initial_regno_reg_rtx instead of static_regno_reg_rtx.
	(init_emit_regs): Likewise.
	* target-globals.h (this_target_rtl): Declare.
	(target_globals): Add a rtl field.
	(restore_target_globals): Copy the rtl field to this_target_rtl.
	* target-globals.c: Include rtl.h.
	(default_target_globals): Initialize the rtl field.
	(save_target_globals): Likewise.
Mark Mitchell - July 7, 2010, 3:23 p.m.
Richard Sandiford wrote:

> gcc/
> 	* Makefile.in (target-globals.o): Depend on $(RTL_H).
> 	* rtl.h: (target_rtl): New structure.

Patches 1-4 OK.
Richard Sandiford - July 7, 2010, 8:31 p.m.
Mark Mitchell <mark@codesourcery.com> writes:
> Richard Sandiford wrote:
>> gcc/
>> 	* Makefile.in (target-globals.o): Depend on $(RTL_H).
>> 	* rtl.h: (target_rtl): New structure.
>
> Patches 1-4 OK.

Thanks Mark.  I'll post the rest now.

Richard

Patch

Index: gcc/Makefile.in
===================================================================
--- gcc/Makefile.in	2010-07-04 14:15:27.000000000 +0100
+++ gcc/Makefile.in	2010-07-04 14:15:45.000000000 +0100
@@ -3479,7 +3479,7 @@  lower-subreg.o : lower-subreg.c $(CONFIG
    $(EXPR_H) $(EXCEPT_H) $(REGS_H) $(TREE_PASS_H) $(DF_H)
 target-globals.o : target-globals.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
    $(TM_H) insn-config.h $(MACHMODE_H) $(GGC_H) $(TOPLEV_H) target-globals.h \
-   $(FLAGS_H) $(REGS_H)
+   $(FLAGS_H) $(REGS_H) $(RTL_H)
 
 $(out_object_file): $(out_file) $(CONFIG_H) coretypes.h $(TM_H) $(TREE_H) \
    $(RTL_H) $(REGS_H) hard-reg-set.h insn-config.h conditions.h \
Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h	2010-07-04 14:15:03.000000000 +0100
+++ gcc/rtl.h	2010-07-04 14:15:32.000000000 +0100
@@ -2006,8 +2006,53 @@  enum global_rtl_index
   GR_MAX
 };
 
-/* Pointers to standard pieces of rtx are stored here.  */
-extern GTY(()) rtx global_rtl[GR_MAX];
+/* Target-dependent globals.  */
+struct GTY(()) target_rtl {
+  /* All references to the hard registers in global_rtl_index go through
+     these unique rtl objects.  On machines where the frame-pointer and
+     arg-pointer are the same register, they use the same unique object.
+
+     After register allocation, other rtl objects which used to be pseudo-regs
+     may be clobbered to refer to the frame-pointer register.
+     But references that were originally to the frame-pointer can be
+     distinguished from the others because they contain frame_pointer_rtx.
+
+     When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
+     tricky: until register elimination has taken place hard_frame_pointer_rtx
+     should be used if it is being set, and frame_pointer_rtx otherwise.  After
+     register elimination hard_frame_pointer_rtx should always be used.
+     On machines where the two registers are same (most) then these are the
+     same.  */
+  rtx x_global_rtl[GR_MAX];
+
+  /* A unique representation of (REG:Pmode PIC_OFFSET_TABLE_REGNUM).  */
+  rtx x_pic_offset_table_rtx;
+
+  /* A unique representation of (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM).
+     This is used to implement __builtin_return_address for some machines;
+     see for instance the MIPS port.  */
+  rtx x_return_address_pointer_rtx;
+
+  /* Commonly used RTL for hard registers.  These objects are not
+     necessarily unique, so we allocate them separately from global_rtl.
+     They are initialized once per compilation unit, then copied into
+     regno_reg_rtx at the beginning of each function.  */
+  rtx x_initial_regno_reg_rtx[FIRST_PSEUDO_REGISTER];
+};
+
+extern GTY(()) struct target_rtl default_target_rtl;
+#if SWITCHABLE_TARGET
+extern struct target_rtl *this_target_rtl;
+#else
+#define this_target_rtl (&default_target_rtl)
+#endif
+
+#define global_rtl				\
+  (this_target_rtl->x_global_rtl)
+#define pic_offset_table_rtx \
+  (this_target_rtl->x_pic_offset_table_rtx)
+#define return_address_pointer_rtx \
+  (this_target_rtl->x_return_address_pointer_rtx)
 
 /* Standard pieces of rtx, to be substituted directly into things.  */
 #define pc_rtx                  (global_rtl[GR_PC])
@@ -2021,9 +2066,6 @@  #define frame_pointer_rtx       (global_
 #define hard_frame_pointer_rtx	(global_rtl[GR_HARD_FRAME_POINTER])
 #define arg_pointer_rtx		(global_rtl[GR_ARG_POINTER])
 
-extern GTY(()) rtx pic_offset_table_rtx;
-extern GTY(()) rtx return_address_pointer_rtx;
-
 /* Include the RTL generation functions.  */
 
 #ifndef GENERATOR_FILE
Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	2010-07-04 14:15:03.000000000 +0100
+++ gcc/emit-rtl.c	2010-07-04 14:15:32.000000000 +0100
@@ -60,6 +60,13 @@  Software Foundation; either version 3, o
 #include "params.h"
 #include "target.h"
 
+struct target_rtl default_target_rtl;
+#if SWITCHABLE_TARGET
+struct target_rtl *this_target_rtl = &default_target_rtl;
+#endif
+
+#define initial_regno_reg_rtx (this_target_rtl->x_initial_regno_reg_rtx)
+
 /* Commonly used modes.  */
 
 enum machine_mode byte_mode;	/* Mode whose width is BITS_PER_UNIT.  */
@@ -83,19 +90,6 @@  struct rtl_data x_rtl;
 
 static GTY(()) int label_num = 1;
 
-/* Commonly used rtx's, so that we only need space for one copy.
-   These are initialized once for the entire compilation.
-   All of these are unique; no other rtx-object will be equal to any
-   of these.  */
-
-rtx global_rtl[GR_MAX];
-
-/* Commonly used RTL for hard registers.  These objects are not necessarily
-   unique, so we allocate them separately from global_rtl.  They are
-   initialized once per compilation unit, then copied into regno_reg_rtx
-   at the beginning of each function.  */
-static GTY(()) rtx static_regno_reg_rtx[FIRST_PSEUDO_REGISTER];
-
 /* We record floating-point CONST_DOUBLEs in each floating-point mode for
    the values of 0, 1, and 2.  For the integer entries and VOIDmode, we
    record a copy of const[012]_rtx.  */
@@ -114,30 +108,6 @@  rtx const_tiny_rtx[3][(int) MAX_MACHINE_
 FIXED_VALUE_TYPE fconst0[MAX_FCONST0];
 FIXED_VALUE_TYPE fconst1[MAX_FCONST1];
 
-/* All references to the following fixed hard registers go through
-   these unique rtl objects.  On machines where the frame-pointer and
-   arg-pointer are the same register, they use the same unique object.
-
-   After register allocation, other rtl objects which used to be pseudo-regs
-   may be clobbered to refer to the frame-pointer register.
-   But references that were originally to the frame-pointer can be
-   distinguished from the others because they contain frame_pointer_rtx.
-
-   When to use frame_pointer_rtx and hard_frame_pointer_rtx is a little
-   tricky: until register elimination has taken place hard_frame_pointer_rtx
-   should be used if it is being set, and frame_pointer_rtx otherwise.  After
-   register elimination hard_frame_pointer_rtx should always be used.
-   On machines where the two registers are same (most) then these are the
-   same.
-
-   In an inline procedure, the stack and frame pointer rtxs may not be
-   used for anything else.  */
-rtx pic_offset_table_rtx;	/* (REG:Pmode PIC_OFFSET_TABLE_REGNUM) */
-
-/* This is used to implement __builtin_return_address for some machines.
-   See for instance the MIPS port.  */
-rtx return_address_pointer_rtx;	/* (REG:Pmode RETURN_ADDRESS_POINTER_REGNUM) */
-
 /* We make one copy of (const_int C) where C is in
    [- MAX_SAVED_CONST_INT, MAX_SAVED_CONST_INT]
    to save space during the compilation and simplify comparisons of
@@ -5586,7 +5556,7 @@  init_emit (void)
 
   /* Put copies of all the hard registers into regno_reg_rtx.  */
   memcpy (regno_reg_rtx,
-	  static_regno_reg_rtx,
+	  initial_regno_reg_rtx,
 	  FIRST_PSEUDO_REGISTER * sizeof (rtx));
 
   /* Put copies of all the virtual register rtx into regno_reg_rtx.  */
@@ -5713,7 +5683,7 @@  init_emit_regs (void)
   /* Initialize RTL for commonly used hard registers.  These are
      copied into regno_reg_rtx as we begin to compile each function.  */
   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
-    static_regno_reg_rtx[i] = gen_raw_REG (reg_raw_mode[i], i);
+    initial_regno_reg_rtx[i] = gen_raw_REG (reg_raw_mode[i], i);
 
 #ifdef RETURN_ADDRESS_POINTER_REGNUM
   return_address_pointer_rtx
Index: gcc/target-globals.h
===================================================================
--- gcc/target-globals.h	2010-07-04 14:15:19.000000000 +0100
+++ gcc/target-globals.h	2010-07-04 14:15:32.000000000 +0100
@@ -23,10 +23,12 @@  #define TARGET_GLOBALS_H 1
 #if SWITCHABLE_TARGET
 extern struct target_flag_state *this_target_flag_state;
 extern struct target_regs *this_target_regs;
+extern struct target_rtl *this_target_rtl;
 
 struct GTY(()) target_globals {
   struct target_flag_state *GTY((skip)) flag_state;
   struct target_regs *GTY((skip)) regs;
+  struct target_rtl *rtl;
 };
 
 extern struct target_globals default_target_globals;
@@ -38,6 +40,7 @@  restore_target_globals (struct target_gl
 {
   this_target_flag_state = g->flag_state;
   this_target_regs = g->regs;
+  this_target_rtl = g->rtl;
 }
 #endif
 
Index: gcc/target-globals.c
===================================================================
--- gcc/target-globals.c	2010-07-04 14:15:19.000000000 +0100
+++ gcc/target-globals.c	2010-07-04 14:15:32.000000000 +0100
@@ -28,11 +28,13 @@  Software Foundation; either version 3, o
 #include "target-globals.h"
 #include "flags.h"
 #include "regs.h"
+#include "rtl.h"
 
 #if SWITCHABLE_TARGET
 struct target_globals default_target_globals = {
   &default_target_flag_state,
-  &default_target_regs
+  &default_target_regs,
+  &default_target_rtl
 };
 
 struct target_globals *
@@ -43,6 +45,7 @@  save_target_globals (void)
   g = ggc_alloc_target_globals ();
   g->flag_state = XCNEW (struct target_flag_state);
   g->regs = XCNEW (struct target_regs);
+  g->rtl = ggc_alloc_cleared_target_rtl ();
   restore_target_globals (g);
   target_reinit ();
   return g;