Make get_insns and friends inline

Jan Hubicka hubicka@ucw.cz
Tue Jun 1 14:13:00 GMT 2010


Hi,
enother most frequent crossmodule inline is get_insns and related functions.
Those are just simple accestor to global xrtl structure, so it makes a lot of
sense to inline them.

This patch moves it to static inline as header. Doing so is however bit tricky.
They can not sit in rtl.h because crtl is defined in function.h. They can not
sit in function.h because NEXT_INSN is defined by rtl.h.

I dediced to move them all to emit-rtl.h that exists anyway and add includes as
needed.
I did not update Makefile since I think Steven might have some comments on this.
If the patch gets accepted as it is, I will udpate dependencies for sure.

It saves about 30Kb from cc1 binary.

Bootstrapped/regtested x86_64-linux, OK?

Honza

	* fwprop.c: Make emit-rtl.h include last.
	* rtlanal.c: Include emit-rtl.h.
	* genautomata.c: Output emit-rtl include into insn-automata.c
	* df-scan.c: Include emit-rtl.h.
	* haifa-sched.c: Indlude emit-rtl.h.
	* mode-switching.c: Indlude emit-rtl.h.
	* graph.c: Indlude emit-rtl.h.
	* sel-sched.c: Include emit-rtl.h.
	* sel-sched-ir.c: Include emit-rtl.h.
	* ira-build.c: Include emit-rtl.h.
	* emit-rtl.c: (first_insn, last_insn): Remove defines.
	(get_insns, set_first_insn, get_last_insn, set_last_insn, get_max_uid):
	Move to emit-rtl.h.
	(set_new_first_and_last_insn, get_last_insn_anywhere, get_first_nonnote_insn,
	get_last_nonnote_insn, try_split, make_call_insn_raw, add_insn_after,
	add_insn_before, remove_insn, delete_insns_since, reorder_insns_nobb,
	emit_insn_after_1, emit_debug_insn_before, emit_insn, start_sequence,
	push_to_sequence, push_to_sequence2, push_topmost_sequence, end_sequence,
	copy_insn): Use accessor functions.
	* emit-rtl.h (gen_blockage, gen_rtvec, copy_insn_1, copy_insn,
	 gen_int_mode, emit_copy_of_insn_after, set_reg_attrs_from_value,
	set_reg_attrs_for_parm, set_reg_attrs_for_decl_rtl, adjust_reg_mode,
	mem_expr_equal_p): Move here from rtl.h
	(get_insns, set_first-insn, get_last_insn, set_last_insn, get_max_uid):
	Move here from emit-rtl.c; make inline.
	* cfglayout.h: Include emit-rtl.h
	* rtl.h (gen_blockage, gen_rtvec, copy_insn_1, copy_insn,
	 gen_int_mode, emit_copy_of_insn_after, set_reg_attrs_from_value,
	set_reg_attrs_for_parm, set_reg_attrs_for_decl_rtl, adjust_reg_mode,
	mem_expr_equal_p, get_insns, set_first-insn, get_last_insn, set_last_insn,
	get_max_uid): Move to emit-rtl.h.
	* reg-stack.c: Include emit-rtl.h
	* dce.c: Likewise.
Index: fwprop.c
===================================================================
--- fwprop.c	(revision 160093)
+++ fwprop.c	(working copy)
@@ -28,7 +28,6 @@ along with GCC; see the file COPYING3.  
 #include "timevar.h"
 #include "rtl.h"
 #include "tm_p.h"
-#include "emit-rtl.h"
 #include "insn-config.h"
 #include "recog.h"
 #include "flags.h"
@@ -40,6 +39,7 @@ along with GCC; see the file COPYING3.  
 #include "cfgloop.h"
 #include "tree-pass.h"
 #include "domwalk.h"
+#include "emit-rtl.h"
 
 
 /* This pass does simple forward propagation and simplification when an
Index: rtlanal.c
===================================================================
--- rtlanal.c	(revision 160093)
+++ rtlanal.c	(working copy)
@@ -37,6 +37,7 @@ along with GCC; see the file COPYING3.  
 #include "function.h"
 #include "df.h"
 #include "tree.h"
+#include "emit-rtl.h"
 
 /* Forward declarations */
 static void set_of_1 (rtx, const_rtx, void *);
Index: genautomata.c
===================================================================
--- genautomata.c	(revision 160093)
+++ genautomata.c	(working copy)
@@ -9569,7 +9569,8 @@ main (int argc, char **argv)
 		"#include \"insn-attr.h\"\n"
 		"#include \"toplev.h\"\n"
 		"#include \"flags.h\"\n"
-		"#include \"function.h\"\n");
+		"#include \"function.h\"\n"
+		"#include \"emit-rtl.h\"\n");
 
 	  write_automata ();
 	}
Index: df-scan.c
===================================================================
--- df-scan.c	(revision 160093)
+++ df-scan.c	(working copy)
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  
 #include "target-def.h"
 #include "df.h"
 #include "tree-pass.h"
+#include "emit-rtl.h"
 
 DEF_VEC_P(df_ref);
 DEF_VEC_ALLOC_P_STACK(df_ref);
Index: haifa-sched.c
===================================================================
--- haifa-sched.c	(revision 160093)
+++ haifa-sched.c	(working copy)
@@ -148,6 +148,7 @@ along with GCC; see the file COPYING3.  
 #include "dbgcnt.h"
 #include "cfgloop.h"
 #include "ira.h"
+#include "emit-rtl.h"
 
 #ifdef INSN_SCHEDULING
 
Index: mode-switching.c
===================================================================
--- mode-switching.c	(revision 160093)
+++ mode-switching.c	(working copy)
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3.  
 #include "tree-pass.h"
 #include "timevar.h"
 #include "df.h"
+#include "emit-rtl.h"
 
 /* We want target macros for the mode switching code to be able to refer
    to instruction attribute values.  */
Index: graph.c
===================================================================
--- graph.c	(revision 160093)
+++ graph.c	(working copy)
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  
 #include "basic-block.h"
 #include "toplev.h"
 #include "graph.h"
+#include "emit-rtl.h"
 
 static const char *const graph_ext[] =
 {
Index: sel-sched.c
===================================================================
--- sel-sched.c	(revision 160093)
+++ sel-sched.c	(working copy)
@@ -45,6 +45,7 @@ along with GCC; see the file COPYING3.  
 #include "langhooks.h"
 #include "rtlhooks-def.h"
 #include "output.h"
+#include "emit-rtl.h"
 
 #ifdef INSN_SCHEDULING
 #include "sel-sched-ir.h"
Index: sel-sched-ir.c
===================================================================
--- sel-sched-ir.c	(revision 160093)
+++ sel-sched-ir.c	(working copy)
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  
 #include "vec.h"
 #include "langhooks.h"
 #include "rtlhooks-def.h"
+#include "emit-rtl.h"
 
 #ifdef INSN_SCHEDULING
 #include "sel-sched-ir.h"
Index: ira-build.c
===================================================================
--- ira-build.c	(revision 160093)
+++ ira-build.c	(working copy)
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  
 #include "reload.h"
 #include "sparseset.h"
 #include "ira-int.h"
+#include "emit-rtl.h"
 
 static ira_copy_t find_allocno_copy (ira_allocno_t, ira_allocno_t, rtx,
 				     ira_loop_tree_node_t);
Index: emit-rtl.c
===================================================================
--- emit-rtl.c	(revision 160093)
+++ emit-rtl.c	(working copy)
@@ -167,8 +167,6 @@ static GTY ((if_marked ("ggc_marked_p"),
 static GTY ((if_marked ("ggc_marked_p"), param_is (struct rtx_def)))
      htab_t const_fixed_htab;
 
-#define first_insn (crtl->emit.x_first_insn)
-#define last_insn (crtl->emit.x_last_insn)
 #define cur_insn_uid (crtl->emit.x_cur_insn_uid)
 #define cur_debug_insn_uid (crtl->emit.x_cur_debug_insn_uid)
 #define last_location (crtl->emit.x_last_location)
@@ -2317,8 +2315,8 @@ set_new_first_and_last_insn (rtx first, 
 {
   rtx insn;
 
-  first_insn = first;
-  last_insn = last;
+  set_first_insn (first);
+  set_last_insn (last);
   cur_insn_uid = 0;
 
   if (MIN_NONDEBUG_INSN_UID || MAY_HAVE_DEBUG_INSNS)
@@ -2926,48 +2924,14 @@ make_safe_from (rtx x, rtx other)
 
 /* Emission of insns (adding them to the doubly-linked list).  */
 
-/* Return the first insn of the current sequence or current function.  */
-
-rtx
-get_insns (void)
-{
-  return first_insn;
-}
-
-/* Specify a new insn as the first in the chain.  */
-
-void
-set_first_insn (rtx insn)
-{
-  gcc_assert (!PREV_INSN (insn));
-  first_insn = insn;
-}
-
-/* Return the last insn emitted in current sequence or current function.  */
-
-rtx
-get_last_insn (void)
-{
-  return last_insn;
-}
-
-/* Specify a new insn as the last in the chain.  */
-
-void
-set_last_insn (rtx insn)
-{
-  gcc_assert (!NEXT_INSN (insn));
-  last_insn = insn;
-}
-
 /* Return the last insn emitted, even if it is in a sequence now pushed.  */
 
 rtx
 get_last_insn_anywhere (void)
 {
   struct sequence_stack *stack;
-  if (last_insn)
-    return last_insn;
+  if (get_last_insn ())
+    return get_last_insn ();
   for (stack = seq_stack; stack; stack = stack->next)
     if (stack->last != 0)
       return stack->last;
@@ -2980,7 +2944,7 @@ get_last_insn_anywhere (void)
 rtx
 get_first_nonnote_insn (void)
 {
-  rtx insn = first_insn;
+  rtx insn = get_insns ();
 
   if (insn)
     {
@@ -3006,7 +2970,7 @@ get_first_nonnote_insn (void)
 rtx
 get_last_nonnote_insn (void)
 {
-  rtx insn = last_insn;
+  rtx insn = get_last_insn ();
 
   if (insn)
     {
@@ -3027,14 +2991,6 @@ get_last_nonnote_insn (void)
   return insn;
 }
 
-/* Return a number larger than any instruction's uid in this function.  */
-
-int
-get_max_uid (void)
-{
-  return cur_insn_uid;
-}
-
 /* Return the number of actual (non-debug) insns emitted in this
    function.  */
 
@@ -3625,7 +3581,7 @@ try_split (rtx pat, rtx trial, int last)
   /* Return either the first or the last insn, depending on which was
      requested.  */
   return last
-    ? (after ? PREV_INSN (after) : last_insn)
+    ? (after ? PREV_INSN (after) : get_last_insn ())
     : NEXT_INSN (before);
 }
 
@@ -3728,16 +3684,16 @@ make_call_insn_raw (rtx pattern)
 void
 add_insn (rtx insn)
 {
-  PREV_INSN (insn) = last_insn;
+  PREV_INSN (insn) = get_last_insn();
   NEXT_INSN (insn) = 0;
 
-  if (NULL != last_insn)
-    NEXT_INSN (last_insn) = insn;
+  if (NULL != get_last_insn())
+    NEXT_INSN (get_last_insn ()) = insn;
 
-  if (NULL == first_insn)
-    first_insn = insn;
+  if (NULL == get_insns ())
+    set_first_insn (insn);
 
-  last_insn = insn;
+  set_last_insn (insn);
 }
 
 /* Add INSN into the doubly-linked list after insn AFTER.  This and
@@ -3761,8 +3717,8 @@ add_insn_after (rtx insn, rtx after, bas
       if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE)
 	PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = insn;
     }
-  else if (last_insn == after)
-    last_insn = insn;
+  else if (get_last_insn () == after)
+    set_last_insn (insn);
   else
     {
       struct sequence_stack *stack = seq_stack;
@@ -3826,8 +3782,8 @@ add_insn_before (rtx insn, rtx before, b
 	  NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = insn;
 	}
     }
-  else if (first_insn == before)
-    first_insn = insn;
+  else if (get_insns () == before)
+    set_first_insn (insn);
   else
     {
       struct sequence_stack *stack = seq_stack;
@@ -3898,8 +3854,11 @@ remove_insn (rtx insn)
 	  NEXT_INSN (XVECEXP (sequence, 0, XVECLEN (sequence, 0) - 1)) = next;
 	}
     }
-  else if (first_insn == insn)
-    first_insn = next;
+  else if (get_insns () == insn)
+    {
+      PREV_INSN (next) = NULL;
+      set_first_insn (next);
+    }
   else
     {
       struct sequence_stack *stack = seq_stack;
@@ -3920,8 +3879,8 @@ remove_insn (rtx insn)
       if (NONJUMP_INSN_P (next) && GET_CODE (PATTERN (next)) == SEQUENCE)
 	PREV_INSN (XVECEXP (PATTERN (next), 0, 0)) = prev;
     }
-  else if (last_insn == insn)
-    last_insn = prev;
+  else if (get_last_insn () == insn)
+    set_last_insn (prev);
   else
     {
       struct sequence_stack *stack = seq_stack;
@@ -3982,10 +3941,10 @@ void
 delete_insns_since (rtx from)
 {
   if (from == 0)
-    first_insn = 0;
+    set_first_insn (0);
   else
     NEXT_INSN (from) = 0;
-  last_insn = from;
+  set_last_insn (from);
 }
 
 /* This function is deprecated, please use sequences instead.
@@ -4006,10 +3965,10 @@ reorder_insns_nobb (rtx from, rtx to, rt
     NEXT_INSN (PREV_INSN (from)) = NEXT_INSN (to);
   if (NEXT_INSN (to))
     PREV_INSN (NEXT_INSN (to)) = PREV_INSN (from);
-  if (last_insn == to)
-    last_insn = PREV_INSN (from);
-  if (first_insn == from)
-    first_insn = NEXT_INSN (to);
+  if (get_last_insn () == to)
+    set_last_insn (PREV_INSN (from));
+  if (get_insns () == from)
+    set_first_insn (NEXT_INSN (to));
 
   /* Make the new neighbors point to it and it to them.  */
   if (NEXT_INSN (after))
@@ -4018,8 +3977,8 @@ reorder_insns_nobb (rtx from, rtx to, rt
   NEXT_INSN (to) = NEXT_INSN (after);
   PREV_INSN (from) = after;
   NEXT_INSN (after) = from;
-  if (after == last_insn)
-    last_insn = to;
+  if (after == get_last_insn())
+    set_last_insn (to);
 }
 
 /* Same as function above, but take care to update BB boundaries.  */
@@ -4344,8 +4303,8 @@ emit_insn_after_1 (rtx first, rtx after,
   if (after_after)
     PREV_INSN (after_after) = last;
 
-  if (after == last_insn)
-    last_insn = last;
+  if (after == get_last_insn())
+    set_last_insn (last);
 
   return last;
 }
@@ -4842,7 +4801,7 @@ emit_debug_insn_before (rtx pattern, rtx
 rtx
 emit_insn (rtx x)
 {
-  rtx last = last_insn;
+  rtx last = get_last_insn();
   rtx insn;
 
   if (x == NULL_RTX)
@@ -4888,7 +4847,7 @@ emit_insn (rtx x)
 rtx
 emit_debug_insn (rtx x)
 {
-  rtx last = last_insn;
+  rtx last = get_last_insn();
   rtx insn;
 
   if (x == NULL_RTX)
@@ -5283,13 +5242,13 @@ start_sequence (void)
     tem = GGC_NEW (struct sequence_stack);
 
   tem->next = seq_stack;
-  tem->first = first_insn;
-  tem->last = last_insn;
+  tem->first = get_insns ();
+  tem->last = get_last_insn ();
 
   seq_stack = tem;
 
-  first_insn = 0;
-  last_insn = 0;
+  set_first_insn (0);
+  set_last_insn (0);
 }
 
 /* Set up the insn chain starting with FIRST as the current sequence,
@@ -5305,8 +5264,8 @@ push_to_sequence (rtx first)
 
   for (last = first; last && NEXT_INSN (last); last = NEXT_INSN (last));
 
-  first_insn = first;
-  last_insn = last;
+  set_first_insn (first);
+  set_last_insn (last);
 }
 
 /* Like push_to_sequence, but take the last insn as an argument to avoid
@@ -5317,8 +5276,8 @@ push_to_sequence2 (rtx first, rtx last)
 {
   start_sequence ();
 
-  first_insn = first;
-  last_insn = last;
+  set_first_insn (first);
+  set_last_insn (last);
 }
 
 /* Set up the outer-level insn chain
@@ -5334,8 +5293,8 @@ push_topmost_sequence (void)
   for (stack = seq_stack; stack; stack = stack->next)
     top = stack;
 
-  first_insn = top->first;
-  last_insn = top->last;
+  set_first_insn (top->first);
+  set_last_insn (top->last);
 }
 
 /* After emitting to the outer-level insn chain, update the outer-level
@@ -5349,8 +5308,8 @@ pop_topmost_sequence (void)
   for (stack = seq_stack; stack; stack = stack->next)
     top = stack;
 
-  top->first = first_insn;
-  top->last = last_insn;
+  top->first = get_insns ();
+  top->last = get_last_insn ();
 
   end_sequence ();
 }
@@ -5373,8 +5332,8 @@ end_sequence (void)
 {
   struct sequence_stack *tem = seq_stack;
 
-  first_insn = tem->first;
-  last_insn = tem->last;
+  set_first_insn (tem->first);
+  set_last_insn (tem->last);
   seq_stack = tem->next;
 
   memset (tem, 0, sizeof (*tem));
@@ -5576,8 +5535,8 @@ copy_insn (rtx insn)
 void
 init_emit (void)
 {
-  first_insn = NULL;
-  last_insn = NULL;
+  set_first_insn (NULL);
+  set_last_insn (NULL);
   if (MIN_NONDEBUG_INSN_UID)
     cur_insn_uid = MIN_NONDEBUG_INSN_UID;
   else
Index: emit-rtl.h
===================================================================
--- emit-rtl.h	(revision 160093)
+++ emit-rtl.h	(working copy)
@@ -51,4 +51,57 @@ extern rtx replace_equiv_address (rtx, r
 /* Likewise, but the reference is not required to be valid.  */
 extern rtx replace_equiv_address_nv (rtx, rtx);
 
+extern rtx gen_blockage (void);
+extern rtvec gen_rtvec (int, ...);
+extern rtx copy_insn_1 (rtx);
+extern rtx copy_insn (rtx);
+extern rtx gen_int_mode (HOST_WIDE_INT, enum machine_mode);
+extern rtx emit_copy_of_insn_after (rtx, rtx);
+extern void set_reg_attrs_from_value (rtx, rtx);
+extern void set_reg_attrs_for_parm (rtx, rtx);
+extern void set_reg_attrs_for_decl_rtl (tree t, rtx x);
+extern void adjust_reg_mode (rtx, enum machine_mode);
+extern int mem_expr_equal_p (const_tree, const_tree);
+
+/* Return the first insn of the current sequence or current function.  */
+
+static inline rtx
+get_insns (void)
+{
+  return crtl->emit.x_first_insn;
+}
+
+/* Specify a new insn as the first in the chain.  */
+
+static inline void
+set_first_insn (rtx insn)
+{
+  gcc_assert (!insn || !PREV_INSN (insn));
+  crtl->emit.x_first_insn = insn;
+}
+
+/* Return the last insn emitted in current sequence or current function.  */
+
+static inline rtx
+get_last_insn (void)
+{
+  return crtl->emit.x_last_insn;
+}
+
+/* Specify a new insn as the last in the chain.  */
+
+static inline void
+set_last_insn (rtx insn)
+{
+  gcc_assert (!insn || !NEXT_INSN (insn));
+  crtl->emit.x_last_insn = insn;
+}
+
+/* Return a number larger than any instruction's uid in this function.  */
+
+static inline int
+get_max_uid (void)
+{
+  return crtl->emit.x_cur_insn_uid;
+}
 #endif /* GCC_EMIT_RTL_H */
Index: cfglayout.c
===================================================================
--- cfglayout.c	(revision 160093)
+++ cfglayout.c	(working copy)
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  
 #include "tree-pass.h"
 #include "df.h"
 #include "vecprim.h"
+#include "emit-rtl.h"
 
 /* Holds the interesting trailing notes for the function.  */
 rtx cfg_layout_function_footer;
Index: rtl.h
===================================================================
--- rtl.h	(revision 160093)
+++ rtl.h	(working copy)
@@ -1051,7 +1051,6 @@ rhs_regno (const_rtx x)
 }
 
 
-
 /* 1 if RTX is a reg or parallel that is the current function's return
    value.  */
 #define REG_FUNCTION_VALUE_P(RTX)					\
@@ -1551,19 +1550,6 @@ extern int ceil_log2 (unsigned HOST_WIDE
 extern HOST_WIDE_INT trunc_int_for_mode	(HOST_WIDE_INT, enum machine_mode);
 extern rtx plus_constant (rtx, HOST_WIDE_INT);
 
-/* In emit-rtl.c */
-extern rtx gen_blockage (void);
-extern rtvec gen_rtvec (int, ...);
-extern rtx copy_insn_1 (rtx);
-extern rtx copy_insn (rtx);
-extern rtx gen_int_mode (HOST_WIDE_INT, enum machine_mode);
-extern rtx emit_copy_of_insn_after (rtx, rtx);
-extern void set_reg_attrs_from_value (rtx, rtx);
-extern void set_reg_attrs_for_parm (rtx, rtx);
-extern void set_reg_attrs_for_decl_rtl (tree t, rtx x);
-extern void adjust_reg_mode (rtx, enum machine_mode);
-extern int mem_expr_equal_p (const_tree, const_tree);
-
 /* In rtl.c */
 extern rtx rtx_alloc_stat (RTX_CODE MEM_STAT_DECL);
 #define rtx_alloc(c) rtx_alloc_stat (c MEM_STAT_INFO)
@@ -1613,9 +1599,7 @@ extern rtx convert_memory_address_addr_s
 					      addr_space_t);
 #define convert_memory_address(to_mode,x) \
 	convert_memory_address_addr_space ((to_mode), (x), ADDR_SPACE_GENERIC)
-extern rtx get_insns (void);
 extern const char *get_insn_name (int);
-extern rtx get_last_insn (void);
 extern rtx get_last_insn_anywhere (void);
 extern rtx get_first_nonnote_insn (void);
 extern rtx get_last_nonnote_insn (void);
@@ -2216,7 +2200,6 @@ extern void reset_used_flags (rtx);
 extern void set_used_flags (rtx);
 extern void reorder_insns (rtx, rtx, rtx);
 extern void reorder_insns_nobb (rtx, rtx, rtx);
-extern int get_max_uid (void);
 extern int get_max_insn_count (void);
 extern int in_sequence_p (void);
 extern void force_next_line_note (void);
@@ -2230,8 +2213,6 @@ extern unsigned int unshare_all_rtl (voi
 extern void unshare_all_rtl_again (rtx);
 extern void unshare_all_rtl_in_chain (rtx);
 extern void verify_rtl_sharing (void);
-extern void set_first_insn (rtx);
-extern void set_last_insn (rtx);
 extern void link_cc0_insns (rtx);
 extern void add_insn (rtx);
 extern void add_insn_before (rtx, rtx, struct basic_block_def *);
Index: reg-stack.c
===================================================================
--- reg-stack.c	(revision 160093)
+++ reg-stack.c	(working copy)
@@ -175,6 +175,7 @@
 #include "target.h"
 #include "df.h"
 #include "vecprim.h"
+#include "emit-rtl.h"
 
 #ifdef STACK_REGS
 
Index: dce.c
===================================================================
--- dce.c	(revision 160093)
+++ dce.c	(working copy)
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  
 #include "tree-pass.h"
 #include "dbgcnt.h"
 #include "tm_p.h"
+#include "emit-rtl.h"
 
 
 /* -------------------------------------------------------------------------



More information about the Gcc-patches mailing list