Daily bump.
[official-gcc.git] / gcc / ra-conflict.c
blobcd983ba8a4cad23d941e2db21163bf0f8e2a80f2
1 /* Allocate registers for pseudo-registers that span basic blocks.
2 Copyright (C) 2007 Free Software Foundation, Inc.
3 Contributed by Kenneth Zadeck <zadeck@naturalbridge.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/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "machmode.h"
27 #include "hard-reg-set.h"
28 #include "rtl.h"
29 #include "tm_p.h"
30 #include "flags.h"
31 #include "regs.h"
32 #include "function.h"
33 #include "insn-config.h"
34 #include "recog.h"
35 #include "reload.h"
36 #include "output.h"
37 #include "toplev.h"
38 #include "tree-pass.h"
39 #include "timevar.h"
40 #include "df.h"
41 #include "vecprim.h"
42 #include "ra.h"
43 #include "sbitmap.h"
45 /* Test, set or clear bit number I in allocnos_live,
46 a bit vector indexed by allocno. */
48 #define SET_ALLOCNO_LIVE(A, I) \
49 ((A)[(unsigned) (I) / HOST_BITS_PER_WIDE_INT] \
50 |= ((HOST_WIDE_INT) 1 << ((unsigned) (I) % HOST_BITS_PER_WIDE_INT)))
52 #define CLEAR_ALLOCNO_LIVE(A, I) \
53 ((A)[(unsigned) (I) / HOST_BITS_PER_WIDE_INT] \
54 &= ~((HOST_WIDE_INT) 1 << ((unsigned) (I) % HOST_BITS_PER_WIDE_INT)))
56 #define GET_ALLOCNO_LIVE(A, I) \
57 ((A)[(unsigned) (I) / HOST_BITS_PER_WIDE_INT] \
58 & ((HOST_WIDE_INT) 1 << ((unsigned) (I) % HOST_BITS_PER_WIDE_INT)))
60 /* Externs defined in regs.h. */
62 int max_allocno;
63 struct allocno *allocno;
64 HOST_WIDE_INT *conflicts;
65 int allocno_row_words;
66 int *reg_allocno;
68 typedef struct df_ref * df_ref_t;
69 DEF_VEC_P(df_ref_t);
70 DEF_VEC_ALLOC_P(df_ref_t,heap);
72 /* Add a conflict between R1 and R2. */
74 static void
75 record_one_conflict_between_regnos (enum machine_mode mode1, int r1,
76 enum machine_mode mode2, int r2)
78 if (dump_file)
79 fprintf (dump_file, " rocbr adding %d<=>%d\n", r1, r2);
80 if (reg_allocno[r1] >= 0 && reg_allocno[r2] >= 0)
82 int tr1 = reg_allocno[r1];
83 int tr2 = reg_allocno[r2];
84 int ialloc_prod = tr1 * allocno_row_words;
86 SET_ALLOCNO_LIVE ((&conflicts[ialloc_prod]), tr2);
88 else if (reg_allocno[r1] >= 0)
90 int tr1 = reg_allocno[r1];
92 if (r2 < FIRST_PSEUDO_REGISTER)
93 add_to_hard_reg_set (&allocno[tr1].hard_reg_conflicts, mode2, r2);
95 else if (reg_allocno[r2] >= 0)
97 int tr2 = reg_allocno[r2];
99 if (r1 < FIRST_PSEUDO_REGISTER)
100 add_to_hard_reg_set (&allocno[tr2].hard_reg_conflicts, mode1, r1);
103 /* Now, recursively handle the reg_renumber cases. */
104 if (reg_renumber[r1] >= 0)
105 record_one_conflict_between_regnos (mode1, reg_renumber[r1], mode2, r2);
107 if (reg_renumber[r2] >= 0)
108 record_one_conflict_between_regnos (mode1, r1, mode2, reg_renumber[r2]);
112 /* Record a conflict between register REGNO and everything currently
113 live. REGNO must not be a pseudo reg that was allocated by
114 local_alloc; such numbers must be translated through reg_renumber
115 before calling here. */
117 static void
118 record_one_conflict (HOST_WIDE_INT *allocnos_live,
119 HARD_REG_SET *hard_regs_live, int regno)
121 int i;
123 if (regno < FIRST_PSEUDO_REGISTER)
124 /* When a hard register becomes live, record conflicts with live
125 pseudo regs. */
126 EXECUTE_IF_SET_IN_ALLOCNO_SET (allocnos_live, i,
128 SET_HARD_REG_BIT (allocno[i].hard_reg_conflicts, regno);
129 if (dump_file)
130 fprintf (dump_file, " roc adding %d<=>%d\n", allocno[i].reg, regno);
132 else
133 /* When a pseudo-register becomes live, record conflicts first
134 with hard regs, then with other pseudo regs. */
136 int ialloc = reg_allocno[regno];
137 int ialloc_prod = ialloc * allocno_row_words;
139 if (dump_file)
141 fprintf (dump_file, " roc adding %d<=>(", regno);
142 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
143 if (TEST_HARD_REG_BIT (*hard_regs_live, i)
144 && !TEST_HARD_REG_BIT (allocno[ialloc].hard_reg_conflicts, i))
145 fprintf (dump_file, "%d ", i);
147 EXECUTE_IF_SET_IN_ALLOCNO_SET (allocnos_live, i,
149 if (!GET_ALLOCNO_LIVE (&conflicts[ialloc_prod], i))
150 fprintf (dump_file, "%d ", allocno[i].reg);
152 fprintf (dump_file, ")\n");
155 IOR_HARD_REG_SET (allocno[ialloc].hard_reg_conflicts, *hard_regs_live);
157 for (i = allocno_row_words - 1; i >= 0; i--)
158 conflicts[ialloc_prod + i] |= allocnos_live[i];
163 /* Handle the case where REG is set by the insn being scanned, during
164 the backward scan to accumulate conflicts. Record a conflict with
165 all other registers already live.
167 REG might actually be something other than a register; if so, we do
168 nothing. */
170 static void
171 mark_reg_store (HOST_WIDE_INT *allocnos_live,
172 HARD_REG_SET *hard_regs_live,
173 struct df_ref *ref)
175 rtx reg = DF_REF_REG (ref);
176 unsigned int regno = DF_REF_REGNO (ref);
177 enum machine_mode mode = GET_MODE (reg);
179 /* Either this is one of the max_allocno pseudo regs not allocated,
180 or it is or has a hardware reg. First handle the pseudo-regs. */
181 if (regno >= FIRST_PSEUDO_REGISTER && reg_allocno[regno] >= 0)
182 record_one_conflict (allocnos_live, hard_regs_live, regno);
184 if (reg_renumber[regno] >= 0)
185 regno = reg_renumber[regno];
187 /* Handle hardware regs (and pseudos allocated to hard regs). */
188 if (regno < FIRST_PSEUDO_REGISTER && ! fixed_regs[regno])
190 unsigned int start = regno;
191 unsigned int last = end_hard_regno (mode, regno);
192 if ((GET_CODE (reg) == SUBREG) && !DF_REF_FLAGS_IS_SET (ref, DF_REF_EXTRACT))
194 start += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
195 SUBREG_BYTE (reg), GET_MODE (reg));
196 last = start + subreg_nregs_with_regno (regno, reg);
199 regno = start;
200 while (regno < last)
201 record_one_conflict (allocnos_live, hard_regs_live, regno++);
206 /* Return true if REGNO with MODE can be assigned to a register in
207 CL. */
209 static bool
210 may_overlap_class_p (enum machine_mode mode, unsigned int regno,
211 enum reg_class rc)
213 if (regno >= FIRST_PSEUDO_REGISTER)
215 enum reg_class pref_class = reg_preferred_class (regno);
216 enum reg_class alt_class = reg_alternate_class (regno);
217 return (reg_classes_intersect_p (rc, pref_class)
218 || reg_classes_intersect_p (rc, alt_class));
220 else
221 return in_hard_reg_set_p (reg_class_contents[rc], mode, regno);
225 /* SRC is an input operand to an instruction in which register DEST is
226 an output operand. SRC may be bound to a member of class SRC_CLASS
227 and DEST may be bound to an earlyclobbered register that overlaps
228 SRC_CLASS. If SRC is a register that might be allocated a member
229 of SRC_CLASS, add a conflict between it and DEST. */
231 static void
232 add_conflicts_for_earlyclobber (rtx dest, enum reg_class src_class, rtx src)
234 if (GET_CODE (src) == SUBREG)
235 src = SUBREG_REG (src);
236 if (REG_P (src)
237 && may_overlap_class_p (GET_MODE (src), REGNO (src), src_class))
238 record_one_conflict_between_regnos (GET_MODE (src), REGNO (src),
239 GET_MODE (dest), REGNO (dest));
243 /* Look at the defs in INSN and determine if any of them are marked as
244 early clobber. If they are marked as early clobber, add a conflict
245 between any input operand that could be allocated to the same
246 register. */
248 static void
249 set_conflicts_for_earlyclobber (rtx insn)
251 int alt;
252 int def;
253 int use;
255 extract_insn (insn);
256 preprocess_constraints ();
258 if (dump_file)
259 fprintf (dump_file, " starting early clobber conflicts.\n");
261 for (alt = 0; alt < recog_data.n_alternatives; alt++)
262 for (def = 0; def < recog_data.n_operands; def++)
263 if ((recog_op_alt[def][alt].earlyclobber)
264 && (recog_op_alt[def][alt].cl != NO_REGS))
266 rtx dreg = recog_data.operand[def];
267 enum machine_mode dmode = recog_data.operand_mode[def];
268 if (GET_CODE (dreg) == SUBREG)
269 dreg = SUBREG_REG (dreg);
270 if (REG_P (dreg)
271 && may_overlap_class_p (dmode, REGNO (dreg), recog_op_alt[def][alt].cl))
273 for (use = 0; use < recog_data.n_operands; use++)
274 if (use != def
275 && recog_data.operand_type[use] != OP_OUT
276 && reg_classes_intersect_p (recog_op_alt[def][alt].cl,
277 recog_op_alt[use][alt].cl))
279 add_conflicts_for_earlyclobber (dreg,
280 recog_op_alt[use][alt].cl,
281 recog_data.operand[use]);
282 /* Reload may end up swapping commutative operands,
283 so you have to take both orderings into account.
284 The constraints for the two operands can be
285 completely different. (Indeed, if the
286 constraints for the two operands are the same
287 for all alternatives, there's no point marking
288 them as commutative.) */
289 if (use < recog_data.n_operands + 1
290 && recog_data.constraints[use][0] == '%')
291 add_conflicts_for_earlyclobber (dreg,
292 recog_op_alt[use][alt].cl,
293 recog_data.operand[use + 1]);
297 if (dump_file)
298 fprintf (dump_file, " finished early clobber conflicts.\n");
302 /* Init LIVE_SUBREGS[ALLOCNUM] and LIVE_SUBREGS_USED[ALLOCNUM] using
303 REG to the the number of nregs, and INIT_VALUE to get the
304 initialization. ALLOCNUM need not be the regno of REG. */
306 void
307 ra_init_live_subregs (bool init_value,
308 sbitmap *live_subregs,
309 int *live_subregs_used,
310 int allocnum,
311 rtx reg)
313 unsigned int regno = REGNO (SUBREG_REG (reg));
314 int size = GET_MODE_SIZE (GET_MODE (regno_reg_rtx[regno]));
316 gcc_assert (size > 0);
318 /* Been there, done that. */
319 if (live_subregs_used[allocnum])
320 return;
322 /* Create a new one with zeros. */
323 if (live_subregs[allocnum] == NULL)
324 live_subregs[allocnum] = sbitmap_alloc (size);
326 /* If the entire reg was live before blasting into subregs, we need
327 to init all of the subregs to ones else init to 0. */
328 if (init_value)
329 sbitmap_ones (live_subregs[allocnum]);
330 else
331 sbitmap_zero (live_subregs[allocnum]);
333 /* Set the number of bits that we really want. */
334 live_subregs_used[allocnum] = size;
338 /* Set REG to be not live in the sets ALLOCNOS_LIVE, LIVE_SUBREGS,
339 HARD_REGS_LIVE. If EXTRACT is false, assume that the entire reg is
340 set not live even if REG is a subreg. */
342 inline static void
343 clear_reg_in_live (HOST_WIDE_INT *allocnos_live,
344 sbitmap *live_subregs,
345 int *live_subregs_used,
346 HARD_REG_SET *hard_regs_live,
347 rtx reg,
348 bool extract)
350 unsigned int regno = (GET_CODE (reg) == SUBREG)
351 ? REGNO (SUBREG_REG (reg)): REGNO (reg);
352 int allocnum = reg_allocno[regno];
354 if (allocnum >= 0)
356 if ((GET_CODE (reg) == SUBREG) && !extract)
359 unsigned int start = SUBREG_BYTE (reg);
360 unsigned int last = start + GET_MODE_SIZE (GET_MODE (reg));
362 ra_init_live_subregs (GET_ALLOCNO_LIVE (allocnos_live, allocnum) != 0,
363 live_subregs, live_subregs_used, allocnum, reg);
365 /* Ignore the paradoxical bits. */
366 if ((int)last > live_subregs_used[allocnum])
367 last = live_subregs_used[allocnum];
369 while (start < last)
371 RESET_BIT (live_subregs[allocnum], start);
372 start++;
375 if (sbitmap_empty_p (live_subregs[allocnum]))
377 live_subregs_used[allocnum] = 0;
378 CLEAR_ALLOCNO_LIVE (allocnos_live, allocnum);
380 else
381 /* Set the allocnos live here because that bit has to be
382 true to get us to look at the live_subregs fields. */
383 SET_ALLOCNO_LIVE (allocnos_live, allocnum);
385 else
387 /* Resetting the live_subregs_used is effectively saying do not use the
388 subregs because we are writing the whole pseudo. */
389 live_subregs_used[allocnum] = 0;
390 CLEAR_ALLOCNO_LIVE (allocnos_live, allocnum);
394 if (regno >= FIRST_PSEUDO_REGISTER)
395 return;
397 /* Handle hardware regs (and pseudos allocated to hard regs). */
398 if (! fixed_regs[regno])
400 unsigned int start = regno;
401 if ((GET_CODE (reg) == SUBREG) && !extract)
403 unsigned int last;
404 start += SUBREG_BYTE (reg);
405 last = start + subreg_nregs_with_regno (regno, reg);
406 regno = start;
408 while (regno < last)
410 CLEAR_HARD_REG_BIT (*hard_regs_live, regno);
411 regno++;
414 else
415 remove_from_hard_reg_set (hard_regs_live, GET_MODE (reg), regno);
421 /* Set REG to be live in the sets ALLOCNOS_LIVE, LIVE_SUBREGS,
422 HARD_REGS_LIVE. If EXTRACT is false, assume that the entire reg is
423 set live even if REG is a subreg. */
425 inline static void
426 set_reg_in_live (HOST_WIDE_INT *allocnos_live,
427 sbitmap *live_subregs,
428 int *live_subregs_used,
429 HARD_REG_SET *hard_regs_live,
430 rtx reg,
431 bool extract)
433 unsigned int regno = (GET_CODE (reg) == SUBREG)
434 ? REGNO (SUBREG_REG (reg)): REGNO (reg);
435 int allocnum = reg_allocno[regno];
437 if (allocnum >= 0)
439 if ((GET_CODE (reg) == SUBREG) && !extract)
441 unsigned int start = SUBREG_BYTE (reg);
442 unsigned int last = start + GET_MODE_SIZE (GET_MODE (reg));
444 ra_init_live_subregs (GET_ALLOCNO_LIVE (allocnos_live, allocnum) != 0,
445 live_subregs, live_subregs_used, allocnum, reg);
447 /* Ignore the paradoxical bits. */
448 if ((int)last > live_subregs_used[allocnum])
449 last = live_subregs_used[allocnum];
451 while (start < last)
453 SET_BIT (live_subregs[allocnum], start);
454 start++;
457 else
458 /* Resetting the live_subregs_used is effectively saying do not use the
459 subregs because we are writing the whole pseudo. */
460 live_subregs_used[allocnum] = 0;
462 SET_ALLOCNO_LIVE (allocnos_live, allocnum);
465 if (regno >= FIRST_PSEUDO_REGISTER)
466 return;
468 /* Handle hardware regs (and pseudos allocated to hard regs). */
469 if (! fixed_regs[regno])
471 if ((GET_CODE (reg) == SUBREG) && !extract)
473 unsigned int start = regno;
474 unsigned int last;
476 start += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
477 SUBREG_BYTE (reg), GET_MODE (reg));
478 last = start + subreg_nregs_with_regno (regno, reg);
479 regno = start;
481 while (regno < last)
483 SET_HARD_REG_BIT (*hard_regs_live, regno);
484 regno++;
487 else
488 add_to_hard_reg_set (hard_regs_live, GET_MODE (reg), regno);
493 /* Add hard reg conflicts to RENUMBERS_LIVE assuming that pseudo in
494 allocno[ALLOCNUM] is allocated to a set of hard regs starting at
495 RENUMBER.
497 We are smart about the case where only subregs of REG have been
498 set, as indicated by LIVE_SUBREGS[ALLOCNUM] and
499 LIVE_SUBREGS_USED[ALLOCNUM]. See global_conflicts for description
500 of LIVE_SUBREGS and LIVE_SUBREGS_USED. */
502 inline static void
503 set_renumbers_live (HARD_REG_SET *renumbers_live,
504 sbitmap *live_subregs,
505 int *live_subregs_used,
506 int allocnum, int renumber)
508 /* The width of the pseudo. */
509 int nbytes = live_subregs_used[allocnum];
510 int regno = allocno[allocnum].reg;
511 enum machine_mode mode = GET_MODE (regno_reg_rtx[regno]);
513 if (dump_file)
514 fprintf (dump_file, " set_renumbers_live %d->%d ",
515 regno, renumber);
517 if (nbytes > 0)
519 int i;
520 sbitmap live_subs = live_subregs[allocnum];
522 /* First figure out how many hard regs we are considering using. */
523 int target_nregs = hard_regno_nregs[renumber][mode];
525 /* Now figure out the number of bytes per hard reg. Note that
526 this may be different that what would be obtained by looking
527 at the mode in the pseudo. For instance, a complex number
528 made up of 2 32-bit parts gets mapped to 2 hard regs, even if
529 the hardregs are 64-bit floating point values. */
530 int target_width = nbytes / target_nregs;
532 if (dump_file)
533 fprintf (dump_file, "target_nregs=%d target_width=%d nbytes=%d",
534 target_nregs, target_width, nbytes);
536 for (i = 0; i < target_nregs; i++)
538 int j;
539 bool set = false;
540 for (j = 0; j < target_width; j++)
542 int reg_start = i * target_width;
543 if (reg_start + j >= nbytes)
544 break;
545 set |= TEST_BIT (live_subs, reg_start + j);
548 if (set)
549 SET_HARD_REG_BIT (*renumbers_live, renumber + i);
552 else
553 add_to_hard_reg_set (renumbers_live, mode, renumber);
555 if (dump_file)
556 fprintf (dump_file, "\n");
559 /* Dump out a REF with its reg_renumber range to FILE using
560 PREFIX. */
562 static void
563 dump_ref (FILE *file,
564 const char * prefix,
565 const char * suffix,
566 rtx reg,
567 unsigned int regno,
568 sbitmap *live_subregs,
569 int *live_subregs_used
572 int allocnum = reg_allocno[regno];
574 fprintf (file, "%s %d", prefix, regno);
575 if (allocnum >= 0
576 && live_subregs_used[allocnum] > 0)
578 int j;
579 char s = '[';
581 for (j = 0; j < live_subregs_used[allocnum]; j++)
582 if (TEST_BIT (live_subregs[allocnum], j))
584 fprintf (dump_file, "%c%d", s, j);
585 s = ',';
587 fprintf (dump_file, "]");
590 if (reg_renumber[regno] >= 0)
592 enum machine_mode mode = GET_MODE (reg);
593 unsigned int start;
594 unsigned int last;
596 regno = reg_renumber[regno];
598 start = regno;
599 last = end_hard_regno (mode, regno);
600 if (GET_CODE (reg) == SUBREG)
602 start += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
603 SUBREG_BYTE (reg), GET_MODE (reg));
604 last = start + subreg_nregs_with_regno (regno, reg);
607 if (start == last - 1)
608 fprintf (file, "(%d)", start);
609 else
610 fprintf (file, "(%d:%d..%d)", regno, start, last-1);
612 fprintf (file, suffix);
616 /* Scan the rtl code and record all conflicts and register preferences in the
617 conflict matrices and preference tables. */
619 void
620 global_conflicts (void)
622 unsigned int i;
623 basic_block bb;
624 rtx insn;
626 /* Regs that have allocnos can be in either
627 hard_regs_live (if regno < FIRST_PSEUDO_REGISTER) or
628 allocnos_live (if regno >= FIRST_PSEUDO_REGISTER) or
629 both if local_alloc has preallocated it and reg_renumber >= 0. */
631 HARD_REG_SET hard_regs_live;
632 HARD_REG_SET renumbers_live;
633 HOST_WIDE_INT *allocnos_live;
634 bitmap live = BITMAP_ALLOC (NULL);
635 VEC (df_ref_t, heap) *clobbers = NULL;
636 VEC (df_ref_t, heap) *dying_regs = NULL;
638 /* live_subregs is a vector used to keep accurate information about
639 which hardregs are live in multiword pseudos. live_subregs and
640 live_subregs_used are indexed by reg_allocno. The live_subreg
641 entry for a particular pseudo is a bitmap with one bit per byte
642 of the register. It is only used if the corresponding element is
643 non zero in live_subregs_used. The value in live_subregs_used is
644 number of bytes that the pseudo can occupy. */
645 sbitmap *live_subregs = XCNEWVEC (sbitmap, max_allocno);
646 int *live_subregs_used = XNEWVEC (int, max_allocno);
648 if (dump_file)
650 fprintf (dump_file, "fixed registers : ");
651 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
652 if (fixed_regs[i])
653 fprintf (dump_file, "%d ", i);
654 fprintf (dump_file, "\n");
657 allocnos_live = XNEWVEC (HOST_WIDE_INT, allocno_row_words);
659 FOR_EACH_BB (bb)
661 bitmap_iterator bi;
663 bitmap_copy (live, DF_LIVE_OUT (bb));
664 df_simulate_artificial_refs_at_end (bb, live);
666 memset (allocnos_live, 0, allocno_row_words * sizeof (HOST_WIDE_INT));
667 memset (live_subregs_used, 0, max_allocno * sizeof (int));
668 CLEAR_HARD_REG_SET (hard_regs_live);
669 CLEAR_HARD_REG_SET (renumbers_live);
671 /* Initialize allocnos_live and hard_regs_live for bottom of block. */
672 EXECUTE_IF_SET_IN_BITMAP (live, 0, i, bi)
674 if (i >= FIRST_PSEUDO_REGISTER)
675 break;
676 if (! fixed_regs[i])
677 SET_HARD_REG_BIT (hard_regs_live, i);
680 EXECUTE_IF_SET_IN_BITMAP (live, FIRST_PSEUDO_REGISTER, i, bi)
682 int allocnum = reg_allocno[i];
684 if (allocnum >= 0)
686 int renumber = reg_renumber[i];
687 rtx reg = regno_reg_rtx[i];
689 set_reg_in_live (allocnos_live, live_subregs, live_subregs_used,
690 &hard_regs_live, reg, false);
691 if (renumber >= 0 && renumber < FIRST_PSEUDO_REGISTER)
692 set_renumbers_live (&renumbers_live, live_subregs, live_subregs_used,
693 allocnum, renumber);
697 if (dump_file)
698 fprintf (dump_file, "\nstarting basic block %d\n\n", bb->index);
700 FOR_BB_INSNS_REVERSE (bb, insn)
702 unsigned int uid = INSN_UID (insn);
703 struct df_ref **def_rec;
704 struct df_ref **use_rec;
706 if (!INSN_P (insn))
707 continue;
709 if (dump_file)
711 fprintf (dump_file, "insn = %d live = hardregs [", uid);
713 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
714 if (TEST_HARD_REG_BIT (hard_regs_live, i))
715 fprintf (dump_file, "%d ", i);
717 fprintf (dump_file, "] renumbered [");
718 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
719 if (TEST_HARD_REG_BIT (renumbers_live, i))
720 fprintf (dump_file, "%d ", i);
722 fprintf (dump_file, "] pseudos [");
723 EXECUTE_IF_SET_IN_ALLOCNO_SET (allocnos_live, i,
725 dump_ref (dump_file, " ", "", regno_reg_rtx[allocno[i].reg],
726 allocno[i].reg, live_subregs, live_subregs_used);
728 fprintf (dump_file, "]\n");
731 /* Add the defs into live. Most of them will already be
732 there, the ones that are missing are the unused ones and
733 the clobbers. We do this in order to make sure that
734 interferences are added between every def and everything
735 that is live across the insn. These defs will be removed
736 later. */
737 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
739 struct df_ref *def = *def_rec;
741 /* FIXME: Ignoring may clobbers is technically the wrong
742 thing to do. However the old version of the this
743 code ignores may clobbers (and instead has many
744 places in the register allocator to handle these
745 constraints). It is quite likely that with a new
746 allocator, the correct thing to do is to not ignore
747 the constraints and then do not put in the large
748 number of special checks. */
749 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
751 rtx reg = DF_REF_REG (def);
752 set_reg_in_live (allocnos_live, live_subregs, live_subregs_used,
753 &hard_regs_live, reg,
754 DF_REF_FLAGS_IS_SET (def, DF_REF_EXTRACT));
755 if (dump_file)
756 dump_ref (dump_file, " adding def", "\n",
757 reg, DF_REF_REGNO (def), live_subregs, live_subregs_used);
761 /* Add the hardregs into renumbers_live to build the
762 interferences. Renumbers_live will be rebuilt in the
763 next step from scratch, so corrupting it here is no
764 problem. */
765 IOR_HARD_REG_SET (renumbers_live, hard_regs_live);
767 /* Add the interferences for the defs. */
768 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
770 struct df_ref *def = *def_rec;
771 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_MAY_CLOBBER))
772 mark_reg_store (allocnos_live, &renumbers_live, def);
775 /* Remove the defs from the live sets. Leave the partial
776 and conditional defs in the set because they do not
777 kill. */
778 VEC_truncate (df_ref_t, clobbers, 0);
779 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++)
781 struct df_ref *def = *def_rec;
783 if (!DF_REF_FLAGS_IS_SET (def, DF_REF_CONDITIONAL))
785 rtx reg = DF_REF_REG (def);
787 clear_reg_in_live (allocnos_live, live_subregs, live_subregs_used,
788 &hard_regs_live, reg,
789 DF_REF_FLAGS_IS_SET (def, DF_REF_EXTRACT));
790 if (dump_file)
791 dump_ref (dump_file, " clearing def", "\n",
792 reg, DF_REF_REGNO (def), live_subregs, live_subregs_used);
795 if (DF_REF_FLAGS_IS_SET (def, DF_REF_MUST_CLOBBER))
796 VEC_safe_push (df_ref_t, heap, clobbers, def);
799 /* Go thru all of the live pseudos and reset renumbers_live.
800 We must start from scratch here because there could have
801 been several pseudos alive that have the same
802 reg_renumber and if we see a clobber for one of them, we
803 cannot not want to kill the renumbers from the other
804 pseudos. */
805 CLEAR_HARD_REG_SET (renumbers_live);
806 EXECUTE_IF_SET_IN_ALLOCNO_SET (allocnos_live, i,
808 unsigned int regno = allocno[i].reg;
809 int renumber = reg_renumber[regno];
811 if (renumber >= 0 && renumber < FIRST_PSEUDO_REGISTER)
812 set_renumbers_live (&renumbers_live, live_subregs, live_subregs_used,
813 i, renumber);
814 });
816 /* Add the uses to the live sets. Keep track of the regs
817 that are dying inside the insn, this set will be useful
818 later. */
819 VEC_truncate (df_ref_t, dying_regs, 0);
820 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++)
822 struct df_ref *use = *use_rec;
823 unsigned int regno = DF_REF_REGNO (use);
824 bool added = false;
825 int renumber = reg_renumber[regno];
826 int allocnum = reg_allocno[regno];
827 bool renumbering = false;
828 rtx reg = DF_REF_REG (use);
830 /* DF_REF_READ_WRITE on a use means that this use is
831 fabricated from a def that is a partial set to a
832 multiword reg. Here, we only model the subreg case
833 precisely so we do not need to look at the fabricated
834 use unless that set also happens to wrapped in a
835 ZERO_EXTRACT. */
836 if (DF_REF_FLAGS_IS_SET (use, DF_REF_READ_WRITE)
837 && (!DF_REF_FLAGS_IS_SET (use, DF_REF_EXTRACT))
838 && DF_REF_FLAGS_IS_SET (use, DF_REF_SUBREG))
839 continue;
841 if (dump_file)
842 dump_ref (dump_file, " seeing use", "\n",
843 reg, regno, live_subregs, live_subregs_used);
845 if (allocnum >= 0)
847 if (GET_CODE (reg) == SUBREG
848 && !DF_REF_FLAGS_IS_SET (use, DF_REF_EXTRACT))
850 unsigned int start = SUBREG_BYTE (reg);
851 unsigned int last = start + GET_MODE_SIZE (GET_MODE (reg));
853 ra_init_live_subregs (GET_ALLOCNO_LIVE (allocnos_live, allocnum) != 0,
854 live_subregs, live_subregs_used, allocnum, reg);
856 /* Ignore the paradoxical bits. */
857 if ((int)last > live_subregs_used[allocnum])
858 last = live_subregs_used[allocnum];
860 while (start < last)
862 if (!TEST_BIT (live_subregs[allocnum], start))
864 if (dump_file)
865 fprintf (dump_file, " dying pseudo subreg %d[%d]\n", regno, start);
866 SET_BIT (live_subregs[allocnum], start);
868 added = true;
870 start++;
873 SET_ALLOCNO_LIVE (allocnos_live, allocnum);
874 if (renumber >= 0 && renumber < FIRST_PSEUDO_REGISTER)
875 set_renumbers_live (&renumbers_live, live_subregs, live_subregs_used,
876 allocnum, renumber);
879 else if (GET_ALLOCNO_LIVE (allocnos_live, allocnum) == 0)
881 if (dump_file)
882 fprintf (dump_file, " dying pseudo\n");
884 /* Resetting the live_subregs_used is
885 effectively saying do not use the subregs
886 because we are reading the whole pseudo. */
887 live_subregs_used[allocnum] = 0;
888 SET_ALLOCNO_LIVE (allocnos_live, allocnum);
889 if (renumber >= 0 && renumber < FIRST_PSEUDO_REGISTER)
890 set_renumbers_live (&renumbers_live, live_subregs, live_subregs_used,
891 allocnum, renumber);
892 added = true;
896 if (renumber >= 0 && renumber < FIRST_PSEUDO_REGISTER)
898 regno = renumber;
899 renumbering = true;
902 if (regno < FIRST_PSEUDO_REGISTER)
904 unsigned int start = regno;
905 unsigned int last;
906 if (GET_CODE (reg) == SUBREG)
908 start += subreg_regno_offset (regno, GET_MODE (SUBREG_REG (reg)),
909 SUBREG_BYTE (reg), GET_MODE (reg));
910 last = start + subreg_nregs_with_regno (regno, reg);
912 else
913 last = end_hard_regno (GET_MODE (reg), regno);
915 regno = start;
916 while (regno < last)
918 if ((!TEST_HARD_REG_BIT (hard_regs_live, regno))
919 && (!TEST_HARD_REG_BIT (renumbers_live, regno))
920 && ! fixed_regs[regno])
922 if (dump_file)
923 fprintf (dump_file, " dying hard reg %d\n", regno);
924 if (renumbering)
925 SET_HARD_REG_BIT (renumbers_live, regno);
926 else
927 SET_HARD_REG_BIT (hard_regs_live, regno);
929 added = true;
931 regno++;
934 if (added)
935 VEC_safe_push (df_ref_t, heap, dying_regs, use);
938 /* These three cases are all closely related, they all deal
939 with some set of outputs of the insn need to conflict
940 with some of the registers that are used by the insn but
941 die within the insn. If no registers die within the insn,
942 the tests can be skipped. */
944 if (VEC_length (df_ref_t, dying_regs) > 0)
946 int k;
947 /* There appears to be an ambiguity as to what a clobber
948 means in an insn. In some cases, the clobber happens
949 within the processing of the insn and in some cases
950 it happens at the end of processing the insn. There
951 is currently no way to distinguish these two cases so
952 this code causes real clobbers to interfere with
953 registers that die within an insn.
955 This is consistent with the prior version of
956 interference graph builder but is was discovered
957 while developing this version of the code, that on
958 some architectures such as the x86-64, the clobbers
959 only appear to happen at the end of the insn.
960 However, the ppc-32 contains clobbers for which these
961 interferences are necessary.
963 FIXME: We should consider either adding a new kind of
964 clobber, or adding a flag to the clobber distinguish
965 these two cases. */
966 for (k = VEC_length (df_ref_t, clobbers) - 1; k >= 0; k--)
968 struct df_ref *def = VEC_index (df_ref_t, clobbers, k);
969 int j;
971 for (j = VEC_length (df_ref_t, dying_regs) - 1; j >= 0; j--)
973 struct df_ref *use = VEC_index (df_ref_t, dying_regs, j);
974 record_one_conflict_between_regnos (GET_MODE (DF_REF_REG (def)),
975 DF_REF_REGNO (def),
976 GET_MODE (DF_REF_REG (use)),
977 DF_REF_REGNO (use));
981 /* Early clobbers, by definition, need to not only
982 clobber the registers that are live accross the insn
983 but need to clobber the registers that die within the
984 insn. The clobbering for registers live across the
985 insn is handled above. */
986 set_conflicts_for_earlyclobber (insn);
988 /* If INSN is a store with multiple outputs, then any
989 reg that dies here and is used inside of the address
990 of the output must conflict with the other outputs.
992 FIXME: There has been some discussion as to whether
993 this is right place to handle this issue. This is a
994 hold over from an early version global conflicts.
996 1) There is some evidence that code only deals with a
997 bug that is only on the m68k. The conditions of this
998 test are such that this case only triggers for a very
999 peculiar insn, one that is a parallel where one of
1000 the sets is a store and the other sets a reg that is
1001 used in the address of the store. See
1002 http://gcc.gnu.org/ml/gcc-patches/1998-12/msg00259.html
1004 2) The situation that this is addressing is a bug in
1005 the part of reload that handles stores, adding this
1006 conflict only hides the problem. (Of course no one
1007 really wants to fix reload so it is understandable
1008 why a bandaid was just added here.)
1010 Just because an output is unused does not mean the
1011 compiler can assume the side effect will not occur.
1012 Consider if REG appears in the address of an output
1013 and we reload the output. If we allocate REG to the
1014 same hard register as an unused output we could set
1015 the hard register before the output reload insn.
1017 3) This could actually be handled by making the other
1018 (non store) operand of the insn be an early clobber.
1019 This would insert the same conflict, even if it is
1020 not technically an early clobber. */
1022 /* It is unsafe to use !single_set here since it will ignore an
1023 unused output. */
1024 if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
1026 int j;
1027 for (j = VEC_length (df_ref_t, dying_regs) - 1; j >= 0; j--)
1029 int used_in_output = 0;
1030 struct df_ref *use = VEC_index (df_ref_t, dying_regs, j);
1031 rtx reg = DF_REF_REG (use);
1032 int uregno = DF_REF_REGNO (use);
1033 enum machine_mode umode = GET_MODE (DF_REF_REG (use));
1034 int k;
1036 for (k = XVECLEN (PATTERN (insn), 0) - 1; k >= 0; k--)
1038 rtx set = XVECEXP (PATTERN (insn), 0, k);
1039 if (GET_CODE (set) == SET
1040 && !REG_P (SET_DEST (set))
1041 && !rtx_equal_p (reg, SET_DEST (set))
1042 && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1043 used_in_output = 1;
1045 if (used_in_output)
1046 for (k = XVECLEN (PATTERN (insn), 0) - 1; k >= 0; k--)
1048 rtx set = XVECEXP (PATTERN (insn), 0, k);
1049 if (GET_CODE (set) == SET
1050 && REG_P (SET_DEST (set))
1051 && !rtx_equal_p (reg, SET_DEST (set)))
1052 record_one_conflict_between_regnos (GET_MODE (SET_DEST (set)),
1053 REGNO (SET_DEST (set)),
1054 umode, uregno);
1061 /* Add the renumbers live to the hard_regs_live for the next few
1062 calls. All of this gets recomputed at the top of the loop so
1063 there is no harm. */
1064 IOR_HARD_REG_SET (hard_regs_live, renumbers_live);
1066 #ifdef EH_RETURN_DATA_REGNO
1067 if (bb_has_eh_pred (bb))
1069 unsigned int i;
1071 for (i = 0; ; ++i)
1073 unsigned int regno = EH_RETURN_DATA_REGNO (i);
1074 if (regno == INVALID_REGNUM)
1075 break;
1076 record_one_conflict (allocnos_live, &hard_regs_live, regno);
1079 #endif
1081 if (bb_has_abnormal_pred (bb))
1083 unsigned int i;
1084 #ifdef STACK_REGS
1085 /* Pseudos can't go in stack regs at the start of a basic block that
1086 is reached by an abnormal edge. Likewise for call clobbered regs,
1087 because caller-save, fixup_abnormal_edges and possibly the table
1088 driven EH machinery are not quite ready to handle such regs live
1089 across such edges. */
1090 EXECUTE_IF_SET_IN_ALLOCNO_SET (allocnos_live, i,
1092 allocno[i].no_stack_reg = 1;
1095 for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++)
1096 record_one_conflict (allocnos_live, &hard_regs_live, i);
1097 #endif
1099 /* No need to record conflicts for call clobbered regs if we have
1100 nonlocal labels around, as we don't ever try to allocate such
1101 regs in this case. */
1102 if (! current_function_has_nonlocal_label)
1103 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1104 if (call_used_regs [i])
1105 record_one_conflict (allocnos_live, &hard_regs_live, i);
1109 for (i = 0; i < (unsigned int)max_allocno; i++)
1110 if (live_subregs[i])
1111 free (live_subregs[i]);
1113 /* Clean up. */
1114 free (allocnos_live);
1115 free (live_subregs);
1116 free (live_subregs_used);
1117 VEC_free (df_ref_t, heap, dying_regs);
1118 VEC_free (df_ref_t, heap, clobbers);
1119 BITMAP_FREE (live);