annotate gcc/config/i386/x86-tune-sched-atom.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Scheduler hooks for IA-32 which implement atom+ specific logic.
kono
parents:
diff changeset
2 Copyright (C) 1988-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 any later version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 GNU General Public License for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "backend.h"
kono
parents:
diff changeset
24 #include "rtl.h"
kono
parents:
diff changeset
25 #include "tree.h"
kono
parents:
diff changeset
26 #include "cfghooks.h"
kono
parents:
diff changeset
27 #include "tm_p.h"
kono
parents:
diff changeset
28 #include "insn-config.h"
kono
parents:
diff changeset
29 #include "insn-attr.h"
kono
parents:
diff changeset
30 #include "recog.h"
kono
parents:
diff changeset
31 #include "target.h"
kono
parents:
diff changeset
32 #include "rtl-iter.h"
kono
parents:
diff changeset
33 #include "regset.h"
kono
parents:
diff changeset
34 #include "sched-int.h"
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 /* Try to reorder ready list to take advantage of Atom pipelined IMUL
kono
parents:
diff changeset
37 execution. It is applied if
kono
parents:
diff changeset
38 (1) IMUL instruction is on the top of list;
kono
parents:
diff changeset
39 (2) There exists the only producer of independent IMUL instruction in
kono
parents:
diff changeset
40 ready list.
kono
parents:
diff changeset
41 Return index of IMUL producer if it was found and -1 otherwise. */
kono
parents:
diff changeset
42 static int
kono
parents:
diff changeset
43 do_reorder_for_imul (rtx_insn **ready, int n_ready)
kono
parents:
diff changeset
44 {
kono
parents:
diff changeset
45 rtx_insn *insn;
kono
parents:
diff changeset
46 rtx set, insn1, insn2;
kono
parents:
diff changeset
47 sd_iterator_def sd_it;
kono
parents:
diff changeset
48 dep_t dep;
kono
parents:
diff changeset
49 int index = -1;
kono
parents:
diff changeset
50 int i;
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 if (!TARGET_BONNELL)
kono
parents:
diff changeset
53 return index;
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 /* Check that IMUL instruction is on the top of ready list. */
kono
parents:
diff changeset
56 insn = ready[n_ready - 1];
kono
parents:
diff changeset
57 set = single_set (insn);
kono
parents:
diff changeset
58 if (!set)
kono
parents:
diff changeset
59 return index;
kono
parents:
diff changeset
60 if (!(GET_CODE (SET_SRC (set)) == MULT
kono
parents:
diff changeset
61 && GET_MODE (SET_SRC (set)) == SImode))
kono
parents:
diff changeset
62 return index;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 /* Search for producer of independent IMUL instruction. */
kono
parents:
diff changeset
65 for (i = n_ready - 2; i >= 0; i--)
kono
parents:
diff changeset
66 {
kono
parents:
diff changeset
67 insn = ready[i];
kono
parents:
diff changeset
68 if (!NONDEBUG_INSN_P (insn))
kono
parents:
diff changeset
69 continue;
kono
parents:
diff changeset
70 /* Skip IMUL instruction. */
kono
parents:
diff changeset
71 insn2 = PATTERN (insn);
kono
parents:
diff changeset
72 if (GET_CODE (insn2) == PARALLEL)
kono
parents:
diff changeset
73 insn2 = XVECEXP (insn2, 0, 0);
kono
parents:
diff changeset
74 if (GET_CODE (insn2) == SET
kono
parents:
diff changeset
75 && GET_CODE (SET_SRC (insn2)) == MULT
kono
parents:
diff changeset
76 && GET_MODE (SET_SRC (insn2)) == SImode)
kono
parents:
diff changeset
77 continue;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 FOR_EACH_DEP (insn, SD_LIST_FORW, sd_it, dep)
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 rtx con;
kono
parents:
diff changeset
82 con = DEP_CON (dep);
kono
parents:
diff changeset
83 if (!NONDEBUG_INSN_P (con))
kono
parents:
diff changeset
84 continue;
kono
parents:
diff changeset
85 insn1 = PATTERN (con);
kono
parents:
diff changeset
86 if (GET_CODE (insn1) == PARALLEL)
kono
parents:
diff changeset
87 insn1 = XVECEXP (insn1, 0, 0);
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 if (GET_CODE (insn1) == SET
kono
parents:
diff changeset
90 && GET_CODE (SET_SRC (insn1)) == MULT
kono
parents:
diff changeset
91 && GET_MODE (SET_SRC (insn1)) == SImode)
kono
parents:
diff changeset
92 {
kono
parents:
diff changeset
93 sd_iterator_def sd_it1;
kono
parents:
diff changeset
94 dep_t dep1;
kono
parents:
diff changeset
95 /* Check if there is no other dependee for IMUL. */
kono
parents:
diff changeset
96 index = i;
kono
parents:
diff changeset
97 FOR_EACH_DEP (con, SD_LIST_BACK, sd_it1, dep1)
kono
parents:
diff changeset
98 {
kono
parents:
diff changeset
99 rtx pro;
kono
parents:
diff changeset
100 pro = DEP_PRO (dep1);
kono
parents:
diff changeset
101 if (!NONDEBUG_INSN_P (pro))
kono
parents:
diff changeset
102 continue;
kono
parents:
diff changeset
103 if (pro != insn)
kono
parents:
diff changeset
104 index = -1;
kono
parents:
diff changeset
105 }
kono
parents:
diff changeset
106 if (index >= 0)
kono
parents:
diff changeset
107 break;
kono
parents:
diff changeset
108 }
kono
parents:
diff changeset
109 }
kono
parents:
diff changeset
110 if (index >= 0)
kono
parents:
diff changeset
111 break;
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113 return index;
kono
parents:
diff changeset
114 }
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 /* Try to find the best candidate on the top of ready list if two insns
kono
parents:
diff changeset
117 have the same priority - candidate is best if its dependees were
kono
parents:
diff changeset
118 scheduled earlier. Applied for Silvermont only.
kono
parents:
diff changeset
119 Return true if top 2 insns must be interchanged. */
kono
parents:
diff changeset
120 static bool
kono
parents:
diff changeset
121 swap_top_of_ready_list (rtx_insn **ready, int n_ready)
kono
parents:
diff changeset
122 {
kono
parents:
diff changeset
123 rtx_insn *top = ready[n_ready - 1];
kono
parents:
diff changeset
124 rtx_insn *next = ready[n_ready - 2];
kono
parents:
diff changeset
125 rtx set;
kono
parents:
diff changeset
126 sd_iterator_def sd_it;
kono
parents:
diff changeset
127 dep_t dep;
kono
parents:
diff changeset
128 int clock1 = -1;
kono
parents:
diff changeset
129 int clock2 = -1;
kono
parents:
diff changeset
130 #define INSN_TICK(INSN) (HID (INSN)->tick)
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 if (!TARGET_SILVERMONT && !TARGET_INTEL)
kono
parents:
diff changeset
133 return false;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 if (!NONDEBUG_INSN_P (top))
kono
parents:
diff changeset
136 return false;
kono
parents:
diff changeset
137 if (!NONJUMP_INSN_P (top))
kono
parents:
diff changeset
138 return false;
kono
parents:
diff changeset
139 if (!NONDEBUG_INSN_P (next))
kono
parents:
diff changeset
140 return false;
kono
parents:
diff changeset
141 if (!NONJUMP_INSN_P (next))
kono
parents:
diff changeset
142 return false;
kono
parents:
diff changeset
143 set = single_set (top);
kono
parents:
diff changeset
144 if (!set)
kono
parents:
diff changeset
145 return false;
kono
parents:
diff changeset
146 set = single_set (next);
kono
parents:
diff changeset
147 if (!set)
kono
parents:
diff changeset
148 return false;
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150 if (INSN_PRIORITY_KNOWN (top) && INSN_PRIORITY_KNOWN (next))
kono
parents:
diff changeset
151 {
kono
parents:
diff changeset
152 if (INSN_PRIORITY (top) != INSN_PRIORITY (next))
kono
parents:
diff changeset
153 return false;
kono
parents:
diff changeset
154 /* Determine winner more precise. */
kono
parents:
diff changeset
155 FOR_EACH_DEP (top, SD_LIST_RES_BACK, sd_it, dep)
kono
parents:
diff changeset
156 {
kono
parents:
diff changeset
157 rtx pro;
kono
parents:
diff changeset
158 pro = DEP_PRO (dep);
kono
parents:
diff changeset
159 if (!NONDEBUG_INSN_P (pro))
kono
parents:
diff changeset
160 continue;
kono
parents:
diff changeset
161 if (INSN_TICK (pro) > clock1)
kono
parents:
diff changeset
162 clock1 = INSN_TICK (pro);
kono
parents:
diff changeset
163 }
kono
parents:
diff changeset
164 FOR_EACH_DEP (next, SD_LIST_RES_BACK, sd_it, dep)
kono
parents:
diff changeset
165 {
kono
parents:
diff changeset
166 rtx pro;
kono
parents:
diff changeset
167 pro = DEP_PRO (dep);
kono
parents:
diff changeset
168 if (!NONDEBUG_INSN_P (pro))
kono
parents:
diff changeset
169 continue;
kono
parents:
diff changeset
170 if (INSN_TICK (pro) > clock2)
kono
parents:
diff changeset
171 clock2 = INSN_TICK (pro);
kono
parents:
diff changeset
172 }
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 if (clock1 == clock2)
kono
parents:
diff changeset
175 {
kono
parents:
diff changeset
176 /* Determine winner - load must win. */
kono
parents:
diff changeset
177 enum attr_memory memory1, memory2;
kono
parents:
diff changeset
178 memory1 = get_attr_memory (top);
kono
parents:
diff changeset
179 memory2 = get_attr_memory (next);
kono
parents:
diff changeset
180 if (memory2 == MEMORY_LOAD && memory1 != MEMORY_LOAD)
kono
parents:
diff changeset
181 return true;
kono
parents:
diff changeset
182 }
kono
parents:
diff changeset
183 return (bool) (clock2 < clock1);
kono
parents:
diff changeset
184 }
kono
parents:
diff changeset
185 return false;
kono
parents:
diff changeset
186 #undef INSN_TICK
kono
parents:
diff changeset
187 }
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 /* Perform possible reodering of ready list for Atom/Silvermont only.
kono
parents:
diff changeset
190 Return issue rate. */
kono
parents:
diff changeset
191 int
kono
parents:
diff changeset
192 ix86_atom_sched_reorder (FILE *dump, int sched_verbose, rtx_insn **ready,
kono
parents:
diff changeset
193 int *pn_ready, int clock_var)
kono
parents:
diff changeset
194 {
kono
parents:
diff changeset
195 int issue_rate = -1;
kono
parents:
diff changeset
196 int n_ready = *pn_ready;
kono
parents:
diff changeset
197 int i;
kono
parents:
diff changeset
198 rtx_insn *insn;
kono
parents:
diff changeset
199 int index = -1;
kono
parents:
diff changeset
200
kono
parents:
diff changeset
201 /* Set up issue rate. */
kono
parents:
diff changeset
202 issue_rate = ix86_issue_rate ();
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 /* Do reodering for BONNELL/SILVERMONT only. */
kono
parents:
diff changeset
205 if (!TARGET_BONNELL && !TARGET_SILVERMONT && !TARGET_INTEL)
kono
parents:
diff changeset
206 return issue_rate;
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 /* Nothing to do if ready list contains only 1 instruction. */
kono
parents:
diff changeset
209 if (n_ready <= 1)
kono
parents:
diff changeset
210 return issue_rate;
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 /* Do reodering for post-reload scheduler only. */
kono
parents:
diff changeset
213 if (!reload_completed)
kono
parents:
diff changeset
214 return issue_rate;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 if ((index = do_reorder_for_imul (ready, n_ready)) >= 0)
kono
parents:
diff changeset
217 {
kono
parents:
diff changeset
218 if (sched_verbose > 1)
kono
parents:
diff changeset
219 fprintf (dump, ";;\tatom sched_reorder: put %d insn on top\n",
kono
parents:
diff changeset
220 INSN_UID (ready[index]));
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 /* Put IMUL producer (ready[index]) at the top of ready list. */
kono
parents:
diff changeset
223 insn = ready[index];
kono
parents:
diff changeset
224 for (i = index; i < n_ready - 1; i++)
kono
parents:
diff changeset
225 ready[i] = ready[i + 1];
kono
parents:
diff changeset
226 ready[n_ready - 1] = insn;
kono
parents:
diff changeset
227 return issue_rate;
kono
parents:
diff changeset
228 }
kono
parents:
diff changeset
229
kono
parents:
diff changeset
230 /* Skip selective scheduling since HID is not populated in it. */
kono
parents:
diff changeset
231 if (clock_var != 0
kono
parents:
diff changeset
232 && !sel_sched_p ()
kono
parents:
diff changeset
233 && swap_top_of_ready_list (ready, n_ready))
kono
parents:
diff changeset
234 {
kono
parents:
diff changeset
235 if (sched_verbose > 1)
kono
parents:
diff changeset
236 fprintf (dump, ";;\tslm sched_reorder: swap %d and %d insns\n",
kono
parents:
diff changeset
237 INSN_UID (ready[n_ready - 1]), INSN_UID (ready[n_ready - 2]));
kono
parents:
diff changeset
238 /* Swap 2 top elements of ready list. */
kono
parents:
diff changeset
239 insn = ready[n_ready - 1];
kono
parents:
diff changeset
240 ready[n_ready - 1] = ready[n_ready - 2];
kono
parents:
diff changeset
241 ready[n_ready - 2] = insn;
kono
parents:
diff changeset
242 }
kono
parents:
diff changeset
243 return issue_rate;
kono
parents:
diff changeset
244 }