From 356c23b3059cc4516ee59c51ab0947a4308624ac Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim@codesourcery.com>
Date: Thu, 9 Jul 2009 18:15:22 +0000
Subject: [PATCH] haifa-sched.c (insn_finishes_cycle_p): New static function.

	* 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.

From-SVN: r149427
---
 gcc/ChangeLog      | 12 ++++++++++++
 gcc/haifa-sched.c  | 22 +++++++++++++++++++++-
 gcc/modulo-sched.c |  1 +
 gcc/sched-ebb.c    |  1 +
 gcc/sched-int.h    |  4 ++++
 gcc/sched-rgn.c    | 14 ++++++++++++++
 gcc/sel-sched-ir.c |  1 +
 7 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9813255fdb86..01dff9e73c6a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,15 @@
+2009-07-09  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.
+
 2009-07-09  Maxim Kuvyrkov  <maxim@codesourcery.com>
 
 	* varasm.c (build_constant_desc): Don't share RTL in pool entries.
diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index eff10c87628e..66be7e5d94b6 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -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 privileged_n, state_t state,
 	  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--;
diff --git a/gcc/modulo-sched.c b/gcc/modulo-sched.c
index 6089580ed4d9..dbe77d9c54cb 100644
--- a/gcc/modulo-sched.c
+++ b/gcc/modulo-sched.c
@@ -270,6 +270,7 @@ static struct haifa_sched_info sms_sched_info =
   NULL,
   sms_print_insn,
   NULL,
+  NULL, /* insn_finishes_block_p */
   NULL, NULL,
   NULL, NULL,
   0, 0,
diff --git a/gcc/sched-ebb.c b/gcc/sched-ebb.c
index 2773a36d1bdc..b3e6c7a72655 100644
--- a/gcc/sched-ebb.c
+++ b/gcc/sched-ebb.c
@@ -286,6 +286,7 @@ static struct haifa_sched_info ebb_sched_info =
   rank,
   ebb_print_insn,
   ebb_contributes_to_priority,
+  NULL, /* insn_finishes_block_p */
 
   NULL, NULL,
   NULL, NULL,
diff --git a/gcc/sched-int.h b/gcc/sched-int.h
index 1b6a0345a014..aa5007ba8633 100644
--- a/gcc/sched-int.h
+++ b/gcc/sched-int.h
@@ -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;
 
diff --git a/gcc/sched-rgn.c b/gcc/sched-rgn.c
index 004064ecf420..a913faa217a8 100644
--- a/gcc/sched-rgn.c
+++ b/gcc/sched-rgn.c
@@ -2338,6 +2338,19 @@ static const struct sched_deps_info_def rgn_const_sel_sched_deps_info =
     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_const_sched_info =
   rgn_rank,
   rgn_print_insn,
   contributes_to_priority,
+  rgn_insn_finishes_block_p,
 
   NULL, NULL,
   NULL, NULL,
diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index 698612fb9a23..2932800f569f 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -5427,6 +5427,7 @@ static struct haifa_sched_info sched_sel_haifa_sched_info =
   NULL, /* rgn_rank */
   sel_print_insn, /* rgn_print_insn */
   contributes_to_priority,
+  NULL, /* insn_finishes_block_p */
 
   NULL, NULL,
   NULL, NULL,