comparison gcc/ira-lives.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* IRA processing allocno lives to build allocno live ranges. 1 /* IRA processing allocno lives to build allocno live ranges.
2 Copyright (C) 2006-2017 Free Software Foundation, Inc. 2 Copyright (C) 2006-2018 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>. 3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
82 82
83 /* The value of get_preferred_alternatives for the current instruction, 83 /* The value of get_preferred_alternatives for the current instruction,
84 supplemental to recog_data. */ 84 supplemental to recog_data. */
85 static alternative_mask preferred_alternatives; 85 static alternative_mask preferred_alternatives;
86 86
87 /* Record the birth of hard register REGNO, updating hard_regs_live and 87 /* If non-NULL, the source operand of a register to register copy for which
88 hard reg conflict information for living allocnos. */ 88 we should not add a conflict with the copy's destination operand. */
89 static void 89 static rtx ignore_reg_for_conflicts;
90 make_hard_regno_born (int regno) 90
91 /* Record hard register REGNO as now being live. */
92 static void
93 make_hard_regno_live (int regno)
94 {
95 SET_HARD_REG_BIT (hard_regs_live, regno);
96 }
97
98 /* Process the definition of hard register REGNO. This updates
99 hard_regs_live and hard reg conflict information for living allocnos. */
100 static void
101 make_hard_regno_dead (int regno)
91 { 102 {
92 unsigned int i; 103 unsigned int i;
93
94 SET_HARD_REG_BIT (hard_regs_live, regno);
95 EXECUTE_IF_SET_IN_SPARSESET (objects_live, i) 104 EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
96 { 105 {
97 ira_object_t obj = ira_object_id_map[i]; 106 ira_object_t obj = ira_object_id_map[i];
107
108 if (ignore_reg_for_conflicts != NULL_RTX
109 && REGNO (ignore_reg_for_conflicts)
110 == (unsigned int) ALLOCNO_REGNO (OBJECT_ALLOCNO (obj)))
111 continue;
98 112
99 SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno); 113 SET_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), regno);
100 SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno); 114 SET_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), regno);
101 } 115 }
102 }
103
104 /* Process the death of hard register REGNO. This updates
105 hard_regs_live. */
106 static void
107 make_hard_regno_dead (int regno)
108 {
109 CLEAR_HARD_REG_BIT (hard_regs_live, regno); 116 CLEAR_HARD_REG_BIT (hard_regs_live, regno);
110 } 117 }
111 118
112 /* Record the birth of object OBJ. Set a bit for it in objects_live, 119 /* Record object OBJ as now being live. Set a bit for it in objects_live,
113 start a new live range for it if necessary and update hard register 120 and start a new live range for it if necessary. */
114 conflicts. */ 121 static void
115 static void 122 make_object_live (ira_object_t obj)
116 make_object_born (ira_object_t obj) 123 {
117 { 124 sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj));
125
118 live_range_t lr = OBJECT_LIVE_RANGES (obj); 126 live_range_t lr = OBJECT_LIVE_RANGES (obj);
119
120 sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj));
121 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), hard_regs_live);
122 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), hard_regs_live);
123
124 if (lr == NULL 127 if (lr == NULL
125 || (lr->finish != curr_point && lr->finish + 1 != curr_point)) 128 || (lr->finish != curr_point && lr->finish + 1 != curr_point))
126 ira_add_live_range_to_object (obj, curr_point, -1); 129 ira_add_live_range_to_object (obj, curr_point, -1);
127 } 130 }
128 131
152 ? high_pressure_start_point[cl] : p->start); 155 ? high_pressure_start_point[cl] : p->start);
153 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) += curr_point - start + 1; 156 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) += curr_point - start + 1;
154 } 157 }
155 } 158 }
156 159
157 /* Process the death of object OBJ, which is associated with allocno 160 /* Process the definition of object OBJ, which is associated with allocno A.
158 A. This finishes the current live range for it. */ 161 This finishes the current live range for it. */
159 static void 162 static void
160 make_object_dead (ira_object_t obj) 163 make_object_dead (ira_object_t obj)
161 { 164 {
162 live_range_t lr; 165 live_range_t lr;
166 int ignore_regno = -1;
167 int end_regno = -1;
163 168
164 sparseset_clear_bit (objects_live, OBJECT_CONFLICT_ID (obj)); 169 sparseset_clear_bit (objects_live, OBJECT_CONFLICT_ID (obj));
170
171 /* Check whether any part of IGNORE_REG_FOR_CONFLICTS already conflicts
172 with OBJ. */
173 if (ignore_reg_for_conflicts != NULL_RTX
174 && REGNO (ignore_reg_for_conflicts) < FIRST_PSEUDO_REGISTER)
175 {
176 end_regno = END_REGNO (ignore_reg_for_conflicts);
177 int src_regno = ignore_regno = REGNO (ignore_reg_for_conflicts);
178
179 while (src_regno < end_regno)
180 {
181 if (TEST_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), src_regno))
182 {
183 ignore_regno = end_regno = -1;
184 break;
185 }
186 src_regno++;
187 }
188 }
189
190 IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), hard_regs_live);
191 IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), hard_regs_live);
192
193 /* If IGNORE_REG_FOR_CONFLICTS did not already conflict with OBJ, make
194 sure it still doesn't. */
195 for (; ignore_regno < end_regno; ignore_regno++)
196 CLEAR_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (obj), ignore_regno);
197
165 lr = OBJECT_LIVE_RANGES (obj); 198 lr = OBJECT_LIVE_RANGES (obj);
166 ira_assert (lr != NULL); 199 ira_assert (lr != NULL);
167 lr->finish = curr_point; 200 lr->finish = curr_point;
168 update_allocno_pressure_excess_length (obj); 201 update_allocno_pressure_excess_length (obj);
169 } 202 }
288 321
289 if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj))) 322 if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
290 continue; 323 continue;
291 324
292 inc_register_pressure (pclass, nregs); 325 inc_register_pressure (pclass, nregs);
293 make_object_born (obj); 326 make_object_live (obj);
294 } 327 }
295 } 328 }
296 329
297 /* Like mark_pseudo_regno_live, but try to only mark one subword of 330 /* Like mark_pseudo_regno_live, but try to only mark one subword of
298 the pseudo as live. SUBWORD indicates which; a value of 0 331 the pseudo as live. SUBWORD indicates which; a value of 0
325 358
326 if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj))) 359 if (sparseset_bit_p (objects_live, OBJECT_CONFLICT_ID (obj)))
327 return; 360 return;
328 361
329 inc_register_pressure (pclass, 1); 362 inc_register_pressure (pclass, 1);
330 make_object_born (obj); 363 make_object_live (obj);
331 } 364 }
332 365
333 /* Mark the register REG as live. Store a 1 in hard_regs_live for 366 /* Mark the register REG as live. Store a 1 in hard_regs_live for
334 this register, record how many consecutive hardware registers it 367 this register, record how many consecutive hardware registers it
335 actually needs. */ 368 actually needs. */
349 && ! TEST_HARD_REG_BIT (eliminable_regset, regno)) 382 && ! TEST_HARD_REG_BIT (eliminable_regset, regno))
350 { 383 {
351 aclass = ira_hard_regno_allocno_class[regno]; 384 aclass = ira_hard_regno_allocno_class[regno];
352 pclass = ira_pressure_class_translate[aclass]; 385 pclass = ira_pressure_class_translate[aclass];
353 inc_register_pressure (pclass, 1); 386 inc_register_pressure (pclass, 1);
354 make_hard_regno_born (regno); 387 make_hard_regno_live (regno);
355 } 388 }
356 regno++; 389 regno++;
357 } 390 }
358 } 391 }
359 } 392 }
455 488
456 dec_register_pressure (cl, 1); 489 dec_register_pressure (cl, 1);
457 make_object_dead (obj); 490 make_object_dead (obj);
458 } 491 }
459 492
460 /* Mark the hard register REG as dead. Store a 0 in hard_regs_live for the 493 /* Process the definition of hard register REG. This updates hard_regs_live
461 register. */ 494 and hard reg conflict information for living allocnos. */
462 static void 495 static void
463 mark_hard_reg_dead (rtx reg) 496 mark_hard_reg_dead (rtx reg)
464 { 497 {
465 int regno = REGNO (reg); 498 int regno = REGNO (reg);
466 499
917 a simplification of: 950 a simplification of:
918 951
919 (subreg:YMODE (reg:XMODE XREGNO) OFFSET). */ 952 (subreg:YMODE (reg:XMODE XREGNO) OFFSET). */
920 machine_mode ymode, xmode; 953 machine_mode ymode, xmode;
921 int xregno, yregno; 954 int xregno, yregno;
922 HOST_WIDE_INT offset; 955 poly_int64 offset;
923 956
924 xmode = recog_data.operand_mode[i]; 957 xmode = recog_data.operand_mode[i];
925 xregno = ira_class_singleton[cl][xmode]; 958 xregno = ira_class_singleton[cl][xmode];
926 gcc_assert (xregno >= 0); 959 gcc_assert (xregno >= 0);
927 ymode = ALLOCNO_MODE (operand_a); 960 ymode = ALLOCNO_MODE (operand_a);
1022 } 1055 }
1023 } 1056 }
1024 return cheap_reg; 1057 return cheap_reg;
1025 } 1058 }
1026 1059
1060 /* Determine whether INSN is a register to register copy of the type where
1061 we do not need to make the source and destiniation registers conflict.
1062 If this is a copy instruction, then return the source reg. Otherwise,
1063 return NULL_RTX. */
1064 rtx
1065 non_conflicting_reg_copy_p (rtx_insn *insn)
1066 {
1067 /* Reload has issues with overlapping pseudos being assigned to the
1068 same hard register, so don't allow it. See PR87600 for details. */
1069 if (!targetm.lra_p ())
1070 return NULL_RTX;
1071
1072 rtx set = single_set (insn);
1073
1074 /* Disallow anything other than a simple register to register copy
1075 that has no side effects. */
1076 if (set == NULL_RTX
1077 || !REG_P (SET_DEST (set))
1078 || !REG_P (SET_SRC (set))
1079 || side_effects_p (set))
1080 return NULL_RTX;
1081
1082 int dst_regno = REGNO (SET_DEST (set));
1083 int src_regno = REGNO (SET_SRC (set));
1084 machine_mode mode = GET_MODE (SET_DEST (set));
1085
1086 /* Computing conflicts for register pairs is difficult to get right, so
1087 for now, disallow it. */
1088 if ((dst_regno < FIRST_PSEUDO_REGISTER
1089 && hard_regno_nregs (dst_regno, mode) != 1)
1090 || (src_regno < FIRST_PSEUDO_REGISTER
1091 && hard_regno_nregs (src_regno, mode) != 1))
1092 return NULL_RTX;
1093
1094 return SET_SRC (set);
1095 }
1096
1027 /* Process insns of the basic block given by its LOOP_TREE_NODE to 1097 /* Process insns of the basic block given by its LOOP_TREE_NODE to
1028 update allocno live ranges, allocno hard register conflicts, 1098 update allocno live ranges, allocno hard register conflicts,
1029 intersected calls, and register pressure info for allocnos for the 1099 intersected calls, and register pressure info for allocnos for the
1030 basic block for and regions containing the basic block. */ 1100 basic block for and regions containing the basic block. */
1031 static void 1101 static void
1107 fprintf (ira_dump_file, " Insn %u(l%d): point = %d\n", 1177 fprintf (ira_dump_file, " Insn %u(l%d): point = %d\n",
1108 INSN_UID (insn), loop_tree_node->parent->loop_num, 1178 INSN_UID (insn), loop_tree_node->parent->loop_num,
1109 curr_point); 1179 curr_point);
1110 1180
1111 call_p = CALL_P (insn); 1181 call_p = CALL_P (insn);
1112 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM 1182 ignore_reg_for_conflicts = non_conflicting_reg_copy_p (insn);
1113 int regno;
1114 bool clear_pic_use_conflict_p = false;
1115 /* Processing insn usage in call insn can create conflict
1116 with pic pseudo and pic hard reg and that is wrong.
1117 Check this situation and fix it at the end of the insn
1118 processing. */
1119 if (call_p && pic_offset_table_rtx != NULL_RTX
1120 && (regno = REGNO (pic_offset_table_rtx)) >= FIRST_PSEUDO_REGISTER
1121 && (a = ira_curr_regno_allocno_map[regno]) != NULL)
1122 clear_pic_use_conflict_p
1123 = (find_regno_fusage (insn, USE, REAL_PIC_OFFSET_TABLE_REGNUM)
1124 && ! TEST_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS
1125 (ALLOCNO_OBJECT (a, 0)),
1126 REAL_PIC_OFFSET_TABLE_REGNUM));
1127 #endif
1128 1183
1129 /* Mark each defined value as live. We need to do this for 1184 /* Mark each defined value as live. We need to do this for
1130 unused values because they still conflict with quantities 1185 unused values because they still conflict with quantities
1131 that are live at the time of the definition. 1186 that are live at the time of the definition.
1132 1187
1207 1262
1208 /* Don't allocate allocnos that cross setjmps or any 1263 /* Don't allocate allocnos that cross setjmps or any
1209 call, if this function receives a nonlocal 1264 call, if this function receives a nonlocal
1210 goto. */ 1265 goto. */
1211 if (cfun->has_nonlocal_label 1266 if (cfun->has_nonlocal_label
1212 || find_reg_note (insn, REG_SETJMP, 1267 || (!targetm.setjmp_preserves_nonvolatile_regs_p ()
1213 NULL_RTX) != NULL_RTX) 1268 && (find_reg_note (insn, REG_SETJMP, NULL_RTX)
1269 != NULL_RTX)))
1214 { 1270 {
1215 SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj)); 1271 SET_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj));
1216 SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj)); 1272 SET_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj));
1217 } 1273 }
1218 if (can_throw_internal (insn)) 1274 if (can_throw_internal (insn))
1275 1331
1276 mark_ref_live (use); 1332 mark_ref_live (use);
1277 } 1333 }
1278 } 1334 }
1279 1335
1280 #ifdef REAL_PIC_OFFSET_TABLE_REGNUM
1281 if (clear_pic_use_conflict_p)
1282 {
1283 regno = REGNO (pic_offset_table_rtx);
1284 a = ira_curr_regno_allocno_map[regno];
1285 CLEAR_HARD_REG_BIT (OBJECT_CONFLICT_HARD_REGS (ALLOCNO_OBJECT (a, 0)),
1286 REAL_PIC_OFFSET_TABLE_REGNUM);
1287 CLEAR_HARD_REG_BIT (OBJECT_TOTAL_CONFLICT_HARD_REGS
1288 (ALLOCNO_OBJECT (a, 0)),
1289 REAL_PIC_OFFSET_TABLE_REGNUM);
1290 }
1291 #endif
1292 curr_point++; 1336 curr_point++;
1293 } 1337 }
1338 ignore_reg_for_conflicts = NULL_RTX;
1294 1339
1295 if (bb_has_eh_pred (bb)) 1340 if (bb_has_eh_pred (bb))
1296 for (j = 0; ; ++j) 1341 for (j = 0; ; ++j)
1297 { 1342 {
1298 unsigned int regno = EH_RETURN_DATA_REGNO (j); 1343 unsigned int regno = EH_RETURN_DATA_REGNO (j);
1299 if (regno == INVALID_REGNUM) 1344 if (regno == INVALID_REGNUM)
1300 break; 1345 break;
1301 make_hard_regno_born (regno); 1346 make_hard_regno_live (regno);
1302 } 1347 }
1303 1348
1304 /* Allocnos can't go in stack regs at the start of a basic block 1349 /* Allocnos can't go in stack regs at the start of a basic block
1305 that is reached by an abnormal edge. Likewise for call 1350 that is reached by an abnormal edge. Likewise for call
1306 clobbered regs, because caller-save, fixup_abnormal_edges and 1351 clobbered regs, because caller-save, fixup_abnormal_edges and
1315 1360
1316 ALLOCNO_NO_STACK_REG_P (a) = true; 1361 ALLOCNO_NO_STACK_REG_P (a) = true;
1317 ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true; 1362 ALLOCNO_TOTAL_NO_STACK_REG_P (a) = true;
1318 } 1363 }
1319 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++) 1364 for (px = FIRST_STACK_REG; px <= LAST_STACK_REG; px++)
1320 make_hard_regno_born (px); 1365 make_hard_regno_live (px);
1321 #endif 1366 #endif
1322 /* No need to record conflicts for call clobbered regs if we 1367 /* No need to record conflicts for call clobbered regs if we
1323 have nonlocal labels around, as we don't ever try to 1368 have nonlocal labels around, as we don't ever try to
1324 allocate such regs in this case. */ 1369 allocate such regs in this case. */
1325 if (!cfun->has_nonlocal_label 1370 if (!cfun->has_nonlocal_label
1338 || (px == REAL_PIC_OFFSET_TABLE_REGNUM 1383 || (px == REAL_PIC_OFFSET_TABLE_REGNUM
1339 && pic_offset_table_rtx != NULL_RTX 1384 && pic_offset_table_rtx != NULL_RTX
1340 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER) 1385 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
1341 #endif 1386 #endif
1342 ) 1387 )
1343 make_hard_regno_born (px); 1388 make_hard_regno_live (px);
1344 } 1389 }
1345 1390
1346 EXECUTE_IF_SET_IN_SPARSESET (objects_live, i) 1391 EXECUTE_IF_SET_IN_SPARSESET (objects_live, i)
1347 make_object_dead (ira_object_id_map[i]); 1392 make_object_dead (ira_object_id_map[i]);
1348 1393