Mercurial > hg > CbC > CbC_gcc
comparison gcc/ira-costs.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | 58ad6c70ea60 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
1 /* IRA hard register and memory cost calculation for allocnos. | 1 /* IRA hard register and memory cost calculation for allocnos or pseudos. |
2 Copyright (C) 2006, 2007, 2008 | 2 Copyright (C) 2006, 2007, 2008, 2009 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 Contributed by Vladimir Makarov <vmakarov@redhat.com>. | 4 Contributed by Vladimir Makarov <vmakarov@redhat.com>. |
5 | 5 |
6 This file is part of GCC. | 6 This file is part of GCC. |
7 | 7 |
36 #include "toplev.h" | 36 #include "toplev.h" |
37 #include "target.h" | 37 #include "target.h" |
38 #include "params.h" | 38 #include "params.h" |
39 #include "ira-int.h" | 39 #include "ira-int.h" |
40 | 40 |
41 /* The file contains code is similar to one in regclass but the code | 41 /* The flags is set up every time when we calculate pseudo register |
42 works on the allocno basis. */ | 42 classes through function ira_set_pseudo_classes. */ |
43 static bool pseudo_classes_defined_p = false; | |
44 | |
45 /* TRUE if we work with allocnos. Otherwise we work with pseudos. */ | |
46 static bool allocno_p; | |
47 | |
48 /* Number of elements in arrays `in_inc_dec' and `costs'. */ | |
49 static int cost_elements_num; | |
43 | 50 |
44 #ifdef FORBIDDEN_INC_DEC_CLASSES | 51 #ifdef FORBIDDEN_INC_DEC_CLASSES |
45 /* Indexed by n, is TRUE if allocno with number N is used in an | 52 /* Indexed by n, is TRUE if allocno or pseudo with number N is used in |
46 auto-inc or auto-dec context. */ | 53 an auto-inc or auto-dec context. */ |
47 static bool *in_inc_dec; | 54 static bool *in_inc_dec; |
48 #endif | 55 #endif |
49 | 56 |
50 /* The `costs' struct records the cost of using hard registers of each | 57 /* The `costs' struct records the cost of using hard registers of each |
51 class considered for the calculation and of using memory for each | 58 class considered for the calculation and of using memory for each |
52 allocno. */ | 59 allocno or pseudo. */ |
53 struct costs | 60 struct costs |
54 { | 61 { |
55 int mem_cost; | 62 int mem_cost; |
56 /* Costs for register classes start here. We process only some | 63 /* Costs for register classes start here. We process only some |
57 register classes (cover classes on the 1st cost calculation | 64 register classes (cover classes on the 1st cost calculation |
72 | 79 |
73 /* Allocated once, and used for the cost calculation. */ | 80 /* Allocated once, and used for the cost calculation. */ |
74 static struct costs *op_costs[MAX_RECOG_OPERANDS]; | 81 static struct costs *op_costs[MAX_RECOG_OPERANDS]; |
75 static struct costs *this_op_costs[MAX_RECOG_OPERANDS]; | 82 static struct costs *this_op_costs[MAX_RECOG_OPERANDS]; |
76 | 83 |
77 /* Original and accumulated costs of each class for each allocno. */ | 84 /* Costs of each class for each allocno or pseudo. */ |
78 static struct costs *allocno_costs, *total_costs; | 85 static struct costs *costs; |
86 | |
87 /* Accumulated costs of each class for each allocno. */ | |
88 static struct costs *total_allocno_costs; | |
79 | 89 |
80 /* Classes used for cost calculation. They may be different on | 90 /* Classes used for cost calculation. They may be different on |
81 different iterations of the cost calculations or in different | 91 different iterations of the cost calculations or in different |
82 optimization modes. */ | 92 optimization modes. */ |
83 static enum reg_class *cost_classes; | 93 static enum reg_class *cost_classes; |
90 static int cost_class_nums[N_REG_CLASSES]; | 100 static int cost_class_nums[N_REG_CLASSES]; |
91 | 101 |
92 /* It is the current size of struct costs. */ | 102 /* It is the current size of struct costs. */ |
93 static int struct_costs_size; | 103 static int struct_costs_size; |
94 | 104 |
95 /* Return pointer to structure containing costs of allocno with given | 105 /* Return pointer to structure containing costs of allocno or pseudo |
96 NUM in array ARR. */ | 106 with given NUM in array ARR. */ |
97 #define COSTS_OF_ALLOCNO(arr, num) \ | 107 #define COSTS(arr, num) \ |
98 ((struct costs *) ((char *) (arr) + (num) * struct_costs_size)) | 108 ((struct costs *) ((char *) (arr) + (num) * struct_costs_size)) |
99 | 109 |
100 /* Record register class preferences of each allocno. Null value | 110 /* Return index in COSTS when processing reg with REGNO. */ |
101 means no preferences. It happens on the 1st iteration of the cost | 111 #define COST_INDEX(regno) (allocno_p \ |
102 calculation. */ | 112 ? ALLOCNO_NUM (ira_curr_regno_allocno_map[regno]) \ |
103 static enum reg_class *allocno_pref; | 113 : (int) regno) |
104 | 114 |
105 /* Allocated buffers for allocno_pref. */ | 115 /* Record register class preferences of each allocno or pseudo. Null |
106 static enum reg_class *allocno_pref_buffer; | 116 value means no preferences. It happens on the 1st iteration of the |
107 | 117 cost calculation. */ |
108 /* Record register class of each allocno with the same regno. */ | 118 static enum reg_class *pref; |
109 static enum reg_class *common_classes; | 119 |
120 /* Allocated buffers for pref. */ | |
121 static enum reg_class *pref_buffer; | |
122 | |
123 /* Record cover register class of each allocno with the same regno. */ | |
124 static enum reg_class *regno_cover_class; | |
110 | 125 |
111 /* Execution frequency of the current insn. */ | 126 /* Execution frequency of the current insn. */ |
112 static int frequency; | 127 static int frequency; |
113 | 128 |
114 | 129 |
187 the alternatives. */ | 202 the alternatives. */ |
188 static void | 203 static void |
189 record_reg_classes (int n_alts, int n_ops, rtx *ops, | 204 record_reg_classes (int n_alts, int n_ops, rtx *ops, |
190 enum machine_mode *modes, const char **constraints, | 205 enum machine_mode *modes, const char **constraints, |
191 rtx insn, struct costs **op_costs, | 206 rtx insn, struct costs **op_costs, |
192 enum reg_class *allocno_pref) | 207 enum reg_class *pref) |
193 { | 208 { |
194 int alt; | 209 int alt; |
195 int i, j, k; | 210 int i, j, k; |
196 rtx set; | 211 rtx set; |
197 int insn_allows_mem[MAX_RECOG_OPERANDS]; | 212 int insn_allows_mem[MAX_RECOG_OPERANDS]; |
203 with the cost for each operand in that alternative. */ | 218 with the cost for each operand in that alternative. */ |
204 for (alt = 0; alt < n_alts; alt++) | 219 for (alt = 0; alt < n_alts; alt++) |
205 { | 220 { |
206 enum reg_class classes[MAX_RECOG_OPERANDS]; | 221 enum reg_class classes[MAX_RECOG_OPERANDS]; |
207 int allows_mem[MAX_RECOG_OPERANDS]; | 222 int allows_mem[MAX_RECOG_OPERANDS]; |
208 int rclass; | 223 enum reg_class rclass; |
209 int alt_fail = 0; | 224 int alt_fail = 0; |
210 int alt_cost = 0, op_cost_add; | 225 int alt_cost = 0, op_cost_add; |
211 | 226 |
212 for (i = 0; i < n_ops; i++) | 227 for (i = 0; i < n_ops; i++) |
213 { | 228 { |
318 first pass, add a cost to this alternative | 333 first pass, add a cost to this alternative |
319 corresponding to what we would add if this allocno | 334 corresponding to what we would add if this allocno |
320 were not in the appropriate class. We could use | 335 were not in the appropriate class. We could use |
321 cover class here but it is less accurate | 336 cover class here but it is less accurate |
322 approximation. */ | 337 approximation. */ |
323 if (allocno_pref) | 338 if (pref) |
324 { | 339 { |
325 enum reg_class pref_class | 340 enum reg_class pref_class = pref[COST_INDEX (REGNO (op))]; |
326 = allocno_pref[ALLOCNO_NUM | |
327 (ira_curr_regno_allocno_map | |
328 [REGNO (op)])]; | |
329 | 341 |
330 if (pref_class == NO_REGS) | 342 if (pref_class == NO_REGS) |
331 alt_cost | 343 alt_cost |
332 += ((recog_data.operand_type[i] != OP_IN | 344 += ((recog_data.operand_type[i] != OP_IN |
333 ? ira_memory_move_cost[mode][classes[i]][0] | 345 ? ira_memory_move_cost[mode][classes[i]][0] |
353 | 365 |
354 constraints[i] = p; | 366 constraints[i] = p; |
355 continue; | 367 continue; |
356 } | 368 } |
357 } | 369 } |
358 | 370 |
359 /* Scan all the constraint letters. See if the operand | 371 /* Scan all the constraint letters. See if the operand |
360 matches any of the constraints. Collect the valid | 372 matches any of the constraints. Collect the valid |
361 register classes and see if this operand accepts | 373 register classes and see if this operand accepts |
362 memory. */ | 374 memory. */ |
363 while ((c = *p)) | 375 while ((c = *p)) |
427 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p)) | 439 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p)) |
428 win = 1; | 440 win = 1; |
429 break; | 441 break; |
430 | 442 |
431 case 's': | 443 case 's': |
432 if (GET_CODE (op) == CONST_INT | 444 if (CONST_INT_P (op) |
433 || (GET_CODE (op) == CONST_DOUBLE | 445 || (GET_CODE (op) == CONST_DOUBLE |
434 && GET_MODE (op) == VOIDmode)) | 446 && GET_MODE (op) == VOIDmode)) |
435 break; | 447 break; |
436 | 448 |
437 case 'i': | 449 case 'i': |
439 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))) | 451 && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))) |
440 win = 1; | 452 win = 1; |
441 break; | 453 break; |
442 | 454 |
443 case 'n': | 455 case 'n': |
444 if (GET_CODE (op) == CONST_INT | 456 if (CONST_INT_P (op) |
445 || (GET_CODE (op) == CONST_DOUBLE | 457 || (GET_CODE (op) == CONST_DOUBLE |
446 && GET_MODE (op) == VOIDmode)) | 458 && GET_MODE (op) == VOIDmode)) |
447 win = 1; | 459 win = 1; |
448 break; | 460 break; |
449 | 461 |
453 case 'L': | 465 case 'L': |
454 case 'M': | 466 case 'M': |
455 case 'N': | 467 case 'N': |
456 case 'O': | 468 case 'O': |
457 case 'P': | 469 case 'P': |
458 if (GET_CODE (op) == CONST_INT | 470 if (CONST_INT_P (op) |
459 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p)) | 471 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p)) |
460 win = 1; | 472 win = 1; |
461 break; | 473 break; |
462 | 474 |
463 case 'X': | 475 case 'X': |
562 first pass, add a cost to this alternative | 574 first pass, add a cost to this alternative |
563 corresponding to what we would add if this allocno | 575 corresponding to what we would add if this allocno |
564 were not in the appropriate class. We could use | 576 were not in the appropriate class. We could use |
565 cover class here but it is less accurate | 577 cover class here but it is less accurate |
566 approximation. */ | 578 approximation. */ |
567 if (allocno_pref) | 579 if (pref) |
568 { | 580 { |
569 enum reg_class pref_class | 581 enum reg_class pref_class = pref[COST_INDEX (REGNO (op))]; |
570 = allocno_pref[ALLOCNO_NUM | |
571 (ira_curr_regno_allocno_map | |
572 [REGNO (op)])]; | |
573 | 582 |
574 if (pref_class == NO_REGS) | 583 if (pref_class == NO_REGS) |
575 alt_cost | 584 alt_cost |
576 += ((recog_data.operand_type[i] != OP_IN | 585 += ((recog_data.operand_type[i] != OP_IN |
577 ? ira_memory_move_cost[mode][classes[i]][0] | 586 ? ira_memory_move_cost[mode][classes[i]][0] |
635 pp->cost[k] | 644 pp->cost[k] |
636 = MIN (pp->cost[k], (qq->cost[k] + op_cost_add) * scale); | 645 = MIN (pp->cost[k], (qq->cost[k] + op_cost_add) * scale); |
637 } | 646 } |
638 } | 647 } |
639 | 648 |
640 for (i = 0; i < n_ops; i++) | 649 if (allocno_p) |
641 { | 650 for (i = 0; i < n_ops; i++) |
642 ira_allocno_t a; | 651 { |
643 rtx op = ops[i]; | 652 ira_allocno_t a; |
644 | 653 rtx op = ops[i]; |
645 if (! REG_P (op) || REGNO (op) < FIRST_PSEUDO_REGISTER) | 654 |
646 continue; | 655 if (! REG_P (op) || REGNO (op) < FIRST_PSEUDO_REGISTER) |
647 a = ira_curr_regno_allocno_map [REGNO (op)]; | 656 continue; |
648 if (! ALLOCNO_BAD_SPILL_P (a) && insn_allows_mem[i] == 0) | 657 a = ira_curr_regno_allocno_map [REGNO (op)]; |
649 ALLOCNO_BAD_SPILL_P (a) = true; | 658 if (! ALLOCNO_BAD_SPILL_P (a) && insn_allows_mem[i] == 0) |
650 } | 659 ALLOCNO_BAD_SPILL_P (a) = true; |
660 } | |
651 | 661 |
652 /* If this insn is a single set copying operand 1 to operand 0 and | 662 /* If this insn is a single set copying operand 1 to operand 0 and |
653 one operand is an allocno with the other a hard reg or an allocno | 663 one operand is an allocno with the other a hard reg or an allocno |
654 that prefers a hard register that is in its own register class | 664 that prefers a hard register that is in its own register class |
655 then we may want to adjust the cost of that register class to -1. | 665 then we may want to adjust the cost of that register class to -1. |
670 for (i = 0; i <= 1; i++) | 680 for (i = 0; i <= 1; i++) |
671 if (REGNO (ops[i]) >= FIRST_PSEUDO_REGISTER) | 681 if (REGNO (ops[i]) >= FIRST_PSEUDO_REGISTER) |
672 { | 682 { |
673 unsigned int regno = REGNO (ops[!i]); | 683 unsigned int regno = REGNO (ops[!i]); |
674 enum machine_mode mode = GET_MODE (ops[!i]); | 684 enum machine_mode mode = GET_MODE (ops[!i]); |
675 int rclass; | 685 enum reg_class rclass; |
676 unsigned int nr; | 686 unsigned int nr; |
677 | 687 |
678 if (regno < FIRST_PSEUDO_REGISTER) | 688 if (regno < FIRST_PSEUDO_REGISTER) |
679 for (k = 0; k < cost_classes_num; k++) | 689 for (k = 0; k < cost_classes_num; k++) |
680 { | 690 { |
691 nr < (unsigned) hard_regno_nregs[regno][mode]; | 701 nr < (unsigned) hard_regno_nregs[regno][mode]; |
692 nr++) | 702 nr++) |
693 if (! TEST_HARD_REG_BIT (reg_class_contents[rclass], | 703 if (! TEST_HARD_REG_BIT (reg_class_contents[rclass], |
694 regno + nr)) | 704 regno + nr)) |
695 break; | 705 break; |
696 | 706 |
697 if (nr == (unsigned) hard_regno_nregs[regno][mode]) | 707 if (nr == (unsigned) hard_regno_nregs[regno][mode]) |
698 op_costs[i]->cost[k] = -frequency; | 708 op_costs[i]->cost[k] = -frequency; |
699 } | 709 } |
700 } | 710 } |
701 } | 711 } |
875 up in the wrong place. If the operand is a pseudo-register, | 885 up in the wrong place. If the operand is a pseudo-register, |
876 show it is being used in an INC_DEC context. */ | 886 show it is being used in an INC_DEC context. */ |
877 #ifdef FORBIDDEN_INC_DEC_CLASSES | 887 #ifdef FORBIDDEN_INC_DEC_CLASSES |
878 if (REG_P (XEXP (x, 0)) | 888 if (REG_P (XEXP (x, 0)) |
879 && REGNO (XEXP (x, 0)) >= FIRST_PSEUDO_REGISTER) | 889 && REGNO (XEXP (x, 0)) >= FIRST_PSEUDO_REGISTER) |
880 in_inc_dec[ALLOCNO_NUM (ira_curr_regno_allocno_map | 890 in_inc_dec[COST_INDEX (REGNO (XEXP (x, 0)))] = true; |
881 [REGNO (XEXP (x, 0))])] = true; | |
882 #endif | 891 #endif |
883 record_address_regs (mode, XEXP (x, 0), 0, code, SCRATCH, 2 * scale); | 892 record_address_regs (mode, XEXP (x, 0), 0, code, SCRATCH, 2 * scale); |
884 break; | 893 break; |
885 | 894 |
886 case REG: | 895 case REG: |
887 { | 896 { |
888 struct costs *pp; | 897 struct costs *pp; |
889 int i, k; | 898 enum reg_class i; |
899 int k; | |
890 | 900 |
891 if (REGNO (x) < FIRST_PSEUDO_REGISTER) | 901 if (REGNO (x) < FIRST_PSEUDO_REGISTER) |
892 break; | 902 break; |
893 | 903 |
894 ALLOCNO_BAD_SPILL_P (ira_curr_regno_allocno_map[REGNO (x)]) = true; | 904 if (allocno_p) |
895 pp = COSTS_OF_ALLOCNO (allocno_costs, | 905 ALLOCNO_BAD_SPILL_P (ira_curr_regno_allocno_map[REGNO (x)]) = true; |
896 ALLOCNO_NUM (ira_curr_regno_allocno_map | 906 pp = COSTS (costs, COST_INDEX (REGNO (x))); |
897 [REGNO (x)])); | |
898 pp->mem_cost += (ira_memory_move_cost[Pmode][rclass][1] * scale) / 2; | 907 pp->mem_cost += (ira_memory_move_cost[Pmode][rclass][1] * scale) / 2; |
899 for (k = 0; k < cost_classes_num; k++) | 908 for (k = 0; k < cost_classes_num; k++) |
900 { | 909 { |
901 i = cost_classes[k]; | 910 i = cost_classes[k]; |
902 pp->cost[k] | 911 pp->cost[k] |
919 | 928 |
920 | 929 |
921 | 930 |
922 /* Calculate the costs of insn operands. */ | 931 /* Calculate the costs of insn operands. */ |
923 static void | 932 static void |
924 record_operand_costs (rtx insn, struct costs **op_costs, | 933 record_operand_costs (rtx insn, struct costs **op_costs, enum reg_class *pref) |
925 enum reg_class *allocno_pref) | |
926 { | 934 { |
927 const char *constraints[MAX_RECOG_OPERANDS]; | 935 const char *constraints[MAX_RECOG_OPERANDS]; |
928 enum machine_mode modes[MAX_RECOG_OPERANDS]; | 936 enum machine_mode modes[MAX_RECOG_OPERANDS]; |
929 int i; | 937 int i; |
930 | 938 |
973 | 981 |
974 xconstraints[i] = constraints[i+1]; | 982 xconstraints[i] = constraints[i+1]; |
975 xconstraints[i+1] = constraints[i]; | 983 xconstraints[i+1] = constraints[i]; |
976 record_reg_classes (recog_data.n_alternatives, recog_data.n_operands, | 984 record_reg_classes (recog_data.n_alternatives, recog_data.n_operands, |
977 recog_data.operand, modes, | 985 recog_data.operand, modes, |
978 xconstraints, insn, op_costs, allocno_pref); | 986 xconstraints, insn, op_costs, pref); |
979 } | 987 } |
980 record_reg_classes (recog_data.n_alternatives, recog_data.n_operands, | 988 record_reg_classes (recog_data.n_alternatives, recog_data.n_operands, |
981 recog_data.operand, modes, | 989 recog_data.operand, modes, |
982 constraints, insn, op_costs, allocno_pref); | 990 constraints, insn, op_costs, pref); |
983 } | 991 } |
984 | 992 |
985 | 993 |
986 | 994 |
987 /* Process one insn INSN. Scan it and record each time it would save | 995 /* Process one insn INSN. Scan it and record each time it would save |
992 { | 1000 { |
993 enum rtx_code pat_code; | 1001 enum rtx_code pat_code; |
994 rtx set, note; | 1002 rtx set, note; |
995 int i, k; | 1003 int i, k; |
996 | 1004 |
997 if (!INSN_P (insn)) | 1005 if (!NONDEBUG_INSN_P (insn)) |
998 return insn; | 1006 return insn; |
999 | 1007 |
1000 pat_code = GET_CODE (PATTERN (insn)); | 1008 pat_code = GET_CODE (PATTERN (insn)); |
1001 if (pat_code == USE || pat_code == CLOBBER || pat_code == ASM_INPUT | 1009 if (pat_code == USE || pat_code == CLOBBER || pat_code == ASM_INPUT |
1002 || pat_code == ADDR_VEC || pat_code == ADDR_DIFF_VEC) | 1010 || pat_code == ADDR_VEC || pat_code == ADDR_DIFF_VEC) |
1012 && (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != NULL_RTX | 1020 && (note = find_reg_note (insn, REG_EQUIV, NULL_RTX)) != NULL_RTX |
1013 && MEM_P (XEXP (note, 0))) | 1021 && MEM_P (XEXP (note, 0))) |
1014 { | 1022 { |
1015 enum reg_class cl = GENERAL_REGS; | 1023 enum reg_class cl = GENERAL_REGS; |
1016 rtx reg = SET_DEST (set); | 1024 rtx reg = SET_DEST (set); |
1017 int num = ALLOCNO_NUM (ira_curr_regno_allocno_map[REGNO (reg)]); | 1025 int num = COST_INDEX (REGNO (reg)); |
1018 | 1026 |
1019 if (allocno_pref) | 1027 if (pref) |
1020 cl = allocno_pref[num]; | 1028 cl = pref[num]; |
1021 COSTS_OF_ALLOCNO (allocno_costs, num)->mem_cost | 1029 COSTS (costs, num)->mem_cost |
1022 -= ira_memory_move_cost[GET_MODE (reg)][cl][1] * frequency; | 1030 -= ira_memory_move_cost[GET_MODE (reg)][cl][1] * frequency; |
1023 record_address_regs (GET_MODE (SET_SRC (set)), XEXP (SET_SRC (set), 0), | 1031 record_address_regs (GET_MODE (SET_SRC (set)), XEXP (SET_SRC (set), 0), |
1024 0, MEM, SCRATCH, frequency * 2); | 1032 0, MEM, SCRATCH, frequency * 2); |
1025 } | 1033 } |
1026 | 1034 |
1027 record_operand_costs (insn, op_costs, allocno_pref); | 1035 record_operand_costs (insn, op_costs, pref); |
1028 | 1036 |
1029 /* Now add the cost for each operand to the total costs for its | 1037 /* Now add the cost for each operand to the total costs for its |
1030 allocno. */ | 1038 allocno. */ |
1031 for (i = 0; i < recog_data.n_operands; i++) | 1039 for (i = 0; i < recog_data.n_operands; i++) |
1032 if (REG_P (recog_data.operand[i]) | 1040 if (REG_P (recog_data.operand[i]) |
1033 && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER) | 1041 && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER) |
1034 { | 1042 { |
1035 int regno = REGNO (recog_data.operand[i]); | 1043 int regno = REGNO (recog_data.operand[i]); |
1036 struct costs *p | 1044 struct costs *p = COSTS (costs, COST_INDEX (regno)); |
1037 = COSTS_OF_ALLOCNO (allocno_costs, | |
1038 ALLOCNO_NUM (ira_curr_regno_allocno_map[regno])); | |
1039 struct costs *q = op_costs[i]; | 1045 struct costs *q = op_costs[i]; |
1040 | 1046 |
1041 p->mem_cost += q->mem_cost; | 1047 p->mem_cost += q->mem_cost; |
1042 for (k = 0; k < cost_classes_num; k++) | 1048 for (k = 0; k < cost_classes_num; k++) |
1043 p->cost[k] += q->cost[k]; | 1049 p->cost[k] += q->cost[k]; |
1048 | 1054 |
1049 | 1055 |
1050 | 1056 |
1051 /* Print allocnos costs to file F. */ | 1057 /* Print allocnos costs to file F. */ |
1052 static void | 1058 static void |
1053 print_costs (FILE *f) | 1059 print_allocno_costs (FILE *f) |
1054 { | 1060 { |
1055 int k; | 1061 int k; |
1056 ira_allocno_t a; | 1062 ira_allocno_t a; |
1057 ira_allocno_iterator ai; | 1063 ira_allocno_iterator ai; |
1058 | 1064 |
1065 ira_assert (allocno_p); | |
1059 fprintf (f, "\n"); | 1066 fprintf (f, "\n"); |
1060 FOR_EACH_ALLOCNO (a, ai) | 1067 FOR_EACH_ALLOCNO (a, ai) |
1061 { | 1068 { |
1062 int i, rclass; | 1069 int i, rclass; |
1063 basic_block bb; | 1070 basic_block bb; |
1082 PSEUDO_REGNO_MODE (regno)) | 1089 PSEUDO_REGNO_MODE (regno)) |
1083 #endif | 1090 #endif |
1084 ) | 1091 ) |
1085 { | 1092 { |
1086 fprintf (f, " %s:%d", reg_class_names[rclass], | 1093 fprintf (f, " %s:%d", reg_class_names[rclass], |
1087 COSTS_OF_ALLOCNO (allocno_costs, i)->cost[k]); | 1094 COSTS (costs, i)->cost[k]); |
1088 if (flag_ira_region == IRA_REGION_ALL | 1095 if (flag_ira_region == IRA_REGION_ALL |
1089 || flag_ira_region == IRA_REGION_MIXED) | 1096 || flag_ira_region == IRA_REGION_MIXED) |
1090 fprintf (f, ",%d", COSTS_OF_ALLOCNO (total_costs, i)->cost[k]); | 1097 fprintf (f, ",%d", COSTS (total_allocno_costs, i)->cost[k]); |
1091 } | 1098 } |
1092 } | 1099 } |
1093 fprintf (f, " MEM:%i\n", COSTS_OF_ALLOCNO (allocno_costs, i)->mem_cost); | 1100 fprintf (f, " MEM:%i\n", COSTS (costs, i)->mem_cost); |
1101 } | |
1102 } | |
1103 | |
1104 /* Print pseudo costs to file F. */ | |
1105 static void | |
1106 print_pseudo_costs (FILE *f) | |
1107 { | |
1108 int regno, k; | |
1109 int rclass; | |
1110 | |
1111 ira_assert (! allocno_p); | |
1112 fprintf (f, "\n"); | |
1113 for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--) | |
1114 { | |
1115 if (regno_reg_rtx[regno] == NULL_RTX) | |
1116 continue; | |
1117 fprintf (f, " r%d costs:", regno); | |
1118 for (k = 0; k < cost_classes_num; k++) | |
1119 { | |
1120 rclass = cost_classes[k]; | |
1121 if (contains_reg_of_mode[rclass][PSEUDO_REGNO_MODE (regno)] | |
1122 #ifdef FORBIDDEN_INC_DEC_CLASSES | |
1123 && (! in_inc_dec[regno] || ! forbidden_inc_dec_class[rclass]) | |
1124 #endif | |
1125 #ifdef CANNOT_CHANGE_MODE_CLASS | |
1126 && ! invalid_mode_change_p (regno, (enum reg_class) rclass, | |
1127 PSEUDO_REGNO_MODE (regno)) | |
1128 #endif | |
1129 ) | |
1130 fprintf (f, " %s:%d", reg_class_names[rclass], | |
1131 COSTS (costs, regno)->cost[k]); | |
1132 } | |
1133 fprintf (f, " MEM:%i\n", COSTS (costs, regno)->mem_cost); | |
1094 } | 1134 } |
1095 } | 1135 } |
1096 | 1136 |
1097 /* Traverse the BB represented by LOOP_TREE_NODE to update the allocno | 1137 /* Traverse the BB represented by LOOP_TREE_NODE to update the allocno |
1098 costs. */ | 1138 costs. */ |
1099 static void | 1139 static void |
1100 process_bb_node_for_costs (ira_loop_tree_node_t loop_tree_node) | 1140 process_bb_for_costs (basic_block bb) |
1101 { | 1141 { |
1102 basic_block bb; | |
1103 rtx insn; | 1142 rtx insn; |
1104 | 1143 |
1105 bb = loop_tree_node->bb; | |
1106 if (bb == NULL) | |
1107 return; | |
1108 frequency = REG_FREQ_FROM_BB (bb); | 1144 frequency = REG_FREQ_FROM_BB (bb); |
1109 if (frequency == 0) | 1145 if (frequency == 0) |
1110 frequency = 1; | 1146 frequency = 1; |
1111 FOR_BB_INSNS (bb, insn) | 1147 FOR_BB_INSNS (bb, insn) |
1112 insn = scan_one_insn (insn); | 1148 insn = scan_one_insn (insn); |
1113 } | 1149 } |
1114 | 1150 |
1115 /* Find costs of register classes and memory for allocnos and their | 1151 /* Traverse the BB represented by LOOP_TREE_NODE to update the allocno |
1116 best costs. */ | 1152 costs. */ |
1117 static void | 1153 static void |
1118 find_allocno_class_costs (void) | 1154 process_bb_node_for_costs (ira_loop_tree_node_t loop_tree_node) |
1119 { | 1155 { |
1120 int i, k; | 1156 basic_block bb; |
1157 | |
1158 bb = loop_tree_node->bb; | |
1159 if (bb != NULL) | |
1160 process_bb_for_costs (bb); | |
1161 } | |
1162 | |
1163 /* Find costs of register classes and memory for allocnos or pseudos | |
1164 and their best costs. Set up preferred, alternative and cover | |
1165 classes for pseudos. */ | |
1166 static void | |
1167 find_costs_and_classes (FILE *dump_file) | |
1168 { | |
1169 int i, k, start; | |
1121 int pass; | 1170 int pass; |
1122 basic_block bb; | 1171 basic_block bb; |
1123 | 1172 |
1124 init_recog (); | 1173 init_recog (); |
1125 #ifdef FORBIDDEN_INC_DEC_CLASSES | 1174 #ifdef FORBIDDEN_INC_DEC_CLASSES |
1126 in_inc_dec = ira_allocate (sizeof (bool) * ira_allocnos_num); | 1175 in_inc_dec = ira_allocate (sizeof (bool) * cost_elements_num); |
1127 #endif /* FORBIDDEN_INC_DEC_CLASSES */ | 1176 #endif /* FORBIDDEN_INC_DEC_CLASSES */ |
1128 allocno_pref = NULL; | 1177 pref = NULL; |
1178 start = 0; | |
1179 if (!resize_reg_info () && allocno_p && pseudo_classes_defined_p) | |
1180 { | |
1181 ira_allocno_t a; | |
1182 ira_allocno_iterator ai; | |
1183 | |
1184 pref = pref_buffer; | |
1185 FOR_EACH_ALLOCNO (a, ai) | |
1186 pref[ALLOCNO_NUM (a)] = reg_preferred_class (ALLOCNO_REGNO (a)); | |
1187 if (flag_expensive_optimizations) | |
1188 start = 1; | |
1189 } | |
1190 if (allocno_p) | |
1191 /* Clear the flag for the next compiled function. */ | |
1192 pseudo_classes_defined_p = false; | |
1129 /* Normally we scan the insns once and determine the best class to | 1193 /* Normally we scan the insns once and determine the best class to |
1130 use for each allocno. However, if -fexpensive-optimizations are | 1194 use for each allocno. However, if -fexpensive-optimizations are |
1131 on, we do so twice, the second time using the tentative best | 1195 on, we do so twice, the second time using the tentative best |
1132 classes to guide the selection. */ | 1196 classes to guide the selection. */ |
1133 for (pass = 0; pass <= flag_expensive_optimizations; pass++) | 1197 for (pass = start; pass <= flag_expensive_optimizations; pass++) |
1134 { | 1198 { |
1135 if (internal_flag_ira_verbose > 0 && ira_dump_file) | 1199 if ((!allocno_p || internal_flag_ira_verbose > 0) && dump_file) |
1136 fprintf (ira_dump_file, "\nPass %i for finding allocno costs\n\n", | 1200 fprintf (dump_file, |
1137 pass); | 1201 "\nPass %i for finding pseudo/allocno costs\n\n", pass); |
1138 /* We could use only cover classes. Unfortunately it does not | 1202 /* We could use only cover classes. Unfortunately it does not |
1139 work well for some targets where some subclass of cover class | 1203 work well for some targets where some subclass of cover class |
1140 is costly and wrong cover class is chosen. */ | 1204 is costly and wrong cover class is chosen. */ |
1141 for (i = 0; i < N_REG_CLASSES; i++) | 1205 for (i = 0; i < N_REG_CLASSES; i++) |
1142 cost_class_nums[i] = -1; | 1206 cost_class_nums[i] = -1; |
1151 } | 1215 } |
1152 struct_costs_size | 1216 struct_costs_size |
1153 = sizeof (struct costs) + sizeof (int) * (cost_classes_num - 1); | 1217 = sizeof (struct costs) + sizeof (int) * (cost_classes_num - 1); |
1154 /* Zero out our accumulation of the cost of each class for each | 1218 /* Zero out our accumulation of the cost of each class for each |
1155 allocno. */ | 1219 allocno. */ |
1156 memset (allocno_costs, 0, ira_allocnos_num * struct_costs_size); | 1220 memset (costs, 0, cost_elements_num * struct_costs_size); |
1157 #ifdef FORBIDDEN_INC_DEC_CLASSES | 1221 #ifdef FORBIDDEN_INC_DEC_CLASSES |
1158 memset (in_inc_dec, 0, ira_allocnos_num * sizeof (bool)); | 1222 memset (in_inc_dec, 0, cost_elements_num * sizeof (bool)); |
1159 #endif | 1223 #endif |
1160 | 1224 |
1161 /* Scan the instructions and record each time it would save code | 1225 if (allocno_p) |
1162 to put a certain allocno in a certain class. */ | 1226 { |
1163 ira_traverse_loop_tree (true, ira_loop_tree_root, | 1227 /* Scan the instructions and record each time it would save code |
1164 process_bb_node_for_costs, NULL); | 1228 to put a certain allocno in a certain class. */ |
1165 | 1229 ira_traverse_loop_tree (true, ira_loop_tree_root, |
1166 memcpy (total_costs, allocno_costs, | 1230 process_bb_node_for_costs, NULL); |
1167 max_struct_costs_size * ira_allocnos_num); | 1231 |
1232 memcpy (total_allocno_costs, costs, | |
1233 max_struct_costs_size * ira_allocnos_num); | |
1234 } | |
1235 else | |
1236 { | |
1237 basic_block bb; | |
1238 | |
1239 FOR_EACH_BB (bb) | |
1240 process_bb_for_costs (bb); | |
1241 } | |
1242 | |
1168 if (pass == 0) | 1243 if (pass == 0) |
1169 allocno_pref = allocno_pref_buffer; | 1244 pref = pref_buffer; |
1170 | 1245 |
1171 /* Now for each allocno look at how desirable each class is and | 1246 /* Now for each allocno look at how desirable each class is and |
1172 find which class is preferred. */ | 1247 find which class is preferred. */ |
1173 for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--) | 1248 for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--) |
1174 { | 1249 { |
1179 enum reg_class best, alt_class; | 1254 enum reg_class best, alt_class; |
1180 #ifdef FORBIDDEN_INC_DEC_CLASSES | 1255 #ifdef FORBIDDEN_INC_DEC_CLASSES |
1181 int inc_dec_p = false; | 1256 int inc_dec_p = false; |
1182 #endif | 1257 #endif |
1183 | 1258 |
1184 if (ira_regno_allocno_map[i] == NULL) | 1259 if (! allocno_p) |
1185 continue; | |
1186 memset (temp_costs, 0, struct_costs_size); | |
1187 /* Find cost of all allocnos with the same regno. */ | |
1188 for (a = ira_regno_allocno_map[i]; | |
1189 a != NULL; | |
1190 a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) | |
1191 { | 1260 { |
1192 a_num = ALLOCNO_NUM (a); | 1261 if (regno_reg_rtx[i] == NULL_RTX) |
1193 if ((flag_ira_region == IRA_REGION_ALL | 1262 continue; |
1194 || flag_ira_region == IRA_REGION_MIXED) | 1263 #ifdef FORBIDDEN_INC_DEC_CLASSES |
1195 && (parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) != NULL | 1264 inc_dec_p = in_inc_dec[i]; |
1196 && (parent_a = parent->regno_allocno_map[i]) != NULL | 1265 #endif |
1197 /* There are no caps yet. */ | 1266 memcpy (temp_costs, COSTS (costs, i), struct_costs_size); |
1198 && bitmap_bit_p (ALLOCNO_LOOP_TREE_NODE (a)->border_allocnos, | 1267 } |
1199 ALLOCNO_NUM (a))) | 1268 else |
1269 { | |
1270 if (ira_regno_allocno_map[i] == NULL) | |
1271 continue; | |
1272 memset (temp_costs, 0, struct_costs_size); | |
1273 /* Find cost of all allocnos with the same regno. */ | |
1274 for (a = ira_regno_allocno_map[i]; | |
1275 a != NULL; | |
1276 a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) | |
1200 { | 1277 { |
1201 /* Propagate costs to upper levels in the region | 1278 a_num = ALLOCNO_NUM (a); |
1202 tree. */ | 1279 if ((flag_ira_region == IRA_REGION_ALL |
1203 parent_a_num = ALLOCNO_NUM (parent_a); | 1280 || flag_ira_region == IRA_REGION_MIXED) |
1281 && (parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) != NULL | |
1282 && (parent_a = parent->regno_allocno_map[i]) != NULL | |
1283 /* There are no caps yet. */ | |
1284 && bitmap_bit_p (ALLOCNO_LOOP_TREE_NODE | |
1285 (a)->border_allocnos, | |
1286 ALLOCNO_NUM (a))) | |
1287 { | |
1288 /* Propagate costs to upper levels in the region | |
1289 tree. */ | |
1290 parent_a_num = ALLOCNO_NUM (parent_a); | |
1291 for (k = 0; k < cost_classes_num; k++) | |
1292 COSTS (total_allocno_costs, parent_a_num)->cost[k] | |
1293 += COSTS (total_allocno_costs, a_num)->cost[k]; | |
1294 COSTS (total_allocno_costs, parent_a_num)->mem_cost | |
1295 += COSTS (total_allocno_costs, a_num)->mem_cost; | |
1296 } | |
1204 for (k = 0; k < cost_classes_num; k++) | 1297 for (k = 0; k < cost_classes_num; k++) |
1205 COSTS_OF_ALLOCNO (total_costs, parent_a_num)->cost[k] | 1298 temp_costs->cost[k] += COSTS (costs, a_num)->cost[k]; |
1206 += COSTS_OF_ALLOCNO (total_costs, a_num)->cost[k]; | 1299 temp_costs->mem_cost += COSTS (costs, a_num)->mem_cost; |
1207 COSTS_OF_ALLOCNO (total_costs, parent_a_num)->mem_cost | 1300 #ifdef FORBIDDEN_INC_DEC_CLASSES |
1208 += COSTS_OF_ALLOCNO (total_costs, a_num)->mem_cost; | 1301 if (in_inc_dec[a_num]) |
1302 inc_dec_p = true; | |
1303 #endif | |
1209 } | 1304 } |
1210 for (k = 0; k < cost_classes_num; k++) | |
1211 temp_costs->cost[k] | |
1212 += COSTS_OF_ALLOCNO (allocno_costs, a_num)->cost[k]; | |
1213 temp_costs->mem_cost | |
1214 += COSTS_OF_ALLOCNO (allocno_costs, a_num)->mem_cost; | |
1215 #ifdef FORBIDDEN_INC_DEC_CLASSES | |
1216 if (in_inc_dec[a_num]) | |
1217 inc_dec_p = true; | |
1218 #endif | |
1219 } | 1305 } |
1220 best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1; | 1306 best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1; |
1221 best = ALL_REGS; | 1307 best = ALL_REGS; |
1222 alt_class = NO_REGS; | 1308 alt_class = NO_REGS; |
1223 /* Find best common class for all allocnos with the same | 1309 /* Find best common class for all allocnos with the same |
1249 && (reg_class_size[reg_class_subunion[alt_class][rclass]] | 1335 && (reg_class_size[reg_class_subunion[alt_class][rclass]] |
1250 > reg_class_size[alt_class])) | 1336 > reg_class_size[alt_class])) |
1251 alt_class = reg_class_subunion[alt_class][rclass]; | 1337 alt_class = reg_class_subunion[alt_class][rclass]; |
1252 } | 1338 } |
1253 alt_class = ira_class_translate[alt_class]; | 1339 alt_class = ira_class_translate[alt_class]; |
1340 if (best_cost > temp_costs->mem_cost) | |
1341 regno_cover_class[i] = NO_REGS; | |
1342 else if (flag_ira_algorithm == IRA_ALGORITHM_PRIORITY) | |
1343 /* Make the common class the biggest class of best and | |
1344 alt_class. */ | |
1345 regno_cover_class[i] = alt_class == NO_REGS ? best : alt_class; | |
1346 else | |
1347 /* Make the common class a cover class. Remember all | |
1348 allocnos with the same regno should have the same cover | |
1349 class. */ | |
1350 regno_cover_class[i] = ira_class_translate[best]; | |
1254 if (pass == flag_expensive_optimizations) | 1351 if (pass == flag_expensive_optimizations) |
1255 { | 1352 { |
1256 if (best_cost > temp_costs->mem_cost) | 1353 if (best_cost > temp_costs->mem_cost) |
1257 best = alt_class = NO_REGS; | 1354 best = alt_class = NO_REGS; |
1258 else if (best == alt_class) | 1355 else if (best == alt_class) |
1259 alt_class = NO_REGS; | 1356 alt_class = NO_REGS; |
1260 setup_reg_classes (i, best, alt_class); | 1357 setup_reg_classes (i, best, alt_class, regno_cover_class[i]); |
1261 if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL) | 1358 if ((!allocno_p || internal_flag_ira_verbose > 2) |
1262 fprintf (ira_dump_file, | 1359 && dump_file != NULL) |
1263 " r%d: preferred %s, alternative %s\n", | 1360 fprintf (dump_file, |
1264 i, reg_class_names[best], reg_class_names[alt_class]); | 1361 " r%d: preferred %s, alternative %s, cover %s\n", |
1362 i, reg_class_names[best], reg_class_names[alt_class], | |
1363 reg_class_names[regno_cover_class[i]]); | |
1265 } | 1364 } |
1266 if (best_cost > temp_costs->mem_cost) | 1365 if (! allocno_p) |
1267 common_classes[i] = NO_REGS; | 1366 { |
1268 else if (flag_ira_algorithm == IRA_ALGORITHM_PRIORITY) | 1367 pref[i] = best_cost > temp_costs->mem_cost ? NO_REGS : best; |
1269 /* Make the common class the biggest class of best and | 1368 continue; |
1270 alt_class. */ | 1369 } |
1271 common_classes[i] = alt_class == NO_REGS ? best : alt_class; | |
1272 else | |
1273 /* Make the common class a cover class. Remember all | |
1274 allocnos with the same regno should have the same cover | |
1275 class. */ | |
1276 common_classes[i] = ira_class_translate[best]; | |
1277 for (a = ira_regno_allocno_map[i]; | 1370 for (a = ira_regno_allocno_map[i]; |
1278 a != NULL; | 1371 a != NULL; |
1279 a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) | 1372 a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) |
1280 { | 1373 { |
1281 a_num = ALLOCNO_NUM (a); | 1374 a_num = ALLOCNO_NUM (a); |
1282 if (common_classes[i] == NO_REGS) | 1375 if (regno_cover_class[i] == NO_REGS) |
1283 best = NO_REGS; | 1376 best = NO_REGS; |
1284 else | 1377 else |
1285 { | 1378 { |
1286 /* Finding best class which is subset of the common | 1379 /* Finding best class which is subset of the common |
1287 class. */ | 1380 class. */ |
1288 best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1; | 1381 best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1; |
1289 allocno_cost = best_cost; | 1382 allocno_cost = best_cost; |
1290 best = ALL_REGS; | 1383 best = ALL_REGS; |
1291 for (k = 0; k < cost_classes_num; k++) | 1384 for (k = 0; k < cost_classes_num; k++) |
1292 { | 1385 { |
1293 rclass = cost_classes[k]; | 1386 rclass = cost_classes[k]; |
1294 if (! ira_class_subset_p[rclass][common_classes[i]]) | 1387 if (! ira_class_subset_p[rclass][regno_cover_class[i]]) |
1295 continue; | 1388 continue; |
1296 /* Ignore classes that are too small for this | 1389 /* Ignore classes that are too small for this |
1297 operand or invalid for an operand that was | 1390 operand or invalid for an operand that was |
1298 auto-incremented. */ | 1391 auto-incremented. */ |
1299 if (! contains_reg_of_mode[rclass][PSEUDO_REGNO_MODE (i)] | 1392 if (! contains_reg_of_mode[rclass][PSEUDO_REGNO_MODE (i)] |
1304 || invalid_mode_change_p (i, (enum reg_class) rclass, | 1397 || invalid_mode_change_p (i, (enum reg_class) rclass, |
1305 PSEUDO_REGNO_MODE (i)) | 1398 PSEUDO_REGNO_MODE (i)) |
1306 #endif | 1399 #endif |
1307 ) | 1400 ) |
1308 ; | 1401 ; |
1309 else if (COSTS_OF_ALLOCNO (total_costs, a_num)->cost[k] | 1402 else if (COSTS (total_allocno_costs, a_num)->cost[k] |
1310 < best_cost) | 1403 < best_cost) |
1311 { | 1404 { |
1312 best_cost | 1405 best_cost |
1313 = COSTS_OF_ALLOCNO (total_costs, a_num)->cost[k]; | 1406 = COSTS (total_allocno_costs, a_num)->cost[k]; |
1314 allocno_cost | 1407 allocno_cost = COSTS (costs, a_num)->cost[k]; |
1315 = COSTS_OF_ALLOCNO (allocno_costs, a_num)->cost[k]; | |
1316 best = (enum reg_class) rclass; | 1408 best = (enum reg_class) rclass; |
1317 } | 1409 } |
1318 else if (COSTS_OF_ALLOCNO (total_costs, a_num)->cost[k] | 1410 else if (COSTS (total_allocno_costs, a_num)->cost[k] |
1319 == best_cost) | 1411 == best_cost) |
1320 { | 1412 { |
1321 best = ira_reg_class_union[best][rclass]; | 1413 best = ira_reg_class_union[best][rclass]; |
1322 allocno_cost | 1414 allocno_cost |
1323 = MAX (allocno_cost, | 1415 = MAX (allocno_cost, COSTS (costs, a_num)->cost[k]); |
1324 COSTS_OF_ALLOCNO (allocno_costs, | |
1325 a_num)->cost[k]); | |
1326 } | 1416 } |
1327 } | 1417 } |
1328 ALLOCNO_COVER_CLASS_COST (a) = allocno_cost; | 1418 ALLOCNO_COVER_CLASS_COST (a) = allocno_cost; |
1329 } | 1419 } |
1330 ira_assert (flag_ira_algorithm == IRA_ALGORITHM_PRIORITY | 1420 ira_assert (flag_ira_algorithm == IRA_ALGORITHM_PRIORITY |
1331 || ira_class_translate[best] == common_classes[i]); | 1421 || ira_class_translate[best] == regno_cover_class[i]); |
1332 if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL | 1422 if (internal_flag_ira_verbose > 2 && dump_file != NULL |
1333 && (pass == 0 || allocno_pref[a_num] != best)) | 1423 && (pass == 0 || pref[a_num] != best)) |
1334 { | 1424 { |
1335 fprintf (ira_dump_file, " a%d (r%d,", a_num, i); | 1425 fprintf (dump_file, " a%d (r%d,", a_num, i); |
1336 if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL) | 1426 if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL) |
1337 fprintf (ira_dump_file, "b%d", bb->index); | 1427 fprintf (dump_file, "b%d", bb->index); |
1338 else | 1428 else |
1339 fprintf (ira_dump_file, "l%d", | 1429 fprintf (dump_file, "l%d", |
1340 ALLOCNO_LOOP_TREE_NODE (a)->loop->num); | 1430 ALLOCNO_LOOP_TREE_NODE (a)->loop->num); |
1341 fprintf (ira_dump_file, ") best %s, cover %s\n", | 1431 fprintf (dump_file, ") best %s, cover %s\n", |
1342 reg_class_names[best], | 1432 reg_class_names[best], |
1343 reg_class_names[common_classes[i]]); | 1433 reg_class_names[regno_cover_class[i]]); |
1344 } | 1434 } |
1345 allocno_pref[a_num] = best; | 1435 pref[a_num] = best; |
1346 } | 1436 } |
1347 } | 1437 } |
1348 | 1438 |
1349 if (internal_flag_ira_verbose > 4 && ira_dump_file) | 1439 if (internal_flag_ira_verbose > 4 && dump_file) |
1350 { | 1440 { |
1351 print_costs (ira_dump_file); | 1441 if (allocno_p) |
1352 fprintf (ira_dump_file,"\n"); | 1442 print_allocno_costs (dump_file); |
1443 else | |
1444 print_pseudo_costs (dump_file); | |
1445 fprintf (dump_file,"\n"); | |
1353 } | 1446 } |
1354 } | 1447 } |
1355 #ifdef FORBIDDEN_INC_DEC_CLASSES | 1448 #ifdef FORBIDDEN_INC_DEC_CLASSES |
1356 ira_free (in_inc_dec); | 1449 ira_free (in_inc_dec); |
1357 #endif | 1450 #endif |
1381 freq = REG_FREQ_FROM_BB (bb); | 1474 freq = REG_FREQ_FROM_BB (bb); |
1382 if (freq == 0) | 1475 if (freq == 0) |
1383 freq = 1; | 1476 freq = 1; |
1384 FOR_BB_INSNS (bb, insn) | 1477 FOR_BB_INSNS (bb, insn) |
1385 { | 1478 { |
1386 if (! INSN_P (insn)) | 1479 if (!NONDEBUG_INSN_P (insn)) |
1387 continue; | 1480 continue; |
1388 set = single_set (insn); | 1481 set = single_set (insn); |
1389 if (set == NULL_RTX) | 1482 if (set == NULL_RTX) |
1390 continue; | 1483 continue; |
1391 dst = SET_DEST (set); | 1484 dst = SET_DEST (set); |
1439 setup_allocno_cover_class_and_costs (void) | 1532 setup_allocno_cover_class_and_costs (void) |
1440 { | 1533 { |
1441 int i, j, n, regno, num; | 1534 int i, j, n, regno, num; |
1442 int *reg_costs; | 1535 int *reg_costs; |
1443 enum reg_class cover_class, rclass; | 1536 enum reg_class cover_class, rclass; |
1444 enum machine_mode mode; | |
1445 HARD_REG_SET *pref; | |
1446 ira_allocno_t a; | 1537 ira_allocno_t a; |
1447 ira_allocno_iterator ai; | 1538 ira_allocno_iterator ai; |
1448 | 1539 |
1540 ira_assert (allocno_p); | |
1449 FOR_EACH_ALLOCNO (a, ai) | 1541 FOR_EACH_ALLOCNO (a, ai) |
1450 { | 1542 { |
1451 i = ALLOCNO_NUM (a); | 1543 i = ALLOCNO_NUM (a); |
1452 mode = ALLOCNO_MODE (a); | 1544 cover_class = regno_cover_class[ALLOCNO_REGNO (a)]; |
1453 cover_class = common_classes[ALLOCNO_REGNO (a)]; | 1545 ira_assert (pref[i] == NO_REGS || cover_class != NO_REGS); |
1454 ira_assert (allocno_pref[i] == NO_REGS || cover_class != NO_REGS); | 1546 ALLOCNO_MEMORY_COST (a) = COSTS (costs, i)->mem_cost; |
1455 ALLOCNO_MEMORY_COST (a) = COSTS_OF_ALLOCNO (allocno_costs, i)->mem_cost; | |
1456 ira_set_allocno_cover_class (a, cover_class); | 1547 ira_set_allocno_cover_class (a, cover_class); |
1457 if (cover_class == NO_REGS) | 1548 if (cover_class == NO_REGS) |
1458 continue; | 1549 continue; |
1459 ALLOCNO_AVAILABLE_REGS_NUM (a) = ira_available_class_regs[cover_class]; | 1550 ALLOCNO_AVAILABLE_REGS_NUM (a) = ira_available_class_regs[cover_class]; |
1460 pref = ®_class_contents[allocno_pref[i]]; | 1551 if (optimize && ALLOCNO_COVER_CLASS (a) != pref[i]) |
1461 if (optimize && ALLOCNO_COVER_CLASS (a) != allocno_pref[i]) | |
1462 { | 1552 { |
1463 n = ira_class_hard_regs_num[cover_class]; | 1553 n = ira_class_hard_regs_num[cover_class]; |
1464 ALLOCNO_HARD_REG_COSTS (a) | 1554 ALLOCNO_HARD_REG_COSTS (a) |
1465 = reg_costs = ira_allocate_cost_vector (cover_class); | 1555 = reg_costs = ira_allocate_cost_vector (cover_class); |
1466 for (j = n - 1; j >= 0; j--) | 1556 for (j = n - 1; j >= 0; j--) |
1467 { | 1557 { |
1468 regno = ira_class_hard_regs[cover_class][j]; | 1558 regno = ira_class_hard_regs[cover_class][j]; |
1469 if (TEST_HARD_REG_BIT (*pref, regno)) | 1559 if (TEST_HARD_REG_BIT (reg_class_contents[pref[i]], regno)) |
1470 reg_costs[j] = ALLOCNO_COVER_CLASS_COST (a); | 1560 reg_costs[j] = ALLOCNO_COVER_CLASS_COST (a); |
1471 else | 1561 else |
1472 { | 1562 { |
1473 rclass = REGNO_REG_CLASS (regno); | 1563 rclass = REGNO_REG_CLASS (regno); |
1474 num = cost_class_nums[rclass]; | 1564 num = cost_class_nums[rclass]; |
1479 the allocno cover class. */ | 1569 the allocno cover class. */ |
1480 ira_assert (ira_hard_regno_cover_class[regno] | 1570 ira_assert (ira_hard_regno_cover_class[regno] |
1481 == cover_class); | 1571 == cover_class); |
1482 num = cost_class_nums[cover_class]; | 1572 num = cost_class_nums[cover_class]; |
1483 } | 1573 } |
1484 reg_costs[j] = COSTS_OF_ALLOCNO (allocno_costs, i)->cost[num]; | 1574 reg_costs[j] = COSTS (costs, i)->cost[num]; |
1485 } | 1575 } |
1486 } | 1576 } |
1487 } | 1577 } |
1488 } | 1578 } |
1489 if (optimize) | 1579 if (optimize) |
1566 free_ira_costs (); | 1656 free_ira_costs (); |
1567 } | 1657 } |
1568 | 1658 |
1569 | 1659 |
1570 | 1660 |
1661 /* Common initialization function for ira_costs and | |
1662 ira_set_pseudo_classes. */ | |
1663 static void | |
1664 init_costs (void) | |
1665 { | |
1666 init_subregs_of_mode (); | |
1667 costs = (struct costs *) ira_allocate (max_struct_costs_size | |
1668 * cost_elements_num); | |
1669 pref_buffer | |
1670 = (enum reg_class *) ira_allocate (sizeof (enum reg_class) | |
1671 * cost_elements_num); | |
1672 regno_cover_class | |
1673 = (enum reg_class *) ira_allocate (sizeof (enum reg_class) | |
1674 * max_reg_num ()); | |
1675 } | |
1676 | |
1677 /* Common finalization function for ira_costs and | |
1678 ira_set_pseudo_classes. */ | |
1679 static void | |
1680 finish_costs (void) | |
1681 { | |
1682 ira_free (regno_cover_class); | |
1683 ira_free (pref_buffer); | |
1684 ira_free (costs); | |
1685 } | |
1686 | |
1571 /* Entry function which defines cover class, memory and hard register | 1687 /* Entry function which defines cover class, memory and hard register |
1572 costs for each allocno. */ | 1688 costs for each allocno. */ |
1573 void | 1689 void |
1574 ira_costs (void) | 1690 ira_costs (void) |
1575 { | 1691 { |
1576 allocno_costs = (struct costs *) ira_allocate (max_struct_costs_size | 1692 allocno_p = true; |
1577 * ira_allocnos_num); | 1693 cost_elements_num = ira_allocnos_num; |
1578 total_costs = (struct costs *) ira_allocate (max_struct_costs_size | 1694 init_costs (); |
1579 * ira_allocnos_num); | 1695 total_allocno_costs = (struct costs *) ira_allocate (max_struct_costs_size |
1580 allocno_pref_buffer | 1696 * ira_allocnos_num); |
1581 = (enum reg_class *) ira_allocate (sizeof (enum reg_class) | 1697 find_costs_and_classes (ira_dump_file); |
1582 * ira_allocnos_num); | |
1583 common_classes | |
1584 = (enum reg_class *) ira_allocate (sizeof (enum reg_class) | |
1585 * max_reg_num ()); | |
1586 find_allocno_class_costs (); | |
1587 setup_allocno_cover_class_and_costs (); | 1698 setup_allocno_cover_class_and_costs (); |
1588 ira_free (common_classes); | 1699 finish_costs (); |
1589 ira_free (allocno_pref_buffer); | 1700 ira_free (total_allocno_costs); |
1590 ira_free (total_costs); | 1701 } |
1591 ira_free (allocno_costs); | 1702 |
1703 /* Entry function which defines classes for pseudos. */ | |
1704 void | |
1705 ira_set_pseudo_classes (FILE *dump_file) | |
1706 { | |
1707 allocno_p = false; | |
1708 internal_flag_ira_verbose = flag_ira_verbose; | |
1709 cost_elements_num = max_reg_num (); | |
1710 init_costs (); | |
1711 find_costs_and_classes (dump_file); | |
1712 pseudo_classes_defined_p = true; | |
1713 finish_costs (); | |
1592 } | 1714 } |
1593 | 1715 |
1594 | 1716 |
1595 | 1717 |
1596 /* Change hard register costs for allocnos which lives through | 1718 /* Change hard register costs for allocnos which lives through |