From 1ece7181023942a7d69a5ad36aab8d8b45226011 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 21 Apr 2016 11:36:35 -0400
Subject: [PATCH 16/28] FIXME: start turning emit_status into a class

---
 gcc/config/rs6000/rs6000.c |  3 ++-
 gcc/config/sparc/sparc.c   |  2 +-
 gcc/emit-rtl.c             | 62 ++++++++++++++++++++++++++++++++++++++--------
 gcc/emit-rtl.h             | 18 +++++++-------
 gcc/function.c             |  2 +-
 gcc/function.h             | 16 ++++++++++++
 gcc/rtl.h                  |  2 --
 gcc/rtl/rtl-frontend.c     |  2 +-
 8 files changed, 81 insertions(+), 26 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 99a2e36..9f2dee6 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -24135,7 +24135,8 @@ compute_save_world_info (rs6000_stack_t *info)
   if (WORLD_SAVE_P (info))
     {
       rtx_insn *insn;
-      for (insn = get_last_insn_anywhere (); insn; insn = PREV_INSN (insn))
+      for (insn = crtl->emit.get_last_insn_anywhere (); insn;
+	   insn = PREV_INSN (insn))
 	if (CALL_P (insn) && SIBLING_CALL_P (insn))
 	  {
 	    info->world_save_p = 0;
diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index 1d2ecaa..dacfb03 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -9746,7 +9746,7 @@ sparc_check_64 (rtx x, rtx_insn *insn)
   if (insn == 0)
     {
       if (set_once)
-	insn = get_last_insn_anywhere ();
+	insn = crtl->emit.get_last_insn_anywhere ();
       else
 	return 0;
     }
diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c
index 0af7612..cc48772 100644
--- a/gcc/emit-rtl.c
+++ b/gcc/emit-rtl.c
@@ -3172,7 +3172,7 @@ make_safe_from (rtx x, rtx other)
 /* Return the last insn emitted, even if it is in a sequence now pushed.  */
 
 rtx_insn *
-get_last_insn_anywhere (void)
+emit_status::get_last_insn_anywhere ()
 {
   struct sequence_stack *seq;
   for (seq = get_current_sequence (); seq; seq = seq->next)
@@ -4007,7 +4007,7 @@ add_insn_after_nobb (rtx_insn *insn, rtx_insn *after)
     {
       struct sequence_stack *seq;
 
-      for (seq = get_current_sequence (); seq; seq = seq->next)
+      for (seq = crtl->emit.get_current_sequence (); seq; seq = seq->next)
 	if (after == seq->last)
 	  {
 	    seq->last = insn;
@@ -4031,7 +4031,7 @@ add_insn_before_nobb (rtx_insn *insn, rtx_insn *before)
     {
       struct sequence_stack *seq;
 
-      for (seq = get_current_sequence (); seq; seq = seq->next)
+      for (seq = crtl->emit.get_current_sequence (); seq; seq = seq->next)
 	if (before == seq->first)
 	  {
 	    seq->first = insn;
@@ -4153,7 +4153,7 @@ remove_insn (rtx uncast_insn)
     {
       struct sequence_stack *seq;
 
-      for (seq = get_current_sequence (); seq; seq = seq->next)
+      for (seq = crtl->emit.get_current_sequence (); seq; seq = seq->next)
 	if (insn == seq->first)
 	  {
 	    seq->first = next;
@@ -4176,7 +4176,7 @@ remove_insn (rtx uncast_insn)
     {
       struct sequence_stack *seq;
 
-      for (seq = get_current_sequence (); seq; seq = seq->next)
+      for (seq = crtl->emit.get_current_sequence (); seq; seq = seq->next)
 	if (insn == seq->last)
 	  {
 	    seq->last = prev;
@@ -5331,6 +5331,14 @@ emit (rtx x, bool allow_barrier_p)
 /* Space for free sequence stack entries.  */
 static GTY ((deletable)) struct sequence_stack *free_sequence_stack;
 
+/* FIXME.  */
+
+void
+start_sequence (void)
+{
+  crtl->emit.start_sequence ();
+}
+
 /* Begin emitting insns to a sequence.  If this sequence will contain
    something that might cause the compiler to pop arguments to function
    calls (because those pops have previously been deferred; see
@@ -5339,7 +5347,7 @@ static GTY ((deletable)) struct sequence_stack *free_sequence_stack;
    pops are not accidentally emitted in the middle of this sequence.  */
 
 void
-start_sequence (void)
+emit_status::start_sequence ()
 {
   struct sequence_stack *tem;
 
@@ -5394,7 +5402,7 @@ push_to_sequence2 (rtx_insn *first, rtx_insn *last)
    as the current sequence, saving the previously current one.  */
 
 void
-push_topmost_sequence (void)
+emit_status::push_topmost_sequence ()
 {
   struct sequence_stack *top;
 
@@ -5405,11 +5413,19 @@ push_topmost_sequence (void)
   set_last_insn (top->last);
 }
 
+/* FIXME. */
+
+void
+push_topmost_sequence (void)
+{
+  crtl->emit.push_topmost_sequence ();
+}
+
 /* After emitting to the outer-level insn chain, update the outer-level
    insn chain, and restore the previous saved state.  */
 
 void
-pop_topmost_sequence (void)
+emit_status::pop_topmost_sequence ()
 {
   struct sequence_stack *top;
 
@@ -5420,6 +5436,14 @@ pop_topmost_sequence (void)
   end_sequence ();
 }
 
+/* FIXME. */
+
+void
+pop_topmost_sequence (void)
+{
+  crtl->emit.pop_topmost_sequence ();
+}
+
 /* After emitting to a sequence, restore previous saved state.
 
    To get the contents of the sequence just made, you must call
@@ -5434,7 +5458,7 @@ pop_topmost_sequence (void)
    information about deferred popping of arguments.  */
 
 void
-end_sequence (void)
+emit_status::end_sequence (void)
 {
   struct sequence_stack *tem = get_current_sequence ()->next;
 
@@ -5447,12 +5471,28 @@ end_sequence (void)
   free_sequence_stack = tem;
 }
 
+/* FIXME.  */
+
+void
+end_sequence (void)
+{
+  crtl->emit.end_sequence ();
+}
+
 /* Return 1 if currently emitting into a sequence.  */
 
+bool
+emit_status::in_sequence_p ()
+{
+  return get_current_sequence ()->next != 0;
+}
+
+/* FIXME.  */
+
 int
 in_sequence_p (void)
 {
-  return get_current_sequence ()->next != 0;
+  return crtl->emit.in_sequence_p ();
 }
 
 /* Put the various virtual registers into REGNO_REG_RTX.  */
@@ -5657,7 +5697,7 @@ copy_delay_slot_insn (rtx_insn *insn)
    before generating rtl for each function.  */
 
 void
-init_emit (void)
+emit_status::init_emit (void)
 {
   set_first_insn (NULL);
   set_last_insn (NULL);
diff --git a/gcc/emit-rtl.h b/gcc/emit-rtl.h
index 80cb50d..23e21c8 100644
--- a/gcc/emit-rtl.h
+++ b/gcc/emit-rtl.h
@@ -367,16 +367,16 @@ extern bool need_atomic_barrier_p (enum memmodel, bool);
 
 /* Return the current sequence.  */
 
-static inline struct sequence_stack *
-get_current_sequence (void)
+inline struct sequence_stack *
+emit_status::get_current_sequence (void)
 {
   return &crtl->emit.seq;
 }
 
 /* Return the outermost sequence.  */
 
-static inline struct sequence_stack *
-get_topmost_sequence (void)
+inline struct sequence_stack *
+emit_status::get_topmost_sequence (void)
 {
   struct sequence_stack *seq, *top;
 
@@ -394,7 +394,7 @@ get_topmost_sequence (void)
 static inline rtx_insn *
 get_insns (void)
 {
-  return get_current_sequence ()->first;
+  return crtl->emit.get_current_sequence ()->first;
 }
 
 /* Specify a new insn as the first in the chain.  */
@@ -403,7 +403,7 @@ static inline void
 set_first_insn (rtx_insn *insn)
 {
   gcc_checking_assert (!insn || !PREV_INSN (insn));
-  get_current_sequence ()->first = insn;
+  crtl->emit.get_current_sequence ()->first = insn;
 }
 
 /* Return the last insn emitted in current sequence or current function.  */
@@ -411,7 +411,7 @@ set_first_insn (rtx_insn *insn)
 static inline rtx_insn *
 get_last_insn (void)
 {
-  return get_current_sequence ()->last;
+  return crtl->emit.get_current_sequence ()->last;
 }
 
 /* Specify a new insn as the last in the chain.  */
@@ -420,12 +420,12 @@ static inline void
 set_last_insn (rtx_insn *insn)
 {
   gcc_checking_assert (!insn || !NEXT_INSN (insn));
-  get_current_sequence ()->last = insn;
+  crtl->emit.get_current_sequence ()->last = insn;
 }
 
 /* Return a number larger than any instruction's uid in this function.  */
 
-static inline int
+inline int
 get_max_uid (void)
 {
   return crtl->emit.x_cur_insn_uid;
diff --git a/gcc/function.c b/gcc/function.c
index 3e910b0..0a232ec 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -4967,7 +4967,7 @@ prepare_function_start (void)
 {
   gcc_assert (!get_last_insn ());
   init_temp_slots ();
-  init_emit ();
+  crtl->emit.init_emit ();
   init_varasm_status ();
   init_expr ();
   default_rtl_profile ();
diff --git a/gcc/function.h b/gcc/function.h
index 5272cbb..f7aebcd 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -34,6 +34,22 @@ struct GTY(()) sequence_stack {
 };
 
 struct GTY(()) emit_status {
+ public:
+  void init_emit ();
+
+  inline struct sequence_stack * get_current_sequence ();
+  inline struct sequence_stack *get_topmost_sequence ();
+  void start_sequence ();
+  void end_sequence ();
+  bool in_sequence_p ();
+  void push_topmost_sequence ();
+  void pop_topmost_sequence ();
+
+  rtx_insn *get_last_insn_anywhere ();
+
+  // private:
+  friend int ::get_max_uid (void);
+
   /* This is reset to LAST_VIRTUAL_REGISTER + 1 at the start of each function.
      After rtl generation, it is 1 plus the largest register number used.  */
   int x_reg_rtx_no;
diff --git a/gcc/rtl.h b/gcc/rtl.h
index 7b86e1a..9eb9238 100644
--- a/gcc/rtl.h
+++ b/gcc/rtl.h
@@ -2754,7 +2754,6 @@ extern rtx convert_memory_address_addr_space (machine_mode, rtx,
 #define convert_memory_address(to_mode,x) \
 	convert_memory_address_addr_space ((to_mode), (x), ADDR_SPACE_GENERIC)
 extern const char *get_insn_name (int);
-extern rtx_insn *get_last_insn_anywhere (void);
 extern rtx_insn *get_first_nonnote_insn (void);
 extern rtx_insn *get_last_nonnote_insn (void);
 extern void start_sequence (void);
@@ -3518,7 +3517,6 @@ extern void reorder_insns (rtx_insn *, rtx_insn *, rtx_insn *);
 extern void reorder_insns_nobb (rtx_insn *, rtx_insn *, rtx_insn *);
 extern int get_max_insn_count (void);
 extern int in_sequence_p (void);
-extern void init_emit (void);
 extern void init_emit_regs (void);
 extern void init_derived_machine_modes (void);
 extern void init_emit_once (void);
diff --git a/gcc/rtl/rtl-frontend.c b/gcc/rtl/rtl-frontend.c
index 1523457..e449628 100644
--- a/gcc/rtl/rtl-frontend.c
+++ b/gcc/rtl/rtl-frontend.c
@@ -234,7 +234,7 @@ rtl_langhook_parse_file (void)
   in_rtl_frontend_p = true;
 
   initialize_rtl ();
-  init_emit ();
+  crtl->emit.init_emit ();
   init_varasm_status ();
 
   auto_vec<const char *> argv (num_in_fnames + 1);
-- 
1.8.5.3

