>From b86515013dec067419d16d11c138ba8b74ede1c5 Mon Sep 17 00:00:00 2001
From: Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
Date: Sun, 18 Jan 2015 13:22:56 +0000
Subject: [PATCH 2/2] Support disabling of sched autoprefetcher from command
 line

	* config/arm/arm.c (arm_cortex_a15_tune, arm_cortex_a57_tune): Update.
	* haifa-sched.c: Increase values for PARAM_SCHED_AUTOPREF_QUEUE_DEPTH
	by +1 throughout.
	(rank_for_schedule, autopref_multipass_dfa_lookahead_guard): Update.
	* params.def (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH): Update.
---
 gcc/config/arm/arm.c |    6 +++---
 gcc/haifa-sched.c    |   16 ++++++++--------
 gcc/params.def       |    4 ++--
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 246298a..cbf6ce0 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -3173,11 +3173,11 @@ arm_option_override (void)
      relevant for L2 auto-prefetcher.  */
   int param_sched_autopref_queue_depth;
   if (current_tune->sched_autopref == ARM_SCHED_AUTOPREF_OFF)
-    param_sched_autopref_queue_depth = -1;
-  else if (current_tune->sched_autopref == ARM_SCHED_AUTOPREF_RANK)
     param_sched_autopref_queue_depth = 0;
+  else if (current_tune->sched_autopref == ARM_SCHED_AUTOPREF_RANK)
+    param_sched_autopref_queue_depth = 1;
   else if (current_tune->sched_autopref == ARM_SCHED_AUTOPREF_FULL)
-    param_sched_autopref_queue_depth = max_insn_queue_index + 1;
+    param_sched_autopref_queue_depth = max_insn_queue_index + 2;
   else
     gcc_unreachable ();
   maybe_set_param_value (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH,
diff --git a/gcc/haifa-sched.c b/gcc/haifa-sched.c
index 25b96d3..3f934b8 100644
--- a/gcc/haifa-sched.c
+++ b/gcc/haifa-sched.c
@@ -2744,7 +2744,7 @@ rank_for_schedule (const void *x, const void *y)
   if (flag_sched_critical_path_heuristic && priority_val)
     return rfs_result (RFS_PRIORITY, priority_val, tmp, tmp2);
 
-  if (PARAM_VALUE (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH) >= 0)
+  if (PARAM_VALUE (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH) >= 1)
     {
       int autopref = autopref_rank_for_schedule (tmp, tmp2);
       if (autopref != 0)
@@ -5552,11 +5552,11 @@ insn_finishes_cycle_p (rtx_insn *insn)
    insns in the ready list (or the queue) that have same memory base, but
    different offsets, then we delay the insns with larger offsets until insns
    with smaller offsets get scheduled.  If PARAM_SCHED_AUTOPREF_QUEUE_DEPTH
-   is "1", then we look at the ready list; if it is N>1, then we also look
-   through N-1 queue entries.
-   If the param is N>=0, then rank_for_schedule will consider auto-prefetching
+   is "2", then we look at the ready list; if it is N>2, then we also look
+   through N-2 queue entries.
+   If the param is N>=1, then rank_for_schedule will consider auto-prefetching
    among its heuristics.
-   Param value of "-1" disables modelling of the auto-prefetcher.  */
+   Param value of "0" disables modelling of the auto-prefetcher.  */
 
 /* Initialize autoprefetcher model data for INSN.  */
 static void
@@ -5680,7 +5680,7 @@ autopref_multipass_dfa_lookahead_guard (rtx_insn *insn1, int ready_index)
 {
   int r = 0;
 
-  if (PARAM_VALUE (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH) <= 0)
+  if (PARAM_VALUE (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH) <= 1)
     return 0;
 
   if (sched_verbose >= 2 && ready_index == 0)
@@ -5733,14 +5733,14 @@ autopref_multipass_dfa_lookahead_guard (rtx_insn *insn1, int ready_index)
 	    }
 	}
 
-      if (PARAM_VALUE (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH) == 1)
+      if (PARAM_VALUE (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH) <= 2)
 	continue;
 
       /* Everything from the current queue slot should have been moved to
 	 the ready list.  */
       gcc_assert (insn_queue[NEXT_Q_AFTER (q_ptr, 0)] == NULL_RTX);
 
-      int n_stalls = PARAM_VALUE (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH) - 1;
+      int n_stalls = PARAM_VALUE (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH) - 2;
       if (n_stalls > max_insn_queue_index)
 	n_stalls = max_insn_queue_index;
 
diff --git a/gcc/params.def b/gcc/params.def
index 4d3b398..a422078 100644
--- a/gcc/params.def
+++ b/gcc/params.def
@@ -670,8 +670,8 @@ DEFPARAM (PARAM_SCHED_MEM_TRUE_DEP_COST,
 
 DEFPARAM (PARAM_SCHED_AUTOPREF_QUEUE_DEPTH,
 	  "sched-autopref-queue-depth",
-	  "Hardware autoprefetcher scheduler model control flag.  Number of lookahead cycles the model looks into; at '0' only enable instruction sorting heuristic.  Disabled by default.",
-	  -1, 0, 0)
+	  "Hardware autoprefetcher scheduler model control flag.  Number of lookahead cycles the model looks into; at '1' only enable instruction sorting heuristic.  Disabled by default.",
+	  0, 0, 0)
 
 DEFPARAM(PARAM_MAX_LAST_VALUE_RTL,
 	 "max-last-value-rtl",
-- 
1.7.9.5

