PR debug/66535
[official-gcc.git] / gcc / ira-conflicts.c
blob52397a7b5ef86b0eeace98c777bbed40c65842ea
1 /* IRA conflict builder.
2 Copyright (C) 2006-2015 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 This file is part of GCC.
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.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "regs.h"
26 #include "rtl.h"
27 #include "tm_p.h"
28 #include "target.h"
29 #include "flags.h"
30 #include "hard-reg-set.h"
31 #include "predict.h"
32 #include "input.h"
33 #include "function.h"
34 #include "basic-block.h"
35 #include "insn-config.h"
36 #include "recog.h"
37 #include "diagnostic-core.h"
38 #include "params.h"
39 #include "df.h"
40 #include "sparseset.h"
41 #include "ira-int.h"
42 #include "addresses.h"
44 /* This file contains code responsible for allocno conflict creation,
45 allocno copy creation and allocno info accumulation on upper level
46 regions. */
48 /* ira_allocnos_num array of arrays of bits, recording whether two
49 allocno's conflict (can't go in the same hardware register).
51 Some arrays will be used as conflict bit vector of the
52 corresponding allocnos see function build_object_conflicts. */
53 static IRA_INT_TYPE **conflicts;
55 /* Macro to test a conflict of C1 and C2 in `conflicts'. */
56 #define OBJECTS_CONFLICT_P(C1, C2) \
57 (OBJECT_MIN (C1) <= OBJECT_CONFLICT_ID (C2) \
58 && OBJECT_CONFLICT_ID (C2) <= OBJECT_MAX (C1) \
59 && TEST_MINMAX_SET_BIT (conflicts[OBJECT_CONFLICT_ID (C1)], \
60 OBJECT_CONFLICT_ID (C2), \
61 OBJECT_MIN (C1), OBJECT_MAX (C1)))
64 /* Record a conflict between objects OBJ1 and OBJ2. If necessary,
65 canonicalize the conflict by recording it for lower-order subobjects
66 of the corresponding allocnos. */
67 static void
68 record_object_conflict (ira_object_t obj1, ira_object_t obj2)
70 ira_allocno_t a1 = OBJECT_ALLOCNO (obj1);
71 ira_allocno_t a2 = OBJECT_ALLOCNO (obj2);
72 int w1 = OBJECT_SUBWORD (obj1);
73 int w2 = OBJECT_SUBWORD (obj2);
74 int id1, id2;
76 /* Canonicalize the conflict. If two identically-numbered words
77 conflict, always record this as a conflict between words 0. That
78 is the only information we need, and it is easier to test for if
79 it is collected in each allocno's lowest-order object. */
80 if (w1 == w2 && w1 > 0)
82 obj1 = ALLOCNO_OBJECT (a1, 0);
83 obj2 = ALLOCNO_OBJECT (a2, 0);
85 id1 = OBJECT_CONFLICT_ID (obj1);
86 id2 = OBJECT_CONFLICT_ID (obj2);
88 SET_MINMAX_SET_BIT (conflicts[id1], id2, OBJECT_MIN (obj1),
89 OBJECT_MAX (obj1));
90 SET_MINMAX_SET_BIT (conflicts[id2], id1, OBJECT_MIN (obj2),
91 OBJECT_MAX (obj2));
94 /* Build allocno conflict table by processing allocno live ranges.
95 Return true if the table was built. The table is not built if it
96 is too big. */
97 static bool
98 build_conflict_bit_table (void)
100 int i;
101 unsigned int j;
102 enum reg_class aclass;
103 int object_set_words, allocated_words_num, conflict_bit_vec_words_num;
104 live_range_t r;
105 ira_allocno_t allocno;
106 ira_allocno_iterator ai;
107 sparseset objects_live;
108 ira_object_t obj;
109 ira_allocno_object_iterator aoi;
111 allocated_words_num = 0;
112 FOR_EACH_ALLOCNO (allocno, ai)
113 FOR_EACH_ALLOCNO_OBJECT (allocno, obj, aoi)
115 if (OBJECT_MAX (obj) < OBJECT_MIN (obj))
116 continue;
117 conflict_bit_vec_words_num
118 = ((OBJECT_MAX (obj) - OBJECT_MIN (obj) + IRA_INT_BITS)
119 / IRA_INT_BITS);
120 allocated_words_num += conflict_bit_vec_words_num;
121 if ((uint64_t) allocated_words_num * sizeof (IRA_INT_TYPE)
122 > (uint64_t) IRA_MAX_CONFLICT_TABLE_SIZE * 1024 * 1024)
124 if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
125 fprintf
126 (ira_dump_file,
127 "+++Conflict table will be too big(>%dMB) -- don't use it\n",
128 IRA_MAX_CONFLICT_TABLE_SIZE);
129 return false;
133 conflicts = (IRA_INT_TYPE **) ira_allocate (sizeof (IRA_INT_TYPE *)
134 * ira_objects_num);
135 allocated_words_num = 0;
136 FOR_EACH_ALLOCNO (allocno, ai)
137 FOR_EACH_ALLOCNO_OBJECT (allocno, obj, aoi)
139 int id = OBJECT_CONFLICT_ID (obj);
140 if (OBJECT_MAX (obj) < OBJECT_MIN (obj))
142 conflicts[id] = NULL;
143 continue;
145 conflict_bit_vec_words_num
146 = ((OBJECT_MAX (obj) - OBJECT_MIN (obj) + IRA_INT_BITS)
147 / IRA_INT_BITS);
148 allocated_words_num += conflict_bit_vec_words_num;
149 conflicts[id]
150 = (IRA_INT_TYPE *) ira_allocate (sizeof (IRA_INT_TYPE)
151 * conflict_bit_vec_words_num);
152 memset (conflicts[id], 0,
153 sizeof (IRA_INT_TYPE) * conflict_bit_vec_words_num);
156 object_set_words = (ira_objects_num + IRA_INT_BITS - 1) / IRA_INT_BITS;
157 if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL)
158 fprintf
159 (ira_dump_file,
160 "+++Allocating %ld bytes for conflict table (uncompressed size %ld)\n",
161 (long) allocated_words_num * sizeof (IRA_INT_TYPE),
162 (long) object_set_words * ira_objects_num * sizeof (IRA_INT_TYPE));
164 objects_live = sparseset_alloc (ira_objects_num);
165 for (i = 0; i < ira_max_point; i++)
167 for (r = ira_start_point_ranges[i]; r != NULL; r = r->start_next)
169 ira_object_t obj = r->object;
170 ira_allocno_t allocno = OBJECT_ALLOCNO (obj);
171 int id = OBJECT_CONFLICT_ID (obj);
173 gcc_assert (id < ira_objects_num);
175 aclass = ALLOCNO_CLASS (allocno);
176 EXECUTE_IF_SET_IN_SPARSESET (objects_live, j)
178 ira_object_t live_obj = ira_object_id_map[j];
179 ira_allocno_t live_a = OBJECT_ALLOCNO (live_obj);
180 enum reg_class live_aclass = ALLOCNO_CLASS (live_a);
182 if (ira_reg_classes_intersect_p[aclass][live_aclass]
183 /* Don't set up conflict for the allocno with itself. */
184 && live_a != allocno)
186 record_object_conflict (obj, live_obj);
189 sparseset_set_bit (objects_live, id);
192 for (r = ira_finish_point_ranges[i]; r != NULL; r = r->finish_next)
193 sparseset_clear_bit (objects_live, OBJECT_CONFLICT_ID (r->object));
195 sparseset_free (objects_live);
196 return true;
199 /* Return true iff allocnos A1 and A2 cannot be allocated to the same
200 register due to conflicts. */
202 static bool
203 allocnos_conflict_for_copy_p (ira_allocno_t a1, ira_allocno_t a2)
205 /* Due to the fact that we canonicalize conflicts (see
206 record_object_conflict), we only need to test for conflicts of
207 the lowest order words. */
208 ira_object_t obj1 = ALLOCNO_OBJECT (a1, 0);
209 ira_object_t obj2 = ALLOCNO_OBJECT (a2, 0);
211 return OBJECTS_CONFLICT_P (obj1, obj2);
214 /* Check that X is REG or SUBREG of REG. */
215 #define REG_SUBREG_P(x) \
216 (REG_P (x) || (GET_CODE (x) == SUBREG && REG_P (SUBREG_REG (x))))
218 /* Return X if X is a REG, otherwise it should be SUBREG of REG and
219 the function returns the reg in this case. *OFFSET will be set to
220 0 in the first case or the regno offset in the first case. */
221 static rtx
222 go_through_subreg (rtx x, int *offset)
224 rtx reg;
226 *offset = 0;
227 if (REG_P (x))
228 return x;
229 ira_assert (GET_CODE (x) == SUBREG);
230 reg = SUBREG_REG (x);
231 ira_assert (REG_P (reg));
232 if (REGNO (reg) < FIRST_PSEUDO_REGISTER)
233 *offset = subreg_regno_offset (REGNO (reg), GET_MODE (reg),
234 SUBREG_BYTE (x), GET_MODE (x));
235 else
236 *offset = (SUBREG_BYTE (x) / REGMODE_NATURAL_SIZE (GET_MODE (x)));
237 return reg;
240 /* Process registers REG1 and REG2 in move INSN with execution
241 frequency FREQ. The function also processes the registers in a
242 potential move insn (INSN == NULL in this case) with frequency
243 FREQ. The function can modify hard register costs of the
244 corresponding allocnos or create a copy involving the corresponding
245 allocnos. The function does nothing if the both registers are hard
246 registers. When nothing is changed, the function returns
247 FALSE. */
248 static bool
249 process_regs_for_copy (rtx reg1, rtx reg2, bool constraint_p,
250 rtx_insn *insn, int freq)
252 int allocno_preferenced_hard_regno, cost, index, offset1, offset2;
253 bool only_regs_p;
254 ira_allocno_t a;
255 reg_class_t rclass, aclass;
256 machine_mode mode;
257 ira_copy_t cp;
259 gcc_assert (REG_SUBREG_P (reg1) && REG_SUBREG_P (reg2));
260 only_regs_p = REG_P (reg1) && REG_P (reg2);
261 reg1 = go_through_subreg (reg1, &offset1);
262 reg2 = go_through_subreg (reg2, &offset2);
263 /* Set up hard regno preferenced by allocno. If allocno gets the
264 hard regno the copy (or potential move) insn will be removed. */
265 if (HARD_REGISTER_P (reg1))
267 if (HARD_REGISTER_P (reg2))
268 return false;
269 allocno_preferenced_hard_regno = REGNO (reg1) + offset1 - offset2;
270 a = ira_curr_regno_allocno_map[REGNO (reg2)];
272 else if (HARD_REGISTER_P (reg2))
274 allocno_preferenced_hard_regno = REGNO (reg2) + offset2 - offset1;
275 a = ira_curr_regno_allocno_map[REGNO (reg1)];
277 else
279 ira_allocno_t a1 = ira_curr_regno_allocno_map[REGNO (reg1)];
280 ira_allocno_t a2 = ira_curr_regno_allocno_map[REGNO (reg2)];
282 if (!allocnos_conflict_for_copy_p (a1, a2) && offset1 == offset2)
284 cp = ira_add_allocno_copy (a1, a2, freq, constraint_p, insn,
285 ira_curr_loop_tree_node);
286 bitmap_set_bit (ira_curr_loop_tree_node->local_copies, cp->num);
287 return true;
289 else
290 return false;
293 if (! IN_RANGE (allocno_preferenced_hard_regno,
294 0, FIRST_PSEUDO_REGISTER - 1))
295 /* Can not be tied. */
296 return false;
297 rclass = REGNO_REG_CLASS (allocno_preferenced_hard_regno);
298 mode = ALLOCNO_MODE (a);
299 aclass = ALLOCNO_CLASS (a);
300 if (only_regs_p && insn != NULL_RTX
301 && reg_class_size[rclass] <= ira_reg_class_max_nregs [rclass][mode])
302 /* It is already taken into account in ira-costs.c. */
303 return false;
304 index = ira_class_hard_reg_index[aclass][allocno_preferenced_hard_regno];
305 if (index < 0)
306 /* Can not be tied. It is not in the allocno class. */
307 return false;
308 ira_init_register_move_cost_if_necessary (mode);
309 if (HARD_REGISTER_P (reg1))
310 cost = ira_register_move_cost[mode][aclass][rclass] * freq;
311 else
312 cost = ira_register_move_cost[mode][rclass][aclass] * freq;
315 ira_allocate_and_set_costs
316 (&ALLOCNO_HARD_REG_COSTS (a), aclass,
317 ALLOCNO_CLASS_COST (a));
318 ira_allocate_and_set_costs
319 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a), aclass, 0);
320 ALLOCNO_HARD_REG_COSTS (a)[index] -= cost;
321 ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[index] -= cost;
322 if (ALLOCNO_HARD_REG_COSTS (a)[index] < ALLOCNO_CLASS_COST (a))
323 ALLOCNO_CLASS_COST (a) = ALLOCNO_HARD_REG_COSTS (a)[index];
324 ira_add_allocno_pref (a, allocno_preferenced_hard_regno, freq);
325 a = ira_parent_or_cap_allocno (a);
327 while (a != NULL);
328 return true;
331 /* Process all of the output registers of the current insn which are
332 not bound (BOUND_P) and the input register REG (its operand number
333 OP_NUM) which dies in the insn as if there were a move insn between
334 them with frequency FREQ. */
335 static void
336 process_reg_shuffles (rtx reg, int op_num, int freq, bool *bound_p)
338 int i;
339 rtx another_reg;
341 gcc_assert (REG_SUBREG_P (reg));
342 for (i = 0; i < recog_data.n_operands; i++)
344 another_reg = recog_data.operand[i];
346 if (!REG_SUBREG_P (another_reg) || op_num == i
347 || recog_data.operand_type[i] != OP_OUT
348 || bound_p[i])
349 continue;
351 process_regs_for_copy (reg, another_reg, false, NULL, freq);
355 /* Process INSN and create allocno copies if necessary. For example,
356 it might be because INSN is a pseudo-register move or INSN is two
357 operand insn. */
358 static void
359 add_insn_allocno_copies (rtx_insn *insn)
361 rtx set, operand, dup;
362 bool bound_p[MAX_RECOG_OPERANDS];
363 int i, n, freq;
364 HARD_REG_SET alts;
366 freq = REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn));
367 if (freq == 0)
368 freq = 1;
369 if ((set = single_set (insn)) != NULL_RTX
370 && REG_SUBREG_P (SET_DEST (set)) && REG_SUBREG_P (SET_SRC (set))
371 && ! side_effects_p (set)
372 && find_reg_note (insn, REG_DEAD,
373 REG_P (SET_SRC (set))
374 ? SET_SRC (set)
375 : SUBREG_REG (SET_SRC (set))) != NULL_RTX)
377 process_regs_for_copy (SET_SRC (set), SET_DEST (set),
378 false, insn, freq);
379 return;
381 /* Fast check of possibility of constraint or shuffle copies. If
382 there are no dead registers, there will be no such copies. */
383 if (! find_reg_note (insn, REG_DEAD, NULL_RTX))
384 return;
385 ira_setup_alts (insn, alts);
386 for (i = 0; i < recog_data.n_operands; i++)
387 bound_p[i] = false;
388 for (i = 0; i < recog_data.n_operands; i++)
390 operand = recog_data.operand[i];
391 if (! REG_SUBREG_P (operand))
392 continue;
393 if ((n = ira_get_dup_out_num (i, alts)) >= 0)
395 bound_p[n] = true;
396 dup = recog_data.operand[n];
397 if (REG_SUBREG_P (dup)
398 && find_reg_note (insn, REG_DEAD,
399 REG_P (operand)
400 ? operand
401 : SUBREG_REG (operand)) != NULL_RTX)
402 process_regs_for_copy (operand, dup, true, NULL,
403 freq);
406 for (i = 0; i < recog_data.n_operands; i++)
408 operand = recog_data.operand[i];
409 if (REG_SUBREG_P (operand)
410 && find_reg_note (insn, REG_DEAD,
411 REG_P (operand)
412 ? operand : SUBREG_REG (operand)) != NULL_RTX)
413 /* If an operand dies, prefer its hard register for the output
414 operands by decreasing the hard register cost or creating
415 the corresponding allocno copies. The cost will not
416 correspond to a real move insn cost, so make the frequency
417 smaller. */
418 process_reg_shuffles (operand, i, freq < 8 ? 1 : freq / 8, bound_p);
422 /* Add copies originated from BB given by LOOP_TREE_NODE. */
423 static void
424 add_copies (ira_loop_tree_node_t loop_tree_node)
426 basic_block bb;
427 rtx_insn *insn;
429 bb = loop_tree_node->bb;
430 if (bb == NULL)
431 return;
432 FOR_BB_INSNS (bb, insn)
433 if (NONDEBUG_INSN_P (insn))
434 add_insn_allocno_copies (insn);
437 /* Propagate copies the corresponding allocnos on upper loop tree
438 level. */
439 static void
440 propagate_copies (void)
442 ira_copy_t cp;
443 ira_copy_iterator ci;
444 ira_allocno_t a1, a2, parent_a1, parent_a2;
446 FOR_EACH_COPY (cp, ci)
448 a1 = cp->first;
449 a2 = cp->second;
450 if (ALLOCNO_LOOP_TREE_NODE (a1) == ira_loop_tree_root)
451 continue;
452 ira_assert ((ALLOCNO_LOOP_TREE_NODE (a2) != ira_loop_tree_root));
453 parent_a1 = ira_parent_or_cap_allocno (a1);
454 parent_a2 = ira_parent_or_cap_allocno (a2);
455 ira_assert (parent_a1 != NULL && parent_a2 != NULL);
456 if (! allocnos_conflict_for_copy_p (parent_a1, parent_a2))
457 ira_add_allocno_copy (parent_a1, parent_a2, cp->freq,
458 cp->constraint_p, cp->insn, cp->loop_tree_node);
462 /* Array used to collect all conflict allocnos for given allocno. */
463 static ira_object_t *collected_conflict_objects;
465 /* Build conflict vectors or bit conflict vectors (whatever is more
466 profitable) for object OBJ from the conflict table. */
467 static void
468 build_object_conflicts (ira_object_t obj)
470 int i, px, parent_num;
471 ira_allocno_t parent_a, another_parent_a;
472 ira_object_t parent_obj;
473 ira_allocno_t a = OBJECT_ALLOCNO (obj);
474 IRA_INT_TYPE *object_conflicts;
475 minmax_set_iterator asi;
476 int parent_min, parent_max ATTRIBUTE_UNUSED;
478 object_conflicts = conflicts[OBJECT_CONFLICT_ID (obj)];
479 px = 0;
480 FOR_EACH_BIT_IN_MINMAX_SET (object_conflicts,
481 OBJECT_MIN (obj), OBJECT_MAX (obj), i, asi)
483 ira_object_t another_obj = ira_object_id_map[i];
484 ira_allocno_t another_a = OBJECT_ALLOCNO (obj);
486 ira_assert (ira_reg_classes_intersect_p
487 [ALLOCNO_CLASS (a)][ALLOCNO_CLASS (another_a)]);
488 collected_conflict_objects[px++] = another_obj;
490 if (ira_conflict_vector_profitable_p (obj, px))
492 ira_object_t *vec;
493 ira_allocate_conflict_vec (obj, px);
494 vec = OBJECT_CONFLICT_VEC (obj);
495 memcpy (vec, collected_conflict_objects, sizeof (ira_object_t) * px);
496 vec[px] = NULL;
497 OBJECT_NUM_CONFLICTS (obj) = px;
499 else
501 int conflict_bit_vec_words_num;
503 OBJECT_CONFLICT_ARRAY (obj) = object_conflicts;
504 if (OBJECT_MAX (obj) < OBJECT_MIN (obj))
505 conflict_bit_vec_words_num = 0;
506 else
507 conflict_bit_vec_words_num
508 = ((OBJECT_MAX (obj) - OBJECT_MIN (obj) + IRA_INT_BITS)
509 / IRA_INT_BITS);
510 OBJECT_CONFLICT_ARRAY_SIZE (obj)
511 = conflict_bit_vec_words_num * sizeof (IRA_INT_TYPE);
514 parent_a = ira_parent_or_cap_allocno (a);
515 if (parent_a == NULL)
516 return;
517 ira_assert (ALLOCNO_CLASS (a) == ALLOCNO_CLASS (parent_a));
518 ira_assert (ALLOCNO_NUM_OBJECTS (a) == ALLOCNO_NUM_OBJECTS (parent_a));
519 parent_obj = ALLOCNO_OBJECT (parent_a, OBJECT_SUBWORD (obj));
520 parent_num = OBJECT_CONFLICT_ID (parent_obj);
521 parent_min = OBJECT_MIN (parent_obj);
522 parent_max = OBJECT_MAX (parent_obj);
523 FOR_EACH_BIT_IN_MINMAX_SET (object_conflicts,
524 OBJECT_MIN (obj), OBJECT_MAX (obj), i, asi)
526 ira_object_t another_obj = ira_object_id_map[i];
527 ira_allocno_t another_a = OBJECT_ALLOCNO (another_obj);
528 int another_word = OBJECT_SUBWORD (another_obj);
530 ira_assert (ira_reg_classes_intersect_p
531 [ALLOCNO_CLASS (a)][ALLOCNO_CLASS (another_a)]);
533 another_parent_a = ira_parent_or_cap_allocno (another_a);
534 if (another_parent_a == NULL)
535 continue;
536 ira_assert (ALLOCNO_NUM (another_parent_a) >= 0);
537 ira_assert (ALLOCNO_CLASS (another_a)
538 == ALLOCNO_CLASS (another_parent_a));
539 ira_assert (ALLOCNO_NUM_OBJECTS (another_a)
540 == ALLOCNO_NUM_OBJECTS (another_parent_a));
541 SET_MINMAX_SET_BIT (conflicts[parent_num],
542 OBJECT_CONFLICT_ID (ALLOCNO_OBJECT (another_parent_a,
543 another_word)),
544 parent_min, parent_max);
548 /* Build conflict vectors or bit conflict vectors (whatever is more
549 profitable) of all allocnos from the conflict table. */
550 static void
551 build_conflicts (void)
553 int i;
554 ira_allocno_t a, cap;
556 collected_conflict_objects
557 = (ira_object_t *) ira_allocate (sizeof (ira_object_t)
558 * ira_objects_num);
559 for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
560 for (a = ira_regno_allocno_map[i];
561 a != NULL;
562 a = ALLOCNO_NEXT_REGNO_ALLOCNO (a))
564 int j, nregs = ALLOCNO_NUM_OBJECTS (a);
565 for (j = 0; j < nregs; j++)
567 ira_object_t obj = ALLOCNO_OBJECT (a, j);
568 build_object_conflicts (obj);
569 for (cap = ALLOCNO_CAP (a); cap != NULL; cap = ALLOCNO_CAP (cap))
571 ira_object_t cap_obj = ALLOCNO_OBJECT (cap, j);
572 gcc_assert (ALLOCNO_NUM_OBJECTS (cap) == ALLOCNO_NUM_OBJECTS (a));
573 build_object_conflicts (cap_obj);
577 ira_free (collected_conflict_objects);
582 /* Print hard reg set SET with TITLE to FILE. */
583 static void
584 print_hard_reg_set (FILE *file, const char *title, HARD_REG_SET set)
586 int i, start;
588 fputs (title, file);
589 for (start = -1, i = 0; i < FIRST_PSEUDO_REGISTER; i++)
591 if (TEST_HARD_REG_BIT (set, i))
593 if (i == 0 || ! TEST_HARD_REG_BIT (set, i - 1))
594 start = i;
596 if (start >= 0
597 && (i == FIRST_PSEUDO_REGISTER - 1 || ! TEST_HARD_REG_BIT (set, i)))
599 if (start == i - 1)
600 fprintf (file, " %d", start);
601 else if (start == i - 2)
602 fprintf (file, " %d %d", start, start + 1);
603 else
604 fprintf (file, " %d-%d", start, i - 1);
605 start = -1;
608 putc ('\n', file);
611 static void
612 print_allocno_conflicts (FILE * file, bool reg_p, ira_allocno_t a)
614 HARD_REG_SET conflicting_hard_regs;
615 basic_block bb;
616 int n, i;
618 if (reg_p)
619 fprintf (file, ";; r%d", ALLOCNO_REGNO (a));
620 else
622 fprintf (file, ";; a%d(r%d,", ALLOCNO_NUM (a), ALLOCNO_REGNO (a));
623 if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL)
624 fprintf (file, "b%d", bb->index);
625 else
626 fprintf (file, "l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num);
627 putc (')', file);
630 fputs (" conflicts:", file);
631 n = ALLOCNO_NUM_OBJECTS (a);
632 for (i = 0; i < n; i++)
634 ira_object_t obj = ALLOCNO_OBJECT (a, i);
635 ira_object_t conflict_obj;
636 ira_object_conflict_iterator oci;
638 if (OBJECT_CONFLICT_ARRAY (obj) == NULL)
639 continue;
640 if (n > 1)
641 fprintf (file, "\n;; subobject %d:", i);
642 FOR_EACH_OBJECT_CONFLICT (obj, conflict_obj, oci)
644 ira_allocno_t conflict_a = OBJECT_ALLOCNO (conflict_obj);
645 if (reg_p)
646 fprintf (file, " r%d,", ALLOCNO_REGNO (conflict_a));
647 else
649 fprintf (file, " a%d(r%d", ALLOCNO_NUM (conflict_a),
650 ALLOCNO_REGNO (conflict_a));
651 if (ALLOCNO_NUM_OBJECTS (conflict_a) > 1)
652 fprintf (file, ",w%d", OBJECT_SUBWORD (conflict_obj));
653 if ((bb = ALLOCNO_LOOP_TREE_NODE (conflict_a)->bb) != NULL)
654 fprintf (file, ",b%d", bb->index);
655 else
656 fprintf (file, ",l%d",
657 ALLOCNO_LOOP_TREE_NODE (conflict_a)->loop_num);
658 putc (')', file);
661 COPY_HARD_REG_SET (conflicting_hard_regs, OBJECT_TOTAL_CONFLICT_HARD_REGS (obj));
662 AND_COMPL_HARD_REG_SET (conflicting_hard_regs, ira_no_alloc_regs);
663 AND_HARD_REG_SET (conflicting_hard_regs,
664 reg_class_contents[ALLOCNO_CLASS (a)]);
665 print_hard_reg_set (file, "\n;; total conflict hard regs:",
666 conflicting_hard_regs);
668 COPY_HARD_REG_SET (conflicting_hard_regs, OBJECT_CONFLICT_HARD_REGS (obj));
669 AND_COMPL_HARD_REG_SET (conflicting_hard_regs, ira_no_alloc_regs);
670 AND_HARD_REG_SET (conflicting_hard_regs,
671 reg_class_contents[ALLOCNO_CLASS (a)]);
672 print_hard_reg_set (file, ";; conflict hard regs:",
673 conflicting_hard_regs);
674 putc ('\n', file);
679 /* Print information about allocno or only regno (if REG_P) conflicts
680 to FILE. */
681 static void
682 print_conflicts (FILE *file, bool reg_p)
684 ira_allocno_t a;
685 ira_allocno_iterator ai;
687 FOR_EACH_ALLOCNO (a, ai)
688 print_allocno_conflicts (file, reg_p, a);
691 /* Print information about allocno or only regno (if REG_P) conflicts
692 to stderr. */
693 void
694 ira_debug_conflicts (bool reg_p)
696 print_conflicts (stderr, reg_p);
701 /* Entry function which builds allocno conflicts and allocno copies
702 and accumulate some allocno info on upper level regions. */
703 void
704 ira_build_conflicts (void)
706 enum reg_class base;
707 ira_allocno_t a;
708 ira_allocno_iterator ai;
709 HARD_REG_SET temp_hard_reg_set;
711 if (ira_conflicts_p)
713 ira_conflicts_p = build_conflict_bit_table ();
714 if (ira_conflicts_p)
716 ira_object_t obj;
717 ira_object_iterator oi;
719 build_conflicts ();
720 ira_traverse_loop_tree (true, ira_loop_tree_root, add_copies, NULL);
721 /* We need finished conflict table for the subsequent call. */
722 if (flag_ira_region == IRA_REGION_ALL
723 || flag_ira_region == IRA_REGION_MIXED)
724 propagate_copies ();
726 /* Now we can free memory for the conflict table (see function
727 build_object_conflicts for details). */
728 FOR_EACH_OBJECT (obj, oi)
730 if (OBJECT_CONFLICT_ARRAY (obj) != conflicts[OBJECT_CONFLICT_ID (obj)])
731 ira_free (conflicts[OBJECT_CONFLICT_ID (obj)]);
733 ira_free (conflicts);
736 base = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC, ADDRESS, SCRATCH);
737 if (! targetm.class_likely_spilled_p (base))
738 CLEAR_HARD_REG_SET (temp_hard_reg_set);
739 else
741 COPY_HARD_REG_SET (temp_hard_reg_set, reg_class_contents[base]);
742 AND_COMPL_HARD_REG_SET (temp_hard_reg_set, ira_no_alloc_regs);
743 AND_HARD_REG_SET (temp_hard_reg_set, call_used_reg_set);
745 FOR_EACH_ALLOCNO (a, ai)
747 int i, n = ALLOCNO_NUM_OBJECTS (a);
749 for (i = 0; i < n; i++)
751 ira_object_t obj = ALLOCNO_OBJECT (a, i);
752 rtx allocno_reg = regno_reg_rtx [ALLOCNO_REGNO (a)];
754 if ((! flag_caller_saves && ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
755 /* For debugging purposes don't put user defined variables in
756 callee-clobbered registers. However, do allow parameters
757 in callee-clobbered registers to improve debugging. This
758 is a bit of a fragile hack. */
759 || (optimize == 0
760 && REG_USERVAR_P (allocno_reg)
761 && ! reg_is_parm_p (allocno_reg)))
763 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj),
764 call_used_reg_set);
765 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj),
766 call_used_reg_set);
768 else if (ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
770 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj),
771 no_caller_save_reg_set);
772 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj),
773 temp_hard_reg_set);
774 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj),
775 no_caller_save_reg_set);
776 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj),
777 temp_hard_reg_set);
780 /* Now we deal with paradoxical subreg cases where certain registers
781 cannot be accessed in the widest mode. */
782 machine_mode outer_mode = ALLOCNO_WMODE (a);
783 machine_mode inner_mode = ALLOCNO_MODE (a);
784 if (GET_MODE_SIZE (outer_mode) > GET_MODE_SIZE (inner_mode))
786 enum reg_class aclass = ALLOCNO_CLASS (a);
787 for (int j = ira_class_hard_regs_num[aclass] - 1; j >= 0; --j)
789 int inner_regno = ira_class_hard_regs[aclass][j];
790 int outer_regno = simplify_subreg_regno (inner_regno,
791 inner_mode, 0,
792 outer_mode);
793 if (outer_regno < 0
794 || !in_hard_reg_set_p (reg_class_contents[aclass],
795 outer_mode, outer_regno))
796 SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj),
797 inner_regno);
801 if (ALLOCNO_CALLS_CROSSED_NUM (a) != 0)
803 int regno;
805 /* Allocnos bigger than the saved part of call saved
806 regs must conflict with them. */
807 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
808 if (!TEST_HARD_REG_BIT (call_used_reg_set, regno)
809 && HARD_REGNO_CALL_PART_CLOBBERED (regno,
810 obj->allocno->mode))
812 SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
813 SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj),
814 regno);
819 if (optimize && ira_conflicts_p
820 && internal_flag_ira_verbose > 2 && ira_dump_file != NULL)
821 print_conflicts (ira_dump_file, false);