Line data Source code
1 : /* Assign reload pseudos.
2 : Copyright (C) 2010-2026 Free Software Foundation, Inc.
3 : Contributed by Vladimir Makarov <vmakarov@redhat.com>.
4 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with GCC; see the file COPYING3. If not see
19 : <http://www.gnu.org/licenses/>. */
20 :
21 :
22 : /* This file's main objective is to assign hard registers to reload
23 : pseudos. It also tries to allocate hard registers to other
24 : pseudos, but at a lower priority than the reload pseudos. The pass
25 : does not transform the RTL.
26 :
27 : We must allocate a hard register to every reload pseudo. We try to
28 : increase the chances of finding a viable allocation by assigning
29 : the pseudos in order of fewest available hard registers first. If
30 : we still fail to find a hard register, we spill other (non-reload)
31 : pseudos in order to make room.
32 :
33 : find_hard_regno_for finds hard registers for allocation without
34 : spilling. spill_for does the same with spilling. Both functions
35 : use a cost model to determine the most profitable choice of hard
36 : and spill registers.
37 :
38 : Once we have finished allocating reload pseudos, we also try to
39 : assign registers to other (non-reload) pseudos. This is useful if
40 : hard registers were freed up by the spilling just described.
41 :
42 : We try to assign hard registers by collecting pseudos into threads.
43 : These threads contain reload and inheritance pseudos that are
44 : connected by copies (move insns). Doing this improves the chances
45 : of pseudos in the thread getting the same hard register and, as a
46 : result, of allowing some move insns to be deleted.
47 :
48 : When we assign a hard register to a pseudo, we decrease the cost of
49 : using the same hard register for pseudos that are connected by
50 : copies.
51 :
52 : If two hard registers have the same frequency-derived cost, we
53 : prefer hard registers with higher priorities. The mapping of
54 : registers to priorities is controlled by the register_priority
55 : target hook. For example, x86-64 has a few register priorities:
56 : hard registers with and without REX prefixes have different
57 : priorities. This permits us to generate smaller code as insns
58 : without REX prefixes are shorter.
59 :
60 : If a few hard registers are still equally good for the assignment,
61 : we choose the least used hard register. It is called leveling and
62 : may be profitable for some targets.
63 :
64 : Only insns with changed allocation pseudos are processed on the
65 : next constraint pass.
66 :
67 : The pseudo live-ranges are used to find conflicting pseudos.
68 :
69 : For understanding the code, it is important to keep in mind that
70 : inheritance, split, and reload pseudos created since last
71 : constraint pass have regno >= lra_constraint_new_regno_start.
72 : Inheritance and split pseudos created on any pass are in the
73 : corresponding bitmaps. Inheritance and split pseudos since the
74 : last constraint pass have also the corresponding non-negative
75 : restore_regno. */
76 :
77 : #include "config.h"
78 : #include "system.h"
79 : #include "coretypes.h"
80 : #include "backend.h"
81 : #include "target.h"
82 : #include "rtl.h"
83 : #include "tree.h"
84 : #include "predict.h"
85 : #include "df.h"
86 : #include "memmodel.h"
87 : #include "tm_p.h"
88 : #include "insn-config.h"
89 : #include "regs.h"
90 : #include "ira.h"
91 : #include "recog.h"
92 : #include "rtl-error.h"
93 : #include "sparseset.h"
94 : #include "lra.h"
95 : #include "lra-int.h"
96 : #include "function-abi.h"
97 :
98 : /* Current iteration number of the pass and current iteration number
99 : of the pass after the latest spill pass when any former reload
100 : pseudo was spilled. */
101 : int lra_assignment_iter;
102 : int lra_assignment_iter_after_spill;
103 :
104 : /* Flag of spilling former reload pseudos on this pass. */
105 : static bool former_reload_pseudo_spill_p;
106 :
107 : /* Array containing corresponding values of function
108 : lra_get_allocno_class. It is used to speed up the code. */
109 : static enum reg_class *regno_allocno_class_array;
110 :
111 : /* Array containing lengths of pseudo live ranges. It is used to
112 : speed up the code. */
113 : static int *regno_live_length;
114 :
115 : /* Information about the thread to which a pseudo belongs. Threads are
116 : a set of connected reload and inheritance pseudos with the same set of
117 : available hard registers. Lone registers belong to their own threads. */
118 : struct regno_assign_info
119 : {
120 : /* First/next pseudo of the same thread. */
121 : int first, next;
122 : /* Frequency of the thread (execution frequency of only reload
123 : pseudos in the thread when the thread contains a reload pseudo).
124 : Defined only for the first thread pseudo. */
125 : int freq;
126 : };
127 :
128 : /* Map regno to the corresponding regno assignment info. */
129 : static struct regno_assign_info *regno_assign_info;
130 :
131 : /* All inherited, subreg or optional pseudos created before last spill
132 : sub-pass. Such pseudos are permitted to get memory instead of hard
133 : regs. */
134 : static bitmap_head non_reload_pseudos;
135 :
136 : /* Process a pseudo copy with execution frequency COPY_FREQ connecting
137 : REGNO1 and REGNO2 to form threads. */
138 : static void
139 1602132 : process_copy_to_form_thread (int regno1, int regno2, int copy_freq)
140 : {
141 1602132 : int last, regno1_first, regno2_first;
142 :
143 1602132 : lra_assert (regno1 >= lra_constraint_new_regno_start
144 : && regno2 >= lra_constraint_new_regno_start);
145 1602132 : regno1_first = regno_assign_info[regno1].first;
146 1602132 : regno2_first = regno_assign_info[regno2].first;
147 1602132 : if (regno1_first != regno2_first)
148 : {
149 2038141 : for (last = regno2_first;
150 3640273 : regno_assign_info[last].next >= 0;
151 2038141 : last = regno_assign_info[last].next)
152 2038141 : regno_assign_info[last].first = regno1_first;
153 1602132 : regno_assign_info[last].first = regno1_first;
154 1602132 : regno_assign_info[last].next = regno_assign_info[regno1_first].next;
155 1602132 : regno_assign_info[regno1_first].next = regno2_first;
156 1602132 : regno_assign_info[regno1_first].freq
157 1602132 : += regno_assign_info[regno2_first].freq;
158 : }
159 1602132 : regno_assign_info[regno1_first].freq -= 2 * copy_freq;
160 1602132 : lra_assert (regno_assign_info[regno1_first].freq >= 0);
161 1602132 : }
162 :
163 : /* Initialize REGNO_ASSIGN_INFO and form threads. */
164 : static void
165 1601843 : init_regno_assign_info (void)
166 : {
167 1601843 : int i, regno1, regno2, max_regno = max_reg_num ();
168 1601843 : lra_copy_t cp;
169 :
170 1601843 : regno_assign_info = XNEWVEC (struct regno_assign_info, max_regno);
171 105841840 : for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
172 : {
173 104239997 : regno_assign_info[i].first = i;
174 104239997 : regno_assign_info[i].next = -1;
175 104239997 : regno_assign_info[i].freq = lra_reg_info[i].freq;
176 : }
177 : /* Form the threads. */
178 4427630 : for (i = 0; (cp = lra_get_copy (i)) != NULL; i++)
179 2825787 : if ((regno1 = cp->regno1) >= lra_constraint_new_regno_start
180 2825787 : && (regno2 = cp->regno2) >= lra_constraint_new_regno_start
181 2825787 : && reg_renumber[regno1] < 0 && lra_reg_info[regno1].nrefs != 0
182 1644821 : && reg_renumber[regno2] < 0 && lra_reg_info[regno2].nrefs != 0
183 2825787 : && (ira_class_hard_regs_num[regno_allocno_class_array[regno1]]
184 1642629 : == ira_class_hard_regs_num[regno_allocno_class_array[regno2]]))
185 1602132 : process_copy_to_form_thread (regno1, regno2, cp->freq);
186 1601843 : }
187 :
188 : /* Free REGNO_ASSIGN_INFO. */
189 : static void
190 1601843 : finish_regno_assign_info (void)
191 : {
192 1601843 : free (regno_assign_info);
193 0 : }
194 :
195 : /* The function is used to sort *reload* and *inheritance* pseudos to
196 : try to assign them hard registers. We put pseudos from the same
197 : thread always nearby. */
198 : static int
199 257047067 : reload_pseudo_compare_func (const void *v1p, const void *v2p)
200 : {
201 257047067 : int r1 = *(const int *) v1p, r2 = *(const int *) v2p;
202 257047067 : enum reg_class cl1 = regno_allocno_class_array[r1];
203 257047067 : enum reg_class cl2 = regno_allocno_class_array[r2];
204 257047067 : int diff;
205 :
206 257047067 : lra_assert (r1 >= lra_constraint_new_regno_start
207 : && r2 >= lra_constraint_new_regno_start);
208 :
209 : /* Prefer to assign reload registers with smaller classes first to
210 : guarantee assignment to all reload registers. */
211 257047067 : if ((diff = (ira_class_hard_regs_num[cl1]
212 257047067 : - ira_class_hard_regs_num[cl2])) != 0)
213 : return diff;
214 : /* Allocate bigger pseudos first to avoid register file
215 : fragmentation. */
216 240830446 : if ((diff
217 240830446 : = (ira_reg_class_max_nregs[cl2][lra_reg_info[r2].biggest_mode]
218 240830446 : - ira_reg_class_max_nregs[cl1][lra_reg_info[r1].biggest_mode])) != 0)
219 : return diff;
220 238456607 : if ((diff = (regno_assign_info[regno_assign_info[r2].first].freq
221 238456607 : - regno_assign_info[regno_assign_info[r1].first].freq)) != 0)
222 : return diff;
223 : /* Put pseudos from the thread nearby. */
224 134698544 : if ((diff = regno_assign_info[r1].first - regno_assign_info[r2].first) != 0)
225 : return diff;
226 : /* Prefer pseudos with longer live ranges. It sets up better
227 : preferred hard registers for the thread pseudos and decreases
228 : register-register moves between the thread pseudos. */
229 16987814 : if ((diff = regno_live_length[r2] - regno_live_length[r1]) != 0)
230 : return diff;
231 : /* If regs are equally good, sort by their numbers, so that the
232 : results of qsort leave nothing to chance. */
233 7536826 : return r1 - r2;
234 : }
235 :
236 : /* The function is used to sort *non-reload* pseudos to try to assign
237 : them hard registers. The order calculation is simpler than in the
238 : previous function and based on the pseudo frequency usage. */
239 : static int
240 1150111578 : pseudo_compare_func (const void *v1p, const void *v2p)
241 : {
242 1150111578 : int r1 = *(const int *) v1p, r2 = *(const int *) v2p;
243 1150111578 : int diff;
244 :
245 : /* Assign hard reg to static chain pointer first pseudo when
246 : non-local goto is used. */
247 1150111578 : if ((diff = (non_spilled_static_chain_regno_p (r2)
248 1150111578 : - non_spilled_static_chain_regno_p (r1))) != 0)
249 : return diff;
250 :
251 : /* Prefer to assign more frequently used registers first. */
252 1150108232 : if ((diff = lra_reg_info[r2].freq - lra_reg_info[r1].freq) != 0)
253 : return diff;
254 :
255 : /* If regs are equally good, sort by their numbers, so that the
256 : results of qsort leave nothing to chance. */
257 681659202 : return r1 - r2;
258 : }
259 :
260 : /* Arrays of size LRA_LIVE_MAX_POINT mapping a program point to the
261 : pseudo live ranges with given start point. We insert only live
262 : ranges of pseudos interesting for assignment purposes. They are
263 : reload pseudos and pseudos assigned to hard registers. */
264 : static lra_live_range_t *start_point_ranges;
265 :
266 : /* Used as a flag that a live range is not inserted in the start point
267 : chain. */
268 : static struct lra_live_range not_in_chain_mark;
269 :
270 : /* Create and set up START_POINT_RANGES. */
271 : static void
272 1601843 : create_live_range_start_chains (void)
273 : {
274 1601843 : int i, max_regno;
275 1601843 : lra_live_range_t r;
276 :
277 1601843 : start_point_ranges = XCNEWVEC (lra_live_range_t, lra_live_max_point);
278 1601843 : max_regno = max_reg_num ();
279 107443683 : for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
280 104239997 : if (i >= lra_constraint_new_regno_start || reg_renumber[i] >= 0)
281 : {
282 110631028 : for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
283 : {
284 59038342 : r->start_next = start_point_ranges[r->start];
285 59038342 : start_point_ranges[r->start] = r;
286 : }
287 : }
288 : else
289 : {
290 55482633 : for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
291 2835322 : r->start_next = ¬_in_chain_mark;
292 : }
293 1601843 : }
294 :
295 : /* Insert live ranges of pseudo REGNO into start chains if they are
296 : not there yet. */
297 : static void
298 450125241 : insert_in_live_range_start_chain (int regno)
299 : {
300 450125241 : lra_live_range_t r = lra_reg_info[regno].live_ranges;
301 :
302 450125241 : if (r->start_next != ¬_in_chain_mark)
303 : return;
304 204729 : for (; r != NULL; r = r->next)
305 : {
306 129949 : r->start_next = start_point_ranges[r->start];
307 129949 : start_point_ranges[r->start] = r;
308 : }
309 : }
310 :
311 : /* Free START_POINT_RANGES. */
312 : static void
313 1601843 : finish_live_range_start_chains (void)
314 : {
315 1601843 : gcc_assert (start_point_ranges != NULL);
316 1601843 : free (start_point_ranges);
317 1601843 : start_point_ranges = NULL;
318 1601843 : }
319 :
320 : /* Map: program point -> bitmap of all pseudos living at the point and
321 : assigned to hard registers. */
322 : static bitmap_head *live_hard_reg_pseudos;
323 : static bitmap_obstack live_hard_reg_pseudos_bitmap_obstack;
324 :
325 : /* reg_renumber corresponding to pseudos marked in
326 : live_hard_reg_pseudos. reg_renumber might be not matched to
327 : live_hard_reg_pseudos but live_pseudos_reg_renumber always reflects
328 : live_hard_reg_pseudos, except that during a spill_for trial a spill
329 : candidate stays in live_hard_reg_pseudos with a value of -1 here. */
330 : static int *live_pseudos_reg_renumber;
331 :
332 : /* Sparseset used to calculate living hard reg pseudos for some program
333 : point range. */
334 : static sparseset live_range_hard_reg_pseudos;
335 :
336 : /* Sparseset used to calculate living reload/inheritance pseudos for
337 : some program point range. */
338 : static sparseset live_range_reload_inheritance_pseudos;
339 :
340 : /* Allocate and initialize the data about living pseudos at program
341 : points. */
342 : static void
343 1601843 : init_lives (void)
344 : {
345 1601843 : int i, max_regno = max_reg_num ();
346 :
347 1601843 : live_range_hard_reg_pseudos = sparseset_alloc (max_regno);
348 1601843 : live_range_reload_inheritance_pseudos = sparseset_alloc (max_regno);
349 1601843 : live_hard_reg_pseudos = XNEWVEC (bitmap_head, lra_live_max_point);
350 1601843 : bitmap_obstack_initialize (&live_hard_reg_pseudos_bitmap_obstack);
351 93469813 : for (i = 0; i < lra_live_max_point; i++)
352 90266127 : bitmap_initialize (&live_hard_reg_pseudos[i],
353 : &live_hard_reg_pseudos_bitmap_obstack);
354 1601843 : live_pseudos_reg_renumber = XNEWVEC (int, max_regno);
355 256415082 : for (i = 0; i < max_regno; i++)
356 254813239 : live_pseudos_reg_renumber[i] = -1;
357 1601843 : }
358 :
359 : /* Free the data about living pseudos at program points. */
360 : static void
361 1601843 : finish_lives (void)
362 : {
363 1601843 : sparseset_free (live_range_hard_reg_pseudos);
364 1601843 : sparseset_free (live_range_reload_inheritance_pseudos);
365 1601843 : free (live_hard_reg_pseudos);
366 1601843 : bitmap_obstack_release (&live_hard_reg_pseudos_bitmap_obstack);
367 1601843 : free (live_pseudos_reg_renumber);
368 1601843 : }
369 :
370 : /* Update the LIVE_HARD_REG_PSEUDOS and LIVE_PSEUDOS_REG_RENUMBER
371 : entries for pseudo REGNO. Assume that the register has been
372 : spilled if FREE_P, otherwise assume that it has been assigned
373 : reg_renumber[REGNO] (if >= 0). We also insert the pseudo live
374 : ranges in the start chains when it is assumed to be assigned to a
375 : hard register because we use the chains of pseudos assigned to hard
376 : registers during allocation. */
377 : static void
378 49504689 : update_lives (int regno, bool free_p)
379 : {
380 49504689 : int p;
381 49504689 : lra_live_range_t r;
382 :
383 49504689 : if (reg_renumber[regno] < 0)
384 : return;
385 49504689 : live_pseudos_reg_renumber[regno] = free_p ? -1 : reg_renumber[regno];
386 107489077 : for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
387 : {
388 507546655 : for (p = r->start; p <= r->finish; p++)
389 449562267 : if (free_p)
390 5055674 : bitmap_clear_bit (&live_hard_reg_pseudos[p], regno);
391 : else
392 : {
393 444506593 : bitmap_set_bit (&live_hard_reg_pseudos[p], regno);
394 444506593 : insert_in_live_range_start_chain (regno);
395 : }
396 : }
397 : }
398 :
399 : /* Sparseset used to calculate reload pseudos conflicting with a given
400 : pseudo when we are trying to find a hard register for the given
401 : pseudo. */
402 : static sparseset conflict_reload_and_inheritance_pseudos;
403 :
404 : /* Map: program point -> bitmap of all reload and inheritance pseudos
405 : living at the point. */
406 : static bitmap_head *live_reload_and_inheritance_pseudos;
407 : static bitmap_obstack live_reload_and_inheritance_pseudos_bitmap_obstack;
408 :
409 : /* Allocate and initialize data about living reload pseudos at any
410 : given program point. */
411 : static void
412 1601843 : init_live_reload_and_inheritance_pseudos (void)
413 : {
414 1601843 : int i, p, max_regno = max_reg_num ();
415 1601843 : lra_live_range_t r;
416 :
417 1601843 : conflict_reload_and_inheritance_pseudos = sparseset_alloc (max_regno);
418 1601843 : live_reload_and_inheritance_pseudos = XNEWVEC (bitmap_head, lra_live_max_point);
419 1601843 : bitmap_obstack_initialize (&live_reload_and_inheritance_pseudos_bitmap_obstack);
420 93469813 : for (p = 0; p < lra_live_max_point; p++)
421 90266127 : bitmap_initialize (&live_reload_and_inheritance_pseudos[p],
422 : &live_reload_and_inheritance_pseudos_bitmap_obstack);
423 1601843 : if ((unsigned) (max_regno - lra_constraint_new_regno_start)
424 1601843 : >= (1U << lra_max_pseudos_points_log2_considered_for_preferences)
425 1601843 : / (lra_live_max_point + 1))
426 16 : return;
427 1601827 : bitmap_head start_points;
428 1601827 : bitmap_initialize (&start_points,
429 : &live_hard_reg_pseudos_bitmap_obstack);
430 13695035 : for (i = lra_constraint_new_regno_start; i < max_regno; i++)
431 23606600 : for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
432 11513392 : bitmap_set_bit (&start_points, r->start);
433 13695035 : for (i = lra_constraint_new_regno_start; i < max_regno; i++)
434 : {
435 23606600 : for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
436 : {
437 11513392 : bitmap_iterator bi;
438 11513392 : unsigned p;
439 47216144 : EXECUTE_IF_SET_IN_BITMAP (&start_points, r->start, p, bi)
440 : {
441 46533894 : if (p > (unsigned) r->finish)
442 : break;
443 35702752 : bitmap_set_bit (&live_reload_and_inheritance_pseudos[p], i);
444 : }
445 : }
446 : }
447 1601827 : bitmap_clear (&start_points);
448 : }
449 :
450 : /* Finalize data about living reload pseudos at any given program
451 : point. */
452 : static void
453 1601843 : finish_live_reload_and_inheritance_pseudos (void)
454 : {
455 1601843 : sparseset_free (conflict_reload_and_inheritance_pseudos);
456 1601843 : free (live_reload_and_inheritance_pseudos);
457 1601843 : bitmap_obstack_release (&live_reload_and_inheritance_pseudos_bitmap_obstack);
458 1601843 : }
459 :
460 : /* The value used to check that cost of given hard reg is really
461 : defined currently. */
462 : static int curr_hard_regno_costs_check = 0;
463 : /* Array used to check that cost of the corresponding hard reg (the
464 : array element index) is really defined currently. */
465 : static int hard_regno_costs_check[FIRST_PSEUDO_REGISTER];
466 : /* The current costs of allocation of hard regs. Defined only if the
467 : value of the corresponding element of the previous array is equal to
468 : CURR_HARD_REGNO_COSTS_CHECK. */
469 : static int hard_regno_costs[FIRST_PSEUDO_REGISTER];
470 :
471 : /* Adjust cost of HARD_REGNO by INCR. Reset the cost first if it is
472 : not defined yet. */
473 : static inline void
474 25012937 : adjust_hard_regno_cost (int hard_regno, int incr)
475 : {
476 25012937 : if (hard_regno_costs_check[hard_regno] != curr_hard_regno_costs_check)
477 12615738 : hard_regno_costs[hard_regno] = 0;
478 25012937 : hard_regno_costs_check[hard_regno] = curr_hard_regno_costs_check;
479 25012937 : hard_regno_costs[hard_regno] += incr;
480 25012937 : }
481 :
482 : /* Try to find a free hard register for pseudo REGNO. Return the
483 : hard register on success and set *COST to the cost of using
484 : that register. (If several registers have equal cost, the one with
485 : the highest priority wins.) Return -1 on failure.
486 :
487 : If FIRST_P, return the first available hard reg ignoring other
488 : criteria, e.g. allocation cost. This approach results in less hard
489 : reg pool fragmentation and permit to allocate hard regs to reload
490 : pseudos in complicated situations where pseudo sizes are different.
491 :
492 : If TRY_ONLY_HARD_REGNO >= 0, consider only that hard register,
493 : otherwise consider all hard registers in REGNO's class.
494 :
495 : If REGNO_SET is not empty, only hard registers from the set are
496 : considered. */
497 : static int
498 14451335 : find_hard_regno_for_1 (int regno, int *cost, int try_only_hard_regno,
499 : bool first_p, HARD_REG_SET regno_set)
500 : {
501 14451335 : HARD_REG_SET conflict_set;
502 14451335 : int best_cost = INT_MAX, best_priority = INT_MIN, best_usage = INT_MAX;
503 14451335 : lra_live_range_t r;
504 14451335 : int p, i, j, rclass_size, best_hard_regno, priority, hard_regno;
505 14451335 : int hr, conflict_hr, nregs;
506 14451335 : machine_mode biggest_mode;
507 14451335 : unsigned int k, conflict_regno;
508 14451335 : poly_int64 offset;
509 14451335 : int val, biggest_nregs, nregs_diff;
510 14451335 : enum reg_class rclass;
511 14451335 : bitmap_iterator bi;
512 14451335 : bool *rclass_intersect_p;
513 14451335 : HARD_REG_SET impossible_start_hard_regs, available_regs;
514 :
515 28902670 : if (hard_reg_set_empty_p (regno_set))
516 14225027 : conflict_set = lra_no_alloc_regs;
517 : else
518 226308 : conflict_set = ~regno_set | lra_no_alloc_regs;
519 14451335 : rclass = regno_allocno_class_array[regno];
520 14451335 : rclass_intersect_p = ira_reg_classes_intersect_p[rclass];
521 14451335 : curr_hard_regno_costs_check++;
522 14451335 : sparseset_clear (conflict_reload_and_inheritance_pseudos);
523 14451335 : sparseset_clear (live_range_hard_reg_pseudos);
524 14451335 : conflict_set |= lra_reg_info[regno].conflict_hard_regs;
525 14451335 : biggest_mode = lra_reg_info[regno].biggest_mode;
526 30815238 : for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
527 : {
528 134097554 : EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[r->start], 0, k, bi)
529 117733651 : if (live_pseudos_reg_renumber[k] >= 0
530 115790115 : && rclass_intersect_p[regno_allocno_class_array[k]])
531 102595688 : sparseset_set_bit (live_range_hard_reg_pseudos, k);
532 142114820 : EXECUTE_IF_SET_IN_BITMAP (&live_reload_and_inheritance_pseudos[r->start],
533 : 0, k, bi)
534 125750917 : if (lra_reg_info[k].preferred_hard_regno1 >= 0
535 36670201 : && live_pseudos_reg_renumber[k] < 0
536 34141010 : && rclass_intersect_p[regno_allocno_class_array[k]])
537 32255944 : sparseset_set_bit (conflict_reload_and_inheritance_pseudos, k);
538 2878408002 : for (p = r->start + 1; p <= r->finish; p++)
539 : {
540 2862044099 : lra_live_range_t r2;
541 :
542 2862044099 : for (r2 = start_point_ranges[p];
543 4869193282 : r2 != NULL;
544 2007149183 : r2 = r2->start_next)
545 : {
546 2007149183 : if (live_pseudos_reg_renumber[r2->regno] < 0
547 640698506 : && r2->regno >= lra_constraint_new_regno_start
548 639531774 : && lra_reg_info[r2->regno].preferred_hard_regno1 >= 0
549 367187022 : && rclass_intersect_p[regno_allocno_class_array[r2->regno]])
550 358763760 : sparseset_set_bit (conflict_reload_and_inheritance_pseudos,
551 : r2->regno);
552 1648385423 : else if (live_pseudos_reg_renumber[r2->regno] >= 0
553 1366450677 : && rclass_intersect_p
554 1366450677 : [regno_allocno_class_array[r2->regno]])
555 1254784755 : sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno);
556 : }
557 : }
558 : }
559 14451335 : if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0)
560 : {
561 6012025 : adjust_hard_regno_cost
562 6012025 : (hard_regno, -lra_reg_info[regno].preferred_hard_regno_profit1);
563 6012025 : if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0)
564 1930829 : adjust_hard_regno_cost
565 1930829 : (hard_regno, -lra_reg_info[regno].preferred_hard_regno_profit2);
566 : }
567 : #ifdef STACK_REGS
568 14451335 : if (lra_reg_info[regno].no_stack_p)
569 475344 : for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
570 422528 : SET_HARD_REG_BIT (conflict_set, i);
571 : #endif
572 14451335 : sparseset_clear_bit (conflict_reload_and_inheritance_pseudos, regno);
573 14451335 : val = lra_reg_info[regno].val;
574 14451335 : offset = lra_reg_info[regno].offset;
575 14451335 : impossible_start_hard_regs = lra_reg_info[regno].exclude_start_hard_regs;
576 200658147 : EXECUTE_IF_SET_IN_SPARSESET (live_range_hard_reg_pseudos, conflict_regno)
577 : {
578 190935851 : conflict_hr = live_pseudos_reg_renumber[conflict_regno];
579 190935851 : if (lra_reg_val_equal_p (conflict_regno, val, offset))
580 : {
581 850566 : conflict_hr = live_pseudos_reg_renumber[conflict_regno];
582 850566 : nregs = hard_regno_nregs (conflict_hr,
583 850566 : lra_reg_info[conflict_regno].biggest_mode);
584 : /* Remember about multi-register pseudos. For example, 2
585 : hard register pseudos can start on the same hard register
586 : but cannot start on HR and HR+1/HR-1. */
587 858084 : for (hr = conflict_hr + 1;
588 858084 : hr < FIRST_PSEUDO_REGISTER && hr < conflict_hr + nregs;
589 : hr++)
590 7518 : SET_HARD_REG_BIT (impossible_start_hard_regs, hr);
591 856086 : for (hr = conflict_hr - 1;
592 856086 : hr >= 0 && (int) end_hard_regno (biggest_mode, hr) > conflict_hr;
593 : hr--)
594 5520 : SET_HARD_REG_BIT (impossible_start_hard_regs, hr);
595 : }
596 : else
597 : {
598 190085285 : machine_mode biggest_conflict_mode
599 190085285 : = lra_reg_info[conflict_regno].biggest_mode;
600 190085285 : int biggest_conflict_nregs
601 190085285 : = hard_regno_nregs (conflict_hr, biggest_conflict_mode);
602 :
603 190085285 : nregs_diff
604 190085285 : = (biggest_conflict_nregs
605 190085285 : - hard_regno_nregs (conflict_hr,
606 190085285 : PSEUDO_REGNO_MODE (conflict_regno)));
607 190085285 : add_to_hard_reg_set (&conflict_set,
608 : biggest_conflict_mode,
609 : conflict_hr
610 : - (WORDS_BIG_ENDIAN ? nregs_diff : 0));
611 380170570 : if (hard_reg_set_subset_p (reg_class_contents[rclass],
612 : conflict_set))
613 : return -1;
614 : }
615 : }
616 21184373 : EXECUTE_IF_SET_IN_SPARSESET (conflict_reload_and_inheritance_pseudos,
617 : conflict_regno)
618 22924154 : if (!lra_reg_val_equal_p (conflict_regno, val, offset))
619 : {
620 11224769 : lra_assert (live_pseudos_reg_renumber[conflict_regno] < 0);
621 11224769 : if ((hard_regno
622 11224769 : = lra_reg_info[conflict_regno].preferred_hard_regno1) >= 0)
623 : {
624 11224769 : adjust_hard_regno_cost
625 11224769 : (hard_regno,
626 : lra_reg_info[conflict_regno].preferred_hard_regno_profit1);
627 11224769 : if ((hard_regno
628 11224769 : = lra_reg_info[conflict_regno].preferred_hard_regno2) >= 0)
629 5845314 : adjust_hard_regno_cost
630 5845314 : (hard_regno,
631 : lra_reg_info[conflict_regno].preferred_hard_regno_profit2);
632 : }
633 : }
634 :
635 : /* If a reference/partner pseudo already has a hardreg, restrict this one
636 : to what the filter permits. */
637 9722296 : if (!lra_reg_info[regno].dependent_filters.is_empty ())
638 : {
639 : unsigned int i;
640 : dependent_filter *filter;
641 0 : FOR_EACH_VEC_ELT (lra_reg_info[regno].dependent_filters, i, filter)
642 : {
643 0 : int partner_regno = live_pseudos_reg_renumber[filter->partner_regno];
644 0 : if (partner_regno < 0)
645 0 : partner_regno = reg_renumber[filter->partner_regno];
646 0 : if (partner_regno < 0)
647 0 : continue;
648 :
649 0 : const HARD_REG_SET *allowed
650 0 : = lra_get_dependent_filter (filter->id, filter->mode,
651 : (unsigned int) partner_regno,
652 : filter->partner_mode, filter->is_ref);
653 0 : conflict_set |= ~*allowed;
654 : }
655 : }
656 :
657 : /* Make sure that all registers in a multi-word pseudo belong to the
658 : required class. */
659 9722296 : conflict_set |= ~reg_class_contents[rclass];
660 9722296 : lra_assert (rclass != NO_REGS);
661 9722296 : rclass_size = ira_class_hard_regs_num[rclass];
662 9722296 : best_hard_regno = -1;
663 9722296 : hard_regno = ira_class_hard_regs[rclass][0];
664 9722296 : biggest_nregs = hard_regno_nregs (hard_regno, biggest_mode);
665 9722296 : nregs_diff = (biggest_nregs
666 9722296 : - hard_regno_nregs (hard_regno, PSEUDO_REGNO_MODE (regno)));
667 9722296 : available_regs = reg_class_contents[rclass] & ~lra_no_alloc_regs;
668 125358591 : for (i = 0; i < rclass_size; i++)
669 : {
670 115708291 : if (try_only_hard_regno >= 0)
671 : hard_regno = try_only_hard_regno;
672 : else
673 115638283 : hard_regno = ira_class_hard_regs[rclass][i];
674 115708291 : if (! overlaps_hard_reg_set_p (conflict_set,
675 115708291 : PSEUDO_REGNO_MODE (regno), hard_regno)
676 60305364 : && targetm.hard_regno_mode_ok (hard_regno, PSEUDO_REGNO_MODE (regno))
677 : /* We cannot use prohibited_class_mode_regs for all classes
678 : because it is not defined for all classes. */
679 60152471 : && (ira_allocno_class_translate[rclass] != rclass
680 22893895 : || ! TEST_HARD_REG_BIT (ira_prohibited_class_mode_regs
681 22893895 : [rclass][biggest_mode],
682 : hard_regno))
683 60152177 : && ! TEST_HARD_REG_BIT (impossible_start_hard_regs, hard_regno)
684 175857687 : && (nregs_diff == 0
685 4572 : || (WORDS_BIG_ENDIAN
686 : ? (hard_regno - nregs_diff >= 0
687 : && TEST_HARD_REG_BIT (available_regs,
688 : hard_regno - nregs_diff))
689 4572 : : TEST_HARD_REG_BIT (available_regs,
690 4572 : hard_regno + nregs_diff))))
691 : {
692 60149014 : if (hard_regno_costs_check[hard_regno]
693 60149014 : != curr_hard_regno_costs_check)
694 : {
695 54723297 : hard_regno_costs_check[hard_regno] = curr_hard_regno_costs_check;
696 54723297 : hard_regno_costs[hard_regno] = 0;
697 : }
698 121514623 : for (j = 0;
699 121514623 : j < hard_regno_nregs (hard_regno, PSEUDO_REGNO_MODE (regno));
700 : j++)
701 61365609 : if (! crtl->abi->clobbers_full_reg_p (hard_regno + j)
702 61365609 : && ! df_regs_ever_live_p (hard_regno + j))
703 : /* It needs save restore. */
704 11976374 : hard_regno_costs[hard_regno]
705 5988187 : += (2
706 16417701 : * REG_FREQ_FROM_BB (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
707 15376713 : + 1);
708 60149014 : priority = targetm.register_priority (hard_regno);
709 50694569 : if (best_hard_regno < 0 || hard_regno_costs[hard_regno] < best_cost
710 108922109 : || (hard_regno_costs[hard_regno] == best_cost
711 25572128 : && (priority > best_priority
712 25469162 : || (targetm.register_usage_leveling_p ()
713 25469162 : && priority == best_priority
714 6506505 : && best_usage > lra_hard_reg_usage[hard_regno]))))
715 : {
716 14182881 : best_hard_regno = hard_regno;
717 14182881 : best_cost = hard_regno_costs[hard_regno];
718 14182881 : best_priority = priority;
719 14182881 : best_usage = lra_hard_reg_usage[hard_regno];
720 : }
721 : }
722 115708291 : if (try_only_hard_regno >= 0 || (first_p && best_hard_regno >= 0))
723 : break;
724 : }
725 9722296 : if (best_hard_regno >= 0)
726 9454445 : *cost = best_cost - lra_reg_info[regno].freq;
727 : return best_hard_regno;
728 : }
729 :
730 : /* A wrapper for find_hard_regno_for_1 (see comments for that function
731 : description). This function tries to find a hard register for
732 : preferred class first if it is worth. */
733 : static int
734 14227886 : find_hard_regno_for (int regno, int *cost, int try_only_hard_regno, bool first_p)
735 : {
736 14227886 : int hard_regno;
737 14227886 : HARD_REG_SET regno_set;
738 :
739 : /* Only original pseudos can have a different preferred class. */
740 14227886 : if (try_only_hard_regno < 0 && regno < lra_new_regno_start)
741 : {
742 1247570 : enum reg_class pref_class = reg_preferred_class (regno);
743 :
744 1247570 : if (regno_allocno_class_array[regno] != pref_class)
745 : {
746 452616 : hard_regno = find_hard_regno_for_1 (regno, cost, -1, first_p,
747 226308 : reg_class_contents[pref_class]);
748 226308 : if (hard_regno >= 0)
749 : return hard_regno;
750 : }
751 : }
752 14225027 : CLEAR_HARD_REG_SET (regno_set);
753 14225027 : return find_hard_regno_for_1 (regno, cost, try_only_hard_regno, first_p,
754 14225027 : regno_set);
755 : }
756 :
757 : /* Current value used for checking elements in
758 : update_hard_regno_preference_check. */
759 : static int curr_update_hard_regno_preference_check;
760 : /* If an element value is equal to the above variable value, then the
761 : corresponding regno has been processed for preference
762 : propagation. */
763 : static int *update_hard_regno_preference_check;
764 :
765 : /* Update the preference for using HARD_REGNO for pseudos that are
766 : connected directly or indirectly with REGNO. Apply divisor DIV
767 : to any preference adjustments.
768 :
769 : The more indirectly a pseudo is connected, the smaller its effect
770 : should be. We therefore increase DIV on each "hop". */
771 : static void
772 9599530 : update_hard_regno_preference (int regno, int hard_regno, int div)
773 : {
774 9599530 : int another_regno, cost;
775 9599530 : lra_copy_t cp, next_cp;
776 :
777 : /* Search depth 5 seems to be enough. */
778 9599530 : if (div > (1 << 5))
779 : return;
780 17355208 : for (cp = lra_reg_info[regno].copies; cp != NULL; cp = next_cp)
781 : {
782 7840087 : if (cp->regno1 == regno)
783 : {
784 3582182 : next_cp = cp->regno1_next;
785 3582182 : another_regno = cp->regno2;
786 : }
787 4257905 : else if (cp->regno2 == regno)
788 : {
789 4257905 : next_cp = cp->regno2_next;
790 4257905 : another_regno = cp->regno1;
791 : }
792 : else
793 0 : gcc_unreachable ();
794 7840087 : if (reg_renumber[another_regno] < 0
795 4290471 : && (update_hard_regno_preference_check[another_regno]
796 4290471 : != curr_update_hard_regno_preference_check))
797 : {
798 2962293 : update_hard_regno_preference_check[another_regno]
799 2962293 : = curr_update_hard_regno_preference_check;
800 2962293 : cost = cp->freq < div ? 1 : cp->freq / div;
801 2962293 : lra_setup_reload_pseudo_preferenced_hard_reg
802 2962293 : (another_regno, hard_regno, cost);
803 2962293 : update_hard_regno_preference (another_regno, hard_regno, div * 2);
804 : }
805 : }
806 : }
807 :
808 : /* Return prefix title for pseudo REGNO. */
809 : static const char *
810 100 : pseudo_prefix_title (int regno)
811 : {
812 100 : return
813 100 : (regno < lra_constraint_new_regno_start ? ""
814 100 : : bitmap_bit_p (&lra_inheritance_pseudos, regno) ? "inheritance "
815 99 : : bitmap_bit_p (&lra_split_regs, regno) ? "split "
816 99 : : bitmap_bit_p (&lra_optional_reload_pseudos, regno) ? "optional reload "
817 97 : : bitmap_bit_p (&lra_subreg_reload_pseudos, regno) ? "subreg reload "
818 100 : : "reload ");
819 : }
820 :
821 : /* Update REG_RENUMBER and other pseudo preferences by assignment of
822 : HARD_REGNO to pseudo REGNO and print about it if PRINT_P. */
823 : void
824 6769246 : lra_setup_reg_renumber (int regno, int hard_regno, bool print_p)
825 : {
826 6769246 : int i, hr;
827 :
828 : /* We cannot just reassign hard register. */
829 6769246 : lra_assert (hard_regno < 0 || reg_renumber[regno] < 0);
830 132009 : if ((hr = hard_regno) < 0)
831 132009 : hr = reg_renumber[regno];
832 6769246 : reg_renumber[regno] = hard_regno;
833 6769246 : lra_assert (hr >= 0);
834 13754307 : for (i = 0; i < hard_regno_nregs (hr, PSEUDO_REGNO_MODE (regno)); i++)
835 6985061 : if (hard_regno < 0)
836 142246 : lra_hard_reg_usage[hr + i] -= lra_reg_info[regno].freq;
837 : else
838 6842815 : lra_hard_reg_usage[hr + i] += lra_reg_info[regno].freq;
839 6769246 : if (print_p && lra_dump_file != NULL)
840 200 : fprintf (lra_dump_file, " Assign %d to %sr%d (freq=%d)\n",
841 100 : reg_renumber[regno], pseudo_prefix_title (regno),
842 100 : regno, lra_reg_info[regno].freq);
843 6769246 : if (hard_regno >= 0)
844 : {
845 6637237 : curr_update_hard_regno_preference_check++;
846 6637237 : update_hard_regno_preference (regno, hard_regno, 1);
847 : }
848 6769246 : }
849 :
850 : /* Pseudos which occur in insns containing a particular pseudo. */
851 : static bitmap_head insn_conflict_pseudos;
852 :
853 : /* Bitmaps used to contain spill pseudos for given pseudo hard regno
854 : and best spill pseudos for given pseudo (and best hard regno). */
855 : static bitmap_head spill_pseudos_bitmap, best_spill_pseudos_bitmap;
856 :
857 : /* Current pseudo check for validity of elements in
858 : TRY_HARD_REG_PSEUDOS. */
859 : static int curr_pseudo_check;
860 : /* Array used for validity of elements in TRY_HARD_REG_PSEUDOS. */
861 : static int try_hard_reg_pseudos_check[FIRST_PSEUDO_REGISTER];
862 : /* Pseudos who hold given hard register at the considered points. */
863 : static bitmap_head try_hard_reg_pseudos[FIRST_PSEUDO_REGISTER];
864 :
865 : /* Set up try_hard_reg_pseudos for given program point P and class
866 : RCLASS. Those are pseudos living at P and assigned to a hard
867 : register of RCLASS. In other words, those are pseudos which can be
868 : spilled to assign a hard register of RCLASS to a pseudo living at
869 : P. */
870 : static void
871 135739 : setup_try_hard_regno_pseudos (int p, enum reg_class rclass)
872 : {
873 135739 : int i, hard_regno;
874 135739 : machine_mode mode;
875 135739 : unsigned int spill_regno;
876 135739 : bitmap_iterator bi;
877 :
878 : /* Find what pseudos could be spilled. */
879 977857 : EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[p], 0, spill_regno, bi)
880 : {
881 842118 : mode = PSEUDO_REGNO_MODE (spill_regno);
882 842118 : hard_regno = live_pseudos_reg_renumber[spill_regno];
883 842118 : if (overlaps_hard_reg_set_p (reg_class_contents[rclass],
884 : mode, hard_regno))
885 : {
886 1284234 : for (i = hard_regno_nregs (hard_regno, mode) - 1; i >= 0; i--)
887 : {
888 654217 : if (try_hard_reg_pseudos_check[hard_regno + i]
889 654217 : != curr_pseudo_check)
890 : {
891 307507 : try_hard_reg_pseudos_check[hard_regno + i]
892 307507 : = curr_pseudo_check;
893 307507 : bitmap_clear (&try_hard_reg_pseudos[hard_regno + i]);
894 : }
895 654217 : bitmap_set_bit (&try_hard_reg_pseudos[hard_regno + i],
896 : spill_regno);
897 : }
898 : }
899 : }
900 135739 : }
901 :
902 : /* Assign temporarily HARD_REGNO to pseudo REGNO. Temporary
903 : assignment means that we might undo the data change. */
904 : static void
905 2113306 : assign_temporarily (int regno, int hard_regno)
906 : {
907 2113306 : int p;
908 2113306 : lra_live_range_t r;
909 :
910 4255604 : for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
911 : {
912 13379594 : for (p = r->start; p <= r->finish; p++)
913 11237296 : if (hard_regno < 0)
914 5618648 : bitmap_clear_bit (&live_hard_reg_pseudos[p], regno);
915 : else
916 : {
917 5618648 : bitmap_set_bit (&live_hard_reg_pseudos[p], regno);
918 5618648 : insert_in_live_range_start_chain (regno);
919 : }
920 : }
921 2113306 : live_pseudos_reg_renumber[regno] = hard_regno;
922 2113306 : }
923 :
924 : /* Return true iff there is a reason why pseudo SPILL_REGNO should not
925 : be spilled. */
926 : static bool
927 312613 : must_not_spill_p (unsigned spill_regno)
928 : {
929 312613 : if ((pic_offset_table_rtx != NULL
930 90671 : && spill_regno == REGNO (pic_offset_table_rtx))
931 397578 : || ((int) spill_regno >= lra_constraint_new_regno_start
932 30542 : && ! bitmap_bit_p (&lra_inheritance_pseudos, spill_regno)
933 14282 : && ! bitmap_bit_p (&lra_split_regs, spill_regno)
934 12056 : && ! bitmap_bit_p (&lra_subreg_reload_pseudos, spill_regno)
935 12056 : && ! bitmap_bit_p (&lra_optional_reload_pseudos, spill_regno)))
936 : return true;
937 : /* A reload pseudo that requires a singleton register class should
938 : not be spilled.
939 : FIXME: this mitigates the issue on certain i386 patterns, but
940 : does not solve the general case where existing reloads fully
941 : cover a limited register class. */
942 296621 : if (!bitmap_bit_p (&non_reload_pseudos, spill_regno)
943 276365 : && reg_class_size [reg_preferred_class (spill_regno)] == 1
944 312204 : && reg_alternate_class (spill_regno) == NO_REGS)
945 390 : return true;
946 : return false;
947 : }
948 :
949 : /* Array used for sorting reload pseudos for subsequent allocation
950 : after spilling some pseudo. */
951 : static int *sorted_reload_pseudos;
952 :
953 : /* Spill some pseudos for a reload pseudo REGNO and return hard
954 : register which should be used for pseudo after spilling. The
955 : function adds spilled pseudos to SPILLED_PSEUDO_BITMAP. When we
956 : choose hard register (and pseudos occupying the hard registers and
957 : to be spilled), we take into account not only how REGNO will
958 : benefit from the spills but also how other reload pseudos not yet
959 : assigned to hard registers benefit from the spills too. In very
960 : rare cases, the function can fail and return -1.
961 :
962 : If FIRST_P, return the first available hard reg ignoring other
963 : criteria, e.g. allocation cost and cost of spilling non-reload
964 : pseudos. This approach results in less hard reg pool fragmentation
965 : and permit to allocate hard regs to reload pseudos in complicated
966 : situations where pseudo sizes are different. */
967 : static int
968 56796 : spill_for (int regno, bitmap spilled_pseudo_bitmap, bool first_p)
969 : {
970 56796 : int i, j, n, p, hard_regno, best_hard_regno, cost, best_cost, rclass_size;
971 56796 : int reload_hard_regno, reload_cost;
972 56796 : bool static_p, best_static_p, too_many_p;
973 56796 : machine_mode mode;
974 56796 : enum reg_class rclass;
975 56796 : unsigned int spill_regno, reload_regno, uid;
976 56796 : int insn_pseudos_num, best_insn_pseudos_num;
977 56796 : int bad_spills_num, smallest_bad_spills_num;
978 56796 : lra_live_range_t r;
979 56796 : bitmap_iterator bi;
980 :
981 56796 : rclass = regno_allocno_class_array[regno];
982 56796 : lra_assert (reg_renumber[regno] < 0 && rclass != NO_REGS);
983 56796 : bitmap_clear (&insn_conflict_pseudos);
984 56796 : bitmap_clear (&best_spill_pseudos_bitmap);
985 167621 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
986 : {
987 110825 : struct lra_insn_reg *ir;
988 :
989 373657 : for (ir = lra_get_insn_regs (uid); ir != NULL; ir = ir->next)
990 262832 : if (ir->regno >= FIRST_PSEUDO_REGISTER)
991 252864 : bitmap_set_bit (&insn_conflict_pseudos, ir->regno);
992 : }
993 56796 : best_hard_regno = -1;
994 56796 : best_cost = INT_MAX;
995 56796 : best_static_p = true;
996 56796 : best_insn_pseudos_num = INT_MAX;
997 56796 : smallest_bad_spills_num = INT_MAX;
998 56796 : rclass_size = ira_class_hard_regs_num[rclass];
999 56796 : mode = PSEUDO_REGNO_MODE (regno);
1000 : /* Invalidate try_hard_reg_pseudos elements. */
1001 56796 : curr_pseudo_check++;
1002 118285 : for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
1003 197228 : for (p = r->start; p <= r->finish; p++)
1004 135739 : setup_try_hard_regno_pseudos (p, rclass);
1005 435708 : for (i = 0; i < rclass_size; i++)
1006 : {
1007 378912 : hard_regno = ira_class_hard_regs[rclass][i];
1008 378912 : bitmap_clear (&spill_pseudos_bitmap);
1009 773959 : for (j = hard_regno_nregs (hard_regno, mode) - 1; j >= 0; j--)
1010 : {
1011 395047 : if (hard_regno + j >= FIRST_PSEUDO_REGISTER)
1012 : break;
1013 395047 : if (try_hard_reg_pseudos_check[hard_regno + j] != curr_pseudo_check)
1014 78719 : continue;
1015 316328 : lra_assert (!bitmap_empty_p (&try_hard_reg_pseudos[hard_regno + j]));
1016 316328 : bitmap_ior_into (&spill_pseudos_bitmap,
1017 316328 : &try_hard_reg_pseudos[hard_regno + j]);
1018 : }
1019 : /* Spill pseudos. */
1020 378912 : static_p = false;
1021 675143 : EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
1022 312613 : if (must_not_spill_p (spill_regno))
1023 16382 : goto fail;
1024 296231 : else if (non_spilled_static_chain_regno_p (spill_regno))
1025 0 : static_p = true;
1026 362530 : insn_pseudos_num = 0;
1027 362530 : bad_spills_num = 0;
1028 362530 : if (lra_dump_file != NULL)
1029 0 : fprintf (lra_dump_file, " Trying %d:", hard_regno);
1030 362530 : sparseset_clear (live_range_reload_inheritance_pseudos);
1031 362530 : too_many_p = false;
1032 658509 : EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
1033 : {
1034 295979 : if (bitmap_bit_p (&insn_conflict_pseudos, spill_regno))
1035 51232 : insn_pseudos_num++;
1036 295979 : if (spill_regno >= (unsigned int) lra_bad_spill_regno_start)
1037 0 : bad_spills_num++;
1038 295979 : for (r = lra_reg_info[spill_regno].live_ranges;
1039 959933 : r != NULL && ! too_many_p;
1040 663954 : r = r->next)
1041 : {
1042 32923232 : for (p = r->start; p <= r->finish && ! too_many_p; p++)
1043 : {
1044 32259278 : lra_live_range_t r2;
1045 :
1046 32259278 : for (r2 = start_point_ranges[p];
1047 54170135 : r2 != NULL;
1048 21910857 : r2 = r2->start_next)
1049 21910857 : if (r2->regno >= lra_constraint_new_regno_start)
1050 8368457 : sparseset_set_bit (live_range_reload_inheritance_pseudos,
1051 : r2->regno);
1052 32259278 : too_many_p
1053 32259278 : = (sparseset_cardinality
1054 32259278 : (live_range_reload_inheritance_pseudos)
1055 32259278 : > (unsigned) param_lra_max_considered_reload_pseudos);
1056 : }
1057 : }
1058 : }
1059 362530 : n = 0;
1060 362530 : if (! too_many_p)
1061 14498028 : EXECUTE_IF_SET_IN_SPARSESET (live_range_reload_inheritance_pseudos,
1062 : reload_regno)
1063 7024830 : if ((int) reload_regno != regno
1064 6752972 : && (ira_reg_classes_intersect_p
1065 6752972 : [rclass][regno_allocno_class_array[reload_regno]])
1066 5945579 : && live_pseudos_reg_renumber[reload_regno] < 0
1067 10508249 : && find_hard_regno_for (reload_regno, &cost, -1, first_p) < 0)
1068 1639786 : sorted_reload_pseudos[n++] = reload_regno;
1069 658509 : EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
1070 : {
1071 295979 : if (reg_renumber[spill_regno] >= 0)
1072 295979 : live_pseudos_reg_renumber[spill_regno] = -1;
1073 295979 : if (lra_dump_file != NULL)
1074 0 : fprintf (lra_dump_file, " spill %d(freq=%d)",
1075 0 : spill_regno, lra_reg_info[spill_regno].freq);
1076 : }
1077 362530 : hard_regno = find_hard_regno_for (regno, &cost, -1, first_p);
1078 362530 : if (hard_regno >= 0)
1079 : {
1080 281587 : assign_temporarily (regno, hard_regno);
1081 281587 : qsort (sorted_reload_pseudos, n, sizeof (int),
1082 : reload_pseudo_compare_func);
1083 2191056 : for (j = 0; j < n; j++)
1084 : {
1085 1627882 : reload_regno = sorted_reload_pseudos[j];
1086 1627882 : lra_assert (live_pseudos_reg_renumber[reload_regno] < 0);
1087 3255764 : if ((reload_hard_regno
1088 1627882 : = find_hard_regno_for (reload_regno,
1089 : &reload_cost, -1, first_p)) >= 0)
1090 : {
1091 775066 : if (lra_dump_file != NULL)
1092 0 : fprintf (lra_dump_file, " assign %d(cost=%d)",
1093 : reload_regno, reload_cost);
1094 775066 : assign_temporarily (reload_regno, reload_hard_regno);
1095 775066 : cost += reload_cost;
1096 : }
1097 : }
1098 567395 : EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
1099 : {
1100 285808 : rtx_insn_list *x;
1101 :
1102 285808 : cost += lra_reg_info[spill_regno].freq;
1103 285808 : if (ira_reg_equiv[spill_regno].memory != NULL
1104 273747 : || ira_reg_equiv[spill_regno].constant != NULL)
1105 14164 : for (x = ira_reg_equiv[spill_regno].init_insns;
1106 24159 : x != NULL;
1107 9995 : x = x->next ())
1108 29539 : cost -= REG_FREQ_FROM_BB (BLOCK_FOR_INSN (x->insn ()));
1109 : }
1110 : /* Avoid spilling static chain pointer pseudo when non-local
1111 : goto is used. */
1112 281587 : if ((! static_p && best_static_p)
1113 231639 : || (static_p == best_static_p
1114 231639 : && (best_insn_pseudos_num > insn_pseudos_num
1115 224503 : || (best_insn_pseudos_num == insn_pseudos_num
1116 201178 : && (bad_spills_num < smallest_bad_spills_num
1117 201178 : || (bad_spills_num == smallest_bad_spills_num
1118 201178 : && best_cost > cost))))))
1119 : {
1120 95334 : best_insn_pseudos_num = insn_pseudos_num;
1121 95334 : smallest_bad_spills_num = bad_spills_num;
1122 95334 : best_static_p = static_p;
1123 95334 : best_cost = cost;
1124 95334 : best_hard_regno = hard_regno;
1125 95334 : bitmap_copy (&best_spill_pseudos_bitmap, &spill_pseudos_bitmap);
1126 95334 : if (lra_dump_file != NULL)
1127 0 : fprintf (lra_dump_file,
1128 : " Now best %d(cost=%d, bad_spills=%d, insn_pseudos=%d)\n",
1129 : hard_regno, cost, bad_spills_num, insn_pseudos_num);
1130 : }
1131 281587 : assign_temporarily (regno, -1);
1132 2191056 : for (j = 0; j < n; j++)
1133 : {
1134 1627882 : reload_regno = sorted_reload_pseudos[j];
1135 1627882 : if (live_pseudos_reg_renumber[reload_regno] >= 0)
1136 775066 : assign_temporarily (reload_regno, -1);
1137 : }
1138 : }
1139 362530 : if (lra_dump_file != NULL)
1140 0 : fprintf (lra_dump_file, "\n");
1141 : /* Restore the live hard reg pseudo info for spilled pseudos. */
1142 658509 : EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi)
1143 295979 : if (reg_renumber[spill_regno] >= 0)
1144 295979 : live_pseudos_reg_renumber[spill_regno] = reg_renumber[spill_regno];
1145 362530 : fail:
1146 378912 : ;
1147 : }
1148 : /* Spill: */
1149 107244 : EXECUTE_IF_SET_IN_BITMAP (&best_spill_pseudos_bitmap, 0, spill_regno, bi)
1150 : {
1151 50448 : if ((int) spill_regno >= lra_constraint_new_regno_start)
1152 4510 : former_reload_pseudo_spill_p = true;
1153 50448 : if (lra_dump_file != NULL)
1154 0 : fprintf (lra_dump_file, " Spill %sr%d(hr=%d, freq=%d) for r%d\n",
1155 : pseudo_prefix_title (spill_regno),
1156 0 : spill_regno, reg_renumber[spill_regno],
1157 0 : lra_reg_info[spill_regno].freq, regno);
1158 50448 : update_lives (spill_regno, true);
1159 50448 : lra_setup_reg_renumber (spill_regno, -1, false);
1160 : }
1161 56796 : bitmap_ior_into (spilled_pseudo_bitmap, &best_spill_pseudos_bitmap);
1162 56796 : return best_hard_regno;
1163 : }
1164 :
1165 : /* Assign HARD_REGNO to REGNO. */
1166 : static void
1167 6637184 : assign_hard_regno (int hard_regno, int regno)
1168 : {
1169 6637184 : int i;
1170 :
1171 6637184 : lra_assert (hard_regno >= 0);
1172 6637184 : lra_setup_reg_renumber (regno, hard_regno, true);
1173 6637184 : update_lives (regno, false);
1174 13482212 : for (i = 0;
1175 13482212 : i < hard_regno_nregs (hard_regno, lra_reg_info[regno].biggest_mode);
1176 : i++)
1177 6845028 : df_set_regs_ever_live (hard_regno + i, true);
1178 6637184 : }
1179 :
1180 : /* Array used for sorting different pseudos. */
1181 : static int *sorted_pseudos;
1182 :
1183 : /* The constraints pass is allowed to create equivalences between
1184 : pseudos that make the current allocation "incorrect" (in the sense
1185 : that pseudos are assigned to hard registers from their own conflict
1186 : sets). The global variable check_and_force_assignment_correctness_p says
1187 : whether this might have happened.
1188 :
1189 : Process pseudos assigned to hard registers (less frequently used
1190 : first), spill if a conflict is found, and mark the spilled pseudos
1191 : in SPILLED_PSEUDO_BITMAP. Set up LIVE_HARD_REG_PSEUDOS from
1192 : pseudos, assigned to hard registers. */
1193 : static void
1194 1601843 : setup_live_pseudos_and_spill_after_risky_transforms (bitmap
1195 : spilled_pseudo_bitmap)
1196 : {
1197 1601843 : int p, i, j, n, regno, hard_regno, biggest_nregs, nregs_diff;
1198 1601843 : unsigned int k, conflict_regno;
1199 1601843 : poly_int64 offset;
1200 1601843 : int val;
1201 1601843 : HARD_REG_SET conflict_set;
1202 1601843 : machine_mode mode, biggest_mode;
1203 1601843 : lra_live_range_t r;
1204 1601843 : bitmap_iterator bi;
1205 1601843 : int max_regno = max_reg_num ();
1206 :
1207 1601843 : if (! check_and_force_assignment_correctness_p)
1208 : {
1209 21501457 : for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1210 21441570 : if (reg_renumber[i] >= 0 && lra_reg_info[i].nrefs > 0)
1211 10270532 : update_lives (i, false);
1212 59887 : return;
1213 : }
1214 84340383 : for (n = 0, i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1215 82798427 : if ((pic_offset_table_rtx == NULL_RTX
1216 7635923 : || i != (int) REGNO (pic_offset_table_rtx))
1217 90384366 : && (hard_regno = reg_renumber[i]) >= 0 && lra_reg_info[i].nrefs > 0)
1218 : {
1219 32433812 : biggest_mode = lra_reg_info[i].biggest_mode;
1220 32433812 : biggest_nregs = hard_regno_nregs (hard_regno, biggest_mode);
1221 32433812 : nregs_diff = (biggest_nregs
1222 32433812 : - hard_regno_nregs (hard_regno, PSEUDO_REGNO_MODE (i)));
1223 32433812 : enum reg_class rclass = lra_get_allocno_class (i);
1224 :
1225 32433812 : if ((WORDS_BIG_ENDIAN
1226 : && (hard_regno - nregs_diff < 0
1227 : || !TEST_HARD_REG_BIT (reg_class_contents[rclass],
1228 : hard_regno - nregs_diff)))
1229 : || (!WORDS_BIG_ENDIAN
1230 32433812 : && (hard_regno + nregs_diff >= FIRST_PSEUDO_REGISTER
1231 32433812 : || !TEST_HARD_REG_BIT (reg_class_contents[rclass],
1232 : hard_regno + nregs_diff))))
1233 : {
1234 : /* Hard registers of paradoxical sub-registers are out of
1235 : range of pseudo register class. Spill the pseudo. */
1236 0 : reg_renumber[i] = -1;
1237 0 : continue;
1238 : }
1239 32433812 : sorted_pseudos[n++] = i;
1240 : }
1241 1541956 : qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func);
1242 1541956 : if (pic_offset_table_rtx != NULL_RTX
1243 49984 : && (regno = REGNO (pic_offset_table_rtx)) >= FIRST_PSEUDO_REGISTER
1244 1591940 : && reg_renumber[regno] >= 0 && lra_reg_info[regno].nrefs > 0)
1245 43539 : sorted_pseudos[n++] = regno;
1246 34019307 : for (i = n - 1; i >= 0; i--)
1247 : {
1248 32477351 : regno = sorted_pseudos[i];
1249 32477351 : hard_regno = reg_renumber[regno];
1250 32477351 : lra_assert (hard_regno >= 0);
1251 32477351 : mode = lra_reg_info[regno].biggest_mode;
1252 32477351 : sparseset_clear (live_range_hard_reg_pseudos);
1253 70568382 : for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
1254 : {
1255 87928809 : EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[r->start], 0, k, bi)
1256 49837778 : sparseset_set_bit (live_range_hard_reg_pseudos, k);
1257 282420772 : for (p = r->start + 1; p <= r->finish; p++)
1258 : {
1259 244329741 : lra_live_range_t r2;
1260 :
1261 244329741 : for (r2 = start_point_ranges[p];
1262 375981983 : r2 != NULL;
1263 131652242 : r2 = r2->start_next)
1264 131652242 : if (live_pseudos_reg_renumber[r2->regno] >= 0)
1265 70676419 : sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno);
1266 : }
1267 : }
1268 32477351 : conflict_set = lra_no_alloc_regs;
1269 32477351 : conflict_set |= lra_reg_info[regno].conflict_hard_regs;
1270 32477351 : val = lra_reg_info[regno].val;
1271 32477351 : offset = lra_reg_info[regno].offset;
1272 132632790 : EXECUTE_IF_SET_IN_SPARSESET (live_range_hard_reg_pseudos, conflict_regno)
1273 100155439 : if (!lra_reg_val_equal_p (conflict_regno, val, offset)
1274 : /* If it is multi-register pseudos they should start on
1275 : the same hard register. */
1276 81859 : || hard_regno != reg_renumber[conflict_regno])
1277 : {
1278 100084669 : int conflict_hard_regno = reg_renumber[conflict_regno];
1279 :
1280 100084669 : biggest_mode = lra_reg_info[conflict_regno].biggest_mode;
1281 100084669 : biggest_nregs = hard_regno_nregs (conflict_hard_regno,
1282 : biggest_mode);
1283 100084669 : nregs_diff
1284 100084669 : = (biggest_nregs
1285 100084669 : - hard_regno_nregs (conflict_hard_regno,
1286 100084669 : PSEUDO_REGNO_MODE (conflict_regno)));
1287 100084669 : add_to_hard_reg_set (&conflict_set,
1288 : biggest_mode,
1289 : conflict_hard_regno
1290 : - (WORDS_BIG_ENDIAN ? nregs_diff : 0));
1291 : }
1292 32477351 : if (! overlaps_hard_reg_set_p (conflict_set, mode, hard_regno))
1293 : {
1294 32464964 : update_lives (regno, false);
1295 32464964 : continue;
1296 : }
1297 12387 : bitmap_set_bit (spilled_pseudo_bitmap, regno);
1298 12387 : for (j = 0;
1299 32888 : j < hard_regno_nregs (hard_regno, PSEUDO_REGNO_MODE (regno));
1300 : j++)
1301 20501 : lra_hard_reg_usage[hard_regno + j] -= lra_reg_info[regno].freq;
1302 12387 : reg_renumber[regno] = -1;
1303 12387 : if (regno >= lra_constraint_new_regno_start)
1304 1 : former_reload_pseudo_spill_p = true;
1305 12387 : if (lra_dump_file != NULL)
1306 0 : fprintf (lra_dump_file, " Spill r%d after risky transformations\n",
1307 : regno);
1308 : }
1309 : }
1310 :
1311 : /* Improve allocation by assigning the same hard regno of inheritance
1312 : pseudos to the connected pseudos. We need this because inheritance
1313 : pseudos are allocated after reload pseudos in the thread and when
1314 : we assign a hard register to a reload pseudo we don't know yet that
1315 : the connected inheritance pseudos can get the same hard register.
1316 : Add pseudos with changed allocation to bitmap CHANGED_PSEUDOS. */
1317 : static void
1318 1601843 : improve_inheritance (bitmap changed_pseudos)
1319 : {
1320 1601843 : unsigned int k;
1321 1601843 : int regno, another_regno, hard_regno, another_hard_regno, cost, i, n;
1322 1601843 : lra_copy_t cp, next_cp;
1323 1601843 : bitmap_iterator bi;
1324 :
1325 1601843 : if (lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
1326 5950 : return;
1327 1595893 : n = 0;
1328 3500823 : EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, k, bi)
1329 1904930 : if (reg_renumber[k] >= 0 && lra_reg_info[k].nrefs != 0)
1330 1249389 : sorted_pseudos[n++] = k;
1331 1595893 : qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func);
1332 4441175 : for (i = 0; i < n; i++)
1333 : {
1334 1249389 : regno = sorted_pseudos[i];
1335 1249389 : hard_regno = reg_renumber[regno];
1336 1249389 : lra_assert (hard_regno >= 0);
1337 3577721 : for (cp = lra_reg_info[regno].copies; cp != NULL; cp = next_cp)
1338 : {
1339 2328332 : if (cp->regno1 == regno)
1340 : {
1341 388314 : next_cp = cp->regno1_next;
1342 388314 : another_regno = cp->regno2;
1343 : }
1344 1940018 : else if (cp->regno2 == regno)
1345 : {
1346 1940018 : next_cp = cp->regno2_next;
1347 1940018 : another_regno = cp->regno1;
1348 : }
1349 : else
1350 0 : gcc_unreachable ();
1351 : /* Don't change reload pseudo allocation. It might have
1352 : this allocation for a purpose and changing it can result
1353 : in LRA cycling. */
1354 2328332 : if ((another_regno < lra_constraint_new_regno_start
1355 2328332 : || bitmap_bit_p (&lra_inheritance_pseudos, another_regno))
1356 801117 : && (another_hard_regno = reg_renumber[another_regno]) >= 0
1357 3010598 : && another_hard_regno != hard_regno)
1358 : {
1359 70008 : if (lra_dump_file != NULL)
1360 0 : fprintf
1361 0 : (lra_dump_file,
1362 : " Improving inheritance for %d(%d) and %d(%d)...\n",
1363 : regno, hard_regno, another_regno, another_hard_regno);
1364 70008 : update_lives (another_regno, true);
1365 70008 : lra_setup_reg_renumber (another_regno, -1, false);
1366 70008 : if (hard_regno == find_hard_regno_for (another_regno, &cost,
1367 : hard_regno, false))
1368 36931 : assign_hard_regno (hard_regno, another_regno);
1369 : else
1370 33077 : assign_hard_regno (another_hard_regno, another_regno);
1371 70008 : bitmap_set_bit (changed_pseudos, another_regno);
1372 : }
1373 : }
1374 : }
1375 : }
1376 :
1377 :
1378 : /* Bitmap finally containing all pseudos spilled on this assignment
1379 : pass. */
1380 : static bitmap_head all_spilled_pseudos;
1381 : /* All pseudos whose allocation was changed. */
1382 : static bitmap_head changed_pseudo_bitmap;
1383 :
1384 :
1385 : /* Add to LIVE_RANGE_HARD_REG_PSEUDOS all pseudos conflicting with
1386 : REGNO and whose hard regs can be assigned to REGNO. */
1387 : static void
1388 3520 : find_all_spills_for (int regno)
1389 : {
1390 3520 : int p;
1391 3520 : lra_live_range_t r;
1392 3520 : unsigned int k;
1393 3520 : bitmap_iterator bi;
1394 3520 : enum reg_class rclass;
1395 3520 : bool *rclass_intersect_p;
1396 :
1397 3520 : rclass = regno_allocno_class_array[regno];
1398 3520 : rclass_intersect_p = ira_reg_classes_intersect_p[rclass];
1399 9369 : for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
1400 : {
1401 17330 : EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[r->start], 0, k, bi)
1402 11481 : if (rclass_intersect_p[regno_allocno_class_array[k]])
1403 11324 : sparseset_set_bit (live_range_hard_reg_pseudos, k);
1404 12601 : for (p = r->start + 1; p <= r->finish; p++)
1405 : {
1406 6752 : lra_live_range_t r2;
1407 :
1408 6752 : for (r2 = start_point_ranges[p];
1409 16420 : r2 != NULL;
1410 9668 : r2 = r2->start_next)
1411 : {
1412 9668 : if (live_pseudos_reg_renumber[r2->regno] >= 0
1413 9600 : && ! sparseset_bit_p (live_range_hard_reg_pseudos, r2->regno)
1414 19251 : && rclass_intersect_p[regno_allocno_class_array[r2->regno]])
1415 9577 : sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno);
1416 : }
1417 : }
1418 : }
1419 3520 : }
1420 :
1421 : /* Assign hard registers to reload pseudos and other pseudos. Return
1422 : true if we was not able to assign hard registers to all reload
1423 : pseudos. */
1424 : static bool
1425 1601843 : assign_by_spills (void)
1426 : {
1427 1601843 : int i, n, nfails, iter, regno, regno2, hard_regno, cost;
1428 1601843 : rtx restore_rtx;
1429 1601843 : bitmap_head changed_insns, do_not_assign_nonreload_pseudos;
1430 1601843 : unsigned int u, conflict_regno;
1431 1601843 : bitmap_iterator bi;
1432 1601843 : bool reload_p, fails_p = false;
1433 1601843 : int max_regno = max_reg_num ();
1434 :
1435 13859582 : for (n = 0, i = lra_constraint_new_regno_start; i < max_regno; i++)
1436 12257739 : if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0
1437 7890471 : && regno_allocno_class_array[i] != NO_REGS)
1438 6929615 : sorted_pseudos[n++] = i;
1439 1601843 : bitmap_initialize (&insn_conflict_pseudos, ®_obstack);
1440 1601843 : bitmap_initialize (&spill_pseudos_bitmap, ®_obstack);
1441 1601843 : bitmap_initialize (&best_spill_pseudos_bitmap, ®_obstack);
1442 1601843 : update_hard_regno_preference_check = XCNEWVEC (int, max_regno);
1443 1601843 : curr_update_hard_regno_preference_check = 0;
1444 1601843 : memset (try_hard_reg_pseudos_check, 0, sizeof (try_hard_reg_pseudos_check));
1445 152175085 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1446 150573242 : bitmap_initialize (&try_hard_reg_pseudos[i], ®_obstack);
1447 1601843 : curr_pseudo_check = 0;
1448 1601843 : bitmap_initialize (&changed_insns, ®_obstack);
1449 1601843 : bitmap_initialize (&non_reload_pseudos, ®_obstack);
1450 1601843 : bitmap_ior (&non_reload_pseudos, &lra_inheritance_pseudos, &lra_split_regs);
1451 1601843 : bitmap_ior_into (&non_reload_pseudos, &lra_subreg_reload_pseudos);
1452 1601843 : bitmap_ior_into (&non_reload_pseudos, &lra_optional_reload_pseudos);
1453 1601843 : for (iter = 0; iter <= 1; iter++)
1454 : {
1455 1604385 : qsort (sorted_pseudos, n, sizeof (int), reload_pseudo_compare_func);
1456 1604385 : nfails = 0;
1457 10146902 : for (i = 0; i < n; i++)
1458 : {
1459 6938132 : regno = sorted_pseudos[i];
1460 6938132 : if (reg_renumber[regno] >= 0)
1461 1178 : continue;
1462 6936954 : if (lra_dump_file != NULL)
1463 200 : fprintf (lra_dump_file, " Assigning to %d "
1464 : "(cl=%s, orig=%d, freq=%d, tfirst=%d, tfreq=%d)...\n",
1465 100 : regno, reg_class_names[regno_allocno_class_array[regno]],
1466 100 : ORIGINAL_REGNO (regno_reg_rtx[regno]),
1467 100 : lra_reg_info[regno].freq, regno_assign_info[regno].first,
1468 100 : regno_assign_info[regno_assign_info[regno].first].freq);
1469 6936954 : hard_regno = find_hard_regno_for (regno, &cost, -1, iter == 1);
1470 6936954 : reload_p = ! bitmap_bit_p (&non_reload_pseudos, regno);
1471 6936954 : if (hard_regno < 0 && reload_p)
1472 56796 : hard_regno = spill_for (regno, &all_spilled_pseudos, iter == 1);
1473 6936954 : if (hard_regno < 0)
1474 : {
1475 496239 : if (reload_p)
1476 : {
1477 : /* Put unassigned reload pseudo first in the array. */
1478 6848 : regno2 = sorted_pseudos[nfails];
1479 6848 : sorted_pseudos[nfails++] = regno;
1480 6848 : sorted_pseudos[i] = regno2;
1481 : }
1482 : else
1483 : {
1484 : /* Consider all alternatives on the next constraint
1485 : subpass. */
1486 489391 : bitmap_set_bit (&all_spilled_pseudos, regno);
1487 : }
1488 : }
1489 : else
1490 : {
1491 : /* This register might have been spilled by the previous
1492 : pass. Indicate that it is no longer spilled. */
1493 6440715 : bitmap_clear_bit (&all_spilled_pseudos, regno);
1494 6440715 : assign_hard_regno (hard_regno, regno);
1495 6440715 : if (! reload_p || regno_allocno_class_array[regno] == ALL_REGS)
1496 : /* As non-reload pseudo assignment is changed we should
1497 : reconsider insns referring for the pseudo. Do the same if a
1498 : reload pseudo did not refine its class which can happens
1499 : when the pseudo occurs only in reload insns. */
1500 1360869 : bitmap_set_bit (&changed_pseudo_bitmap, regno);
1501 : }
1502 : }
1503 1604385 : if (nfails == 0 || iter > 0)
1504 : {
1505 1601843 : fails_p = nfails != 0;
1506 1601843 : break;
1507 : }
1508 : /* This is a very rare event. We cannot assign a hard register
1509 : to reload pseudo because the hard register was assigned to
1510 : another reload pseudo on a previous assignment pass. For x86
1511 : example, on the 1st pass we assigned CX (although another
1512 : hard register could be used for this) to reload pseudo in an
1513 : insn, on the 2nd pass we need CX (and only this) hard
1514 : register for a new reload pseudo in the same insn. Another
1515 : possible situation may occur in assigning to multi-regs
1516 : reload pseudos when hard regs pool is too fragmented even
1517 : after spilling non-reload pseudos.
1518 :
1519 : We should do something radical here to succeed. Here we
1520 : spill *all* conflicting pseudos and reassign them. */
1521 2542 : if (lra_dump_file != NULL)
1522 0 : fprintf (lra_dump_file, " 2nd iter for reload pseudo assignments:\n");
1523 2542 : sparseset_clear (live_range_hard_reg_pseudos);
1524 6062 : for (i = 0; i < nfails; i++)
1525 : {
1526 3520 : if (lra_dump_file != NULL)
1527 0 : fprintf (lra_dump_file, " Reload r%d assignment failure\n",
1528 0 : sorted_pseudos[i]);
1529 3520 : find_all_spills_for (sorted_pseudos[i]);
1530 : }
1531 25648 : EXECUTE_IF_SET_IN_SPARSESET (live_range_hard_reg_pseudos, conflict_regno)
1532 : {
1533 11553 : if ((int) conflict_regno >= lra_constraint_new_regno_start)
1534 : {
1535 1743 : sorted_pseudos[nfails++] = conflict_regno;
1536 1743 : former_reload_pseudo_spill_p = true;
1537 : }
1538 : else
1539 : /* It is better to do reloads before spilling as after the
1540 : spill-subpass we will reload memory instead of pseudos
1541 : and this will make reusing reload pseudos more
1542 : complicated. Going directly to the spill pass in such
1543 : case might result in worse code performance or even LRA
1544 : cycling if we have few registers. */
1545 9810 : bitmap_set_bit (&all_spilled_pseudos, conflict_regno);
1546 11553 : if (lra_dump_file != NULL)
1547 0 : fprintf (lra_dump_file, " Spill %s r%d(hr=%d, freq=%d)\n",
1548 : pseudo_prefix_title (conflict_regno), conflict_regno,
1549 0 : reg_renumber[conflict_regno],
1550 0 : lra_reg_info[conflict_regno].freq);
1551 11553 : update_lives (conflict_regno, true);
1552 11553 : lra_setup_reg_renumber (conflict_regno, -1, false);
1553 : }
1554 2542 : if (n < nfails)
1555 : n = nfails;
1556 : }
1557 1601843 : improve_inheritance (&changed_pseudo_bitmap);
1558 1601843 : bitmap_clear (&non_reload_pseudos);
1559 1601843 : bitmap_clear (&changed_insns);
1560 1601843 : if (! lra_simple_p)
1561 : {
1562 : /* We should not assign to original pseudos of inheritance
1563 : pseudos or split pseudos if any its inheritance pseudo did
1564 : not get hard register or any its split pseudo was not split
1565 : because undo inheritance/split pass will extend live range of
1566 : such inheritance or split pseudos. */
1567 1601837 : bitmap_initialize (&do_not_assign_nonreload_pseudos, ®_obstack);
1568 3690193 : EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, u, bi)
1569 2088356 : if ((restore_rtx = lra_reg_info[u].restore_rtx) != NULL_RTX
1570 1208062 : && REG_P (restore_rtx)
1571 1177568 : && reg_renumber[u] < 0
1572 2549907 : && bitmap_bit_p (&lra_inheritance_pseudos, u))
1573 461551 : bitmap_set_bit (&do_not_assign_nonreload_pseudos, REGNO (restore_rtx));
1574 2587470 : EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, u, bi)
1575 985633 : if ((restore_rtx = lra_reg_info[u].restore_rtx) != NULL_RTX
1576 985633 : && reg_renumber[u] >= 0)
1577 : {
1578 966 : lra_assert (REG_P (restore_rtx));
1579 966 : bitmap_set_bit (&do_not_assign_nonreload_pseudos, REGNO (restore_rtx));
1580 : }
1581 105610921 : for (n = 0, i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1582 104009084 : if (((i < lra_constraint_new_regno_start
1583 91755189 : && ! bitmap_bit_p (&do_not_assign_nonreload_pseudos, i))
1584 12567756 : || (bitmap_bit_p (&lra_inheritance_pseudos, i)
1585 2088356 : && lra_reg_info[i].restore_rtx != NULL_RTX)
1586 11359694 : || (bitmap_bit_p (&lra_split_regs, i)
1587 985633 : && lra_reg_info[i].restore_rtx != NULL_RTX)
1588 10687350 : || bitmap_bit_p (&lra_subreg_reload_pseudos, i)
1589 10686889 : || bitmap_bit_p (&lra_optional_reload_pseudos, i))
1590 94412783 : && reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0
1591 106465504 : && regno_allocno_class_array[i] != NO_REGS)
1592 1747093 : sorted_pseudos[n++] = i;
1593 1601837 : bitmap_clear (&do_not_assign_nonreload_pseudos);
1594 1601837 : if (n != 0 && lra_dump_file != NULL)
1595 1 : fprintf (lra_dump_file, " Reassigning non-reload pseudos\n");
1596 1601837 : qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func);
1597 4950767 : for (i = 0; i < n; i++)
1598 : {
1599 1747093 : regno = sorted_pseudos[i];
1600 1747093 : hard_regno = find_hard_regno_for (regno, &cost, -1, false);
1601 1747093 : if (hard_regno >= 0)
1602 : {
1603 126461 : assign_hard_regno (hard_regno, regno);
1604 : /* We change allocation for non-reload pseudo on this
1605 : iteration -- mark the pseudo for invalidation of used
1606 : alternatives of insns containing the pseudo. */
1607 126461 : bitmap_set_bit (&changed_pseudo_bitmap, regno);
1608 : }
1609 : else
1610 : {
1611 1620632 : enum reg_class rclass = lra_get_allocno_class (regno);
1612 1620632 : enum reg_class spill_class;
1613 :
1614 3241264 : if (targetm.spill_class == NULL
1615 1620632 : || lra_reg_info[regno].restore_rtx == NULL_RTX
1616 474654 : || ! bitmap_bit_p (&lra_inheritance_pseudos, regno)
1617 1620632 : || (spill_class
1618 459043 : = ((enum reg_class)
1619 459043 : targetm.spill_class
1620 459043 : ((reg_class_t) rclass,
1621 459043 : PSEUDO_REGNO_MODE (regno)))) == NO_REGS)
1622 1620632 : continue;
1623 0 : regno_allocno_class_array[regno] = spill_class;
1624 0 : hard_regno = find_hard_regno_for (regno, &cost, -1, false);
1625 0 : if (hard_regno < 0)
1626 0 : regno_allocno_class_array[regno] = rclass;
1627 : else
1628 : {
1629 0 : setup_reg_classes
1630 0 : (regno, spill_class, spill_class, spill_class);
1631 0 : assign_hard_regno (hard_regno, regno);
1632 0 : bitmap_set_bit (&changed_pseudo_bitmap, regno);
1633 : }
1634 : }
1635 : }
1636 : }
1637 1601843 : free (update_hard_regno_preference_check);
1638 1601843 : bitmap_clear (&best_spill_pseudos_bitmap);
1639 1601843 : bitmap_clear (&spill_pseudos_bitmap);
1640 1601843 : bitmap_clear (&insn_conflict_pseudos);
1641 1601843 : return fails_p;
1642 : }
1643 :
1644 : /* Entry function to assign hard registers to new reload pseudos
1645 : starting with LRA_CONSTRAINT_NEW_REGNO_START (by possible spilling
1646 : of old pseudos) and possibly to the old pseudos. The function adds
1647 : what insns to process for the next constraint pass. Those are all
1648 : insns who contains non-reload and non-inheritance pseudos with
1649 : changed allocation.
1650 :
1651 : Return true if we did not spill any non-reload and non-inheritance
1652 : pseudos. Set up FAILS_P if we failed to assign hard registers to
1653 : all reload pseudos. */
1654 : bool
1655 1601843 : lra_assign (bool &fails_p)
1656 : {
1657 1601843 : int i;
1658 1601843 : unsigned int u;
1659 1601843 : bitmap_iterator bi;
1660 1601843 : bitmap_head insns_to_process;
1661 1601843 : bool no_spills_p;
1662 1601843 : int max_regno = max_reg_num ();
1663 :
1664 1601843 : timevar_push (TV_LRA_ASSIGN);
1665 1601843 : lra_assignment_iter++;
1666 1601843 : if (lra_dump_file != NULL)
1667 96 : fprintf (lra_dump_file, "\n********** Assignment #%d: **********\n\n",
1668 : lra_assignment_iter);
1669 1601843 : init_lives ();
1670 1601843 : sorted_pseudos = XNEWVEC (int, max_regno);
1671 1601843 : sorted_reload_pseudos = XNEWVEC (int, max_regno);
1672 1601843 : regno_allocno_class_array = XNEWVEC (enum reg_class, max_regno);
1673 1601843 : regno_live_length = XNEWVEC (int, max_regno);
1674 105841840 : for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1675 : {
1676 104239997 : int l;
1677 104239997 : lra_live_range_t r;
1678 :
1679 104239997 : regno_allocno_class_array[i] = lra_get_allocno_class (i);
1680 166113661 : for (l = 0, r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
1681 61873664 : l += r->finish - r->start + 1;
1682 104239997 : regno_live_length[i] = l;
1683 : }
1684 1601843 : former_reload_pseudo_spill_p = false;
1685 1601843 : init_regno_assign_info ();
1686 1601843 : bitmap_initialize (&all_spilled_pseudos, ®_obstack);
1687 1601843 : create_live_range_start_chains ();
1688 1601843 : setup_live_pseudos_and_spill_after_risky_transforms (&all_spilled_pseudos);
1689 1601843 : if (! lra_hard_reg_split_p && ! lra_asm_error_p && flag_checking)
1690 : /* Check correctness of allocation but only when there are no hard reg
1691 : splits and asm errors as in the case of errors explicit insns involving
1692 : hard regs are added or the asm is removed and this can result in
1693 : incorrect allocation. */
1694 104762896 : for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1695 103163424 : if (lra_reg_info[i].nrefs != 0
1696 51443883 : && reg_renumber[i] >= 0
1697 103163424 : && overlaps_hard_reg_set_p (lra_reg_info[i].conflict_hard_regs,
1698 42214829 : PSEUDO_REGNO_MODE (i), reg_renumber[i]))
1699 0 : gcc_unreachable ();
1700 : /* Setup insns to process on the next constraint pass. */
1701 1601843 : bitmap_initialize (&changed_pseudo_bitmap, ®_obstack);
1702 1601843 : init_live_reload_and_inheritance_pseudos ();
1703 1601843 : fails_p = assign_by_spills ();
1704 1601843 : finish_live_reload_and_inheritance_pseudos ();
1705 1601843 : bitmap_ior_into (&changed_pseudo_bitmap, &all_spilled_pseudos);
1706 1601843 : no_spills_p = true;
1707 1887685 : EXECUTE_IF_SET_IN_BITMAP (&all_spilled_pseudos, 0, u, bi)
1708 : /* We ignore spilled pseudos created on last inheritance pass
1709 : because they will be removed. */
1710 316672 : if (lra_reg_info[u].restore_rtx == NULL_RTX)
1711 : {
1712 : no_spills_p = false;
1713 : break;
1714 : }
1715 1601843 : finish_live_range_start_chains ();
1716 1601843 : bitmap_clear (&all_spilled_pseudos);
1717 1601843 : bitmap_initialize (&insns_to_process, ®_obstack);
1718 3612021 : EXECUTE_IF_SET_IN_BITMAP (&changed_pseudo_bitmap, 0, u, bi)
1719 2010178 : bitmap_ior_into (&insns_to_process, &lra_reg_info[u].insn_bitmap);
1720 1601843 : bitmap_clear (&changed_pseudo_bitmap);
1721 6461404 : EXECUTE_IF_SET_IN_BITMAP (&insns_to_process, 0, u, bi)
1722 : {
1723 4859561 : lra_push_insn_by_uid (u);
1724 : /* Invalidate alternatives for insn should be processed. */
1725 4859561 : lra_set_used_insn_alternative_by_uid (u, -1);
1726 : }
1727 1601843 : bitmap_clear (&insns_to_process);
1728 1601843 : finish_regno_assign_info ();
1729 1601843 : free (regno_live_length);
1730 1601843 : free (regno_allocno_class_array);
1731 1601843 : free (sorted_pseudos);
1732 1601843 : free (sorted_reload_pseudos);
1733 1601843 : finish_lives ();
1734 1601843 : timevar_pop (TV_LRA_ASSIGN);
1735 1601843 : if (former_reload_pseudo_spill_p)
1736 2202 : lra_assignment_iter_after_spill++;
1737 : /* This is conditional on flag_checking because valid code can take
1738 : more than this maximum number of iteration, but at the same time
1739 : the test can uncover errors in machine descriptions. */
1740 1601843 : if (flag_checking
1741 1601823 : && (lra_assignment_iter_after_spill
1742 1601823 : > LRA_MAX_ASSIGNMENT_ITERATION_NUMBER))
1743 0 : internal_error
1744 0 : ("maximum number of LRA assignment passes is achieved (%d)",
1745 : LRA_MAX_ASSIGNMENT_ITERATION_NUMBER);
1746 : /* Reset the assignment correctness flag: */
1747 1601843 : check_and_force_assignment_correctness_p = false;
1748 1601843 : return no_spills_p;
1749 : }
1750 :
1751 : /* Find start and finish insns for reload pseudo REGNO. Return true
1752 : if we managed to find the expected insns. Return false,
1753 : otherwise. */
1754 : static bool
1755 3328 : find_reload_regno_insns (int regno, rtx_insn * &start, rtx_insn * &finish)
1756 : {
1757 3328 : unsigned int uid;
1758 3328 : bitmap_iterator bi;
1759 3328 : int insns_num = 0;
1760 3328 : bool clobber_p = false;
1761 3328 : rtx_insn *prev_insn, *next_insn;
1762 3328 : rtx_insn *start_insn = NULL, *first_insn = NULL, *second_insn = NULL;
1763 :
1764 12107 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
1765 : {
1766 8779 : if (start_insn == NULL)
1767 3328 : start_insn = lra_insn_recog_data[uid]->insn;
1768 8779 : if (GET_CODE (PATTERN (lra_insn_recog_data[uid]->insn)) == CLOBBER)
1769 : clobber_p = true;
1770 : else
1771 8779 : insns_num++;
1772 : }
1773 : /* For reload pseudo we should have at most 3 insns besides clobber referring for
1774 : it: input/output reload insns and the original insn. */
1775 3328 : if (insns_num > 3)
1776 : return false;
1777 3328 : if (clobber_p)
1778 0 : insns_num++;
1779 3328 : if (insns_num > 1)
1780 : {
1781 3104 : for (prev_insn = PREV_INSN (start_insn),
1782 3104 : next_insn = NEXT_INSN (start_insn);
1783 222413 : insns_num != 1 && (prev_insn != NULL
1784 2328 : || (next_insn != NULL && second_insn == NULL)); )
1785 : {
1786 : if (prev_insn != NULL)
1787 : {
1788 219309 : if (bitmap_bit_p (&lra_reg_info[regno].insn_bitmap,
1789 219309 : INSN_UID (prev_insn)))
1790 : {
1791 590 : first_insn = prev_insn;
1792 590 : insns_num--;
1793 : }
1794 219309 : prev_insn = PREV_INSN (prev_insn);
1795 : }
1796 219309 : if (next_insn != NULL && second_insn == NULL)
1797 : {
1798 5477 : if (! bitmap_bit_p (&lra_reg_info[regno].insn_bitmap,
1799 5477 : INSN_UID (next_insn)))
1800 2944 : next_insn = NEXT_INSN (next_insn);
1801 : else
1802 : {
1803 2533 : second_insn = next_insn;
1804 2533 : insns_num--;
1805 : }
1806 : }
1807 : }
1808 3104 : if (insns_num > 1)
1809 : return false;
1810 : }
1811 776 : start = first_insn != NULL ? first_insn : start_insn;
1812 1000 : finish = second_insn != NULL ? second_insn : start_insn;
1813 1000 : return true;
1814 : }
1815 :
1816 : /* Process reload pseudos which did not get a hard reg, split a hard reg live
1817 : range in live range of a reload pseudo, and then return TRUE. Otherwise,
1818 : return FALSE. When FAIL_P is TRUE and if we did not split a hard reg live
1819 : range for failed reload pseudos, report an error and modify related asm
1820 : insns. */
1821 : bool
1822 2488 : lra_split_hard_reg_for (bool fail_p)
1823 : {
1824 2488 : int i, regno;
1825 2488 : rtx_insn *insn, *first, *last;
1826 2488 : unsigned int u;
1827 2488 : bitmap_iterator bi;
1828 2488 : enum reg_class rclass;
1829 2488 : int max_regno = max_reg_num ();
1830 : /* We did not assign hard regs to reload pseudos after two
1831 : iterations. Either it's an asm and something is wrong with the
1832 : constraints, or we have run out of spill registers; error out in
1833 : either case. */
1834 2488 : bool asm_p = false, spill_p = false;
1835 2488 : bitmap_head failed_reload_insns, failed_reload_pseudos, over_split_insns;
1836 :
1837 2488 : if (lra_dump_file != NULL)
1838 0 : fprintf (lra_dump_file,
1839 : "\n****** Splitting a hard reg after assignment #%d: ******\n\n",
1840 : lra_assignment_iter);
1841 2488 : bitmap_initialize (&failed_reload_pseudos, ®_obstack);
1842 2488 : bitmap_initialize (&non_reload_pseudos, ®_obstack);
1843 2488 : bitmap_ior (&non_reload_pseudos, &lra_inheritance_pseudos, &lra_split_regs);
1844 2488 : bitmap_ior_into (&non_reload_pseudos, &lra_subreg_reload_pseudos);
1845 2488 : bitmap_ior_into (&non_reload_pseudos, &lra_optional_reload_pseudos);
1846 2488 : bitmap_initialize (&over_split_insns, ®_obstack);
1847 2488 : update_hard_regno_preference_check = XCNEWVEC (int, max_regno);
1848 2488 : curr_update_hard_regno_preference_check = 0;
1849 17308 : for (i = lra_constraint_new_regno_start; i < max_regno; i++)
1850 6247 : if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0
1851 5422 : && (rclass = lra_get_allocno_class (i)) != NO_REGS
1852 20237 : && ! bitmap_bit_p (&non_reload_pseudos, i))
1853 : {
1854 3328 : if (! find_reload_regno_insns (i, first, last))
1855 2328 : continue;
1856 1000 : if (BLOCK_FOR_INSN (first) == BLOCK_FOR_INSN (last))
1857 : {
1858 : /* Check that we are not trying to split over the same insn
1859 : requiring reloads to avoid splitting the same hard reg twice or
1860 : more. If we need several hard regs splitting over the same insn
1861 : it can be finished on the next iterations.
1862 :
1863 : The following loop iteration number is small as we split hard
1864 : reg in a very small range. */
1865 1826 : for (insn = first;
1866 2826 : insn != NEXT_INSN (last);
1867 1826 : insn = NEXT_INSN (insn))
1868 1835 : if (bitmap_bit_p (&over_split_insns, INSN_UID (insn)))
1869 : break;
1870 1000 : if (insn != NEXT_INSN (last)
1871 1000 : || !spill_hard_reg_in_range (i, rclass, first, last))
1872 : {
1873 839 : bitmap_set_bit (&failed_reload_pseudos, i);
1874 : }
1875 : else
1876 : {
1877 306 : for (insn = first;
1878 467 : insn != NEXT_INSN (last);
1879 306 : insn = NEXT_INSN (insn))
1880 306 : bitmap_set_bit (&over_split_insns, INSN_UID (insn));
1881 : spill_p = true;
1882 : }
1883 : }
1884 : }
1885 2488 : bitmap_clear (&over_split_insns);
1886 2488 : bitmap_clear (&non_reload_pseudos);
1887 2488 : if (spill_p)
1888 : {
1889 100 : lra_dump_insns_if_possible ("changed func after splitting hard regs");
1890 : }
1891 : else
1892 : {
1893 2388 : bitmap_initialize (&failed_reload_insns, ®_obstack);
1894 3218 : EXECUTE_IF_SET_IN_BITMAP (&failed_reload_pseudos, 0, u, bi)
1895 : {
1896 830 : regno = u;
1897 830 : bitmap_ior_into (&failed_reload_insns,
1898 830 : &lra_reg_info[regno].insn_bitmap);
1899 830 : if (fail_p)
1900 53 : lra_setup_reg_renumber
1901 106 : (regno, ira_class_hard_regs[lra_get_allocno_class (regno)][0],
1902 : false);
1903 : }
1904 2388 : if (fail_p)
1905 287 : EXECUTE_IF_SET_IN_BITMAP (&failed_reload_insns, 0, u, bi)
1906 : {
1907 92 : insn = lra_insn_recog_data[u]->insn;
1908 92 : if (asm_noperands (PATTERN (insn)) >= 0)
1909 : {
1910 53 : asm_p = true;
1911 53 : lra_asm_insn_error (insn);
1912 : }
1913 39 : else if (!asm_p)
1914 : {
1915 0 : error ("unable to find a register to spill");
1916 0 : fatal_insn ("this is the insn:", insn);
1917 : }
1918 : }
1919 2388 : bitmap_clear (&failed_reload_insns);
1920 : }
1921 2488 : free (update_hard_regno_preference_check);
1922 2488 : bitmap_clear (&failed_reload_pseudos);
1923 2488 : return spill_p;
1924 : }
|