diff mbox

Remove obfuscation from the scheduler

Message ID 4DD51D17.7000508@codesourcery.com
State New
Headers show

Commit Message

Bernd Schmidt May 19, 2011, 1:37 p.m. UTC
In the scheduler initialization code, we want to set up the h_i_d array.
So we call haifa_init_h_i_d, which has a table of function pointers
which it passes to sched_scan, which copies the function pointer table
pointer to a global variable and then calls functions like init_insn,
which checks the global variable whether one of the function pointers is
nonnull, and if not calls the function we actually want (init_h_i_d).

Half of the arguments to sched_scan are never actually used. sel-sched
pretends to use the insns vector, but it actually passes in a global
variable that's always NULL. Another argument can be eliminated by
simply calling the necessary function(s) directly rather than going
through sched_scan.

This patch removes most of the craziness. The forest of indirections is
gone, and sched_scan is moved (in a much reduced form) to sel-sched-ir.c
where the sel-sched maintainers can decide whether to eliminate it
altogether.

Bootstrapped on i686-linux; regression tests running. Ok?


Bernd
* haifa-sched.c (sched_scan_info): Remove.
	(schedule_block): Call sched_extend_luids rather than sched_init_luids
	with NULL args.
	(extend_bb, init_bb, extend_insn, init_insn, init_insns_in_bb):
	Remove functions.
	(sched_scan): Remove.
	(sched_extend_luids): Renamed from luids_extend_insn and no longer
	static.  All callers changed.
	(sched_init_insn_luid): Renamed from luids_init_insn and no longer
	static.  All callers changed.
	(sched_init_luids): Remove all arguments except the first.  All
	callers changed.  Don't use sched_scan.
	(haifa_init_h_i_d): Likewise.
	(haifa_init_insn): Call sched_extend_luids and sched_init_insn_luid
	manually rather than using sched_init_luids.  Likewise with
	extend_h_i_d, init_h_i_d and haifa_init_h_i_d.
	* sel-sched.c (sel_region_target_finish): Call sched_extend_luids
	rather than sched_init_luids with NULL args.
	* sel-sched-ir.c (new_insns): Remove variable.
	(sched_scan): New static function, previously in haifa-sched.c.  Remove
	all arguments but the first two; all callers changed.
	(sel_init_new_insn): Call sched_extend_luids and sched_init_insn_luid
	rather than sched_init_luids.
	(sel_init_bbs): Remove second argument.  All callers changed.
	(sel_add_bb): Call sched_extend_luids rather than sched_init_luids
	with NULL arguments.
	(create_insn_rtx_from_pattern): Likewise.
	* sel-sched-ir.h (sel_init_bbs): Adjust declaration.
	* sched-int.h (sched_init_luids, haifa_init_h_i_d): Likewise.
	(sched_init_insn_luid, sched_extend_luids): Declare.
	(sched_scan_info_def, sched_scan_info, sched_scan): Remove
	declarations.

Comments

Jeff Law May 23, 2011, 4:18 p.m. UTC | #1
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/19/11 07:37, Bernd Schmidt wrote:
> In the scheduler initialization code, we want to set up the h_i_d array.
> So we call haifa_init_h_i_d, which has a table of function pointers
> which it passes to sched_scan, which copies the function pointer table
> pointer to a global variable and then calls functions like init_insn,
> which checks the global variable whether one of the function pointers is
> nonnull, and if not calls the function we actually want (init_h_i_d).
> 
> Half of the arguments to sched_scan are never actually used. sel-sched
> pretends to use the insns vector, but it actually passes in a global
> variable that's always NULL. Another argument can be eliminated by
> simply calling the necessary function(s) directly rather than going
> through sched_scan.
> 
> This patch removes most of the craziness. The forest of indirections is
> gone, and sched_scan is moved (in a much reduced form) to sel-sched-ir.c
> where the sel-sched maintainers can decide whether to eliminate it
> altogether.
> 
> Bootstrapped on i686-linux; regression tests running. Ok?
Ok.
jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJN2ojZAAoJEBRtltQi2kC7hyYIAJ2IZ91/I4o0fqNljWPQy33o
7hgnV6Uy790QAlrfIVhQ/K4ceJRyo/0oHe/L/R87lemqronnUZiSSvA917G1mXEb
LbjzjK0meGEl9pZZ3kwiCkJIWyUGqpEhDlRlVICqabpnFyu6fsOPJVrG9ZI8IIbz
4t+BwrawtB4+kAcsDZR2XvCEH4mte9an7nRlWUrHLvXuNWR8hxUS6T2Mx8dTtRH9
tC4BEodedbMGHeg8Sz3nAAftZ6SvGdS3K/Huwpl+VZ1uL2d2w+bTkgoLxobvNxtU
hqrRgKlYGaeDuqgUyDmayPR9mNwM9GC7OXsJ8n12vmVe6p9FlFPV5yN/d8hCfpU=
=aYbv
-----END PGP SIGNATURE-----
diff mbox

Patch

Index: haifa-sched.c
===================================================================
--- haifa-sched.c	(revision 173854)
+++ haifa-sched.c	(working copy)
@@ -332,8 +332,6 @@  const struct common_sched_info_def haifa
     SCHED_PASS_UNKNOWN /* sched_pass_id */
   };
 
-const struct sched_scan_info_def *sched_scan_info;
-
 /* Mapping from instruction UID to its Logical UID.  */
 VEC (int, heap) *sched_luids = NULL;
 
@@ -3360,7 +3358,7 @@  schedule_block (basic_block *target_bb)
 	 in its md_finish () hook.  These new insns don't have any data
 	 initialized and to identify them we extend h_i_d so that they'll
 	 get zero luids.  */
-      sched_init_luids (NULL, NULL, NULL, NULL);
+      sched_extend_luids ();
     }
 
   if (sched_verbose)
@@ -3568,10 +3566,10 @@  haifa_sched_init (void)
 
     FOR_EACH_BB (bb)
       VEC_quick_push (basic_block, bbs, bb);
-    sched_init_luids (bbs, NULL, NULL, NULL);
+    sched_init_luids (bbs);
     sched_deps_init (true);
     sched_extend_target ();
-    haifa_init_h_i_d (bbs, NULL, NULL, NULL);
+    haifa_init_h_i_d (bbs);
 
     VEC_free (basic_block, heap, bbs);
   }
@@ -5359,105 +5357,9 @@  check_cfg (rtx head, rtx tail)
 
 #endif /* ENABLE_CHECKING */
 
-/* Extend per basic block data structures.  */
-static void
-extend_bb (void)
-{
-  if (sched_scan_info->extend_bb)
-    sched_scan_info->extend_bb ();
-}
-
-/* Init data for BB.  */
-static void
-init_bb (basic_block bb)
-{
-  if (sched_scan_info->init_bb)
-    sched_scan_info->init_bb (bb);
-}
-
-/* Extend per insn data structures.  */
-static void
-extend_insn (void)
-{
-  if (sched_scan_info->extend_insn)
-    sched_scan_info->extend_insn ();
-}
-
-/* Init data structures for INSN.  */
-static void
-init_insn (rtx insn)
-{
-  if (sched_scan_info->init_insn)
-    sched_scan_info->init_insn (insn);
-}
-
-/* Init all insns in BB.  */
-static void
-init_insns_in_bb (basic_block bb)
-{
-  rtx insn;
-
-  FOR_BB_INSNS (bb, insn)
-    init_insn (insn);
-}
-
-/* A driver function to add a set of basic blocks (BBS),
-   a single basic block (BB), a set of insns (INSNS) or a single insn (INSN)
-   to the scheduling region.  */
-void
-sched_scan (const struct sched_scan_info_def *ssi,
-	    bb_vec_t bbs, basic_block bb, insn_vec_t insns, rtx insn)
-{
-  sched_scan_info = ssi;
-
-  if (bbs != NULL || bb != NULL)
-    {
-      extend_bb ();
-
-      if (bbs != NULL)
-	{
-	  unsigned i;
-	  basic_block x;
-
-	  FOR_EACH_VEC_ELT (basic_block, bbs, i, x)
-	    init_bb (x);
-	}
-
-      if (bb != NULL)
-	init_bb (bb);
-    }
-
-  extend_insn ();
-
-  if (bbs != NULL)
-    {
-      unsigned i;
-      basic_block x;
-
-      FOR_EACH_VEC_ELT (basic_block, bbs, i, x)
-	init_insns_in_bb (x);
-    }
-
-  if (bb != NULL)
-    init_insns_in_bb (bb);
-
-  if (insns != NULL)
-    {
-      unsigned i;
-      rtx x;
-
-      FOR_EACH_VEC_ELT (rtx, insns, i, x)
-	init_insn (x);
-    }
-
-  if (insn != NULL)
-    init_insn (insn);
-}
-
-
 /* Extend data structures for logical insn UID.  */
-static void
-luids_extend_insn (void)
+void
+sched_extend_luids (void)
 {
   int new_luids_max_uid = get_max_uid () + 1;
 
@@ -5465,8 +5367,8 @@  luids_extend_insn (void)
 }
 
 /* Initialize LUID for INSN.  */
-static void
-luids_init_insn (rtx insn)
+void
+sched_init_insn_luid (rtx insn)
 {
   int i = INSN_P (insn) ? 1 : common_sched_info->luid_for_non_insn (insn);
   int luid;
@@ -5482,21 +5384,23 @@  luids_init_insn (rtx insn)
   SET_INSN_LUID (insn, luid);
 }
 
-/* Initialize luids for BBS, BB, INSNS and INSN.
+/* Initialize luids for BBS.
    The hook common_sched_info->luid_for_non_insn () is used to determine
    if notes, labels, etc. need luids.  */
 void
-sched_init_luids (bb_vec_t bbs, basic_block bb, insn_vec_t insns, rtx insn)
+sched_init_luids (bb_vec_t bbs)
 {
-  const struct sched_scan_info_def ssi =
+  int i;
+  basic_block bb;
+
+  sched_extend_luids ();
+  FOR_EACH_VEC_ELT (basic_block, bbs, i, bb)
     {
-      NULL, /* extend_bb */
-      NULL, /* init_bb */
-      luids_extend_insn, /* extend_insn */
-      luids_init_insn /* init_insn */
-    };
+      rtx insn;
 
-  sched_scan (&ssi, bbs, bb, insns, insn);
+      FOR_BB_INSNS (bb, insn)
+	sched_init_insn_luid (insn);
+    }
 }
 
 /* Free LUIDs.  */
@@ -5553,19 +5457,21 @@  init_h_i_d (rtx insn)
     }
 }
 
-/* Initialize haifa_insn_data for BBS, BB, INSNS and INSN.  */
+/* Initialize haifa_insn_data for BBS.  */
 void
-haifa_init_h_i_d (bb_vec_t bbs, basic_block bb, insn_vec_t insns, rtx insn)
+haifa_init_h_i_d (bb_vec_t bbs)
 {
-  const struct sched_scan_info_def ssi =
+  int i;
+  basic_block bb;
+
+  extend_h_i_d ();
+  FOR_EACH_VEC_ELT (basic_block, bbs, i, bb)
     {
-      NULL, /* extend_bb */
-      NULL, /* init_bb */
-      extend_h_i_d, /* extend_insn */
-      init_h_i_d /* init_insn */
-    };
+      rtx insn;
 
-  sched_scan (&ssi, bbs, bb, insns, insn);
+      FOR_BB_INSNS (bb, insn)
+	init_h_i_d (insn);
+    }
 }
 
 /* Finalize haifa_insn_data.  */
@@ -5594,10 +5500,12 @@  haifa_init_insn (rtx insn)
 {
   gcc_assert (insn != NULL);
 
-  sched_init_luids (NULL, NULL, NULL, insn);
+  sched_extend_luids ();
+  sched_init_insn_luid (insn);
   sched_extend_target ();
   sched_deps_init (false);
-  haifa_init_h_i_d (NULL, NULL, NULL, insn);
+  extend_h_i_d ();
+  init_h_i_d (insn);
 
   if (adding_bb_to_current_region_p)
     {
Index: sel-sched.c
===================================================================
--- sel-sched.c	(revision 173854)
+++ sel-sched.c	(working copy)
@@ -6868,7 +6868,7 @@  sel_region_init (int rgn)
   for (i = 0; i < current_nr_blocks; i++)
     VEC_quick_push (basic_block, bbs, BASIC_BLOCK (BB_TO_BLOCK (i)));
 
-  sel_init_bbs (bbs, NULL);
+  sel_init_bbs (bbs);
 
   if (flag_sel_sched_pipelining)
     setup_current_loop_nest (rgn, &bbs);
@@ -6877,13 +6877,13 @@  sel_region_init (int rgn)
 
   /* Initialize luids and dependence analysis which both sel-sched and haifa
      need.  */
-  sched_init_luids (bbs, NULL, NULL, NULL);
+  sched_init_luids (bbs);
   sched_deps_init (false);
 
   /* Initialize haifa data.  */
   rgn_setup_sched_infos ();
   sel_set_sched_flags ();
-  haifa_init_h_i_d (bbs, NULL, NULL, NULL);
+  haifa_init_h_i_d (bbs);
 
   sel_compute_priorities (rgn);
   init_deps_global ();
@@ -7215,7 +7215,7 @@  sel_region_target_finish (bool reset_sch
 
 	  /* Extend luids so that insns generated by the target will
 	     get zero luid.  */
-	  sched_init_luids (NULL, NULL, NULL, NULL);
+	  sched_extend_luids ();
 	}
     }
 
Index: sel-sched-ir.c
===================================================================
--- sel-sched-ir.c	(revision 173854)
+++ sel-sched-ir.c	(working copy)
@@ -2720,6 +2720,54 @@  deps_init_id (idata_t id, insn_t insn, b
 }
 
 
+struct sched_scan_info_def
+{
+  /* This hook notifies scheduler frontend to extend its internal per basic
+     block data structures.  This hook should be called once before a series of
+     calls to bb_init ().  */
+  void (*extend_bb) (void);
+
+  /* This hook makes scheduler frontend to initialize its internal data
+     structures for the passed basic block.  */
+  void (*init_bb) (basic_block);
+
+  /* This hook notifies scheduler frontend to extend its internal per insn data
+     structures.  This hook should be called once before a series of calls to
+     insn_init ().  */
+  void (*extend_insn) (void);
+
+  /* This hook makes scheduler frontend to initialize its internal data
+     structures for the passed insn.  */
+  void (*init_insn) (rtx);
+};
+
+/* A driver function to add a set of basic blocks (BBS) to the
+   scheduling region.  */
+static void
+sched_scan (const struct sched_scan_info_def *ssi, bb_vec_t bbs)
+{
+  unsigned i;
+  basic_block bb;
+
+  if (ssi->extend_bb)
+    ssi->extend_bb ();
+
+  if (ssi->init_bb)
+    FOR_EACH_VEC_ELT (basic_block, bbs, i, bb)
+      ssi->init_bb (bb);
+
+  if (ssi->extend_insn)
+    ssi->extend_insn ();
+
+  if (ssi->init_insn)
+    FOR_EACH_VEC_ELT (basic_block, bbs, i, bb)
+      {
+	rtx insn;
+
+	FOR_BB_INSNS (bb, insn)
+	  ssi->init_insn (insn);
+      }
+}
 
 /* Implement hooks for collecting fundamental insn properties like if insn is
    an ASM or is within a SCHED_GROUP.  */
@@ -2944,7 +2992,7 @@  sel_init_global_and_expr (bb_vec_t bbs)
       init_global_and_expr_for_insn /* init_insn */
     };
 
-  sched_scan (&ssi, bbs, NULL, NULL, NULL);
+  sched_scan (&ssi, bbs);
 }
 
 /* Finalize region-scope data structures for basic blocks.  */
@@ -3001,7 +3049,7 @@  sel_finish_global_and_expr (void)
 	  finish_global_and_expr_insn /* init_insn */
 	};
 
-      sched_scan (&ssi, bbs, NULL, NULL, NULL);
+      sched_scan (&ssi, bbs);
     }
 
     VEC_free (basic_block, heap, bbs);
@@ -3990,9 +4038,6 @@  finish_region_bb_info (void)
 /* Data for each insn in current region.  */
 VEC (sel_insn_data_def, heap) *s_i_d = NULL;
 
-/* A vector for the insns we've emitted.  */
-static insn_vec_t new_insns = NULL;
-
 /* Extend data structures for insns from current region.  */
 static void
 extend_insn_data (void)
@@ -4131,7 +4176,10 @@  sel_init_new_insn (insn_t insn, int flag
     }
 
   if (flags & INSN_INIT_TODO_LUID)
-    sched_init_luids (NULL, NULL, NULL, insn);
+    {
+      sched_extend_luids ();
+      sched_init_insn_luid (insn);
+    }
 
   if (flags & INSN_INIT_TODO_SSID)
     {
@@ -4473,7 +4521,7 @@  init_bb (basic_block bb)
 }
 
 void
-sel_init_bbs (bb_vec_t bbs, basic_block bb)
+sel_init_bbs (bb_vec_t bbs)
 {
   const struct sched_scan_info_def ssi =
     {
@@ -4483,7 +4531,7 @@  sel_init_bbs (bb_vec_t bbs, basic_block
       NULL /* init_insn */
     };
 
-  sched_scan (&ssi, bbs, bb, new_insns, NULL);
+  sched_scan (&ssi, bbs);
 }
 
 /* Restore notes for the whole region.  */
@@ -5040,9 +5088,9 @@  static void
 sel_add_bb (basic_block bb)
 {
   /* Extend luids so that new notes will receive zero luids.  */
-  sched_init_luids (NULL, NULL, NULL, NULL);
+  sched_extend_luids ();
   sched_init_bbs ();
-  sel_init_bbs (last_added_blocks, NULL);
+  sel_init_bbs (last_added_blocks);
 
   /* When bb is passed explicitly, the vector should contain
      the only element that equals to bb; otherwise, the vector
@@ -5583,7 +5631,7 @@  create_insn_rtx_from_pattern (rtx patter
 
   end_sequence ();
 
-  sched_init_luids (NULL, NULL, NULL, NULL);
+  sched_extend_luids ();
   sched_extend_target ();
   sched_deps_init (false);
 
Index: sel-sched-ir.h
===================================================================
--- sel-sched-ir.h	(revision 173854)
+++ sel-sched-ir.h	(working copy)
@@ -1602,7 +1602,7 @@  extern bool sel_bb_empty_p (basic_block)
 extern bool in_current_region_p (basic_block);
 extern basic_block fallthru_bb_of_jump (rtx);
 
-extern void sel_init_bbs (bb_vec_t, basic_block);
+extern void sel_init_bbs (bb_vec_t);
 extern void sel_finish_bbs (void);
 
 extern struct succs_info * compute_succs_info (insn_t, short);
Index: sched-int.h
===================================================================
--- sched-int.h	(revision 173854)
+++ sched-int.h	(working copy)
@@ -39,42 +39,18 @@  enum sched_pass_id_t { SCHED_PASS_UNKNOW
 
 typedef VEC (basic_block, heap) *bb_vec_t;
 typedef VEC (rtx, heap) *insn_vec_t;
-typedef VEC(rtx, heap) *rtx_vec_t;
-
-struct sched_scan_info_def
-{
-  /* This hook notifies scheduler frontend to extend its internal per basic
-     block data structures.  This hook should be called once before a series of
-     calls to bb_init ().  */
-  void (*extend_bb) (void);
-
-  /* This hook makes scheduler frontend to initialize its internal data
-     structures for the passed basic block.  */
-  void (*init_bb) (basic_block);
-
-  /* This hook notifies scheduler frontend to extend its internal per insn data
-     structures.  This hook should be called once before a series of calls to
-     insn_init ().  */
-  void (*extend_insn) (void);
-
-  /* This hook makes scheduler frontend to initialize its internal data
-     structures for the passed insn.  */
-  void (*init_insn) (rtx);
-};
-
-extern const struct sched_scan_info_def *sched_scan_info;
-
-extern void sched_scan (const struct sched_scan_info_def *,
-			bb_vec_t, basic_block, insn_vec_t, rtx);
+typedef VEC (rtx, heap) *rtx_vec_t;
 
 extern void sched_init_bbs (void);
 
-extern void sched_init_luids (bb_vec_t, basic_block, insn_vec_t, rtx);
+extern void sched_extend_luids (void);
+extern void sched_init_insn_luid (rtx);
+extern void sched_init_luids (bb_vec_t);
 extern void sched_finish_luids (void);
 
 extern void sched_extend_target (void);
 
-extern void haifa_init_h_i_d (bb_vec_t, basic_block, insn_vec_t, rtx);
+extern void haifa_init_h_i_d (bb_vec_t);
 extern void haifa_finish_h_i_d (void);
 
 /* Hooks that are common to all the schedulers.  */