This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Improve scheduling at the end of basic blocks


Hi,

The first attached patch improves scheduling at the end of basic blocks by making scheduler take into account the fact that some instructions force end of the cycle (the last instruction of a basic blocks being the most common case).

OK for trunk?

The second patch fixes handling of internal to max_issue() data structure choice_stack. Specifically, the 'rest' field of this structure is handled funny.

  /* The number of the rest insns whose issues we should try.  */
  int rest;

As far as I understand this field is to track how many instruction the procedure has left to try to issue this cycle. If dfa_lookahead is 2, max_issue() should happily exit after 2 instructions have been accepted by DFA and not try to stuff more instructions into it.

top->rest = dfa_lookahead;

...

	      if (state_dead_lock_p (state))
		top->rest = 0;
	      else
		top->rest--;

...

	      /* Advance to the next choice_entry.  */
	      top++;
	      /* Initialize it.  */
	      top->rest = dfa_lookahead;

Note, when state_dead_lock_p() returns 'true', max_issue tries to issue instructions from the ready_list anyway.

The second patch makes max_issue() handle top->rest with respect to my understanding outlined above; maybe there's something I've missed and it is intended to handle top->rest this way.


Thanks,


--
Maxim
2009-06-21  Maxim Kuvyrkov  <maxim@codesourcery.com>
        
	* haifa-sched.c (insn_finishes_cycle_p): New static function.
        (max_issue): Use it.
        * sched-int.h (struct sched_info: insn_finishes_block_p): New
        scheduler hook.
        * sched-rgn.c (rgn_insn_finishes_block_p): Implement it.
        (region_sched_info): Update.
        * sched-ebb.c (ebb_sched_info): Update.
        * modulo-sched.c (sms_sched_info): Update.
	* sel-sched-ir.c (sched_sel_haifa_sched_info): Update.
Index: sched-ebb.c
===================================================================
--- sched-ebb.c	(revision 148757)
+++ sched-ebb.c	(working copy)
@@ -286,6 +286,7 @@ static struct haifa_sched_info ebb_sched
   rank,
   ebb_print_insn,
   ebb_contributes_to_priority,
+  NULL, /* insn_finishes_block_p */
 
   NULL, NULL,
   NULL, NULL,
Index: haifa-sched.c
===================================================================
--- haifa-sched.c	(revision 148757)
+++ haifa-sched.c	(working copy)
@@ -1990,6 +1990,23 @@ move_insn (rtx insn, rtx last, rtx nt)
   SCHED_GROUP_P (insn) = 0;  
 }
 
+/* Return true if scheduling INSN will finish current clock cycle.  */
+static bool
+insn_finishes_cycle_p (rtx insn)
+{
+  if (SCHED_GROUP_P (insn))
+    /* After issuing INSN, rest of the sched_group will be forced to issue
+       in order.  Don't make any plans for the rest of cycle.  */
+    return true;
+
+  /* Finishing the block will, apparently, finish the cycle.  */
+  if (current_sched_info->insn_finishes_block_p
+      && current_sched_info->insn_finishes_block_p (insn))
+    return true;
+
+  return false;
+}
+
 /* The following structure describe an entry of the stack of choices.  */
 struct choice_entry
 {
@@ -2168,7 +2185,10 @@ max_issue (struct ready_list *ready, int
 	  delay = state_transition (state, insn);
 	  if (delay < 0)
 	    {
-	      if (state_dead_lock_p (state))
+	      if (state_dead_lock_p (state)
+		  || insn_finishes_cycle_p (insn))
+ 		/* We won't issue any more instructions in the next
+ 		   choice_state.  */
 		top->rest = 0;
 	      else
 		top->rest--;
Index: modulo-sched.c
===================================================================
--- modulo-sched.c	(revision 148757)
+++ modulo-sched.c	(working copy)
@@ -270,6 +270,7 @@ static struct haifa_sched_info sms_sched
   NULL,
   sms_print_insn,
   NULL,
+  NULL, /* insn_finishes_block_p */
   NULL, NULL,
   NULL, NULL,
   0, 0,
Index: sel-sched-ir.c
===================================================================
--- sel-sched-ir.c	(revision 148757)
+++ sel-sched-ir.c	(working copy)
@@ -5427,6 +5427,7 @@ static struct haifa_sched_info sched_sel
   NULL, /* rgn_rank */
   sel_print_insn, /* rgn_print_insn */
   contributes_to_priority,
+  NULL, /* insn_finishes_block_p */
 
   NULL, NULL,
   NULL, NULL,
Index: sched-int.h
===================================================================
--- sched-int.h	(revision 148757)
+++ sched-int.h	(working copy)
@@ -570,6 +570,10 @@ struct haifa_sched_info
      calculations.  */
   int (*contributes_to_priority) (rtx, rtx);
 
+  /* Return true if scheduling insn (passed as the parameter) will trigger
+     finish of scheduling current block.  */
+  bool (*insn_finishes_block_p) (rtx);
+
   /* The boundaries of the set of insns to be scheduled.  */
   rtx prev_head, next_tail;
 
Index: sched-rgn.c
===================================================================
--- sched-rgn.c	(revision 148757)
+++ sched-rgn.c	(working copy)
@@ -2338,6 +2338,19 @@ static const struct sched_deps_info_def 
     0, 0, 0
   };
 
+/* Return true if scheduling INSN will trigger finish of scheduling
+   current block.  */
+static bool
+rgn_insn_finishes_block_p (rtx insn)
+{
+  if (INSN_BB (insn) == target_bb
+      && sched_target_n_insns + 1 == target_n_insns)
+    /* INSN is the last not-scheduled instruction in the current block.  */
+    return true;
+
+  return false;
+}
+
 /* Used in schedule_insns to initialize current_sched_info for scheduling
    regions (or single basic blocks).  */
 
@@ -2350,6 +2363,7 @@ static const struct haifa_sched_info rgn
   rgn_rank,
   rgn_print_insn,
   contributes_to_priority,
+  rgn_insn_finishes_block_p,
 
   NULL, NULL,
   NULL, NULL,
2009-06-21  Maxim Kuvyrkov  <maxim@codesourcery.com>
        
	* haifa-sched.c (max_issue): Fix handling of number of instruction to
	try.
Index: haifa-sched.c
===================================================================
--- haifa-sched.c	(revision 148757)
+++ haifa-sched.c	(working copy)
@@ -2100,7 +2100,8 @@ max_issue (struct ready_list *ready, int
 
   /* Set initial state of the search.  */
   memcpy (top->state, state, dfa_state_size);
-  top->rest = dfa_lookahead;
+  /* Add +1 to account for the empty initial state.  */
+  top->rest = dfa_lookahead + 1;
   top->n = 0;
 
   /* Count the number of the insns to search among.  */
@@ -2168,10 +2169,13 @@ max_issue (struct ready_list *ready, int
 	  delay = state_transition (state, insn);
 	  if (delay < 0)
 	    {
+	      int rest;
+
+	      rest = top->rest;
 	      if (state_dead_lock_p (state))
-		top->rest = 0;
+ 		rest = 0;
 	      else
-		top->rest--;
+		rest--;
 
 	      n = top->n;
 	      if (memcmp (top->state, state, dfa_state_size) != 0)
@@ -2180,7 +2184,7 @@ max_issue (struct ready_list *ready, int
 	      /* Advance to the next choice_entry.  */
 	      top++;
 	      /* Initialize it.  */
-	      top->rest = dfa_lookahead;
+	      top->rest = rest;
 	      top->index = i;
 	      top->n = n;
 	      memcpy (top->state, state, dfa_state_size);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]