2007-03-16 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ira-conflicts.c
blob8c29233e8ae080f53a5ac85476bfdf1c9eb5ec54
1 /* IRA conflict builder.
2 Copyright (C) 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "regs.h"
28 #include "rtl.h"
29 #include "tm_p.h"
30 #include "target.h"
31 #include "flags.h"
32 #include "hard-reg-set.h"
33 #include "basic-block.h"
34 #include "insn-config.h"
35 #include "recog.h"
36 #include "toplev.h"
37 #include "params.h"
38 #include "df.h"
39 #include "ira-int.h"
41 /* The file contains code is analogous to one in global but the code
42 works on the pseudo basis. */
44 static void set_pseudo_live (pseudo_t);
45 static void clear_pseudo_live (pseudo_t);
46 static void record_regno_conflict (int);
47 static void mark_reg_store (rtx, rtx, void *);
48 static void mark_reg_clobber (rtx, rtx, void *);
49 static void mark_reg_conflicts (rtx);
50 static void mark_reg_death (rtx);
51 static int commutative_constraint_p (const char *);
52 static int get_dup_num (int, int);
53 static rtx get_dup (int, int);
54 static void add_pseudo_copy_to_list (copy_t);
55 static void remove_pseudo_copy_from_list (copy_t);
56 static void swap_pseudo_copy_ends_if_necessary (copy_t);
57 static void add_pseudo_copies (rtx);
58 static enum reg_class single_reg_class (const char *, rtx op, rtx);
59 static enum reg_class single_reg_operand_class (int);
60 static void process_single_reg_class_operands (int);
61 static void process_bb_node_for_conflicts (struct ira_loop_tree_node *);
62 static void build_conflict_bit_table (void);
63 static void propagate_pseudo_info (pseudo_t);
64 static void propagate_info (void);
65 static void mirror_conflicts (void);
66 static void remove_conflict_pseudo_copies (void);
67 static void build_pseudo_conflict_vects (void);
68 static void propagate_modified_regnos (struct ira_loop_tree_node *);
69 static void print_conflicts (FILE *);
71 /* The number of bits in each element of `conflicts' and what
72 type that element has. We use the largest integer format on the
73 host machine. */
74 #define INT_BITS HOST_BITS_PER_WIDE_INT
75 #define INT_TYPE HOST_WIDE_INT
77 /* Bit mask for pseudos live at current point in the scan. */
78 static INT_TYPE *pseudos_live;
80 /* The same as previous but as bitmap. */
81 static bitmap pseudos_live_bitmap;
83 /* Set, clear or test bit number I in R, a bit vector indexed by
84 pseudo number. */
85 #define SET_PSEUDO_CONFLICT_ROW(R, I) \
86 ((R)[(unsigned) (I) / INT_BITS] \
87 |= ((INT_TYPE) 1 << ((unsigned) (I) % INT_BITS)))
89 #define CLEAR_PSEUDO_CONFLICT_ROW(R, I) \
90 ((R) [(unsigned) (I) / INT_BITS] \
91 &= ~((INT_TYPE) 1 << ((unsigned) (I) % INT_BITS)))
93 #define TEST_PSEUDO_CONFLICT_ROW(R, I) \
94 ((R) [(unsigned) (I) / INT_BITS] \
95 & ((INT_TYPE) 1 << ((unsigned) (I) % INT_BITS)))
97 /* Set, clear or test bit number I in `pseudos_live',
98 a bit vector indexed by pseudo number. */
99 #define SET_PSEUDO_LIVE(I) SET_PSEUDO_CONFLICT_ROW (pseudos_live, I)
101 #define CLEAR_PSEUDO_LIVE(I) CLEAR_PSEUDO_CONFLICT_ROW (pseudos_live, I)
103 #define TEST_PSEUDO_LIVE(I) TEST_PSEUDO_CONFLICT_ROW (pseudos_live, I)
105 /* pseudos_num by pseudos_num array of bits, recording whether two
106 pseudo's conflict (can't go in the same hardware register).
108 `conflicts' is symmetric after the call to mirror_conflicts. */
109 static INT_TYPE *conflicts;
111 /* Number of ints required to hold pseudos_num bits. This is the
112 length of a row in `conflicts'. */
113 static int pseudo_row_words;
115 /* Two macros to test 1 in an element of `conflicts'. */
116 #define CONFLICTP(I, J) \
117 (conflicts[(I) * pseudo_row_words + (unsigned) (J) / INT_BITS] \
118 & ((INT_TYPE) 1 << ((unsigned) (J) % INT_BITS)))
120 /* For each pseudo set in PSEUDO_SET, set PSEUDO to that pseudo, and
121 execute CODE. */
122 #define EXECUTE_IF_SET_IN_PSEUDO_SET(PSEUDO_SET, PSEUDO, CODE) \
123 do { \
124 int i_; \
125 int pseudo_; \
126 INT_TYPE *p_ = (PSEUDO_SET); \
128 for (i_ = pseudo_row_words - 1, pseudo_ = 0; i_ >= 0; \
129 i_--, pseudo_ += INT_BITS) \
131 unsigned INT_TYPE word_ = (unsigned INT_TYPE) *p_++; \
133 for ((PSEUDO) = pseudo_; word_; word_ >>= 1, (PSEUDO)++) \
135 if (word_ & 1) \
136 {CODE;} \
139 } while (0)
142 /* Set of hard regs (except eliminable ones) currently live (during
143 scan of all insns). */
144 static HARD_REG_SET hard_regs_live;
146 /* Loop tree node corresponding to the current basic block. */
147 static struct ira_loop_tree_node *curr_bb_node;
149 /* Current map regno -> pseudo. */
150 static pseudo_t *curr_regno_pseudo_map;
152 /* The current pressure for the current basic block. */
153 static int curr_reg_pressure [N_REG_CLASSES];
155 /* The function marks pseudo P as currently living. */
156 static void
157 set_pseudo_live (pseudo_t p)
159 enum reg_class cover_class;
161 if (TEST_PSEUDO_LIVE (PSEUDO_NUM (p)))
162 return;
163 SET_PSEUDO_LIVE (PSEUDO_NUM (p));
164 bitmap_set_bit (pseudos_live_bitmap, PSEUDO_NUM (p));
165 cover_class = PSEUDO_COVER_CLASS (p);
166 curr_reg_pressure [cover_class]
167 += reg_class_nregs [cover_class] [PSEUDO_MODE (p)];
168 if (curr_bb_node->reg_pressure [cover_class]
169 < curr_reg_pressure [cover_class])
170 curr_bb_node->reg_pressure [cover_class]
171 = curr_reg_pressure [cover_class];
174 /* The function marks pseudo P as currently not living. */
175 static void
176 clear_pseudo_live (pseudo_t p)
178 enum reg_class cover_class;
180 if (bitmap_bit_p (pseudos_live_bitmap, PSEUDO_NUM (p)))
182 cover_class = PSEUDO_COVER_CLASS (p);
183 curr_reg_pressure [cover_class]
184 -= reg_class_nregs [cover_class] [PSEUDO_MODE (p)];
185 ira_assert (curr_reg_pressure [cover_class] >= 0);
187 CLEAR_PSEUDO_LIVE (PSEUDO_NUM (p));
188 bitmap_clear_bit (pseudos_live_bitmap, PSEUDO_NUM (p));
191 /* Record all regs that are set in any one insn. Communication from
192 mark_reg_{store,clobber} and build_conflict_bit_table. */
193 static rtx *regs_set;
195 /* Number elelments in the previous array. */
196 static int n_regs_set;
198 /* Record a conflict between hard register REGNO or pseudo
199 corresponding to pseudo-register REGNO and everything currently
200 live. */
201 static void
202 record_regno_conflict (int regno)
204 int j;
206 if (regno < FIRST_PSEUDO_REGISTER)
208 /* When a hard register becomes live, record conflicts with live
209 pseudo regs. */
210 EXECUTE_IF_SET_IN_PSEUDO_SET (pseudos_live, j,
212 SET_HARD_REG_BIT (PSEUDO_CONFLICT_HARD_REGS (pseudos [j]), regno);
215 else
217 /* When a pseudo-register becomes live, record conflicts first
218 with hard regs, then with other pseudos. */
219 pseudo_t p = curr_regno_pseudo_map [regno];
220 int pn, pn_prod;
222 ira_assert (p != NULL || REG_N_REFS (regno) == 0);
223 if (p == NULL)
224 return;
225 pn = PSEUDO_NUM (p);
226 pn_prod = pn * pseudo_row_words;
227 IOR_HARD_REG_SET (PSEUDO_CONFLICT_HARD_REGS (p), hard_regs_live);
228 for (j = pseudo_row_words - 1; j >= 0; j--)
229 conflicts [pn_prod + j] |= pseudos_live [j];
230 /* Don't set up conflict for the pseudo with itself. */
231 CLEAR_PSEUDO_CONFLICT_ROW (conflicts + pn_prod, pn);
235 /* Handle the case where REG is set by the insn being scanned, during
236 the scan to accumulate conflicts. Store a 1 in hard_regs_live or
237 pseudos_live for this register or the corresponding pseudo, record
238 how many consecutive hardware registers it actually needs, and
239 record a conflict with all other pseudos already live.
241 Note that even if REG does not remain alive after this insn, we
242 must mark it here as live, to ensure a conflict between REG and any
243 other pseudos set in this insn that really do live. This is
244 because those other pseudos could be considered after this.
246 REG might actually be something other than a register; if so, we do
247 nothing.
249 SETTER is 0 if this register was modified by an auto-increment
250 (i.e., a REG_INC note was found for it). */
251 static void
252 mark_reg_store (rtx reg, rtx setter ATTRIBUTE_UNUSED,
253 void *data ATTRIBUTE_UNUSED)
255 int regno;
257 if (GET_CODE (reg) == SUBREG)
258 reg = SUBREG_REG (reg);
260 if (! REG_P (reg))
261 return;
263 regs_set [n_regs_set++] = reg;
265 regno = REGNO (reg);
267 if (regno >= FIRST_PSEUDO_REGISTER)
269 pseudo_t p = curr_regno_pseudo_map [regno];
271 ira_assert (p != NULL || REG_N_REFS (regno) == 0);
272 if (p != NULL)
273 set_pseudo_live (p);
274 record_regno_conflict (regno);
276 else if (! TEST_HARD_REG_BIT (no_alloc_regs, regno))
278 int last = regno + hard_regno_nregs [regno] [GET_MODE (reg)];
279 enum reg_class cover_class;
281 while (regno < last)
283 record_regno_conflict (regno);
284 if (! TEST_HARD_REG_BIT (eliminable_regset, regno)
285 && ! TEST_HARD_REG_BIT (hard_regs_live, regno))
287 cover_class = class_translate [REGNO_REG_CLASS (regno)];
288 curr_reg_pressure [cover_class]++;
289 SET_HARD_REG_BIT (hard_regs_live, regno);
290 if (curr_bb_node->reg_pressure [cover_class]
291 < curr_reg_pressure [cover_class])
292 curr_bb_node->reg_pressure [cover_class]
293 = curr_reg_pressure [cover_class];
295 regno++;
300 /* Like mark_reg_store except notice just CLOBBERs; ignore SETs. */
301 static void
302 mark_reg_clobber (rtx reg, rtx setter, void *data)
304 if (GET_CODE (setter) == CLOBBER)
305 mark_reg_store (reg, setter, data);
308 /* Record that REG (or the corresponding pseudo) has conflicts with
309 all the pseudo currently live. Do not mark REG (or the pseudo)
310 itself as live. */
311 static void
312 mark_reg_conflicts (rtx reg)
314 int regno;
316 if (GET_CODE (reg) == SUBREG)
317 reg = SUBREG_REG (reg);
319 if (! REG_P (reg))
320 return;
322 regno = REGNO (reg);
324 if (regno >= FIRST_PSEUDO_REGISTER)
325 record_regno_conflict (regno);
326 else if (! TEST_HARD_REG_BIT (no_alloc_regs, regno))
328 int last = regno + hard_regno_nregs [regno] [GET_MODE (reg)];
330 while (regno < last)
332 record_regno_conflict (regno);
333 regno++;
338 /* Mark REG (or the corresponding pseudo) as being dead (following the
339 insn being scanned now). Store a 0 in hard_regs_live or
340 pseudos_live for this register. */
341 static void
342 mark_reg_death (rtx reg)
344 int regno = REGNO (reg);
346 if (regno >= FIRST_PSEUDO_REGISTER)
348 pseudo_t p = curr_regno_pseudo_map [regno];
350 ira_assert (p != NULL || REG_N_REFS (regno) == 0);
351 if (p != NULL)
352 clear_pseudo_live (p);
354 else if (! TEST_HARD_REG_BIT (no_alloc_regs, regno))
356 int last = regno + hard_regno_nregs [regno] [GET_MODE (reg)];
357 enum reg_class cover_class;
359 while (regno < last)
361 if (TEST_HARD_REG_BIT (hard_regs_live, regno))
363 cover_class = class_translate [REGNO_REG_CLASS (regno)];
364 curr_reg_pressure [cover_class]--;
365 ira_assert (curr_reg_pressure [cover_class] >= 0);
366 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
368 regno++;
373 /* The function returns nonzero, if the operand constraint STR is
374 commutative. */
375 static int
376 commutative_constraint_p (const char *str)
378 int ignore_p;
379 int c;
381 for (ignore_p = FALSE;;)
383 c = *str;
384 if (c == '\0')
385 break;
386 str += CONSTRAINT_LEN (c, str);
387 if (c == '#')
388 ignore_p = TRUE;
389 else if (c == ',')
390 ignore_p = FALSE;
391 else if (! ignore_p)
393 if (c == '%')
394 return TRUE;
397 return FALSE;
400 /* The function returns number of the operand which should be the same
401 in any case as operand with number OP_NUM. If USE_COMMUT_OP_P is
402 non-zero, the function makes temporarily commutative operand
403 exchange before this. The function takes only really possible
404 alternatives into consideration. */
405 static int
406 get_dup_num (int op_num, int use_commut_op_p)
408 int curr_alt, c, original, dup;
409 int ignore_p, commut_op_used_p;
410 const char *str;
411 rtx op, equiv_const = NULL_RTX; /* ??? */
413 if (op_num < 0 || recog_data.n_alternatives == 0)
414 return -1;
415 op = recog_data.operand [op_num];
416 ira_assert (REG_P (op));
417 commut_op_used_p = TRUE;
418 if (use_commut_op_p)
420 if (commutative_constraint_p (recog_data.constraints [op_num]))
421 op_num++;
422 else if (op_num > 0 && commutative_constraint_p (recog_data.constraints
423 [op_num - 1]))
424 op_num--;
425 else
426 commut_op_used_p = FALSE;
428 str = recog_data.constraints [op_num];
429 for (ignore_p = FALSE, original = -1, curr_alt = 0;;)
431 c = *str;
432 if (c == '\0')
433 break;
434 if (c == '#')
435 ignore_p = TRUE;
436 else if (c == ',')
438 curr_alt++;
439 ignore_p = FALSE;
441 else if (! ignore_p)
442 switch (c)
444 case 'X':
445 return -1;
447 case 'i':
448 if (equiv_const != NULL_RTX && CONSTANT_P (equiv_const))
449 return -1;
450 break;
452 case 'n':
453 if (equiv_const != NULL_RTX
454 && (GET_CODE (equiv_const) == CONST_INT
455 || (GET_CODE (equiv_const) == CONST_DOUBLE
456 && GET_MODE (equiv_const) == VOIDmode)))
457 return -1;
458 break;
460 case 's':
461 if (equiv_const != NULL_RTX
462 && CONSTANT_P (equiv_const)
463 && GET_CODE (equiv_const) != CONST_INT
464 && (GET_CODE (equiv_const) != CONST_DOUBLE
465 || GET_MODE (equiv_const) != VOIDmode))
466 return -1;
467 break;
469 case 'I':
470 case 'J':
471 case 'K':
472 case 'L':
473 case 'M':
474 case 'N':
475 case 'O':
476 case 'P':
477 if ((equiv_const != NULL_RTX
478 && GET_CODE (equiv_const) == CONST_INT
479 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (equiv_const),
480 c, str)))
481 return -1;
482 break;
484 case 'E':
485 case 'F':
486 if (equiv_const != NULL_RTX
487 && (GET_CODE (equiv_const) == CONST_DOUBLE
488 || (GET_CODE (equiv_const) == CONST_VECTOR
489 && (GET_MODE_CLASS (GET_MODE (equiv_const))
490 == MODE_VECTOR_FLOAT))))
491 return -1;
492 break;
494 case 'G':
495 case 'H':
496 if (equiv_const != NULL_RTX
497 && GET_CODE (equiv_const) == CONST_DOUBLE
498 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (equiv_const, c, str))
499 return -1;
500 break;
502 case 'm':
503 case 'o':
504 /* Accept a register which might be placed in memory. */
505 return -1;
506 break;
508 case 'V':
509 case '<':
510 case '>':
511 break;
513 case 'p':
514 GO_IF_LEGITIMATE_ADDRESS (VOIDmode, op, win_p);
515 break;
517 win_p:
518 return -1;
520 case 'g':
521 return -1;
523 case 'r':
524 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
525 case 'h': case 'j': case 'k': case 'l':
526 case 'q': case 't': case 'u':
527 case 'v': case 'w': case 'x': case 'y': case 'z':
528 case 'A': case 'B': case 'C': case 'D':
529 case 'Q': case 'R': case 'S': case 'T': case 'U':
530 case 'W': case 'Y': case 'Z':
532 enum reg_class cl;
534 cl = (c == 'r'
535 ? GENERAL_REGS : REG_CLASS_FROM_CONSTRAINT (c, str));
536 if (cl != NO_REGS)
537 return -1;
538 #ifdef EXTRA_CONSTRAINT_STR
539 else if (EXTRA_CONSTRAINT_STR (op, c, str))
540 return -1;
541 #endif
542 break;
545 case '0': case '1': case '2': case '3': case '4':
546 case '5': case '6': case '7': case '8': case '9':
547 if (original != -1 && original != c)
548 return -1;
549 original = c;
550 break;
552 str += CONSTRAINT_LEN (c, str);
554 if (original == -1)
555 return -1;
556 dup = original - '0';
557 if (use_commut_op_p)
559 if (commutative_constraint_p (recog_data.constraints [dup]))
560 dup++;
561 else if (dup > 0
562 && commutative_constraint_p (recog_data.constraints [dup -1]))
563 dup--;
564 else if (! commut_op_used_p)
565 return -1;
567 return dup;
570 /* The function returns operand which should be in any case the same
571 as operand with number OP_NUM. If USE_COMMUT_OP_P is non-zero, the
572 function makes temporarily commutative operand exchange before
573 this. */
574 static rtx
575 get_dup (int op_num, int use_commut_op_p)
577 int n = get_dup_num (op_num, use_commut_op_p);
579 if (n < 0)
580 return NULL_RTX;
581 else
582 return recog_data.operand [n];
585 /* The function attaches copy CP to pseudos involved into the copy. */
586 static void
587 add_pseudo_copy_to_list (copy_t cp)
589 pseudo_t first = cp->first, second = cp->second;
591 cp->prev_first_pseudo_copy = NULL;
592 cp->prev_second_pseudo_copy = NULL;
593 cp->next_first_pseudo_copy = PSEUDO_COPIES (first);
594 if (cp->next_first_pseudo_copy != NULL)
596 if (cp->next_first_pseudo_copy->first == first)
597 cp->next_first_pseudo_copy->prev_first_pseudo_copy = cp;
598 else
599 cp->next_first_pseudo_copy->prev_second_pseudo_copy = cp;
601 cp->next_second_pseudo_copy = PSEUDO_COPIES (second);
602 if (cp->next_second_pseudo_copy != NULL)
604 if (cp->next_second_pseudo_copy->second == second)
605 cp->next_second_pseudo_copy->prev_second_pseudo_copy = cp;
606 else
607 cp->next_second_pseudo_copy->prev_first_pseudo_copy = cp;
609 PSEUDO_COPIES (first) = cp;
610 PSEUDO_COPIES (second) = cp;
613 /* The function detaches copy CP from pseudos involved into the copy. */
614 static void
615 remove_pseudo_copy_from_list (copy_t cp)
617 pseudo_t first = cp->first, second = cp->second;
618 copy_t prev, next;
620 next = cp->next_first_pseudo_copy;
621 prev = cp->prev_first_pseudo_copy;
622 if (prev == NULL)
623 PSEUDO_COPIES (first) = next;
624 else if (prev->first == first)
625 prev->next_first_pseudo_copy = next;
626 else
627 prev->next_second_pseudo_copy = next;
628 if (next != NULL)
630 if (next->first == first)
631 next->prev_first_pseudo_copy = prev;
632 else
633 next->prev_second_pseudo_copy = prev;
635 cp->prev_first_pseudo_copy = cp->next_first_pseudo_copy = NULL;
637 next = cp->next_second_pseudo_copy;
638 prev = cp->prev_second_pseudo_copy;
639 if (prev == NULL)
640 PSEUDO_COPIES (second) = next;
641 else if (prev->second == second)
642 prev->next_second_pseudo_copy = next;
643 else
644 prev->next_first_pseudo_copy = next;
645 if (next != NULL)
647 if (next->second == second)
648 next->prev_second_pseudo_copy = prev;
649 else
650 next->prev_first_pseudo_copy = prev;
652 cp->prev_second_pseudo_copy = cp->next_second_pseudo_copy = NULL;
655 /* The function makes copy CP a canonical copy where number of the
656 first pseudo is less than the second one. */
657 static void
658 swap_pseudo_copy_ends_if_necessary (copy_t cp)
660 pseudo_t temp;
661 copy_t temp_cp;
663 if (PSEUDO_NUM (cp->first) <= PSEUDO_NUM (cp->second))
664 return;
666 temp = cp->first;
667 cp->first = cp->second;
668 cp->second = temp;
670 temp_cp = cp->prev_first_pseudo_copy;
671 cp->prev_first_pseudo_copy = cp->prev_second_pseudo_copy;
672 cp->prev_second_pseudo_copy = temp_cp;
674 temp_cp = cp->next_first_pseudo_copy;
675 cp->next_first_pseudo_copy = cp->next_second_pseudo_copy;
676 cp->next_second_pseudo_copy = temp_cp;
679 /* The function creates and returns new copy of pseudos FIRST and
680 SECOND with frequency FREQ corresponding to move insn INSN (if
681 any). */
682 copy_t
683 add_pseudo_copy (pseudo_t first, pseudo_t second, int freq, rtx insn)
685 copy_t cp;
687 cp = create_copy (first, second, freq, insn);
688 ira_assert (first != NULL && second != NULL);
689 add_pseudo_copy_to_list (cp);
690 swap_pseudo_copy_ends_if_necessary (cp);
691 return cp;
694 /* The function processes INSN and create pseudo copies if
695 necessary. For example, it might be because INSN is a
696 pseudo-register move or INSN is two operand insn. */
697 static void
698 add_pseudo_copies (rtx insn)
700 rtx set, operand, dup;
701 const char *str;
702 int commut_p, bound_p;
703 int i, j, freq, hard_regno, cost, index;
704 copy_t cp;
705 pseudo_t p;
706 enum reg_class class, cover_class;
707 enum machine_mode mode;
709 freq = REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn));
710 if (freq == 0)
711 freq = 1;
712 if ((set = single_set (insn)) != NULL_RTX
713 && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set))
714 && ! side_effects_p (set)
715 && find_reg_note (insn, REG_DEAD, SET_SRC (set)) != NULL_RTX
716 && find_reg_note (insn, REG_RETVAL, NULL_RTX) == NULL_RTX)
718 if (HARD_REGISTER_P (SET_SRC (set)) || HARD_REGISTER_P (SET_DEST (set)))
720 if (HARD_REGISTER_P (SET_DEST (set)))
722 if (HARD_REGISTER_P (SET_SRC (set)))
723 return;
724 hard_regno = REGNO (SET_DEST (set));
725 p = curr_regno_pseudo_map [REGNO (SET_SRC (set))];
727 else
729 hard_regno = REGNO (SET_SRC (set));
730 p = curr_regno_pseudo_map [REGNO (SET_DEST (set))];
732 class = REGNO_REG_CLASS (hard_regno);
733 mode = PSEUDO_MODE (p);
734 cover_class = PSEUDO_COVER_CLASS (p);
735 if (! class_subset_p [class] [cover_class])
736 return;
737 if (reg_class_size [class]
738 <= (unsigned) CLASS_MAX_NREGS (class, mode))
739 /* It is already taken into account in ira-costs.c. */
740 return;
741 index = class_hard_reg_index [cover_class] [hard_regno];
742 if (index < 0)
743 return;
744 if (HARD_REGISTER_P (SET_DEST (set)))
745 cost = register_move_cost [mode] [cover_class] [class] * freq;
746 else
747 cost = register_move_cost [mode] [class] [cover_class] * freq;
748 PSEUDO_HARD_REG_COSTS (p) [index] -= cost;
749 PSEUDO_CONFLICT_HARD_REG_COSTS (p) [index] -= cost;
751 else
753 cp = add_pseudo_copy (curr_regno_pseudo_map [REGNO (SET_DEST (set))],
754 curr_regno_pseudo_map [REGNO (SET_SRC (set))],
755 freq, insn);
756 bitmap_set_bit (ira_curr_loop_tree_node->local_copies, cp->num);
759 else
761 extract_insn (insn);
762 for (i = 0; i < recog_data.n_operands; i++)
764 operand = recog_data.operand [i];
765 if (REG_P (operand)
766 && find_reg_note (insn, REG_DEAD, operand) != NULL_RTX)
768 str = recog_data.constraints [i];
769 while (*str == ' ' && *str == '\t')
770 str++;
771 bound_p = FALSE;
772 for (j = 0, commut_p = FALSE; j < 2; j++, commut_p = TRUE)
773 if ((dup = get_dup (i, commut_p)) != NULL_RTX
774 && REG_P (dup) && GET_MODE (operand) == GET_MODE (dup))
776 if (HARD_REGISTER_NUM_P (REGNO (operand))
777 || HARD_REGISTER_NUM_P (REGNO (dup)))
779 if (HARD_REGISTER_P (operand))
781 if (HARD_REGISTER_P (dup))
782 continue;
783 hard_regno = REGNO (operand);
784 p = curr_regno_pseudo_map [REGNO (dup)];
786 else
788 hard_regno = REGNO (dup);
789 p = curr_regno_pseudo_map [REGNO (operand)];
791 class = REGNO_REG_CLASS (hard_regno);
792 mode = PSEUDO_MODE (p);
793 cover_class = PSEUDO_COVER_CLASS (p);
794 if (! class_subset_p [class] [cover_class])
795 continue;
796 index
797 = class_hard_reg_index [cover_class] [hard_regno];
798 if (index < 0)
799 continue;
800 if (HARD_REGISTER_P (operand))
801 cost
802 = register_move_cost [mode] [cover_class] [class];
803 else
804 cost
805 = register_move_cost [mode] [class] [cover_class];
806 cost *= freq;
807 PSEUDO_HARD_REG_COSTS (p) [index] -= cost;
808 PSEUDO_CONFLICT_HARD_REG_COSTS (p) [index] -= cost;
809 bound_p = TRUE;
811 else
813 bound_p = TRUE;
814 cp = add_pseudo_copy
815 (curr_regno_pseudo_map [REGNO (dup)],
816 curr_regno_pseudo_map [REGNO (operand)],
817 freq, NULL_RTX);
818 bitmap_set_bit
819 (ira_curr_loop_tree_node->local_copies, cp->num);
822 if (bound_p)
823 continue;
824 /* If an operand dies, prefer its hard register for the
825 output operands by decreasing the hard register cost
826 or creating the corresponding pseudo copies. */
827 for (j = 0; j < recog_data.n_operands; j++)
829 dup = recog_data.operand [j];
831 if (i == j || recog_data.operand_type [j] != OP_OUT
832 || !REG_P (dup))
833 continue;
835 if (HARD_REGISTER_NUM_P (REGNO (operand))
836 || HARD_REGISTER_NUM_P (REGNO (dup)))
838 if (HARD_REGISTER_P (operand))
840 if (HARD_REGISTER_P (dup))
841 continue;
842 hard_regno = REGNO (operand);
843 p = curr_regno_pseudo_map [REGNO (dup)];
845 else
847 hard_regno = REGNO (dup);
848 p = curr_regno_pseudo_map [REGNO (operand)];
850 class = REGNO_REG_CLASS (hard_regno);
851 mode = PSEUDO_MODE (p);
852 cover_class = PSEUDO_COVER_CLASS (p);
853 if (! class_subset_p [class] [cover_class])
854 continue;
855 index
856 = class_hard_reg_index [cover_class] [hard_regno];
857 if (index < 0)
858 continue;
859 if (HARD_REGISTER_P (operand))
860 cost
861 = register_move_cost [mode] [cover_class] [class];
862 else
863 cost
864 = register_move_cost [mode] [class] [cover_class];
865 cost *= (freq < 8 ? 1 : freq / 8);
866 PSEUDO_HARD_REG_COSTS (p) [index] -= cost;
867 PSEUDO_CONFLICT_HARD_REG_COSTS (p) [index] -= cost;
869 else
871 cp = add_pseudo_copy
872 (curr_regno_pseudo_map [REGNO (dup)],
873 curr_regno_pseudo_map [REGNO (operand)],
874 (freq < 8 ? 1 : freq / 8), NULL_RTX);
875 bitmap_set_bit
876 (ira_curr_loop_tree_node->local_copies, cp->num);
884 /* The function checks that CONSTRAINTS permits to use only one hard
885 register. If it is so, the function returns the class of the hard
886 register. Otherwise it returns NO_REGS.
888 EQUIV_COSNT ??? */
889 static enum reg_class
890 single_reg_class (const char *constraints, rtx op, rtx equiv_const)
892 int ignore_p;
893 enum reg_class cl, next_cl;
894 int c;
896 cl = NO_REGS;
897 for (ignore_p = FALSE;
898 (c = *constraints);
899 constraints += CONSTRAINT_LEN (c, constraints))
900 if (c == '#')
901 ignore_p = TRUE;
902 else if (c == ',')
903 ignore_p = FALSE;
904 else if (! ignore_p)
905 switch (c)
907 case ' ':
908 case '\t':
909 case '=':
910 case '+':
911 case '*':
912 case '&':
913 case '%':
914 case '!':
915 case '?':
916 break;
917 case 'i':
918 if (CONSTANT_P (op)
919 || (equiv_const != NULL_RTX && CONSTANT_P (equiv_const)))
920 return NO_REGS;
921 break;
923 case 'n':
924 if (GET_CODE (op) == CONST_INT
925 || (GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == VOIDmode)
926 || (equiv_const != NULL_RTX
927 && (GET_CODE (equiv_const) == CONST_INT
928 || (GET_CODE (equiv_const) == CONST_DOUBLE
929 && GET_MODE (equiv_const) == VOIDmode))))
930 return NO_REGS;
931 break;
933 case 's':
934 if ((CONSTANT_P (op) && GET_CODE (op) != CONST_INT
935 && (GET_CODE (op) != CONST_DOUBLE || GET_MODE (op) != VOIDmode))
936 || (equiv_const != NULL_RTX
937 && CONSTANT_P (equiv_const)
938 && GET_CODE (equiv_const) != CONST_INT
939 && (GET_CODE (equiv_const) != CONST_DOUBLE
940 || GET_MODE (equiv_const) != VOIDmode)))
941 return NO_REGS;
942 break;
944 case 'I':
945 case 'J':
946 case 'K':
947 case 'L':
948 case 'M':
949 case 'N':
950 case 'O':
951 case 'P':
952 if ((GET_CODE (op) == CONST_INT
953 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, constraints))
954 || (equiv_const != NULL_RTX
955 && GET_CODE (equiv_const) == CONST_INT
956 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (equiv_const),
957 c, constraints)))
958 return NO_REGS;
959 break;
961 case 'E':
962 case 'F':
963 if (GET_CODE (op) == CONST_DOUBLE
964 || (GET_CODE (op) == CONST_VECTOR
965 && GET_MODE_CLASS (GET_MODE (op)) == MODE_VECTOR_FLOAT)
966 || (equiv_const != NULL_RTX
967 && (GET_CODE (equiv_const) == CONST_DOUBLE
968 || (GET_CODE (equiv_const) == CONST_VECTOR
969 && (GET_MODE_CLASS (GET_MODE (equiv_const))
970 == MODE_VECTOR_FLOAT)))))
971 return NO_REGS;
972 break;
974 case 'G':
975 case 'H':
976 if ((GET_CODE (op) == CONST_DOUBLE
977 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, constraints))
978 || (equiv_const != NULL_RTX
979 && GET_CODE (equiv_const) == CONST_DOUBLE
980 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (equiv_const,
981 c, constraints)))
982 return NO_REGS;
983 /* ??? what about memory */
984 case 'r':
985 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
986 case 'h': case 'j': case 'k': case 'l':
987 case 'q': case 't': case 'u':
988 case 'v': case 'w': case 'x': case 'y': case 'z':
989 case 'A': case 'B': case 'C': case 'D':
990 case 'Q': case 'R': case 'S': case 'T': case 'U':
991 case 'W': case 'Y': case 'Z':
992 next_cl = (c == 'r'
993 ? GENERAL_REGS
994 : REG_CLASS_FROM_CONSTRAINT (c, constraints));
995 if ((cl != NO_REGS && next_cl != cl)
996 || available_class_regs [next_cl] > 1)
997 return NO_REGS;
998 cl = next_cl;
999 break;
1001 case '0': case '1': case '2': case '3': case '4':
1002 case '5': case '6': case '7': case '8': case '9':
1003 next_cl
1004 = single_reg_class (recog_data.constraints [c - '0'],
1005 recog_data.operand [c - '0'], NULL_RTX);
1006 if ((cl != NO_REGS && next_cl != cl) || next_cl == NO_REGS
1007 || available_class_regs [next_cl] > 1)
1008 return NO_REGS;
1009 cl = next_cl;
1010 break;
1012 default:
1013 return NO_REGS;
1015 return cl;
1018 /* The function checks that operand OP_NUM of the current insn can use
1019 only one hard register. If it is so, the function returns the
1020 class of the hard register. Otherwise it returns NO_REGS. */
1021 static enum reg_class
1022 single_reg_operand_class (int op_num)
1024 if (op_num < 0 || recog_data.n_alternatives == 0)
1025 return NO_REGS;
1026 return single_reg_class (recog_data.constraints [op_num],
1027 recog_data.operand [op_num], NULL_RTX);
1030 /* The function processes input (if IN_P) or output operands to find
1031 pseudo which can use only one hard register and makes other
1032 currently living pseudos conflicting with the hard register. */
1033 static void
1034 process_single_reg_class_operands (int in_p)
1036 int i, regno, px;
1037 enum reg_class cl, cover_class;
1038 rtx operand;
1039 pseudo_t operand_p, p;
1041 for (i = 0; i < recog_data.n_operands; i++)
1043 operand = recog_data.operand [i];
1044 if (in_p && recog_data.operand_type [i] != OP_IN
1045 && recog_data.operand_type [i] != OP_INOUT)
1046 continue;
1047 if (! in_p && recog_data.operand_type [i] != OP_OUT
1048 && recog_data.operand_type [i] != OP_INOUT)
1049 continue;
1050 cl = single_reg_operand_class (i);
1051 if (cl == NO_REGS)
1052 continue;
1054 operand_p = NULL;
1056 if (GET_CODE (operand) == SUBREG)
1057 operand = SUBREG_REG (operand);
1059 if (REG_P (operand)
1060 && (regno = REGNO (operand)) >= FIRST_PSEUDO_REGISTER)
1062 enum machine_mode mode;
1063 enum reg_class cover_class;
1065 operand_p = curr_regno_pseudo_map [regno];
1066 mode = PSEUDO_MODE (operand_p);
1067 cover_class = PSEUDO_MODE (operand_p);
1068 if (class_subset_p [cl] [cover_class]
1069 && (reg_class_size [cl]
1070 <= (unsigned) CLASS_MAX_NREGS (cl, mode)))
1071 PSEUDO_CONFLICT_HARD_REG_COSTS (operand_p)
1072 [class_hard_reg_index [cover_class] [class_hard_regs [cl] [0]]]
1073 -= (in_p
1074 ? register_move_cost [mode] [cover_class] [cl]
1075 : register_move_cost [mode] [cl] [cover_class]);
1078 EXECUTE_IF_SET_IN_PSEUDO_SET (pseudos_live, px,
1080 p = pseudos [px];
1081 cover_class = PSEUDO_COVER_CLASS (p);
1082 if (p != operand_p)
1083 /* We could increase costs of P instead of making it
1084 conflicting with the hard register. But it works worse
1085 because it will be spilled in reload in anyway. */
1086 IOR_HARD_REG_SET (PSEUDO_CONFLICT_HARD_REGS (p),
1087 reg_class_contents [cl]);
1092 /* The function processes insns of the basic block given by its
1093 LOOP_TREE_NODE to update pseudo conflict table. */
1094 static void
1095 process_bb_node_for_conflicts (struct ira_loop_tree_node *loop_tree_node)
1097 int i;
1098 unsigned int j;
1099 basic_block bb;
1100 rtx insn;
1101 edge e;
1102 edge_iterator ei;
1103 bitmap_iterator bi;
1104 bitmap reg_live_in, reg_live_out;
1105 int px = 0;
1107 bb = loop_tree_node->bb;
1108 if (bb != NULL)
1110 for (i = 0; i < reg_class_cover_size; i++)
1111 curr_reg_pressure [reg_class_cover [i]] = 0;
1112 curr_bb_node = loop_tree_node;
1113 curr_regno_pseudo_map = ira_curr_loop_tree_node->regno_pseudo_map;
1114 reg_live_in = DF_UPWARD_LIVE_IN (build_df, bb);
1115 reg_live_out = DF_UPWARD_LIVE_OUT (build_df, bb);
1116 memset (pseudos_live, 0, pseudo_row_words * sizeof (INT_TYPE));
1117 REG_SET_TO_HARD_REG_SET (hard_regs_live, reg_live_in);
1118 AND_COMPL_HARD_REG_SET (hard_regs_live, eliminable_regset);
1119 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1120 if (TEST_HARD_REG_BIT (hard_regs_live, i))
1122 enum reg_class cover_class;
1124 cover_class = class_translate [REGNO_REG_CLASS (i)];
1125 curr_reg_pressure [cover_class]++;
1126 if (curr_bb_node->reg_pressure [cover_class]
1127 < curr_reg_pressure [cover_class])
1128 curr_bb_node->reg_pressure [cover_class]
1129 = curr_reg_pressure [cover_class];
1131 bitmap_clear (pseudos_live_bitmap);
1132 EXECUTE_IF_SET_IN_BITMAP (reg_live_in, FIRST_PSEUDO_REGISTER, j, bi)
1134 pseudo_t p = curr_regno_pseudo_map [j];
1136 ira_assert (p != NULL || REG_N_REFS (j) == 0);
1137 if (p == NULL)
1138 continue;
1139 set_pseudo_live (p);
1140 record_regno_conflict (j);
1143 #ifdef EH_RETURN_DATA_REGNO
1144 if (bb_has_eh_pred (bb))
1146 for (j = 0; ; ++j)
1148 unsigned int regno = EH_RETURN_DATA_REGNO (j);
1150 if (regno == INVALID_REGNUM)
1151 break;
1152 record_regno_conflict (regno);
1155 #endif
1157 /* Pseudos can't go in stack regs at the start of a basic block
1158 that is reached by an abnormal edge. Likewise for call
1159 clobbered regs, because caller-save, fixup_abnormal_edges and
1160 possibly the table driven EH machinery are not quite ready to
1161 handle such pseudos live across such edges. */
1162 FOR_EACH_EDGE (e, ei, bb->preds)
1163 if (e->flags & EDGE_ABNORMAL)
1164 break;
1166 if (e != NULL)
1168 #ifdef STACK_REGS
1169 EXECUTE_IF_SET_IN_PSEUDO_SET (pseudos_live, px,
1171 PSEUDO_NO_STACK_REG_P (pseudos [px]) = TRUE;
1173 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
1174 record_regno_conflict (px);
1175 #endif
1176 /* No need to record conflicts for call clobbered regs if we
1177 have nonlocal labels around, as we don't ever try to
1178 allocate such regs in this case. */
1179 if (! current_function_has_nonlocal_label)
1180 for (px = 0; px < FIRST_PSEUDO_REGISTER; px++)
1181 if (call_used_regs [px])
1182 record_regno_conflict (px);
1185 /* Scan the code of this basic block, noting which pseudos and
1186 hard regs are born or die. When one is born, record a
1187 conflict with all others currently live. */
1188 FOR_BB_INSNS (bb, insn)
1190 rtx link;
1192 if (! INSN_P (insn))
1193 continue;
1195 /* Make regs_set an empty set. */
1196 n_regs_set = 0;
1198 /* Mark any pseudos clobbered by INSN as live, so they
1199 conflict with the inputs. */
1200 note_stores (PATTERN (insn), mark_reg_clobber, NULL);
1202 extract_insn (insn);
1203 process_single_reg_class_operands (TRUE);
1205 /* Mark any pseudos dead after INSN as dead now. */
1206 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1207 if (REG_NOTE_KIND (link) == REG_DEAD)
1208 mark_reg_death (XEXP (link, 0));
1210 if (CALL_P (insn))
1212 HARD_REG_SET clobbered_regs;
1214 get_call_invalidated_used_regs (insn, &clobbered_regs, FALSE);
1215 IOR_HARD_REG_SET (cfun->emit->call_used_regs, clobbered_regs);
1216 EXECUTE_IF_SET_IN_PSEUDO_SET (pseudos_live, i,
1218 int freq;
1219 pseudo_t p = pseudos [i];
1221 freq = REG_FREQ_FROM_BB (BLOCK_FOR_INSN (insn));
1222 if (freq == 0)
1223 freq = 1;
1224 PSEUDO_CALL_FREQ (p) += freq;
1225 PSEUDO_CALLS_CROSSED (p) [PSEUDO_CALLS_CROSSED_NUM (p)++]
1226 = insn;
1227 ira_assert (PSEUDO_CALLS_CROSSED_NUM (p)
1228 <= REG_N_CALLS_CROSSED (PSEUDO_REGNO (p)));
1230 /* Don't allocate pseudos that cross calls, if this
1231 function receives a nonlocal goto. */
1232 if (current_function_has_nonlocal_label)
1233 SET_HARD_REG_SET (PSEUDO_CONFLICT_HARD_REGS (p));
1237 /* Mark any pseudos set in INSN as live, and mark them as
1238 conflicting with all other live pseudos. Clobbers are
1239 processed again, so they conflict with the pseudos that
1240 are set. */
1241 note_stores (PATTERN (insn), mark_reg_store, NULL);
1243 #ifdef AUTO_INC_DEC
1244 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1245 if (REG_NOTE_KIND (link) == REG_INC)
1246 mark_reg_store (XEXP (link, 0), NULL_RTX, NULL);
1247 #endif
1249 /* If INSN has multiple outputs, then any pseudo that dies
1250 here and is used inside of an output must conflict with
1251 the other outputs.
1253 It is unsafe to use !single_set here since it will ignore
1254 an unused output. Just because an output is unused does
1255 not mean the compiler can assume the side effect will not
1256 occur. Consider if PSEUDO appears in the address of an
1257 output and we reload the output. If we allocate PSEUDO
1258 to the same hard register as an unused output we could
1259 set the hard register before the output reload insn. */
1260 if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
1261 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
1262 if (REG_NOTE_KIND (link) == REG_DEAD)
1264 int i;
1265 int used_in_output = 0;
1266 rtx reg = XEXP (link, 0);
1268 for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
1270 rtx set = XVECEXP (PATTERN (insn), 0, i);
1272 if (GET_CODE (set) == SET
1273 && ! REG_P (SET_DEST (set))
1274 && ! rtx_equal_p (reg, SET_DEST (set))
1275 && reg_overlap_mentioned_p (reg, SET_DEST (set)))
1276 used_in_output = 1;
1278 if (used_in_output)
1279 mark_reg_conflicts (reg);
1282 process_single_reg_class_operands (FALSE);
1284 /* Mark any pseudos set in INSN and then never used. */
1285 while (n_regs_set-- > 0)
1287 rtx note = find_regno_note (insn, REG_UNUSED,
1288 REGNO (regs_set [n_regs_set]));
1289 if (note)
1290 mark_reg_death (XEXP (note, 0));
1292 add_pseudo_copies (insn);
1295 /* Propagate register pressure: */
1296 if (loop_tree_node != ira_loop_tree_root)
1297 for (i = 0; i < reg_class_cover_size; i++)
1299 enum reg_class cover_class;
1301 cover_class = reg_class_cover [i];
1302 if (loop_tree_node->reg_pressure [cover_class]
1303 > loop_tree_node->father->reg_pressure [cover_class])
1304 loop_tree_node->father->reg_pressure [cover_class]
1305 = loop_tree_node->reg_pressure [cover_class];
1309 /* The function builds pseudo conflict table by traversing all basic
1310 blocks and their insns. */
1311 static void
1312 build_conflict_bit_table (void)
1314 pseudo_row_words = (pseudos_num + INT_BITS - 1) / INT_BITS;
1315 conflicts = ira_allocate (sizeof (INT_TYPE)
1316 * pseudos_num * pseudo_row_words);
1317 memset (conflicts, 0, sizeof (INT_TYPE) * pseudos_num * pseudo_row_words);
1318 pseudos_live = ira_allocate (sizeof (INT_TYPE) * pseudo_row_words);
1319 pseudos_live_bitmap = ira_allocate_bitmap ();
1320 /* Make a vector that mark_reg_{store,clobber} will store in. */
1321 regs_set = ira_allocate (sizeof (rtx) * max_parallel * 2);
1322 traverse_loop_tree (ira_loop_tree_root, NULL, process_bb_node_for_conflicts);
1323 /* Clean up. */
1324 ira_free (regs_set);
1325 ira_free_bitmap (pseudos_live_bitmap);
1326 ira_free (pseudos_live);
1329 /* The function propagates info about pseudo P to the corresponding
1330 pseudo on upper loop tree level. So pseudos on upper levels
1331 accumulate information about the corresponding pseudos in nested
1332 loops. */
1333 static void
1334 propagate_pseudo_info (pseudo_t p)
1336 int regno, j, n, pn, father_pn, another_father_pn;
1337 pseudo_t father_p, another_p, another_father_p;
1338 struct ira_loop_tree_node *father;
1339 struct pseudo_copy *cp, *next_cp;
1341 regno = PSEUDO_REGNO (p);
1342 if ((father = PSEUDO_LOOP_TREE_NODE (p)->father) != NULL
1343 && (father_p = father->regno_pseudo_map [regno]) != NULL)
1345 PSEUDO_CALL_FREQ (father_p) += PSEUDO_CALL_FREQ (p);
1346 #ifdef STACK_REGS
1347 if (PSEUDO_NO_STACK_REG_P (p))
1348 PSEUDO_NO_STACK_REG_P (father_p) = TRUE;
1349 #endif
1350 IOR_HARD_REG_SET (PSEUDO_CONFLICT_HARD_REGS (father_p),
1351 PSEUDO_CONFLICT_HARD_REGS (p));
1352 pn = PSEUDO_NUM (p);
1353 EXECUTE_IF_SET_IN_PSEUDO_SET (conflicts + pn * pseudo_row_words, j,
1355 another_p = pseudos [j];
1356 if ((another_father_p = (father->regno_pseudo_map
1357 [PSEUDO_REGNO (another_p)])) == NULL)
1358 continue;
1359 father_pn = PSEUDO_NUM (father_p);
1360 another_father_pn = PSEUDO_NUM (another_father_p);
1361 SET_PSEUDO_CONFLICT_ROW
1362 (conflicts + father_pn * pseudo_row_words, another_father_pn);
1363 SET_PSEUDO_CONFLICT_ROW
1364 (conflicts + another_father_pn * pseudo_row_words, father_pn);
1366 if ((n = PSEUDO_CALLS_CROSSED_NUM (p)) != 0)
1368 memcpy (PSEUDO_CALLS_CROSSED (father_p)
1369 + PSEUDO_CALLS_CROSSED_NUM (father_p),
1370 PSEUDO_CALLS_CROSSED (p), sizeof (rtx) * n);
1371 PSEUDO_CALLS_CROSSED_NUM (father_p) += n;
1372 ira_assert (PSEUDO_CALLS_CROSSED_NUM (father_p)
1373 <= REG_N_CALLS_CROSSED (regno));
1375 for (cp = PSEUDO_COPIES (p); cp != NULL; cp = next_cp)
1377 if (cp->first == p)
1379 next_cp = cp->next_first_pseudo_copy;
1380 another_p = cp->second;
1382 else if (cp->second == p)
1384 next_cp = cp->next_second_pseudo_copy;
1385 another_p = cp->first;
1387 else
1388 gcc_unreachable ();
1389 if ((another_father_p = (father->regno_pseudo_map
1390 [PSEUDO_REGNO (another_p)])) != NULL)
1391 add_pseudo_copy
1392 (father_p, another_father_p, cp->freq, cp->move_insn);
1397 /* The function propagates info about pseudos to the corresponding
1398 pseudos on upper loop tree level. */
1399 static void
1400 propagate_info (void)
1402 int i;
1403 pseudo_t p;
1405 for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--)
1406 for (p = regno_pseudo_map [i]; p != NULL; p = PSEUDO_NEXT_REGNO_PSEUDO (p))
1407 propagate_pseudo_info (p);
1410 /* If CONFLICTP (i, j) is TRUE, make sure CONFLICTP (j, i) is also TRUE. */
1411 static void
1412 mirror_conflicts (void)
1414 int i, j;
1415 unsigned INT_TYPE mask;
1416 int rw = pseudo_row_words;
1417 int rwb = rw * INT_BITS;
1418 INT_TYPE *p = conflicts;
1419 INT_TYPE *q0 = conflicts;
1420 INT_TYPE *q1, *q2;
1422 for (i = pseudos_num - 1, mask = 1; i >= 0; i--, mask <<= 1)
1424 if (! mask)
1426 mask = 1;
1427 q0++;
1429 for (j = pseudo_row_words - 1, q1 = q0; j >= 0; j--, q1 += rwb)
1431 unsigned INT_TYPE word;
1433 for (word = (unsigned INT_TYPE) *p++, q2 = q1;
1434 word;
1435 word >>= 1, q2 += rw)
1437 if (word & 1)
1438 *q2 |= mask;
1444 /* The function returns TRUE if pseudo-registers REGNO1 and REGNO2
1445 conflict. The function is called from reload. */
1447 pseudo_reg_conflict_p (int regno1, int regno2)
1449 int p_no1, p_no2;
1451 ira_assert (regno1 >= FIRST_PSEUDO_REGISTER
1452 && regno2 >= FIRST_PSEUDO_REGISTER);
1453 /* Reg info caclulated by dataflow infrastructure can be different
1454 from one calculated by regclass. */
1455 if (curr_regno_pseudo_map [regno1] == NULL
1456 || curr_regno_pseudo_map [regno2] == NULL)
1457 return FALSE;
1458 p_no1 = PSEUDO_NUM (curr_regno_pseudo_map [regno1]);
1459 p_no2 = PSEUDO_NUM (curr_regno_pseudo_map [regno2]);
1460 ira_assert (p_no1 >= 0 && p_no1 < pseudos_num
1461 && p_no2 >= 0 && p_no2 < pseudos_num);
1462 return CONFLICTP (p_no1, p_no2) != 0;
1465 /* Remove copies involving conflicting pseudos. */
1466 static void
1467 remove_conflict_pseudo_copies (void)
1469 int i;
1470 pseudo_t p;
1471 copy_t cp, next_cp;
1472 varray_type conflict_pseudo_copy_varray;
1474 VARRAY_GENERIC_PTR_NOGC_INIT (conflict_pseudo_copy_varray, get_max_uid (),
1475 "copies of conflicting pseudos");
1476 for (i = 0; i < pseudos_num; i++)
1478 p = pseudos [i];
1479 for (cp = PSEUDO_COPIES (p); cp != NULL; cp = next_cp)
1480 if (cp->first == p)
1481 next_cp = cp->next_first_pseudo_copy;
1482 else
1484 next_cp = cp->next_second_pseudo_copy;
1485 VARRAY_PUSH_GENERIC_PTR (conflict_pseudo_copy_varray, cp);
1488 for (i = VARRAY_ACTIVE_SIZE (conflict_pseudo_copy_varray) - 1; i >= 0; i--)
1490 cp = VARRAY_GENERIC_PTR (conflict_pseudo_copy_varray, i);
1491 if (CONFLICTP (PSEUDO_NUM (cp->first), PSEUDO_NUM (cp->second)))
1492 remove_pseudo_copy_from_list (cp);
1494 VARRAY_FREE (conflict_pseudo_copy_varray);
1497 /* The function builds conflict vectors of all pseudos from the
1498 conflict table. */
1499 static void
1500 build_pseudo_conflict_vects (void)
1502 int i, j, px;
1503 pseudo_t p, *conflict_pseudos, *vec;
1505 conflict_pseudos = ira_allocate (sizeof (pseudo_t) * pseudos_num);
1506 for (i = 0; i < pseudos_num; i++)
1508 p = pseudos [i];
1509 ira_assert (i == PSEUDO_NUM (p));
1510 px = 0;
1511 EXECUTE_IF_SET_IN_PSEUDO_SET (conflicts + i * pseudo_row_words, j,
1513 conflict_pseudos [px++] = pseudos [j];
1515 allocate_pseudo_conflicts (p, px);
1516 vec = PSEUDO_CONFLICT_PSEUDO_VEC (p);
1517 memcpy (vec, conflict_pseudos, sizeof (pseudo_t) * px);
1518 vec [px] = NULL;
1519 PSEUDO_CONFLICT_PSEUDO_VEC_ACTIVE_SIZE (p) = px;
1521 ira_free (conflict_pseudos);
1526 /* The function propagates information about pseudos modified inside
1527 the loops. */
1528 static void
1529 propagate_modified_regnos (struct ira_loop_tree_node *loop_tree_node)
1531 if (loop_tree_node->bb != NULL || loop_tree_node == ira_loop_tree_root)
1532 return;
1533 bitmap_ior_into (loop_tree_node->father->modified_regnos,
1534 loop_tree_node->modified_regnos);
1539 /* The function outputs information about pseudo conflicts to FILE. */
1540 static void
1541 print_conflicts (FILE *file)
1543 int i;
1545 for (i = 0; i < pseudos_num; i++)
1547 int j;
1548 pseudo_t p;
1549 basic_block bb;
1551 p = pseudos [i];
1552 fprintf (file, ";; p%d(r%d,", PSEUDO_NUM (p), PSEUDO_REGNO (p));
1553 if ((bb = PSEUDO_LOOP_TREE_NODE (p)->bb) != NULL)
1554 fprintf (file, "b%d", bb->index);
1555 else
1556 fprintf (file, "l%d", PSEUDO_LOOP_TREE_NODE (p)->loop->num);
1557 fprintf (file, ") conflicts:");
1558 for (j = 0; j < pseudos_num; j++)
1559 if (CONFLICTP (j, i))
1561 fprintf (file, " p%d(r%d,",
1562 PSEUDO_NUM (pseudos [j]), PSEUDO_REGNO (pseudos [j]));
1563 if ((bb = PSEUDO_LOOP_TREE_NODE (pseudos [j])->bb) != NULL)
1564 fprintf (file, "b%d)", bb->index);
1565 else
1566 fprintf (file, "l%d)",
1567 PSEUDO_LOOP_TREE_NODE (pseudos [j])->loop->num);
1569 fprintf (file, "\n;; conflict hard regs:");
1570 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
1571 if (TEST_HARD_REG_BIT (PSEUDO_CONFLICT_HARD_REGS (p), j))
1572 fprintf (file, " %d", j);
1573 fprintf (file, "\n");
1576 fprintf (file, "\n");
1579 /* The function outputs information about pseudo conflicts to
1580 stderr. */
1581 void
1582 debug_conflicts (void)
1584 print_conflicts (stderr);
1589 /* Entry function which builds pseudo conflicts. */
1590 void
1591 ira_build_conflicts (void)
1593 int i;
1594 pseudo_t p;
1596 build_conflict_bit_table ();
1597 mirror_conflicts ();
1598 if (flag_ira_algorithm == IRA_ALGORITHM_REGIONAL
1599 || flag_ira_algorithm == IRA_ALGORITHM_MIXED)
1600 propagate_info ();
1601 /* We need finished conflict table for the subsequent call. */
1602 remove_conflict_pseudo_copies ();
1603 build_pseudo_conflict_vects ();
1604 for (i = 0; i < pseudos_num; i++)
1606 p = pseudos [i];
1607 if (PSEUDO_CALLS_CROSSED_NUM (p) != 0)
1609 if (! flag_caller_saves
1610 || (flag_ira_split_around_calls
1611 && ((ira_max_regno_before > PSEUDO_REGNO (p)
1612 && (reg_equiv_const [PSEUDO_REGNO (p)]
1613 || reg_equiv_invariant_p [PSEUDO_REGNO (p)]))
1614 || (ira_max_regno_before <= PSEUDO_REGNO (p)
1615 && PSEUDO_REGNO (p) < ira_max_regno_call_before))))
1616 IOR_HARD_REG_SET (PSEUDO_CONFLICT_HARD_REGS (p),
1617 call_used_reg_set);
1618 else
1619 IOR_HARD_REG_SET (PSEUDO_CONFLICT_HARD_REGS (p),
1620 no_caller_save_reg_set);
1623 traverse_loop_tree (ira_loop_tree_root, NULL, propagate_modified_regnos);
1624 if (ira_dump_file != NULL)
1625 print_conflicts (ira_dump_file);