]>
Commit | Line | Data |
---|---|---|
47dd2e78 | 1 | /* Building internal representation for IRA. |
1180227d | 2 | Copyright (C) 2006, 2007, 2008, 2009, 2010 |
47dd2e78 | 3 | Free Software Foundation, Inc. |
4 | Contributed by Vladimir Makarov <vmakarov@redhat.com>. | |
5 | ||
6 | This file is part of GCC. | |
7 | ||
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 3, or (at your option) any later | |
11 | version. | |
12 | ||
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. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GCC; see the file COPYING3. If not see | |
20 | <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "system.h" | |
24 | #include "coretypes.h" | |
25 | #include "tm.h" | |
26 | #include "rtl.h" | |
27 | #include "tm_p.h" | |
28 | #include "target.h" | |
29 | #include "regs.h" | |
30 | #include "flags.h" | |
31 | #include "hard-reg-set.h" | |
32 | #include "basic-block.h" | |
33 | #include "insn-config.h" | |
34 | #include "recog.h" | |
0b205f4c | 35 | #include "diagnostic-core.h" |
47dd2e78 | 36 | #include "params.h" |
37 | #include "df.h" | |
47dd2e78 | 38 | #include "reload.h" |
39 | #include "sparseset.h" | |
40 | #include "ira-int.h" | |
06f9d6ef | 41 | #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */ |
47dd2e78 | 42 | |
43 | static ira_copy_t find_allocno_copy (ira_allocno_t, ira_allocno_t, rtx, | |
44 | ira_loop_tree_node_t); | |
45 | ||
46 | /* The root of the loop tree corresponding to the all function. */ | |
47 | ira_loop_tree_node_t ira_loop_tree_root; | |
48 | ||
49 | /* Height of the loop tree. */ | |
50 | int ira_loop_tree_height; | |
51 | ||
52 | /* All nodes representing basic blocks are referred through the | |
53 | following array. We can not use basic block member `aux' for this | |
54 | because it is used for insertion of insns on edges. */ | |
55 | ira_loop_tree_node_t ira_bb_nodes; | |
56 | ||
57 | /* All nodes representing loops are referred through the following | |
58 | array. */ | |
59 | ira_loop_tree_node_t ira_loop_nodes; | |
60 | ||
48e1416a | 61 | /* Map regno -> allocnos with given regno (see comments for |
47dd2e78 | 62 | allocno member `next_regno_allocno'). */ |
63 | ira_allocno_t *ira_regno_allocno_map; | |
64 | ||
65 | /* Array of references to all allocnos. The order number of the | |
66 | allocno corresponds to the index in the array. Removed allocnos | |
67 | have NULL element value. */ | |
68 | ira_allocno_t *ira_allocnos; | |
69 | ||
70 | /* Sizes of the previous array. */ | |
71 | int ira_allocnos_num; | |
72 | ||
ae9587ed | 73 | /* Count of conflict record structures we've created, used when creating |
74 | a new conflict id. */ | |
75 | int ira_objects_num; | |
76 | ||
77 | /* Map a conflict id to its conflict record. */ | |
78 | ira_object_t *ira_object_id_map; | |
47dd2e78 | 79 | |
80 | /* Array of references to all copies. The order number of the copy | |
81 | corresponds to the index in the array. Removed copies have NULL | |
82 | element value. */ | |
83 | ira_copy_t *ira_copies; | |
84 | ||
85 | /* Size of the previous array. */ | |
86 | int ira_copies_num; | |
87 | ||
88 | \f | |
89 | ||
90 | /* LAST_BASIC_BLOCK before generating additional insns because of live | |
91 | range splitting. Emitting insns on a critical edge creates a new | |
92 | basic block. */ | |
93 | static int last_basic_block_before_change; | |
94 | ||
9f8ac546 | 95 | /* Initialize some members in loop tree node NODE. Use LOOP_NUM for |
96 | the member loop_num. */ | |
47dd2e78 | 97 | static void |
9f8ac546 | 98 | init_loop_tree_node (struct ira_loop_tree_node *node, int loop_num) |
99 | { | |
100 | int max_regno = max_reg_num (); | |
101 | ||
102 | node->regno_allocno_map | |
103 | = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t) * max_regno); | |
104 | memset (node->regno_allocno_map, 0, sizeof (ira_allocno_t) * max_regno); | |
105 | memset (node->reg_pressure, 0, sizeof (node->reg_pressure)); | |
106 | node->all_allocnos = ira_allocate_bitmap (); | |
107 | node->modified_regnos = ira_allocate_bitmap (); | |
108 | node->border_allocnos = ira_allocate_bitmap (); | |
109 | node->local_copies = ira_allocate_bitmap (); | |
110 | node->loop_num = loop_num; | |
111 | node->children = NULL; | |
112 | node->subloops = NULL; | |
113 | } | |
114 | ||
115 | ||
116 | /* The following function allocates the loop tree nodes. If | |
117 | CURRENT_LOOPS is NULL, the nodes corresponding to the loops (except | |
118 | the root which corresponds the all function) will be not allocated | |
119 | but nodes will still be allocated for basic blocks. */ | |
120 | static void | |
121 | create_loop_tree_nodes (void) | |
47dd2e78 | 122 | { |
123 | unsigned int i, j; | |
47dd2e78 | 124 | bool skip_p; |
125 | edge_iterator ei; | |
126 | edge e; | |
127 | VEC (edge, heap) *edges; | |
128 | loop_p loop; | |
129 | ||
130 | ira_bb_nodes | |
131 | = ((struct ira_loop_tree_node *) | |
132 | ira_allocate (sizeof (struct ira_loop_tree_node) * last_basic_block)); | |
133 | last_basic_block_before_change = last_basic_block; | |
134 | for (i = 0; i < (unsigned int) last_basic_block; i++) | |
135 | { | |
136 | ira_bb_nodes[i].regno_allocno_map = NULL; | |
137 | memset (ira_bb_nodes[i].reg_pressure, 0, | |
138 | sizeof (ira_bb_nodes[i].reg_pressure)); | |
2bae4acc | 139 | ira_bb_nodes[i].all_allocnos = NULL; |
47dd2e78 | 140 | ira_bb_nodes[i].modified_regnos = NULL; |
141 | ira_bb_nodes[i].border_allocnos = NULL; | |
142 | ira_bb_nodes[i].local_copies = NULL; | |
143 | } | |
9f8ac546 | 144 | if (current_loops == NULL) |
145 | { | |
146 | ira_loop_nodes = ((struct ira_loop_tree_node *) | |
147 | ira_allocate (sizeof (struct ira_loop_tree_node))); | |
148 | init_loop_tree_node (ira_loop_nodes, 0); | |
149 | return; | |
150 | } | |
47dd2e78 | 151 | ira_loop_nodes = ((struct ira_loop_tree_node *) |
152 | ira_allocate (sizeof (struct ira_loop_tree_node) | |
153 | * VEC_length (loop_p, ira_loops.larray))); | |
48148244 | 154 | FOR_EACH_VEC_ELT (loop_p, ira_loops.larray, i, loop) |
47dd2e78 | 155 | { |
156 | if (loop != ira_loops.tree_root) | |
157 | { | |
158 | ira_loop_nodes[i].regno_allocno_map = NULL; | |
47dd2e78 | 159 | skip_p = false; |
160 | FOR_EACH_EDGE (e, ei, loop->header->preds) | |
161 | if (e->src != loop->latch | |
162 | && (e->flags & EDGE_ABNORMAL) && EDGE_CRITICAL_P (e)) | |
163 | { | |
164 | skip_p = true; | |
165 | break; | |
166 | } | |
167 | if (skip_p) | |
168 | continue; | |
169 | edges = get_loop_exit_edges (loop); | |
48148244 | 170 | FOR_EACH_VEC_ELT (edge, edges, j, e) |
47dd2e78 | 171 | if ((e->flags & EDGE_ABNORMAL) && EDGE_CRITICAL_P (e)) |
172 | { | |
173 | skip_p = true; | |
174 | break; | |
175 | } | |
176 | VEC_free (edge, heap, edges); | |
177 | if (skip_p) | |
178 | continue; | |
179 | } | |
9f8ac546 | 180 | init_loop_tree_node (&ira_loop_nodes[i], loop->num); |
47dd2e78 | 181 | } |
182 | } | |
183 | ||
184 | /* The function returns TRUE if there are more one allocation | |
185 | region. */ | |
186 | static bool | |
187 | more_one_region_p (void) | |
188 | { | |
189 | unsigned int i; | |
190 | loop_p loop; | |
191 | ||
9f8ac546 | 192 | if (current_loops != NULL) |
193 | FOR_EACH_VEC_ELT (loop_p, ira_loops.larray, i, loop) | |
194 | if (ira_loop_nodes[i].regno_allocno_map != NULL | |
195 | && ira_loop_tree_root != &ira_loop_nodes[i]) | |
196 | return true; | |
47dd2e78 | 197 | return false; |
198 | } | |
199 | ||
200 | /* Free the loop tree node of a loop. */ | |
201 | static void | |
202 | finish_loop_tree_node (ira_loop_tree_node_t loop) | |
203 | { | |
204 | if (loop->regno_allocno_map != NULL) | |
205 | { | |
206 | ira_assert (loop->bb == NULL); | |
207 | ira_free_bitmap (loop->local_copies); | |
208 | ira_free_bitmap (loop->border_allocnos); | |
209 | ira_free_bitmap (loop->modified_regnos); | |
2bae4acc | 210 | ira_free_bitmap (loop->all_allocnos); |
47dd2e78 | 211 | ira_free (loop->regno_allocno_map); |
212 | loop->regno_allocno_map = NULL; | |
213 | } | |
214 | } | |
215 | ||
216 | /* Free the loop tree nodes. */ | |
217 | static void | |
218 | finish_loop_tree_nodes (void) | |
219 | { | |
220 | unsigned int i; | |
221 | loop_p loop; | |
222 | ||
9f8ac546 | 223 | if (current_loops == NULL) |
224 | finish_loop_tree_node (&ira_loop_nodes[0]); | |
225 | else | |
226 | FOR_EACH_VEC_ELT (loop_p, ira_loops.larray, i, loop) | |
227 | finish_loop_tree_node (&ira_loop_nodes[i]); | |
47dd2e78 | 228 | ira_free (ira_loop_nodes); |
229 | for (i = 0; i < (unsigned int) last_basic_block_before_change; i++) | |
230 | { | |
231 | if (ira_bb_nodes[i].local_copies != NULL) | |
232 | ira_free_bitmap (ira_bb_nodes[i].local_copies); | |
233 | if (ira_bb_nodes[i].border_allocnos != NULL) | |
234 | ira_free_bitmap (ira_bb_nodes[i].border_allocnos); | |
235 | if (ira_bb_nodes[i].modified_regnos != NULL) | |
236 | ira_free_bitmap (ira_bb_nodes[i].modified_regnos); | |
2bae4acc | 237 | if (ira_bb_nodes[i].all_allocnos != NULL) |
238 | ira_free_bitmap (ira_bb_nodes[i].all_allocnos); | |
47dd2e78 | 239 | if (ira_bb_nodes[i].regno_allocno_map != NULL) |
240 | ira_free (ira_bb_nodes[i].regno_allocno_map); | |
241 | } | |
242 | ira_free (ira_bb_nodes); | |
243 | } | |
244 | ||
245 | \f | |
246 | ||
247 | /* The following recursive function adds LOOP to the loop tree | |
9f8ac546 | 248 | hierarchy. LOOP is added only once. If LOOP is NULL we adding |
249 | loop designating the whole function when CFG loops are not | |
250 | built. */ | |
47dd2e78 | 251 | static void |
252 | add_loop_to_tree (struct loop *loop) | |
253 | { | |
9f8ac546 | 254 | int loop_num; |
47dd2e78 | 255 | struct loop *parent; |
256 | ira_loop_tree_node_t loop_node, parent_node; | |
257 | ||
258 | /* We can not use loop node access macros here because of potential | |
259 | checking and because the nodes are not initialized enough | |
260 | yet. */ | |
9f8ac546 | 261 | if (loop != NULL && loop_outer (loop) != NULL) |
47dd2e78 | 262 | add_loop_to_tree (loop_outer (loop)); |
9f8ac546 | 263 | loop_num = loop != NULL ? loop->num : 0; |
264 | if (ira_loop_nodes[loop_num].regno_allocno_map != NULL | |
265 | && ira_loop_nodes[loop_num].children == NULL) | |
47dd2e78 | 266 | { |
267 | /* We have not added loop node to the tree yet. */ | |
9f8ac546 | 268 | loop_node = &ira_loop_nodes[loop_num]; |
47dd2e78 | 269 | loop_node->loop = loop; |
270 | loop_node->bb = NULL; | |
9f8ac546 | 271 | if (loop == NULL) |
272 | parent = NULL; | |
273 | else | |
274 | { | |
275 | for (parent = loop_outer (loop); | |
276 | parent != NULL; | |
277 | parent = loop_outer (parent)) | |
278 | if (ira_loop_nodes[parent->num].regno_allocno_map != NULL) | |
279 | break; | |
280 | } | |
47dd2e78 | 281 | if (parent == NULL) |
282 | { | |
283 | loop_node->next = NULL; | |
284 | loop_node->subloop_next = NULL; | |
285 | loop_node->parent = NULL; | |
286 | } | |
287 | else | |
288 | { | |
289 | parent_node = &ira_loop_nodes[parent->num]; | |
290 | loop_node->next = parent_node->children; | |
291 | parent_node->children = loop_node; | |
292 | loop_node->subloop_next = parent_node->subloops; | |
293 | parent_node->subloops = loop_node; | |
294 | loop_node->parent = parent_node; | |
295 | } | |
296 | } | |
297 | } | |
298 | ||
299 | /* The following recursive function sets up levels of nodes of the | |
300 | tree given its root LOOP_NODE. The enumeration starts with LEVEL. | |
301 | The function returns maximal value of level in the tree + 1. */ | |
302 | static int | |
303 | setup_loop_tree_level (ira_loop_tree_node_t loop_node, int level) | |
304 | { | |
305 | int height, max_height; | |
306 | ira_loop_tree_node_t subloop_node; | |
307 | ||
308 | ira_assert (loop_node->bb == NULL); | |
309 | loop_node->level = level; | |
310 | max_height = level + 1; | |
311 | for (subloop_node = loop_node->subloops; | |
312 | subloop_node != NULL; | |
313 | subloop_node = subloop_node->subloop_next) | |
314 | { | |
315 | ira_assert (subloop_node->bb == NULL); | |
316 | height = setup_loop_tree_level (subloop_node, level + 1); | |
317 | if (height > max_height) | |
318 | max_height = height; | |
319 | } | |
320 | return max_height; | |
321 | } | |
322 | ||
323 | /* Create the loop tree. The algorithm is designed to provide correct | |
324 | order of loops (they are ordered by their last loop BB) and basic | |
325 | blocks in the chain formed by member next. */ | |
326 | static void | |
327 | form_loop_tree (void) | |
328 | { | |
47dd2e78 | 329 | basic_block bb; |
330 | struct loop *parent; | |
331 | ira_loop_tree_node_t bb_node, loop_node; | |
47dd2e78 | 332 | |
333 | /* We can not use loop/bb node access macros because of potential | |
334 | checking and because the nodes are not initialized enough | |
335 | yet. */ | |
7e03a244 | 336 | FOR_EACH_BB (bb) |
47dd2e78 | 337 | { |
338 | bb_node = &ira_bb_nodes[bb->index]; | |
339 | bb_node->bb = bb; | |
340 | bb_node->loop = NULL; | |
341 | bb_node->subloops = NULL; | |
342 | bb_node->children = NULL; | |
343 | bb_node->subloop_next = NULL; | |
344 | bb_node->next = NULL; | |
9f8ac546 | 345 | if (current_loops == NULL) |
346 | parent = NULL; | |
347 | else | |
348 | { | |
349 | for (parent = bb->loop_father; | |
350 | parent != NULL; | |
351 | parent = loop_outer (parent)) | |
352 | if (ira_loop_nodes[parent->num].regno_allocno_map != NULL) | |
353 | break; | |
354 | } | |
47dd2e78 | 355 | add_loop_to_tree (parent); |
9f8ac546 | 356 | loop_node = &ira_loop_nodes[parent == NULL ? 0 : parent->num]; |
47dd2e78 | 357 | bb_node->next = loop_node->children; |
358 | bb_node->parent = loop_node; | |
359 | loop_node->children = bb_node; | |
360 | } | |
9f8ac546 | 361 | ira_loop_tree_root = IRA_LOOP_NODE_BY_INDEX (0); |
47dd2e78 | 362 | ira_loop_tree_height = setup_loop_tree_level (ira_loop_tree_root, 0); |
363 | ira_assert (ira_loop_tree_root->regno_allocno_map != NULL); | |
364 | } | |
365 | ||
366 | \f | |
367 | ||
368 | /* Rebuild IRA_REGNO_ALLOCNO_MAP and REGNO_ALLOCNO_MAPs of the loop | |
369 | tree nodes. */ | |
370 | static void | |
371 | rebuild_regno_allocno_maps (void) | |
372 | { | |
373 | unsigned int l; | |
374 | int max_regno, regno; | |
375 | ira_allocno_t a; | |
376 | ira_loop_tree_node_t loop_tree_node; | |
377 | loop_p loop; | |
378 | ira_allocno_iterator ai; | |
379 | ||
9f8ac546 | 380 | ira_assert (current_loops != NULL); |
47dd2e78 | 381 | max_regno = max_reg_num (); |
48148244 | 382 | FOR_EACH_VEC_ELT (loop_p, ira_loops.larray, l, loop) |
47dd2e78 | 383 | if (ira_loop_nodes[l].regno_allocno_map != NULL) |
384 | { | |
385 | ira_free (ira_loop_nodes[l].regno_allocno_map); | |
386 | ira_loop_nodes[l].regno_allocno_map | |
387 | = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t) | |
388 | * max_regno); | |
389 | memset (ira_loop_nodes[l].regno_allocno_map, 0, | |
390 | sizeof (ira_allocno_t) * max_regno); | |
391 | } | |
392 | ira_free (ira_regno_allocno_map); | |
393 | ira_regno_allocno_map | |
394 | = (ira_allocno_t *) ira_allocate (max_regno * sizeof (ira_allocno_t)); | |
395 | memset (ira_regno_allocno_map, 0, max_regno * sizeof (ira_allocno_t)); | |
396 | FOR_EACH_ALLOCNO (a, ai) | |
397 | { | |
398 | if (ALLOCNO_CAP_MEMBER (a) != NULL) | |
399 | /* Caps are not in the regno allocno maps. */ | |
400 | continue; | |
401 | regno = ALLOCNO_REGNO (a); | |
402 | loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a); | |
403 | ALLOCNO_NEXT_REGNO_ALLOCNO (a) = ira_regno_allocno_map[regno]; | |
404 | ira_regno_allocno_map[regno] = a; | |
405 | if (loop_tree_node->regno_allocno_map[regno] == NULL) | |
406 | /* Remember that we can create temporary allocnos to break | |
407 | cycles in register shuffle. */ | |
408 | loop_tree_node->regno_allocno_map[regno] = a; | |
409 | } | |
410 | } | |
47dd2e78 | 411 | \f |
412 | ||
ae9587ed | 413 | /* Pools for allocnos, allocno live ranges and objects. */ |
414 | static alloc_pool allocno_pool, live_range_pool, object_pool; | |
47dd2e78 | 415 | |
416 | /* Vec containing references to all created allocnos. It is a | |
417 | container of array allocnos. */ | |
418 | static VEC(ira_allocno_t,heap) *allocno_vec; | |
419 | ||
ae9587ed | 420 | /* Vec containing references to all created ira_objects. It is a |
421 | container of ira_object_id_map. */ | |
422 | static VEC(ira_object_t,heap) *ira_object_id_map_vec; | |
47dd2e78 | 423 | |
424 | /* Initialize data concerning allocnos. */ | |
425 | static void | |
426 | initiate_allocnos (void) | |
427 | { | |
fbff82f4 | 428 | live_range_pool |
429 | = create_alloc_pool ("live ranges", | |
430 | sizeof (struct live_range), 100); | |
47dd2e78 | 431 | allocno_pool |
432 | = create_alloc_pool ("allocnos", sizeof (struct ira_allocno), 100); | |
ae9587ed | 433 | object_pool |
434 | = create_alloc_pool ("objects", sizeof (struct ira_object), 100); | |
47dd2e78 | 435 | allocno_vec = VEC_alloc (ira_allocno_t, heap, max_reg_num () * 2); |
436 | ira_allocnos = NULL; | |
437 | ira_allocnos_num = 0; | |
ae9587ed | 438 | ira_objects_num = 0; |
439 | ira_object_id_map_vec | |
440 | = VEC_alloc (ira_object_t, heap, max_reg_num () * 2); | |
441 | ira_object_id_map = NULL; | |
47dd2e78 | 442 | ira_regno_allocno_map |
66d9a7b9 | 443 | = (ira_allocno_t *) ira_allocate (max_reg_num () |
444 | * sizeof (ira_allocno_t)); | |
47dd2e78 | 445 | memset (ira_regno_allocno_map, 0, max_reg_num () * sizeof (ira_allocno_t)); |
446 | } | |
447 | ||
ae9587ed | 448 | /* Create and return an object corresponding to a new allocno A. */ |
449 | static ira_object_t | |
be18556f | 450 | ira_create_object (ira_allocno_t a, int subword) |
ae9587ed | 451 | { |
66d9a7b9 | 452 | enum reg_class aclass = ALLOCNO_CLASS (a); |
ae9587ed | 453 | ira_object_t obj = (ira_object_t) pool_alloc (object_pool); |
454 | ||
455 | OBJECT_ALLOCNO (obj) = a; | |
be18556f | 456 | OBJECT_SUBWORD (obj) = subword; |
ae9587ed | 457 | OBJECT_CONFLICT_ID (obj) = ira_objects_num; |
458 | OBJECT_CONFLICT_VEC_P (obj) = false; | |
459 | OBJECT_CONFLICT_ARRAY (obj) = NULL; | |
460 | OBJECT_NUM_CONFLICTS (obj) = 0; | |
461 | COPY_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), ira_no_alloc_regs); | |
462 | COPY_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), ira_no_alloc_regs); | |
463 | IOR_COMPL_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), | |
66d9a7b9 | 464 | reg_class_contents[aclass]); |
ae9587ed | 465 | IOR_COMPL_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), |
66d9a7b9 | 466 | reg_class_contents[aclass]); |
ae9587ed | 467 | OBJECT_MIN (obj) = INT_MAX; |
468 | OBJECT_MAX (obj) = -1; | |
9d53e372 | 469 | OBJECT_LIVE_RANGES (obj) = NULL; |
ae9587ed | 470 | |
471 | VEC_safe_push (ira_object_t, heap, ira_object_id_map_vec, obj); | |
472 | ira_object_id_map | |
473 | = VEC_address (ira_object_t, ira_object_id_map_vec); | |
474 | ira_objects_num = VEC_length (ira_object_t, ira_object_id_map_vec); | |
be18556f | 475 | |
ae9587ed | 476 | return obj; |
477 | } | |
478 | ||
47dd2e78 | 479 | /* Create and return the allocno corresponding to REGNO in |
480 | LOOP_TREE_NODE. Add the allocno to the list of allocnos with the | |
481 | same regno if CAP_P is FALSE. */ | |
482 | ira_allocno_t | |
66d9a7b9 | 483 | ira_create_allocno (int regno, bool cap_p, |
484 | ira_loop_tree_node_t loop_tree_node) | |
47dd2e78 | 485 | { |
486 | ira_allocno_t a; | |
487 | ||
488 | a = (ira_allocno_t) pool_alloc (allocno_pool); | |
489 | ALLOCNO_REGNO (a) = regno; | |
490 | ALLOCNO_LOOP_TREE_NODE (a) = loop_tree_node; | |
491 | if (! cap_p) | |
492 | { | |
493 | ALLOCNO_NEXT_REGNO_ALLOCNO (a) = ira_regno_allocno_map[regno]; | |
494 | ira_regno_allocno_map[regno] = a; | |
495 | if (loop_tree_node->regno_allocno_map[regno] == NULL) | |
496 | /* Remember that we can create temporary allocnos to break | |
497 | cycles in register shuffle on region borders (see | |
498 | ira-emit.c). */ | |
499 | loop_tree_node->regno_allocno_map[regno] = a; | |
500 | } | |
501 | ALLOCNO_CAP (a) = NULL; | |
502 | ALLOCNO_CAP_MEMBER (a) = NULL; | |
503 | ALLOCNO_NUM (a) = ira_allocnos_num; | |
2bae4acc | 504 | bitmap_set_bit (loop_tree_node->all_allocnos, ALLOCNO_NUM (a)); |
47dd2e78 | 505 | ALLOCNO_NREFS (a) = 0; |
1e2504ec | 506 | ALLOCNO_FREQ (a) = 0; |
47dd2e78 | 507 | ALLOCNO_HARD_REGNO (a) = -1; |
508 | ALLOCNO_CALL_FREQ (a) = 0; | |
509 | ALLOCNO_CALLS_CROSSED_NUM (a) = 0; | |
c8010b80 | 510 | ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a) = 0; |
47dd2e78 | 511 | #ifdef STACK_REGS |
512 | ALLOCNO_NO_STACK_REG_P (a) = false; | |
513 | ALLOCNO_TOTAL_NO_STACK_REG_P (a) = false; | |
514 | #endif | |
47dd2e78 | 515 | ALLOCNO_DONT_REASSIGN_P (a) = false; |
68d4bdfb | 516 | ALLOCNO_BAD_SPILL_P (a) = false; |
47dd2e78 | 517 | ALLOCNO_ASSIGNED_P (a) = false; |
47dd2e78 | 518 | ALLOCNO_MODE (a) = (regno < 0 ? VOIDmode : PSEUDO_REGNO_MODE (regno)); |
519 | ALLOCNO_COPIES (a) = NULL; | |
520 | ALLOCNO_HARD_REG_COSTS (a) = NULL; | |
521 | ALLOCNO_CONFLICT_HARD_REG_COSTS (a) = NULL; | |
522 | ALLOCNO_UPDATED_HARD_REG_COSTS (a) = NULL; | |
523 | ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) = NULL; | |
66d9a7b9 | 524 | ALLOCNO_CLASS (a) = NO_REGS; |
525 | ALLOCNO_UPDATED_CLASS_COST (a) = 0; | |
526 | ALLOCNO_CLASS_COST (a) = 0; | |
47dd2e78 | 527 | ALLOCNO_MEMORY_COST (a) = 0; |
528 | ALLOCNO_UPDATED_MEMORY_COST (a) = 0; | |
529 | ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) = 0; | |
be18556f | 530 | ALLOCNO_NUM_OBJECTS (a) = 0; |
ae9587ed | 531 | |
66d9a7b9 | 532 | ALLOCNO_ADD_DATA (a) = NULL; |
47dd2e78 | 533 | VEC_safe_push (ira_allocno_t, heap, allocno_vec, a); |
534 | ira_allocnos = VEC_address (ira_allocno_t, allocno_vec); | |
535 | ira_allocnos_num = VEC_length (ira_allocno_t, allocno_vec); | |
be18556f | 536 | |
47dd2e78 | 537 | return a; |
538 | } | |
539 | ||
66d9a7b9 | 540 | /* Set up register class for A and update its conflict hard |
541 | registers. */ | |
47dd2e78 | 542 | void |
66d9a7b9 | 543 | ira_set_allocno_class (ira_allocno_t a, enum reg_class aclass) |
47dd2e78 | 544 | { |
66d9a7b9 | 545 | ira_allocno_object_iterator oi; |
546 | ira_object_t obj; | |
547 | ||
548 | ALLOCNO_CLASS (a) = aclass; | |
549 | FOR_EACH_ALLOCNO_OBJECT (a, obj, oi) | |
550 | { | |
551 | IOR_COMPL_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), | |
552 | reg_class_contents[aclass]); | |
553 | IOR_COMPL_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), | |
554 | reg_class_contents[aclass]); | |
555 | } | |
ae9587ed | 556 | } |
557 | ||
be18556f | 558 | /* Determine the number of objects we should associate with allocno A |
559 | and allocate them. */ | |
ae9587ed | 560 | void |
be18556f | 561 | ira_create_allocno_objects (ira_allocno_t a) |
ae9587ed | 562 | { |
be18556f | 563 | enum machine_mode mode = ALLOCNO_MODE (a); |
66d9a7b9 | 564 | enum reg_class aclass = ALLOCNO_CLASS (a); |
565 | int n = ira_reg_class_max_nregs[aclass][mode]; | |
be18556f | 566 | int i; |
567 | ||
568 | if (GET_MODE_SIZE (mode) != 2 * UNITS_PER_WORD || n != 2) | |
569 | n = 1; | |
570 | ||
571 | ALLOCNO_NUM_OBJECTS (a) = n; | |
572 | for (i = 0; i < n; i++) | |
573 | ALLOCNO_OBJECT (a, i) = ira_create_object (a, i); | |
ae9587ed | 574 | } |
575 | ||
be18556f | 576 | /* For each allocno, set ALLOCNO_NUM_OBJECTS and create the |
66d9a7b9 | 577 | ALLOCNO_OBJECT structures. This must be called after the allocno |
be18556f | 578 | classes are known. */ |
ae9587ed | 579 | static void |
580 | create_allocno_objects (void) | |
581 | { | |
582 | ira_allocno_t a; | |
583 | ira_allocno_iterator ai; | |
584 | ||
585 | FOR_EACH_ALLOCNO (a, ai) | |
be18556f | 586 | ira_create_allocno_objects (a); |
47dd2e78 | 587 | } |
588 | ||
be18556f | 589 | /* Merge hard register conflict information for all objects associated with |
590 | allocno TO into the corresponding objects associated with FROM. | |
591 | If TOTAL_ONLY is true, we only merge OBJECT_TOTAL_CONFLICT_HARD_REGS. */ | |
b4f5e198 | 592 | static void |
593 | merge_hard_reg_conflicts (ira_allocno_t from, ira_allocno_t to, | |
594 | bool total_only) | |
595 | { | |
be18556f | 596 | int i; |
597 | gcc_assert (ALLOCNO_NUM_OBJECTS (to) == ALLOCNO_NUM_OBJECTS (from)); | |
598 | for (i = 0; i < ALLOCNO_NUM_OBJECTS (to); i++) | |
599 | { | |
600 | ira_object_t from_obj = ALLOCNO_OBJECT (from, i); | |
601 | ira_object_t to_obj = ALLOCNO_OBJECT (to, i); | |
66d9a7b9 | 602 | |
be18556f | 603 | if (!total_only) |
604 | IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (to_obj), | |
605 | OBJECT_CONFLICT_HARD_REGS (from_obj)); | |
606 | IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (to_obj), | |
607 | OBJECT_TOTAL_CONFLICT_HARD_REGS (from_obj)); | |
608 | } | |
b4f5e198 | 609 | #ifdef STACK_REGS |
610 | if (!total_only && ALLOCNO_NO_STACK_REG_P (from)) | |
611 | ALLOCNO_NO_STACK_REG_P (to) = true; | |
612 | if (ALLOCNO_TOTAL_NO_STACK_REG_P (from)) | |
613 | ALLOCNO_TOTAL_NO_STACK_REG_P (to) = true; | |
614 | #endif | |
615 | } | |
616 | ||
be18556f | 617 | /* Update hard register conflict information for all objects associated with |
618 | A to include the regs in SET. */ | |
619 | void | |
620 | ior_hard_reg_conflicts (ira_allocno_t a, HARD_REG_SET *set) | |
621 | { | |
622 | ira_allocno_object_iterator i; | |
623 | ira_object_t obj; | |
66d9a7b9 | 624 | |
be18556f | 625 | FOR_EACH_ALLOCNO_OBJECT (a, obj, i) |
626 | { | |
627 | IOR_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), *set); | |
628 | IOR_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), *set); | |
629 | } | |
630 | } | |
631 | ||
ae9587ed | 632 | /* Return TRUE if a conflict vector with NUM elements is more |
633 | profitable than a conflict bit vector for OBJ. */ | |
47dd2e78 | 634 | bool |
ae9587ed | 635 | ira_conflict_vector_profitable_p (ira_object_t obj, int num) |
47dd2e78 | 636 | { |
637 | int nw; | |
ae9587ed | 638 | int max = OBJECT_MAX (obj); |
639 | int min = OBJECT_MIN (obj); | |
47dd2e78 | 640 | |
ae9587ed | 641 | if (max < min) |
642 | /* We prefer a bit vector in such case because it does not result | |
643 | in allocation. */ | |
47dd2e78 | 644 | return false; |
645 | ||
ae9587ed | 646 | nw = (max - min + IRA_INT_BITS) / IRA_INT_BITS; |
647 | return (2 * sizeof (ira_object_t) * (num + 1) | |
47dd2e78 | 648 | < 3 * nw * sizeof (IRA_INT_TYPE)); |
649 | } | |
650 | ||
ae9587ed | 651 | /* Allocates and initialize the conflict vector of OBJ for NUM |
652 | conflicting objects. */ | |
47dd2e78 | 653 | void |
ae9587ed | 654 | ira_allocate_conflict_vec (ira_object_t obj, int num) |
47dd2e78 | 655 | { |
656 | int size; | |
ae9587ed | 657 | ira_object_t *vec; |
47dd2e78 | 658 | |
ae9587ed | 659 | ira_assert (OBJECT_CONFLICT_ARRAY (obj) == NULL); |
47dd2e78 | 660 | num++; /* for NULL end marker */ |
ae9587ed | 661 | size = sizeof (ira_object_t) * num; |
662 | OBJECT_CONFLICT_ARRAY (obj) = ira_allocate (size); | |
663 | vec = (ira_object_t *) OBJECT_CONFLICT_ARRAY (obj); | |
47dd2e78 | 664 | vec[0] = NULL; |
ae9587ed | 665 | OBJECT_NUM_CONFLICTS (obj) = 0; |
666 | OBJECT_CONFLICT_ARRAY_SIZE (obj) = size; | |
667 | OBJECT_CONFLICT_VEC_P (obj) = true; | |
47dd2e78 | 668 | } |
669 | ||
ae9587ed | 670 | /* Allocate and initialize the conflict bit vector of OBJ. */ |
47dd2e78 | 671 | static void |
ae9587ed | 672 | allocate_conflict_bit_vec (ira_object_t obj) |
47dd2e78 | 673 | { |
674 | unsigned int size; | |
675 | ||
ae9587ed | 676 | ira_assert (OBJECT_CONFLICT_ARRAY (obj) == NULL); |
677 | size = ((OBJECT_MAX (obj) - OBJECT_MIN (obj) + IRA_INT_BITS) | |
47dd2e78 | 678 | / IRA_INT_BITS * sizeof (IRA_INT_TYPE)); |
ae9587ed | 679 | OBJECT_CONFLICT_ARRAY (obj) = ira_allocate (size); |
680 | memset (OBJECT_CONFLICT_ARRAY (obj), 0, size); | |
681 | OBJECT_CONFLICT_ARRAY_SIZE (obj) = size; | |
682 | OBJECT_CONFLICT_VEC_P (obj) = false; | |
47dd2e78 | 683 | } |
684 | ||
685 | /* Allocate and initialize the conflict vector or conflict bit vector | |
be18556f | 686 | of OBJ for NUM conflicting allocnos whatever is more profitable. */ |
47dd2e78 | 687 | void |
be18556f | 688 | ira_allocate_object_conflicts (ira_object_t obj, int num) |
47dd2e78 | 689 | { |
be18556f | 690 | if (ira_conflict_vector_profitable_p (obj, num)) |
691 | ira_allocate_conflict_vec (obj, num); | |
47dd2e78 | 692 | else |
be18556f | 693 | allocate_conflict_bit_vec (obj); |
47dd2e78 | 694 | } |
695 | ||
ae9587ed | 696 | /* Add OBJ2 to the conflicts of OBJ1. */ |
47dd2e78 | 697 | static void |
ae9587ed | 698 | add_to_conflicts (ira_object_t obj1, ira_object_t obj2) |
47dd2e78 | 699 | { |
700 | int num; | |
701 | unsigned int size; | |
702 | ||
ae9587ed | 703 | if (OBJECT_CONFLICT_VEC_P (obj1)) |
47dd2e78 | 704 | { |
ae9587ed | 705 | ira_object_t *vec = OBJECT_CONFLICT_VEC (obj1); |
706 | int curr_num = OBJECT_NUM_CONFLICTS (obj1); | |
707 | num = curr_num + 2; | |
708 | if (OBJECT_CONFLICT_ARRAY_SIZE (obj1) < num * sizeof (ira_object_t)) | |
47dd2e78 | 709 | { |
ae9587ed | 710 | ira_object_t *newvec; |
47dd2e78 | 711 | size = (3 * num / 2 + 1) * sizeof (ira_allocno_t); |
ae9587ed | 712 | newvec = (ira_object_t *) ira_allocate (size); |
713 | memcpy (newvec, vec, curr_num * sizeof (ira_object_t)); | |
714 | ira_free (vec); | |
715 | vec = newvec; | |
716 | OBJECT_CONFLICT_ARRAY (obj1) = vec; | |
717 | OBJECT_CONFLICT_ARRAY_SIZE (obj1) = size; | |
47dd2e78 | 718 | } |
ae9587ed | 719 | vec[num - 2] = obj2; |
47dd2e78 | 720 | vec[num - 1] = NULL; |
ae9587ed | 721 | OBJECT_NUM_CONFLICTS (obj1)++; |
47dd2e78 | 722 | } |
723 | else | |
724 | { | |
725 | int nw, added_head_nw, id; | |
ae9587ed | 726 | IRA_INT_TYPE *vec = OBJECT_CONFLICT_BITVEC (obj1); |
47dd2e78 | 727 | |
ae9587ed | 728 | id = OBJECT_CONFLICT_ID (obj2); |
729 | if (OBJECT_MIN (obj1) > id) | |
47dd2e78 | 730 | { |
731 | /* Expand head of the bit vector. */ | |
ae9587ed | 732 | added_head_nw = (OBJECT_MIN (obj1) - id - 1) / IRA_INT_BITS + 1; |
733 | nw = (OBJECT_MAX (obj1) - OBJECT_MIN (obj1)) / IRA_INT_BITS + 1; | |
47dd2e78 | 734 | size = (nw + added_head_nw) * sizeof (IRA_INT_TYPE); |
ae9587ed | 735 | if (OBJECT_CONFLICT_ARRAY_SIZE (obj1) >= size) |
47dd2e78 | 736 | { |
737 | memmove ((char *) vec + added_head_nw * sizeof (IRA_INT_TYPE), | |
738 | vec, nw * sizeof (IRA_INT_TYPE)); | |
739 | memset (vec, 0, added_head_nw * sizeof (IRA_INT_TYPE)); | |
740 | } | |
741 | else | |
742 | { | |
743 | size | |
744 | = (3 * (nw + added_head_nw) / 2 + 1) * sizeof (IRA_INT_TYPE); | |
745 | vec = (IRA_INT_TYPE *) ira_allocate (size); | |
746 | memcpy ((char *) vec + added_head_nw * sizeof (IRA_INT_TYPE), | |
ae9587ed | 747 | OBJECT_CONFLICT_ARRAY (obj1), nw * sizeof (IRA_INT_TYPE)); |
47dd2e78 | 748 | memset (vec, 0, added_head_nw * sizeof (IRA_INT_TYPE)); |
749 | memset ((char *) vec | |
750 | + (nw + added_head_nw) * sizeof (IRA_INT_TYPE), | |
751 | 0, size - (nw + added_head_nw) * sizeof (IRA_INT_TYPE)); | |
ae9587ed | 752 | ira_free (OBJECT_CONFLICT_ARRAY (obj1)); |
753 | OBJECT_CONFLICT_ARRAY (obj1) = vec; | |
754 | OBJECT_CONFLICT_ARRAY_SIZE (obj1) = size; | |
47dd2e78 | 755 | } |
ae9587ed | 756 | OBJECT_MIN (obj1) -= added_head_nw * IRA_INT_BITS; |
47dd2e78 | 757 | } |
ae9587ed | 758 | else if (OBJECT_MAX (obj1) < id) |
47dd2e78 | 759 | { |
ae9587ed | 760 | nw = (id - OBJECT_MIN (obj1)) / IRA_INT_BITS + 1; |
47dd2e78 | 761 | size = nw * sizeof (IRA_INT_TYPE); |
ae9587ed | 762 | if (OBJECT_CONFLICT_ARRAY_SIZE (obj1) < size) |
47dd2e78 | 763 | { |
764 | /* Expand tail of the bit vector. */ | |
765 | size = (3 * nw / 2 + 1) * sizeof (IRA_INT_TYPE); | |
766 | vec = (IRA_INT_TYPE *) ira_allocate (size); | |
ae9587ed | 767 | memcpy (vec, OBJECT_CONFLICT_ARRAY (obj1), OBJECT_CONFLICT_ARRAY_SIZE (obj1)); |
768 | memset ((char *) vec + OBJECT_CONFLICT_ARRAY_SIZE (obj1), | |
769 | 0, size - OBJECT_CONFLICT_ARRAY_SIZE (obj1)); | |
770 | ira_free (OBJECT_CONFLICT_ARRAY (obj1)); | |
771 | OBJECT_CONFLICT_ARRAY (obj1) = vec; | |
772 | OBJECT_CONFLICT_ARRAY_SIZE (obj1) = size; | |
47dd2e78 | 773 | } |
ae9587ed | 774 | OBJECT_MAX (obj1) = id; |
47dd2e78 | 775 | } |
ae9587ed | 776 | SET_MINMAX_SET_BIT (vec, id, OBJECT_MIN (obj1), OBJECT_MAX (obj1)); |
47dd2e78 | 777 | } |
778 | } | |
779 | ||
ae9587ed | 780 | /* Add OBJ1 to the conflicts of OBJ2 and vice versa. */ |
781 | static void | |
782 | ira_add_conflict (ira_object_t obj1, ira_object_t obj2) | |
47dd2e78 | 783 | { |
ae9587ed | 784 | add_to_conflicts (obj1, obj2); |
785 | add_to_conflicts (obj2, obj1); | |
47dd2e78 | 786 | } |
787 | ||
ae9587ed | 788 | /* Clear all conflicts of OBJ. */ |
47dd2e78 | 789 | static void |
ae9587ed | 790 | clear_conflicts (ira_object_t obj) |
47dd2e78 | 791 | { |
ae9587ed | 792 | if (OBJECT_CONFLICT_VEC_P (obj)) |
47dd2e78 | 793 | { |
ae9587ed | 794 | OBJECT_NUM_CONFLICTS (obj) = 0; |
795 | OBJECT_CONFLICT_VEC (obj)[0] = NULL; | |
47dd2e78 | 796 | } |
ae9587ed | 797 | else if (OBJECT_CONFLICT_ARRAY_SIZE (obj) != 0) |
47dd2e78 | 798 | { |
799 | int nw; | |
800 | ||
ae9587ed | 801 | nw = (OBJECT_MAX (obj) - OBJECT_MIN (obj)) / IRA_INT_BITS + 1; |
802 | memset (OBJECT_CONFLICT_BITVEC (obj), 0, nw * sizeof (IRA_INT_TYPE)); | |
47dd2e78 | 803 | } |
804 | } | |
805 | ||
806 | /* The array used to find duplications in conflict vectors of | |
807 | allocnos. */ | |
ae9587ed | 808 | static int *conflict_check; |
47dd2e78 | 809 | |
810 | /* The value used to mark allocation presence in conflict vector of | |
811 | the current allocno. */ | |
ae9587ed | 812 | static int curr_conflict_check_tick; |
47dd2e78 | 813 | |
ae9587ed | 814 | /* Remove duplications in conflict vector of OBJ. */ |
47dd2e78 | 815 | static void |
ae9587ed | 816 | compress_conflict_vec (ira_object_t obj) |
47dd2e78 | 817 | { |
ae9587ed | 818 | ira_object_t *vec, conflict_obj; |
47dd2e78 | 819 | int i, j; |
820 | ||
ae9587ed | 821 | ira_assert (OBJECT_CONFLICT_VEC_P (obj)); |
822 | vec = OBJECT_CONFLICT_VEC (obj); | |
823 | curr_conflict_check_tick++; | |
824 | for (i = j = 0; (conflict_obj = vec[i]) != NULL; i++) | |
47dd2e78 | 825 | { |
ae9587ed | 826 | int id = OBJECT_CONFLICT_ID (conflict_obj); |
827 | if (conflict_check[id] != curr_conflict_check_tick) | |
47dd2e78 | 828 | { |
ae9587ed | 829 | conflict_check[id] = curr_conflict_check_tick; |
830 | vec[j++] = conflict_obj; | |
47dd2e78 | 831 | } |
832 | } | |
ae9587ed | 833 | OBJECT_NUM_CONFLICTS (obj) = j; |
47dd2e78 | 834 | vec[j] = NULL; |
835 | } | |
836 | ||
837 | /* Remove duplications in conflict vectors of all allocnos. */ | |
838 | static void | |
839 | compress_conflict_vecs (void) | |
840 | { | |
be18556f | 841 | ira_object_t obj; |
842 | ira_object_iterator oi; | |
47dd2e78 | 843 | |
ae9587ed | 844 | conflict_check = (int *) ira_allocate (sizeof (int) * ira_objects_num); |
845 | memset (conflict_check, 0, sizeof (int) * ira_objects_num); | |
846 | curr_conflict_check_tick = 0; | |
be18556f | 847 | FOR_EACH_OBJECT (obj, oi) |
ae9587ed | 848 | { |
ae9587ed | 849 | if (OBJECT_CONFLICT_VEC_P (obj)) |
850 | compress_conflict_vec (obj); | |
851 | } | |
852 | ira_free (conflict_check); | |
47dd2e78 | 853 | } |
854 | ||
855 | /* This recursive function outputs allocno A and if it is a cap the | |
856 | function outputs its members. */ | |
857 | void | |
858 | ira_print_expanded_allocno (ira_allocno_t a) | |
859 | { | |
860 | basic_block bb; | |
861 | ||
862 | fprintf (ira_dump_file, " a%d(r%d", ALLOCNO_NUM (a), ALLOCNO_REGNO (a)); | |
863 | if ((bb = ALLOCNO_LOOP_TREE_NODE (a)->bb) != NULL) | |
864 | fprintf (ira_dump_file, ",b%d", bb->index); | |
865 | else | |
9f8ac546 | 866 | fprintf (ira_dump_file, ",l%d", ALLOCNO_LOOP_TREE_NODE (a)->loop_num); |
47dd2e78 | 867 | if (ALLOCNO_CAP_MEMBER (a) != NULL) |
868 | { | |
869 | fprintf (ira_dump_file, ":"); | |
870 | ira_print_expanded_allocno (ALLOCNO_CAP_MEMBER (a)); | |
871 | } | |
872 | fprintf (ira_dump_file, ")"); | |
873 | } | |
874 | ||
875 | /* Create and return the cap representing allocno A in the | |
876 | parent loop. */ | |
877 | static ira_allocno_t | |
878 | create_cap_allocno (ira_allocno_t a) | |
879 | { | |
880 | ira_allocno_t cap; | |
881 | ira_loop_tree_node_t parent; | |
66d9a7b9 | 882 | enum reg_class aclass; |
47dd2e78 | 883 | |
47dd2e78 | 884 | parent = ALLOCNO_LOOP_TREE_NODE (a)->parent; |
885 | cap = ira_create_allocno (ALLOCNO_REGNO (a), true, parent); | |
886 | ALLOCNO_MODE (cap) = ALLOCNO_MODE (a); | |
66d9a7b9 | 887 | aclass = ALLOCNO_CLASS (a); |
888 | ira_set_allocno_class (cap, aclass); | |
be18556f | 889 | ira_create_allocno_objects (cap); |
47dd2e78 | 890 | ALLOCNO_CAP_MEMBER (cap) = a; |
47dd2e78 | 891 | ALLOCNO_CAP (a) = cap; |
66d9a7b9 | 892 | ALLOCNO_CLASS_COST (cap) = ALLOCNO_CLASS_COST (a); |
47dd2e78 | 893 | ALLOCNO_MEMORY_COST (cap) = ALLOCNO_MEMORY_COST (a); |
47dd2e78 | 894 | ira_allocate_and_copy_costs |
66d9a7b9 | 895 | (&ALLOCNO_HARD_REG_COSTS (cap), aclass, ALLOCNO_HARD_REG_COSTS (a)); |
47dd2e78 | 896 | ira_allocate_and_copy_costs |
66d9a7b9 | 897 | (&ALLOCNO_CONFLICT_HARD_REG_COSTS (cap), aclass, |
47dd2e78 | 898 | ALLOCNO_CONFLICT_HARD_REG_COSTS (a)); |
68d4bdfb | 899 | ALLOCNO_BAD_SPILL_P (cap) = ALLOCNO_BAD_SPILL_P (a); |
47dd2e78 | 900 | ALLOCNO_NREFS (cap) = ALLOCNO_NREFS (a); |
901 | ALLOCNO_FREQ (cap) = ALLOCNO_FREQ (a); | |
902 | ALLOCNO_CALL_FREQ (cap) = ALLOCNO_CALL_FREQ (a); | |
be18556f | 903 | |
b4f5e198 | 904 | merge_hard_reg_conflicts (a, cap, false); |
be18556f | 905 | |
47dd2e78 | 906 | ALLOCNO_CALLS_CROSSED_NUM (cap) = ALLOCNO_CALLS_CROSSED_NUM (a); |
c8010b80 | 907 | ALLOCNO_CHEAP_CALLS_CROSSED_NUM (cap) = ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a); |
47dd2e78 | 908 | if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL) |
909 | { | |
910 | fprintf (ira_dump_file, " Creating cap "); | |
911 | ira_print_expanded_allocno (cap); | |
912 | fprintf (ira_dump_file, "\n"); | |
913 | } | |
914 | return cap; | |
915 | } | |
916 | ||
be18556f | 917 | /* Create and return a live range for OBJECT with given attributes. */ |
fbff82f4 | 918 | live_range_t |
9d53e372 | 919 | ira_create_live_range (ira_object_t obj, int start, int finish, |
920 | live_range_t next) | |
47dd2e78 | 921 | { |
fbff82f4 | 922 | live_range_t p; |
47dd2e78 | 923 | |
fbff82f4 | 924 | p = (live_range_t) pool_alloc (live_range_pool); |
9d53e372 | 925 | p->object = obj; |
47dd2e78 | 926 | p->start = start; |
927 | p->finish = finish; | |
928 | p->next = next; | |
929 | return p; | |
930 | } | |
931 | ||
be18556f | 932 | /* Create a new live range for OBJECT and queue it at the head of its |
933 | live range list. */ | |
934 | void | |
935 | ira_add_live_range_to_object (ira_object_t object, int start, int finish) | |
936 | { | |
937 | live_range_t p; | |
938 | p = ira_create_live_range (object, start, finish, | |
939 | OBJECT_LIVE_RANGES (object)); | |
940 | OBJECT_LIVE_RANGES (object) = p; | |
941 | } | |
942 | ||
47dd2e78 | 943 | /* Copy allocno live range R and return the result. */ |
fbff82f4 | 944 | static live_range_t |
9d53e372 | 945 | copy_live_range (live_range_t r) |
47dd2e78 | 946 | { |
fbff82f4 | 947 | live_range_t p; |
47dd2e78 | 948 | |
fbff82f4 | 949 | p = (live_range_t) pool_alloc (live_range_pool); |
47dd2e78 | 950 | *p = *r; |
951 | return p; | |
952 | } | |
953 | ||
954 | /* Copy allocno live range list given by its head R and return the | |
955 | result. */ | |
fbff82f4 | 956 | live_range_t |
9d53e372 | 957 | ira_copy_live_range_list (live_range_t r) |
47dd2e78 | 958 | { |
fbff82f4 | 959 | live_range_t p, first, last; |
47dd2e78 | 960 | |
961 | if (r == NULL) | |
962 | return NULL; | |
963 | for (first = last = NULL; r != NULL; r = r->next) | |
964 | { | |
9d53e372 | 965 | p = copy_live_range (r); |
47dd2e78 | 966 | if (first == NULL) |
967 | first = p; | |
968 | else | |
969 | last->next = p; | |
970 | last = p; | |
971 | } | |
972 | return first; | |
973 | } | |
974 | ||
69f8e080 | 975 | /* Merge ranges R1 and R2 and returns the result. The function |
976 | maintains the order of ranges and tries to minimize number of the | |
977 | result ranges. */ | |
fbff82f4 | 978 | live_range_t |
9d53e372 | 979 | ira_merge_live_ranges (live_range_t r1, live_range_t r2) |
69f8e080 | 980 | { |
fbff82f4 | 981 | live_range_t first, last, temp; |
69f8e080 | 982 | |
983 | if (r1 == NULL) | |
984 | return r2; | |
985 | if (r2 == NULL) | |
986 | return r1; | |
987 | for (first = last = NULL; r1 != NULL && r2 != NULL;) | |
988 | { | |
989 | if (r1->start < r2->start) | |
990 | { | |
991 | temp = r1; | |
992 | r1 = r2; | |
993 | r2 = temp; | |
994 | } | |
995 | if (r1->start <= r2->finish + 1) | |
996 | { | |
997 | /* Intersected ranges: merge r1 and r2 into r1. */ | |
998 | r1->start = r2->start; | |
999 | if (r1->finish < r2->finish) | |
1000 | r1->finish = r2->finish; | |
1001 | temp = r2; | |
1002 | r2 = r2->next; | |
9d53e372 | 1003 | ira_finish_live_range (temp); |
69f8e080 | 1004 | if (r2 == NULL) |
1005 | { | |
1006 | /* To try to merge with subsequent ranges in r1. */ | |
1007 | r2 = r1->next; | |
1008 | r1->next = NULL; | |
1009 | } | |
1010 | } | |
1011 | else | |
1012 | { | |
1013 | /* Add r1 to the result. */ | |
1014 | if (first == NULL) | |
1015 | first = last = r1; | |
1016 | else | |
1017 | { | |
1018 | last->next = r1; | |
1019 | last = r1; | |
1020 | } | |
1021 | r1 = r1->next; | |
1022 | if (r1 == NULL) | |
1023 | { | |
1024 | /* To try to merge with subsequent ranges in r2. */ | |
1025 | r1 = r2->next; | |
1026 | r2->next = NULL; | |
1027 | } | |
1028 | } | |
1029 | } | |
1030 | if (r1 != NULL) | |
1031 | { | |
1032 | if (first == NULL) | |
1033 | first = r1; | |
1034 | else | |
1035 | last->next = r1; | |
1036 | ira_assert (r1->next == NULL); | |
1037 | } | |
1038 | else if (r2 != NULL) | |
1039 | { | |
1040 | if (first == NULL) | |
1041 | first = r2; | |
1042 | else | |
1043 | last->next = r2; | |
1044 | ira_assert (r2->next == NULL); | |
1045 | } | |
1046 | else | |
1047 | { | |
1048 | ira_assert (last->next == NULL); | |
1049 | } | |
1050 | return first; | |
1051 | } | |
1052 | ||
1053 | /* Return TRUE if live ranges R1 and R2 intersect. */ | |
1054 | bool | |
9d53e372 | 1055 | ira_live_ranges_intersect_p (live_range_t r1, live_range_t r2) |
69f8e080 | 1056 | { |
1057 | /* Remember the live ranges are always kept ordered. */ | |
1058 | while (r1 != NULL && r2 != NULL) | |
1059 | { | |
1060 | if (r1->start > r2->finish) | |
1061 | r1 = r1->next; | |
1062 | else if (r2->start > r1->finish) | |
1063 | r2 = r2->next; | |
1064 | else | |
1065 | return true; | |
1066 | } | |
1067 | return false; | |
1068 | } | |
1069 | ||
47dd2e78 | 1070 | /* Free allocno live range R. */ |
1071 | void | |
9d53e372 | 1072 | ira_finish_live_range (live_range_t r) |
47dd2e78 | 1073 | { |
fbff82f4 | 1074 | pool_free (live_range_pool, r); |
47dd2e78 | 1075 | } |
1076 | ||
69f8e080 | 1077 | /* Free list of allocno live ranges starting with R. */ |
1078 | void | |
9d53e372 | 1079 | ira_finish_live_range_list (live_range_t r) |
69f8e080 | 1080 | { |
fbff82f4 | 1081 | live_range_t next_r; |
69f8e080 | 1082 | |
1083 | for (; r != NULL; r = next_r) | |
1084 | { | |
1085 | next_r = r->next; | |
9d53e372 | 1086 | ira_finish_live_range (r); |
69f8e080 | 1087 | } |
1088 | } | |
1089 | ||
47dd2e78 | 1090 | /* Free updated register costs of allocno A. */ |
1091 | void | |
1092 | ira_free_allocno_updated_costs (ira_allocno_t a) | |
1093 | { | |
66d9a7b9 | 1094 | enum reg_class aclass; |
47dd2e78 | 1095 | |
66d9a7b9 | 1096 | aclass = ALLOCNO_CLASS (a); |
47dd2e78 | 1097 | if (ALLOCNO_UPDATED_HARD_REG_COSTS (a) != NULL) |
66d9a7b9 | 1098 | ira_free_cost_vector (ALLOCNO_UPDATED_HARD_REG_COSTS (a), aclass); |
47dd2e78 | 1099 | ALLOCNO_UPDATED_HARD_REG_COSTS (a) = NULL; |
1100 | if (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) != NULL) | |
1101 | ira_free_cost_vector (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a), | |
66d9a7b9 | 1102 | aclass); |
47dd2e78 | 1103 | ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) = NULL; |
1104 | } | |
1105 | ||
66d9a7b9 | 1106 | /* Free and nullify all cost vectors allocated earlier for allocno |
1107 | A. */ | |
47dd2e78 | 1108 | static void |
66d9a7b9 | 1109 | ira_free_allocno_costs (ira_allocno_t a) |
47dd2e78 | 1110 | { |
66d9a7b9 | 1111 | enum reg_class aclass = ALLOCNO_CLASS (a); |
be18556f | 1112 | ira_object_t obj; |
1113 | ira_allocno_object_iterator oi; | |
47dd2e78 | 1114 | |
be18556f | 1115 | FOR_EACH_ALLOCNO_OBJECT (a, obj, oi) |
1116 | { | |
1117 | ira_finish_live_range_list (OBJECT_LIVE_RANGES (obj)); | |
1118 | ira_object_id_map[OBJECT_CONFLICT_ID (obj)] = NULL; | |
1119 | if (OBJECT_CONFLICT_ARRAY (obj) != NULL) | |
1120 | ira_free (OBJECT_CONFLICT_ARRAY (obj)); | |
1121 | pool_free (object_pool, obj); | |
1122 | } | |
9d53e372 | 1123 | |
47dd2e78 | 1124 | ira_allocnos[ALLOCNO_NUM (a)] = NULL; |
47dd2e78 | 1125 | if (ALLOCNO_HARD_REG_COSTS (a) != NULL) |
66d9a7b9 | 1126 | ira_free_cost_vector (ALLOCNO_HARD_REG_COSTS (a), aclass); |
47dd2e78 | 1127 | if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a) != NULL) |
66d9a7b9 | 1128 | ira_free_cost_vector (ALLOCNO_CONFLICT_HARD_REG_COSTS (a), aclass); |
47dd2e78 | 1129 | if (ALLOCNO_UPDATED_HARD_REG_COSTS (a) != NULL) |
66d9a7b9 | 1130 | ira_free_cost_vector (ALLOCNO_UPDATED_HARD_REG_COSTS (a), aclass); |
47dd2e78 | 1131 | if (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) != NULL) |
1132 | ira_free_cost_vector (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a), | |
66d9a7b9 | 1133 | aclass); |
1134 | ALLOCNO_HARD_REG_COSTS (a) = NULL; | |
1135 | ALLOCNO_CONFLICT_HARD_REG_COSTS (a) = NULL; | |
1136 | ALLOCNO_UPDATED_HARD_REG_COSTS (a) = NULL; | |
1137 | ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) = NULL; | |
1138 | } | |
1139 | ||
1140 | /* Free the memory allocated for allocno A. */ | |
1141 | static void | |
1142 | finish_allocno (ira_allocno_t a) | |
1143 | { | |
1144 | ira_free_allocno_costs (a); | |
47dd2e78 | 1145 | pool_free (allocno_pool, a); |
1146 | } | |
1147 | ||
1148 | /* Free the memory allocated for all allocnos. */ | |
1149 | static void | |
1150 | finish_allocnos (void) | |
1151 | { | |
1152 | ira_allocno_t a; | |
1153 | ira_allocno_iterator ai; | |
1154 | ||
1155 | FOR_EACH_ALLOCNO (a, ai) | |
1156 | finish_allocno (a); | |
1157 | ira_free (ira_regno_allocno_map); | |
ae9587ed | 1158 | VEC_free (ira_object_t, heap, ira_object_id_map_vec); |
47dd2e78 | 1159 | VEC_free (ira_allocno_t, heap, allocno_vec); |
1160 | free_alloc_pool (allocno_pool); | |
ae9587ed | 1161 | free_alloc_pool (object_pool); |
fbff82f4 | 1162 | free_alloc_pool (live_range_pool); |
47dd2e78 | 1163 | } |
1164 | ||
1165 | \f | |
1166 | ||
1167 | /* Pools for copies. */ | |
1168 | static alloc_pool copy_pool; | |
1169 | ||
1170 | /* Vec containing references to all created copies. It is a | |
1171 | container of array ira_copies. */ | |
1172 | static VEC(ira_copy_t,heap) *copy_vec; | |
1173 | ||
1174 | /* The function initializes data concerning allocno copies. */ | |
1175 | static void | |
1176 | initiate_copies (void) | |
1177 | { | |
1178 | copy_pool | |
1179 | = create_alloc_pool ("copies", sizeof (struct ira_allocno_copy), 100); | |
1180 | copy_vec = VEC_alloc (ira_copy_t, heap, get_max_uid ()); | |
1181 | ira_copies = NULL; | |
1182 | ira_copies_num = 0; | |
1183 | } | |
1184 | ||
1185 | /* Return copy connecting A1 and A2 and originated from INSN of | |
1186 | LOOP_TREE_NODE if any. */ | |
1187 | static ira_copy_t | |
1188 | find_allocno_copy (ira_allocno_t a1, ira_allocno_t a2, rtx insn, | |
1189 | ira_loop_tree_node_t loop_tree_node) | |
1190 | { | |
1191 | ira_copy_t cp, next_cp; | |
1192 | ira_allocno_t another_a; | |
1193 | ||
1194 | for (cp = ALLOCNO_COPIES (a1); cp != NULL; cp = next_cp) | |
1195 | { | |
1196 | if (cp->first == a1) | |
1197 | { | |
1198 | next_cp = cp->next_first_allocno_copy; | |
1199 | another_a = cp->second; | |
1200 | } | |
1201 | else if (cp->second == a1) | |
1202 | { | |
1203 | next_cp = cp->next_second_allocno_copy; | |
1204 | another_a = cp->first; | |
1205 | } | |
1206 | else | |
1207 | gcc_unreachable (); | |
1208 | if (another_a == a2 && cp->insn == insn | |
1209 | && cp->loop_tree_node == loop_tree_node) | |
1210 | return cp; | |
1211 | } | |
1212 | return NULL; | |
1213 | } | |
1214 | ||
1215 | /* Create and return copy with given attributes LOOP_TREE_NODE, FIRST, | |
b7c06809 | 1216 | SECOND, FREQ, CONSTRAINT_P, and INSN. */ |
47dd2e78 | 1217 | ira_copy_t |
b7c06809 | 1218 | ira_create_copy (ira_allocno_t first, ira_allocno_t second, int freq, |
1219 | bool constraint_p, rtx insn, | |
47dd2e78 | 1220 | ira_loop_tree_node_t loop_tree_node) |
1221 | { | |
1222 | ira_copy_t cp; | |
1223 | ||
1224 | cp = (ira_copy_t) pool_alloc (copy_pool); | |
1225 | cp->num = ira_copies_num; | |
1226 | cp->first = first; | |
1227 | cp->second = second; | |
1228 | cp->freq = freq; | |
b7c06809 | 1229 | cp->constraint_p = constraint_p; |
47dd2e78 | 1230 | cp->insn = insn; |
1231 | cp->loop_tree_node = loop_tree_node; | |
1232 | VEC_safe_push (ira_copy_t, heap, copy_vec, cp); | |
1233 | ira_copies = VEC_address (ira_copy_t, copy_vec); | |
1234 | ira_copies_num = VEC_length (ira_copy_t, copy_vec); | |
1235 | return cp; | |
1236 | } | |
1237 | ||
1238 | /* Attach a copy CP to allocnos involved into the copy. */ | |
1239 | void | |
1240 | ira_add_allocno_copy_to_list (ira_copy_t cp) | |
1241 | { | |
1242 | ira_allocno_t first = cp->first, second = cp->second; | |
1243 | ||
1244 | cp->prev_first_allocno_copy = NULL; | |
1245 | cp->prev_second_allocno_copy = NULL; | |
1246 | cp->next_first_allocno_copy = ALLOCNO_COPIES (first); | |
1247 | if (cp->next_first_allocno_copy != NULL) | |
1248 | { | |
1249 | if (cp->next_first_allocno_copy->first == first) | |
1250 | cp->next_first_allocno_copy->prev_first_allocno_copy = cp; | |
1251 | else | |
1252 | cp->next_first_allocno_copy->prev_second_allocno_copy = cp; | |
1253 | } | |
1254 | cp->next_second_allocno_copy = ALLOCNO_COPIES (second); | |
1255 | if (cp->next_second_allocno_copy != NULL) | |
1256 | { | |
1257 | if (cp->next_second_allocno_copy->second == second) | |
1258 | cp->next_second_allocno_copy->prev_second_allocno_copy = cp; | |
1259 | else | |
1260 | cp->next_second_allocno_copy->prev_first_allocno_copy = cp; | |
1261 | } | |
1262 | ALLOCNO_COPIES (first) = cp; | |
1263 | ALLOCNO_COPIES (second) = cp; | |
1264 | } | |
1265 | ||
47dd2e78 | 1266 | /* Make a copy CP a canonical copy where number of the |
1267 | first allocno is less than the second one. */ | |
1268 | void | |
1269 | ira_swap_allocno_copy_ends_if_necessary (ira_copy_t cp) | |
1270 | { | |
1271 | ira_allocno_t temp; | |
1272 | ira_copy_t temp_cp; | |
1273 | ||
1274 | if (ALLOCNO_NUM (cp->first) <= ALLOCNO_NUM (cp->second)) | |
1275 | return; | |
1276 | ||
1277 | temp = cp->first; | |
1278 | cp->first = cp->second; | |
1279 | cp->second = temp; | |
1280 | ||
1281 | temp_cp = cp->prev_first_allocno_copy; | |
1282 | cp->prev_first_allocno_copy = cp->prev_second_allocno_copy; | |
1283 | cp->prev_second_allocno_copy = temp_cp; | |
1284 | ||
1285 | temp_cp = cp->next_first_allocno_copy; | |
1286 | cp->next_first_allocno_copy = cp->next_second_allocno_copy; | |
1287 | cp->next_second_allocno_copy = temp_cp; | |
1288 | } | |
1289 | ||
1290 | /* Create (or update frequency if the copy already exists) and return | |
1291 | the copy of allocnos FIRST and SECOND with frequency FREQ | |
1292 | corresponding to move insn INSN (if any) and originated from | |
1293 | LOOP_TREE_NODE. */ | |
1294 | ira_copy_t | |
1295 | ira_add_allocno_copy (ira_allocno_t first, ira_allocno_t second, int freq, | |
b7c06809 | 1296 | bool constraint_p, rtx insn, |
1297 | ira_loop_tree_node_t loop_tree_node) | |
47dd2e78 | 1298 | { |
1299 | ira_copy_t cp; | |
1300 | ||
1301 | if ((cp = find_allocno_copy (first, second, insn, loop_tree_node)) != NULL) | |
1302 | { | |
1303 | cp->freq += freq; | |
1304 | return cp; | |
1305 | } | |
b7c06809 | 1306 | cp = ira_create_copy (first, second, freq, constraint_p, insn, |
1307 | loop_tree_node); | |
47dd2e78 | 1308 | ira_assert (first != NULL && second != NULL); |
1309 | ira_add_allocno_copy_to_list (cp); | |
1310 | ira_swap_allocno_copy_ends_if_necessary (cp); | |
1311 | return cp; | |
1312 | } | |
1313 | ||
55c858c5 | 1314 | /* Print info about copy CP into file F. */ |
1315 | static void | |
1316 | print_copy (FILE *f, ira_copy_t cp) | |
1317 | { | |
b7c06809 | 1318 | fprintf (f, " cp%d:a%d(r%d)<->a%d(r%d)@%d:%s\n", cp->num, |
55c858c5 | 1319 | ALLOCNO_NUM (cp->first), ALLOCNO_REGNO (cp->first), |
b7c06809 | 1320 | ALLOCNO_NUM (cp->second), ALLOCNO_REGNO (cp->second), cp->freq, |
1321 | cp->insn != NULL | |
1322 | ? "move" : cp->constraint_p ? "constraint" : "shuffle"); | |
55c858c5 | 1323 | } |
1324 | ||
1325 | /* Print info about copy CP into stderr. */ | |
1326 | void | |
1327 | ira_debug_copy (ira_copy_t cp) | |
1328 | { | |
1329 | print_copy (stderr, cp); | |
1330 | } | |
1331 | ||
1332 | /* Print info about all copies into file F. */ | |
1333 | static void | |
1334 | print_copies (FILE *f) | |
1335 | { | |
1336 | ira_copy_t cp; | |
1337 | ira_copy_iterator ci; | |
1338 | ||
1339 | FOR_EACH_COPY (cp, ci) | |
1340 | print_copy (f, cp); | |
1341 | } | |
1342 | ||
1343 | /* Print info about all copies into stderr. */ | |
1344 | void | |
1345 | ira_debug_copies (void) | |
1346 | { | |
1347 | print_copies (stderr); | |
1348 | } | |
1349 | ||
47dd2e78 | 1350 | /* Print info about copies involving allocno A into file F. */ |
1351 | static void | |
1352 | print_allocno_copies (FILE *f, ira_allocno_t a) | |
1353 | { | |
1354 | ira_allocno_t another_a; | |
1355 | ira_copy_t cp, next_cp; | |
1356 | ||
1357 | fprintf (f, " a%d(r%d):", ALLOCNO_NUM (a), ALLOCNO_REGNO (a)); | |
1358 | for (cp = ALLOCNO_COPIES (a); cp != NULL; cp = next_cp) | |
1359 | { | |
1360 | if (cp->first == a) | |
1361 | { | |
1362 | next_cp = cp->next_first_allocno_copy; | |
1363 | another_a = cp->second; | |
1364 | } | |
1365 | else if (cp->second == a) | |
1366 | { | |
1367 | next_cp = cp->next_second_allocno_copy; | |
1368 | another_a = cp->first; | |
1369 | } | |
1370 | else | |
1371 | gcc_unreachable (); | |
1372 | fprintf (f, " cp%d:a%d(r%d)@%d", cp->num, | |
1373 | ALLOCNO_NUM (another_a), ALLOCNO_REGNO (another_a), cp->freq); | |
1374 | } | |
1375 | fprintf (f, "\n"); | |
1376 | } | |
1377 | ||
1378 | /* Print info about copies involving allocno A into stderr. */ | |
1379 | void | |
1380 | ira_debug_allocno_copies (ira_allocno_t a) | |
1381 | { | |
1382 | print_allocno_copies (stderr, a); | |
1383 | } | |
1384 | ||
1385 | /* The function frees memory allocated for copy CP. */ | |
1386 | static void | |
1387 | finish_copy (ira_copy_t cp) | |
1388 | { | |
1389 | pool_free (copy_pool, cp); | |
1390 | } | |
1391 | ||
1392 | ||
1393 | /* Free memory allocated for all copies. */ | |
1394 | static void | |
1395 | finish_copies (void) | |
1396 | { | |
1397 | ira_copy_t cp; | |
1398 | ira_copy_iterator ci; | |
1399 | ||
1400 | FOR_EACH_COPY (cp, ci) | |
1401 | finish_copy (cp); | |
1402 | VEC_free (ira_copy_t, heap, copy_vec); | |
1403 | free_alloc_pool (copy_pool); | |
1404 | } | |
1405 | ||
1406 | \f | |
1407 | ||
66d9a7b9 | 1408 | /* Pools for cost vectors. It is defined only for allocno classes. */ |
47dd2e78 | 1409 | static alloc_pool cost_vector_pool[N_REG_CLASSES]; |
1410 | ||
1411 | /* The function initiates work with hard register cost vectors. It | |
66d9a7b9 | 1412 | creates allocation pool for each allocno class. */ |
47dd2e78 | 1413 | static void |
1414 | initiate_cost_vectors (void) | |
1415 | { | |
1416 | int i; | |
66d9a7b9 | 1417 | enum reg_class aclass; |
47dd2e78 | 1418 | |
66d9a7b9 | 1419 | for (i = 0; i < ira_allocno_classes_num; i++) |
47dd2e78 | 1420 | { |
66d9a7b9 | 1421 | aclass = ira_allocno_classes[i]; |
1422 | cost_vector_pool[aclass] | |
47dd2e78 | 1423 | = create_alloc_pool ("cost vectors", |
66d9a7b9 | 1424 | sizeof (int) * ira_class_hard_regs_num[aclass], |
47dd2e78 | 1425 | 100); |
1426 | } | |
1427 | } | |
1428 | ||
66d9a7b9 | 1429 | /* Allocate and return a cost vector VEC for ACLASS. */ |
47dd2e78 | 1430 | int * |
ade444a4 | 1431 | ira_allocate_cost_vector (reg_class_t aclass) |
47dd2e78 | 1432 | { |
ade444a4 | 1433 | return (int *) pool_alloc (cost_vector_pool[(int) aclass]); |
47dd2e78 | 1434 | } |
1435 | ||
66d9a7b9 | 1436 | /* Free a cost vector VEC for ACLASS. */ |
47dd2e78 | 1437 | void |
ade444a4 | 1438 | ira_free_cost_vector (int *vec, reg_class_t aclass) |
47dd2e78 | 1439 | { |
1440 | ira_assert (vec != NULL); | |
ade444a4 | 1441 | pool_free (cost_vector_pool[(int) aclass], vec); |
47dd2e78 | 1442 | } |
1443 | ||
1444 | /* Finish work with hard register cost vectors. Release allocation | |
66d9a7b9 | 1445 | pool for each allocno class. */ |
47dd2e78 | 1446 | static void |
1447 | finish_cost_vectors (void) | |
1448 | { | |
1449 | int i; | |
66d9a7b9 | 1450 | enum reg_class aclass; |
47dd2e78 | 1451 | |
66d9a7b9 | 1452 | for (i = 0; i < ira_allocno_classes_num; i++) |
47dd2e78 | 1453 | { |
66d9a7b9 | 1454 | aclass = ira_allocno_classes[i]; |
1455 | free_alloc_pool (cost_vector_pool[aclass]); | |
47dd2e78 | 1456 | } |
1457 | } | |
1458 | ||
1459 | \f | |
1460 | ||
1461 | /* The current loop tree node and its regno allocno map. */ | |
1462 | ira_loop_tree_node_t ira_curr_loop_tree_node; | |
1463 | ira_allocno_t *ira_curr_regno_allocno_map; | |
1464 | ||
1465 | /* This recursive function traverses loop tree with root LOOP_NODE | |
1466 | calling non-null functions PREORDER_FUNC and POSTORDER_FUNC | |
1467 | correspondingly in preorder and postorder. The function sets up | |
1468 | IRA_CURR_LOOP_TREE_NODE and IRA_CURR_REGNO_ALLOCNO_MAP. If BB_P, | |
1469 | basic block nodes of LOOP_NODE is also processed (before its | |
1470 | subloop nodes). */ | |
1471 | void | |
1472 | ira_traverse_loop_tree (bool bb_p, ira_loop_tree_node_t loop_node, | |
1473 | void (*preorder_func) (ira_loop_tree_node_t), | |
1474 | void (*postorder_func) (ira_loop_tree_node_t)) | |
1475 | { | |
1476 | ira_loop_tree_node_t subloop_node; | |
1477 | ||
1478 | ira_assert (loop_node->bb == NULL); | |
1479 | ira_curr_loop_tree_node = loop_node; | |
1480 | ira_curr_regno_allocno_map = ira_curr_loop_tree_node->regno_allocno_map; | |
1481 | ||
1482 | if (preorder_func != NULL) | |
1483 | (*preorder_func) (loop_node); | |
48e1416a | 1484 | |
47dd2e78 | 1485 | if (bb_p) |
1486 | for (subloop_node = loop_node->children; | |
1487 | subloop_node != NULL; | |
1488 | subloop_node = subloop_node->next) | |
1489 | if (subloop_node->bb != NULL) | |
1490 | { | |
1491 | if (preorder_func != NULL) | |
1492 | (*preorder_func) (subloop_node); | |
48e1416a | 1493 | |
47dd2e78 | 1494 | if (postorder_func != NULL) |
1495 | (*postorder_func) (subloop_node); | |
1496 | } | |
48e1416a | 1497 | |
47dd2e78 | 1498 | for (subloop_node = loop_node->subloops; |
1499 | subloop_node != NULL; | |
1500 | subloop_node = subloop_node->subloop_next) | |
1501 | { | |
1502 | ira_assert (subloop_node->bb == NULL); | |
1503 | ira_traverse_loop_tree (bb_p, subloop_node, | |
1504 | preorder_func, postorder_func); | |
1505 | } | |
1506 | ||
1507 | ira_curr_loop_tree_node = loop_node; | |
1508 | ira_curr_regno_allocno_map = ira_curr_loop_tree_node->regno_allocno_map; | |
1509 | ||
1510 | if (postorder_func != NULL) | |
1511 | (*postorder_func) (loop_node); | |
1512 | } | |
1513 | ||
1514 | \f | |
1515 | ||
1516 | /* The basic block currently being processed. */ | |
1517 | static basic_block curr_bb; | |
1518 | ||
1519 | /* This recursive function creates allocnos corresponding to | |
1520 | pseudo-registers containing in X. True OUTPUT_P means that X is | |
1521 | a lvalue. */ | |
1522 | static void | |
1523 | create_insn_allocnos (rtx x, bool output_p) | |
1524 | { | |
1525 | int i, j; | |
1526 | const char *fmt; | |
1527 | enum rtx_code code = GET_CODE (x); | |
1528 | ||
1529 | if (code == REG) | |
1530 | { | |
1531 | int regno; | |
1532 | ||
1533 | if ((regno = REGNO (x)) >= FIRST_PSEUDO_REGISTER) | |
1534 | { | |
1535 | ira_allocno_t a; | |
1536 | ||
1537 | if ((a = ira_curr_regno_allocno_map[regno]) == NULL) | |
1538 | a = ira_create_allocno (regno, false, ira_curr_loop_tree_node); | |
48e1416a | 1539 | |
47dd2e78 | 1540 | ALLOCNO_NREFS (a)++; |
1541 | ALLOCNO_FREQ (a) += REG_FREQ_FROM_BB (curr_bb); | |
47dd2e78 | 1542 | if (output_p) |
1543 | bitmap_set_bit (ira_curr_loop_tree_node->modified_regnos, regno); | |
1544 | } | |
1545 | return; | |
1546 | } | |
1547 | else if (code == SET) | |
1548 | { | |
1549 | create_insn_allocnos (SET_DEST (x), true); | |
1550 | create_insn_allocnos (SET_SRC (x), false); | |
1551 | return; | |
1552 | } | |
1553 | else if (code == CLOBBER) | |
1554 | { | |
1555 | create_insn_allocnos (XEXP (x, 0), true); | |
1556 | return; | |
1557 | } | |
1558 | else if (code == MEM) | |
1559 | { | |
1560 | create_insn_allocnos (XEXP (x, 0), false); | |
1561 | return; | |
1562 | } | |
48e1416a | 1563 | else if (code == PRE_DEC || code == POST_DEC || code == PRE_INC || |
47dd2e78 | 1564 | code == POST_INC || code == POST_MODIFY || code == PRE_MODIFY) |
1565 | { | |
1566 | create_insn_allocnos (XEXP (x, 0), true); | |
1567 | create_insn_allocnos (XEXP (x, 0), false); | |
1568 | return; | |
1569 | } | |
1570 | ||
1571 | fmt = GET_RTX_FORMAT (code); | |
1572 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) | |
1573 | { | |
1574 | if (fmt[i] == 'e') | |
1575 | create_insn_allocnos (XEXP (x, i), output_p); | |
1576 | else if (fmt[i] == 'E') | |
1577 | for (j = 0; j < XVECLEN (x, i); j++) | |
1578 | create_insn_allocnos (XVECEXP (x, i, j), output_p); | |
1579 | } | |
1580 | } | |
1581 | ||
1582 | /* Create allocnos corresponding to pseudo-registers living in the | |
1583 | basic block represented by the corresponding loop tree node | |
1584 | BB_NODE. */ | |
1585 | static void | |
1586 | create_bb_allocnos (ira_loop_tree_node_t bb_node) | |
1587 | { | |
1588 | basic_block bb; | |
1589 | rtx insn; | |
1590 | unsigned int i; | |
1591 | bitmap_iterator bi; | |
1592 | ||
1593 | curr_bb = bb = bb_node->bb; | |
1594 | ira_assert (bb != NULL); | |
7e03a244 | 1595 | FOR_BB_INSNS_REVERSE (bb, insn) |
9845d120 | 1596 | if (NONDEBUG_INSN_P (insn)) |
47dd2e78 | 1597 | create_insn_allocnos (PATTERN (insn), false); |
1598 | /* It might be a allocno living through from one subloop to | |
1599 | another. */ | |
2dd81ece | 1600 | EXECUTE_IF_SET_IN_REG_SET (DF_LR_IN (bb), FIRST_PSEUDO_REGISTER, i, bi) |
47dd2e78 | 1601 | if (ira_curr_regno_allocno_map[i] == NULL) |
1602 | ira_create_allocno (i, false, ira_curr_loop_tree_node); | |
1603 | } | |
1604 | ||
1605 | /* Create allocnos corresponding to pseudo-registers living on edge E | |
1606 | (a loop entry or exit). Also mark the allocnos as living on the | |
1607 | loop border. */ | |
1608 | static void | |
1609 | create_loop_allocnos (edge e) | |
1610 | { | |
1611 | unsigned int i; | |
1612 | bitmap live_in_regs, border_allocnos; | |
1613 | bitmap_iterator bi; | |
1614 | ira_loop_tree_node_t parent; | |
1615 | ||
2dd81ece | 1616 | live_in_regs = DF_LR_IN (e->dest); |
47dd2e78 | 1617 | border_allocnos = ira_curr_loop_tree_node->border_allocnos; |
2dd81ece | 1618 | EXECUTE_IF_SET_IN_REG_SET (DF_LR_OUT (e->src), |
47dd2e78 | 1619 | FIRST_PSEUDO_REGISTER, i, bi) |
1620 | if (bitmap_bit_p (live_in_regs, i)) | |
1621 | { | |
1622 | if (ira_curr_regno_allocno_map[i] == NULL) | |
1623 | { | |
1624 | /* The order of creations is important for right | |
1625 | ira_regno_allocno_map. */ | |
1626 | if ((parent = ira_curr_loop_tree_node->parent) != NULL | |
1627 | && parent->regno_allocno_map[i] == NULL) | |
1628 | ira_create_allocno (i, false, parent); | |
1629 | ira_create_allocno (i, false, ira_curr_loop_tree_node); | |
1630 | } | |
1631 | bitmap_set_bit (border_allocnos, | |
1632 | ALLOCNO_NUM (ira_curr_regno_allocno_map[i])); | |
1633 | } | |
1634 | } | |
1635 | ||
1636 | /* Create allocnos corresponding to pseudo-registers living in loop | |
1637 | represented by the corresponding loop tree node LOOP_NODE. This | |
1638 | function is called by ira_traverse_loop_tree. */ | |
1639 | static void | |
1640 | create_loop_tree_node_allocnos (ira_loop_tree_node_t loop_node) | |
1641 | { | |
1642 | if (loop_node->bb != NULL) | |
1643 | create_bb_allocnos (loop_node); | |
1644 | else if (loop_node != ira_loop_tree_root) | |
1645 | { | |
1646 | int i; | |
1647 | edge_iterator ei; | |
1648 | edge e; | |
1649 | VEC (edge, heap) *edges; | |
1650 | ||
9f8ac546 | 1651 | ira_assert (current_loops != NULL); |
47dd2e78 | 1652 | FOR_EACH_EDGE (e, ei, loop_node->loop->header->preds) |
1653 | if (e->src != loop_node->loop->latch) | |
1654 | create_loop_allocnos (e); | |
48e1416a | 1655 | |
47dd2e78 | 1656 | edges = get_loop_exit_edges (loop_node->loop); |
48148244 | 1657 | FOR_EACH_VEC_ELT (edge, edges, i, e) |
47dd2e78 | 1658 | create_loop_allocnos (e); |
1659 | VEC_free (edge, heap, edges); | |
1660 | } | |
1661 | } | |
1662 | ||
1663 | /* Propagate information about allocnos modified inside the loop given | |
1664 | by its LOOP_TREE_NODE to its parent. */ | |
1665 | static void | |
1666 | propagate_modified_regnos (ira_loop_tree_node_t loop_tree_node) | |
1667 | { | |
1668 | if (loop_tree_node == ira_loop_tree_root) | |
1669 | return; | |
1670 | ira_assert (loop_tree_node->bb == NULL); | |
1671 | bitmap_ior_into (loop_tree_node->parent->modified_regnos, | |
1672 | loop_tree_node->modified_regnos); | |
1673 | } | |
1674 | ||
1675 | /* Propagate new info about allocno A (see comments about accumulated | |
1676 | info in allocno definition) to the corresponding allocno on upper | |
1677 | loop tree level. So allocnos on upper levels accumulate | |
1678 | information about the corresponding allocnos in nested regions. | |
1679 | The new info means allocno info finally calculated in this | |
1680 | file. */ | |
1681 | static void | |
1682 | propagate_allocno_info (void) | |
1683 | { | |
1684 | int i; | |
1685 | ira_allocno_t a, parent_a; | |
1686 | ira_loop_tree_node_t parent; | |
66d9a7b9 | 1687 | enum reg_class aclass; |
47dd2e78 | 1688 | |
14792f4e | 1689 | if (flag_ira_region != IRA_REGION_ALL |
1690 | && flag_ira_region != IRA_REGION_MIXED) | |
47dd2e78 | 1691 | return; |
1692 | for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--) | |
1693 | for (a = ira_regno_allocno_map[i]; | |
1694 | a != NULL; | |
1695 | a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) | |
1696 | if ((parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) != NULL | |
1697 | && (parent_a = parent->regno_allocno_map[i]) != NULL | |
1698 | /* There are no caps yet at this point. So use | |
1699 | border_allocnos to find allocnos for the propagation. */ | |
1700 | && bitmap_bit_p (ALLOCNO_LOOP_TREE_NODE (a)->border_allocnos, | |
1701 | ALLOCNO_NUM (a))) | |
1702 | { | |
68d4bdfb | 1703 | if (! ALLOCNO_BAD_SPILL_P (a)) |
1704 | ALLOCNO_BAD_SPILL_P (parent_a) = false; | |
47dd2e78 | 1705 | ALLOCNO_NREFS (parent_a) += ALLOCNO_NREFS (a); |
1706 | ALLOCNO_FREQ (parent_a) += ALLOCNO_FREQ (a); | |
1707 | ALLOCNO_CALL_FREQ (parent_a) += ALLOCNO_CALL_FREQ (a); | |
b4f5e198 | 1708 | merge_hard_reg_conflicts (a, parent_a, true); |
47dd2e78 | 1709 | ALLOCNO_CALLS_CROSSED_NUM (parent_a) |
1710 | += ALLOCNO_CALLS_CROSSED_NUM (a); | |
c8010b80 | 1711 | ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a) |
1712 | += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a); | |
47dd2e78 | 1713 | ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a) |
1714 | += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a); | |
66d9a7b9 | 1715 | aclass = ALLOCNO_CLASS (a); |
1716 | ira_assert (aclass == ALLOCNO_CLASS (parent_a)); | |
47dd2e78 | 1717 | ira_allocate_and_accumulate_costs |
66d9a7b9 | 1718 | (&ALLOCNO_HARD_REG_COSTS (parent_a), aclass, |
47dd2e78 | 1719 | ALLOCNO_HARD_REG_COSTS (a)); |
1720 | ira_allocate_and_accumulate_costs | |
1721 | (&ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a), | |
66d9a7b9 | 1722 | aclass, |
47dd2e78 | 1723 | ALLOCNO_CONFLICT_HARD_REG_COSTS (a)); |
66d9a7b9 | 1724 | ALLOCNO_CLASS_COST (parent_a) |
1725 | += ALLOCNO_CLASS_COST (a); | |
47dd2e78 | 1726 | ALLOCNO_MEMORY_COST (parent_a) += ALLOCNO_MEMORY_COST (a); |
47dd2e78 | 1727 | } |
1728 | } | |
1729 | ||
1730 | /* Create allocnos corresponding to pseudo-registers in the current | |
1731 | function. Traverse the loop tree for this. */ | |
1732 | static void | |
1733 | create_allocnos (void) | |
1734 | { | |
1735 | /* We need to process BB first to correctly link allocnos by member | |
1736 | next_regno_allocno. */ | |
1737 | ira_traverse_loop_tree (true, ira_loop_tree_root, | |
1738 | create_loop_tree_node_allocnos, NULL); | |
1739 | if (optimize) | |
1740 | ira_traverse_loop_tree (false, ira_loop_tree_root, NULL, | |
1741 | propagate_modified_regnos); | |
1742 | } | |
1743 | ||
1744 | \f | |
1745 | ||
1746 | /* The page contains function to remove some regions from a separate | |
1747 | register allocation. We remove regions whose separate allocation | |
1748 | will hardly improve the result. As a result we speed up regional | |
1749 | register allocation. */ | |
1750 | ||
9d53e372 | 1751 | /* The function changes the object in range list given by R to OBJ. */ |
47dd2e78 | 1752 | static void |
9d53e372 | 1753 | change_object_in_range_list (live_range_t r, ira_object_t obj) |
47dd2e78 | 1754 | { |
1755 | for (; r != NULL; r = r->next) | |
9d53e372 | 1756 | r->object = obj; |
47dd2e78 | 1757 | } |
1758 | ||
b4f5e198 | 1759 | /* Move all live ranges associated with allocno FROM to allocno TO. */ |
1760 | static void | |
1761 | move_allocno_live_ranges (ira_allocno_t from, ira_allocno_t to) | |
1762 | { | |
be18556f | 1763 | int i; |
1764 | int n = ALLOCNO_NUM_OBJECTS (from); | |
1765 | ||
1766 | gcc_assert (n == ALLOCNO_NUM_OBJECTS (to)); | |
b4f5e198 | 1767 | |
be18556f | 1768 | for (i = 0; i < n; i++) |
b4f5e198 | 1769 | { |
be18556f | 1770 | ira_object_t from_obj = ALLOCNO_OBJECT (from, i); |
1771 | ira_object_t to_obj = ALLOCNO_OBJECT (to, i); | |
1772 | live_range_t lr = OBJECT_LIVE_RANGES (from_obj); | |
1773 | ||
1774 | if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL) | |
1775 | { | |
1776 | fprintf (ira_dump_file, | |
1777 | " Moving ranges of a%dr%d to a%dr%d: ", | |
1778 | ALLOCNO_NUM (from), ALLOCNO_REGNO (from), | |
1779 | ALLOCNO_NUM (to), ALLOCNO_REGNO (to)); | |
1780 | ira_print_live_range_list (ira_dump_file, lr); | |
1781 | } | |
1782 | change_object_in_range_list (lr, to_obj); | |
1783 | OBJECT_LIVE_RANGES (to_obj) | |
1784 | = ira_merge_live_ranges (lr, OBJECT_LIVE_RANGES (to_obj)); | |
1785 | OBJECT_LIVE_RANGES (from_obj) = NULL; | |
b4f5e198 | 1786 | } |
b4f5e198 | 1787 | } |
1788 | ||
b4f5e198 | 1789 | static void |
1790 | copy_allocno_live_ranges (ira_allocno_t from, ira_allocno_t to) | |
1791 | { | |
be18556f | 1792 | int i; |
1793 | int n = ALLOCNO_NUM_OBJECTS (from); | |
b4f5e198 | 1794 | |
be18556f | 1795 | gcc_assert (n == ALLOCNO_NUM_OBJECTS (to)); |
1796 | ||
1797 | for (i = 0; i < n; i++) | |
b4f5e198 | 1798 | { |
be18556f | 1799 | ira_object_t from_obj = ALLOCNO_OBJECT (from, i); |
1800 | ira_object_t to_obj = ALLOCNO_OBJECT (to, i); | |
1801 | live_range_t lr = OBJECT_LIVE_RANGES (from_obj); | |
1802 | ||
1803 | if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL) | |
1804 | { | |
1805 | fprintf (ira_dump_file, " Copying ranges of a%dr%d to a%dr%d: ", | |
1806 | ALLOCNO_NUM (from), ALLOCNO_REGNO (from), | |
1807 | ALLOCNO_NUM (to), ALLOCNO_REGNO (to)); | |
1808 | ira_print_live_range_list (ira_dump_file, lr); | |
1809 | } | |
1810 | lr = ira_copy_live_range_list (lr); | |
1811 | change_object_in_range_list (lr, to_obj); | |
1812 | OBJECT_LIVE_RANGES (to_obj) | |
1813 | = ira_merge_live_ranges (lr, OBJECT_LIVE_RANGES (to_obj)); | |
b4f5e198 | 1814 | } |
b4f5e198 | 1815 | } |
1816 | ||
47dd2e78 | 1817 | /* Return TRUE if NODE represents a loop with low register |
1818 | pressure. */ | |
1819 | static bool | |
1820 | low_pressure_loop_node_p (ira_loop_tree_node_t node) | |
1821 | { | |
1822 | int i; | |
66d9a7b9 | 1823 | enum reg_class pclass; |
48e1416a | 1824 | |
47dd2e78 | 1825 | if (node->bb != NULL) |
1826 | return false; | |
48e1416a | 1827 | |
66d9a7b9 | 1828 | for (i = 0; i < ira_pressure_classes_num; i++) |
47dd2e78 | 1829 | { |
66d9a7b9 | 1830 | pclass = ira_pressure_classes[i]; |
1072fecf | 1831 | if (node->reg_pressure[pclass] > ira_class_hard_regs_num[pclass] |
1832 | && ira_class_hard_regs_num[pclass] > 1) | |
47dd2e78 | 1833 | return false; |
1834 | } | |
1835 | return true; | |
1836 | } | |
1837 | ||
a977d63f | 1838 | #ifdef STACK_REGS |
1839 | /* Return TRUE if LOOP has a complex enter or exit edge. We don't | |
1840 | form a region from such loop if the target use stack register | |
1841 | because reg-stack.c can not deal with such edges. */ | |
c199e49c | 1842 | static bool |
a977d63f | 1843 | loop_with_complex_edge_p (struct loop *loop) |
c199e49c | 1844 | { |
1845 | int i; | |
1846 | edge_iterator ei; | |
1847 | edge e; | |
1848 | VEC (edge, heap) *edges; | |
1849 | ||
1850 | FOR_EACH_EDGE (e, ei, loop->header->preds) | |
1851 | if (e->flags & EDGE_EH) | |
1852 | return true; | |
1853 | edges = get_loop_exit_edges (loop); | |
1854 | FOR_EACH_VEC_ELT (edge, edges, i, e) | |
a977d63f | 1855 | if (e->flags & EDGE_COMPLEX) |
c199e49c | 1856 | return true; |
1857 | return false; | |
1858 | } | |
a977d63f | 1859 | #endif |
c199e49c | 1860 | |
ddf888a5 | 1861 | /* Sort loops for marking them for removal. We put already marked |
1862 | loops first, then less frequent loops next, and then outer loops | |
1863 | next. */ | |
1864 | static int | |
1865 | loop_compare_func (const void *v1p, const void *v2p) | |
1866 | { | |
1867 | int diff; | |
1868 | ira_loop_tree_node_t l1 = *(const ira_loop_tree_node_t *) v1p; | |
1869 | ira_loop_tree_node_t l2 = *(const ira_loop_tree_node_t *) v2p; | |
1870 | ||
1871 | ira_assert (l1->parent != NULL && l2->parent != NULL); | |
1872 | if (l1->to_remove_p && ! l2->to_remove_p) | |
1873 | return -1; | |
1874 | if (! l1->to_remove_p && l2->to_remove_p) | |
1875 | return 1; | |
1876 | if ((diff = l1->loop->header->frequency - l2->loop->header->frequency) != 0) | |
1877 | return diff; | |
1878 | if ((diff = (int) loop_depth (l1->loop) - (int) loop_depth (l2->loop)) != 0) | |
1879 | return diff; | |
1880 | /* Make sorting stable. */ | |
9f8ac546 | 1881 | return l1->loop_num - l2->loop_num; |
ddf888a5 | 1882 | } |
1883 | ||
ddf888a5 | 1884 | /* Mark loops which should be removed from regional allocation. We |
1885 | remove a loop with low register pressure inside another loop with | |
1886 | register pressure. In this case a separate allocation of the loop | |
1887 | hardly helps (for irregular register file architecture it could | |
1888 | help by choosing a better hard register in the loop but we prefer | |
1889 | faster allocation even in this case). We also remove cheap loops | |
c199e49c | 1890 | if there are more than IRA_MAX_LOOPS_NUM of them. Loop with EH |
1891 | exit or enter edges are removed too because the allocation might | |
1892 | require put pseudo moves on the EH edges (we could still do this | |
1893 | for pseudos with caller saved hard registers in some cases but it | |
1894 | is impossible to say here or during top-down allocation pass what | |
1895 | hard register the pseudos get finally). */ | |
ddf888a5 | 1896 | static void |
1897 | mark_loops_for_removal (void) | |
47dd2e78 | 1898 | { |
ddf888a5 | 1899 | int i, n; |
1900 | ira_loop_tree_node_t *sorted_loops; | |
1901 | loop_p loop; | |
1902 | ||
9f8ac546 | 1903 | ira_assert (current_loops != NULL); |
ddf888a5 | 1904 | sorted_loops |
1905 | = (ira_loop_tree_node_t *) ira_allocate (sizeof (ira_loop_tree_node_t) | |
1906 | * VEC_length (loop_p, | |
1907 | ira_loops.larray)); | |
1908 | for (n = i = 0; VEC_iterate (loop_p, ira_loops.larray, i, loop); i++) | |
1909 | if (ira_loop_nodes[i].regno_allocno_map != NULL) | |
1910 | { | |
1911 | if (ira_loop_nodes[i].parent == NULL) | |
1912 | { | |
1913 | /* Don't remove the root. */ | |
1914 | ira_loop_nodes[i].to_remove_p = false; | |
1915 | continue; | |
1916 | } | |
1917 | sorted_loops[n++] = &ira_loop_nodes[i]; | |
1918 | ira_loop_nodes[i].to_remove_p | |
c199e49c | 1919 | = ((low_pressure_loop_node_p (ira_loop_nodes[i].parent) |
1920 | && low_pressure_loop_node_p (&ira_loop_nodes[i])) | |
a977d63f | 1921 | #ifdef STACK_REGS |
1922 | || loop_with_complex_edge_p (ira_loop_nodes[i].loop) | |
1923 | #endif | |
1924 | ); | |
ddf888a5 | 1925 | } |
1926 | qsort (sorted_loops, n, sizeof (ira_loop_tree_node_t), loop_compare_func); | |
1927 | for (i = 0; n - i + 1 > IRA_MAX_LOOPS_NUM; i++) | |
1928 | { | |
1929 | sorted_loops[i]->to_remove_p = true; | |
1930 | if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL) | |
1931 | fprintf | |
1932 | (ira_dump_file, | |
1933 | " Mark loop %d (header %d, freq %d, depth %d) for removal (%s)\n", | |
9f8ac546 | 1934 | sorted_loops[i]->loop_num, sorted_loops[i]->loop->header->index, |
ddf888a5 | 1935 | sorted_loops[i]->loop->header->frequency, |
1936 | loop_depth (sorted_loops[i]->loop), | |
1937 | low_pressure_loop_node_p (sorted_loops[i]->parent) | |
1938 | && low_pressure_loop_node_p (sorted_loops[i]) | |
1939 | ? "low pressure" : "cheap loop"); | |
1940 | } | |
1941 | ira_free (sorted_loops); | |
47dd2e78 | 1942 | } |
1943 | ||
95c83f01 | 1944 | /* Mark all loops but root for removing. */ |
1945 | static void | |
1946 | mark_all_loops_for_removal (void) | |
1947 | { | |
1948 | int i; | |
1949 | loop_p loop; | |
1950 | ||
9f8ac546 | 1951 | ira_assert (current_loops != NULL); |
48148244 | 1952 | FOR_EACH_VEC_ELT (loop_p, ira_loops.larray, i, loop) |
95c83f01 | 1953 | if (ira_loop_nodes[i].regno_allocno_map != NULL) |
1954 | { | |
1955 | if (ira_loop_nodes[i].parent == NULL) | |
1956 | { | |
1957 | /* Don't remove the root. */ | |
1958 | ira_loop_nodes[i].to_remove_p = false; | |
1959 | continue; | |
1960 | } | |
1961 | ira_loop_nodes[i].to_remove_p = true; | |
1962 | if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL) | |
1963 | fprintf | |
1964 | (ira_dump_file, | |
1965 | " Mark loop %d (header %d, freq %d, depth %d) for removal\n", | |
9f8ac546 | 1966 | ira_loop_nodes[i].loop_num, |
95c83f01 | 1967 | ira_loop_nodes[i].loop->header->index, |
1968 | ira_loop_nodes[i].loop->header->frequency, | |
1969 | loop_depth (ira_loop_nodes[i].loop)); | |
1970 | } | |
1971 | } | |
ddf888a5 | 1972 | |
47dd2e78 | 1973 | /* Definition of vector of loop tree nodes. */ |
1974 | DEF_VEC_P(ira_loop_tree_node_t); | |
1975 | DEF_VEC_ALLOC_P(ira_loop_tree_node_t, heap); | |
1976 | ||
1977 | /* Vec containing references to all removed loop tree nodes. */ | |
1978 | static VEC(ira_loop_tree_node_t,heap) *removed_loop_vec; | |
1979 | ||
1980 | /* Vec containing references to all children of loop tree nodes. */ | |
1981 | static VEC(ira_loop_tree_node_t,heap) *children_vec; | |
1982 | ||
1983 | /* Remove subregions of NODE if their separate allocation will not | |
1984 | improve the result. */ | |
1985 | static void | |
1986 | remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_node_t node) | |
1987 | { | |
1988 | unsigned int start; | |
1989 | bool remove_p; | |
1990 | ira_loop_tree_node_t subnode; | |
1991 | ||
ddf888a5 | 1992 | remove_p = node->to_remove_p; |
47dd2e78 | 1993 | if (! remove_p) |
1994 | VEC_safe_push (ira_loop_tree_node_t, heap, children_vec, node); | |
1995 | start = VEC_length (ira_loop_tree_node_t, children_vec); | |
1996 | for (subnode = node->children; subnode != NULL; subnode = subnode->next) | |
1997 | if (subnode->bb == NULL) | |
1998 | remove_uneccesary_loop_nodes_from_loop_tree (subnode); | |
1999 | else | |
2000 | VEC_safe_push (ira_loop_tree_node_t, heap, children_vec, subnode); | |
2001 | node->children = node->subloops = NULL; | |
2002 | if (remove_p) | |
2003 | { | |
2004 | VEC_safe_push (ira_loop_tree_node_t, heap, removed_loop_vec, node); | |
2005 | return; | |
2006 | } | |
2007 | while (VEC_length (ira_loop_tree_node_t, children_vec) > start) | |
2008 | { | |
2009 | subnode = VEC_pop (ira_loop_tree_node_t, children_vec); | |
2010 | subnode->parent = node; | |
2011 | subnode->next = node->children; | |
2012 | node->children = subnode; | |
2013 | if (subnode->bb == NULL) | |
2014 | { | |
2015 | subnode->subloop_next = node->subloops; | |
2016 | node->subloops = subnode; | |
2017 | } | |
2018 | } | |
2019 | } | |
2020 | ||
09c8c6cc | 2021 | /* Return TRUE if NODE is inside PARENT. */ |
2022 | static bool | |
2023 | loop_is_inside_p (ira_loop_tree_node_t node, ira_loop_tree_node_t parent) | |
2024 | { | |
2025 | for (node = node->parent; node != NULL; node = node->parent) | |
2026 | if (node == parent) | |
2027 | return true; | |
2028 | return false; | |
2029 | } | |
2030 | ||
2031 | /* Sort allocnos according to their order in regno allocno list. */ | |
2032 | static int | |
2033 | regno_allocno_order_compare_func (const void *v1p, const void *v2p) | |
2034 | { | |
2035 | ira_allocno_t a1 = *(const ira_allocno_t *) v1p; | |
2036 | ira_allocno_t a2 = *(const ira_allocno_t *) v2p; | |
2037 | ira_loop_tree_node_t n1 = ALLOCNO_LOOP_TREE_NODE (a1); | |
2038 | ira_loop_tree_node_t n2 = ALLOCNO_LOOP_TREE_NODE (a2); | |
2039 | ||
2040 | if (loop_is_inside_p (n1, n2)) | |
2041 | return -1; | |
2042 | else if (loop_is_inside_p (n2, n1)) | |
2043 | return 1; | |
2044 | /* If allocnos are equally good, sort by allocno numbers, so that | |
2045 | the results of qsort leave nothing to chance. We put allocnos | |
2046 | with higher number first in the list because it is the original | |
2047 | order for allocnos from loops on the same levels. */ | |
2048 | return ALLOCNO_NUM (a2) - ALLOCNO_NUM (a1); | |
2049 | } | |
2050 | ||
2051 | /* This array is used to sort allocnos to restore allocno order in | |
2052 | the regno allocno list. */ | |
2053 | static ira_allocno_t *regno_allocnos; | |
2054 | ||
2055 | /* Restore allocno order for REGNO in the regno allocno list. */ | |
2056 | static void | |
2057 | ira_rebuild_regno_allocno_list (int regno) | |
2058 | { | |
2059 | int i, n; | |
2060 | ira_allocno_t a; | |
2061 | ||
2062 | for (n = 0, a = ira_regno_allocno_map[regno]; | |
2063 | a != NULL; | |
2064 | a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) | |
2065 | regno_allocnos[n++] = a; | |
2066 | ira_assert (n > 0); | |
48e1416a | 2067 | qsort (regno_allocnos, n, sizeof (ira_allocno_t), |
09c8c6cc | 2068 | regno_allocno_order_compare_func); |
2069 | for (i = 1; i < n; i++) | |
2070 | ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos[i - 1]) = regno_allocnos[i]; | |
2071 | ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos[n - 1]) = NULL; | |
2072 | ira_regno_allocno_map[regno] = regno_allocnos[0]; | |
2073 | if (internal_flag_ira_verbose > 1 && ira_dump_file != NULL) | |
2074 | fprintf (ira_dump_file, " Rebuilding regno allocno list for %d\n", regno); | |
2075 | } | |
2076 | ||
95c83f01 | 2077 | /* Propagate info from allocno FROM_A to allocno A. */ |
2078 | static void | |
2079 | propagate_some_info_from_allocno (ira_allocno_t a, ira_allocno_t from_a) | |
2080 | { | |
66d9a7b9 | 2081 | enum reg_class aclass; |
95c83f01 | 2082 | |
b4f5e198 | 2083 | merge_hard_reg_conflicts (from_a, a, false); |
95c83f01 | 2084 | ALLOCNO_NREFS (a) += ALLOCNO_NREFS (from_a); |
2085 | ALLOCNO_FREQ (a) += ALLOCNO_FREQ (from_a); | |
2086 | ALLOCNO_CALL_FREQ (a) += ALLOCNO_CALL_FREQ (from_a); | |
95c83f01 | 2087 | ALLOCNO_CALLS_CROSSED_NUM (a) += ALLOCNO_CALLS_CROSSED_NUM (from_a); |
c8010b80 | 2088 | ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a) |
2089 | += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (from_a); | |
95c83f01 | 2090 | ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a) |
2091 | += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (from_a); | |
2092 | if (! ALLOCNO_BAD_SPILL_P (from_a)) | |
2093 | ALLOCNO_BAD_SPILL_P (a) = false; | |
66d9a7b9 | 2094 | aclass = ALLOCNO_CLASS (from_a); |
2095 | ira_assert (aclass == ALLOCNO_CLASS (a)); | |
2096 | ira_allocate_and_accumulate_costs (&ALLOCNO_HARD_REG_COSTS (a), aclass, | |
95c83f01 | 2097 | ALLOCNO_HARD_REG_COSTS (from_a)); |
2098 | ira_allocate_and_accumulate_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a), | |
66d9a7b9 | 2099 | aclass, |
95c83f01 | 2100 | ALLOCNO_CONFLICT_HARD_REG_COSTS (from_a)); |
66d9a7b9 | 2101 | ALLOCNO_CLASS_COST (a) += ALLOCNO_CLASS_COST (from_a); |
95c83f01 | 2102 | ALLOCNO_MEMORY_COST (a) += ALLOCNO_MEMORY_COST (from_a); |
2103 | } | |
2104 | ||
47dd2e78 | 2105 | /* Remove allocnos from loops removed from the allocation |
2106 | consideration. */ | |
2107 | static void | |
2108 | remove_unnecessary_allocnos (void) | |
2109 | { | |
2110 | int regno; | |
09c8c6cc | 2111 | bool merged_p, rebuild_p; |
47dd2e78 | 2112 | ira_allocno_t a, prev_a, next_a, parent_a; |
2113 | ira_loop_tree_node_t a_node, parent; | |
47dd2e78 | 2114 | |
2115 | merged_p = false; | |
09c8c6cc | 2116 | regno_allocnos = NULL; |
47dd2e78 | 2117 | for (regno = max_reg_num () - 1; regno >= FIRST_PSEUDO_REGISTER; regno--) |
09c8c6cc | 2118 | { |
2119 | rebuild_p = false; | |
2120 | for (prev_a = NULL, a = ira_regno_allocno_map[regno]; | |
2121 | a != NULL; | |
2122 | a = next_a) | |
2123 | { | |
2124 | next_a = ALLOCNO_NEXT_REGNO_ALLOCNO (a); | |
2125 | a_node = ALLOCNO_LOOP_TREE_NODE (a); | |
2126 | if (! a_node->to_remove_p) | |
2127 | prev_a = a; | |
2128 | else | |
2129 | { | |
2130 | for (parent = a_node->parent; | |
2131 | (parent_a = parent->regno_allocno_map[regno]) == NULL | |
2132 | && parent->to_remove_p; | |
2133 | parent = parent->parent) | |
2134 | ; | |
2135 | if (parent_a == NULL) | |
2136 | { | |
95c83f01 | 2137 | /* There are no allocnos with the same regno in |
2138 | upper region -- just move the allocno to the | |
2139 | upper region. */ | |
09c8c6cc | 2140 | prev_a = a; |
2141 | ALLOCNO_LOOP_TREE_NODE (a) = parent; | |
2142 | parent->regno_allocno_map[regno] = a; | |
2143 | bitmap_set_bit (parent->all_allocnos, ALLOCNO_NUM (a)); | |
2144 | rebuild_p = true; | |
2145 | } | |
2146 | else | |
2147 | { | |
2148 | /* Remove the allocno and update info of allocno in | |
2149 | the upper region. */ | |
2150 | if (prev_a == NULL) | |
2151 | ira_regno_allocno_map[regno] = next_a; | |
2152 | else | |
2153 | ALLOCNO_NEXT_REGNO_ALLOCNO (prev_a) = next_a; | |
b4f5e198 | 2154 | move_allocno_live_ranges (a, parent_a); |
09c8c6cc | 2155 | merged_p = true; |
95c83f01 | 2156 | propagate_some_info_from_allocno (parent_a, a); |
7ec7a88e | 2157 | /* Remove it from the corresponding regno allocno |
2158 | map to avoid info propagation of subsequent | |
2159 | allocno into this already removed allocno. */ | |
2160 | a_node->regno_allocno_map[regno] = NULL; | |
09c8c6cc | 2161 | finish_allocno (a); |
2162 | } | |
2163 | } | |
2164 | } | |
2165 | if (rebuild_p) | |
2166 | /* We need to restore the order in regno allocno list. */ | |
2167 | { | |
2168 | if (regno_allocnos == NULL) | |
2169 | regno_allocnos | |
2170 | = (ira_allocno_t *) ira_allocate (sizeof (ira_allocno_t) | |
2171 | * ira_allocnos_num); | |
2172 | ira_rebuild_regno_allocno_list (regno); | |
2173 | } | |
2174 | } | |
47dd2e78 | 2175 | if (merged_p) |
2176 | ira_rebuild_start_finish_chains (); | |
09c8c6cc | 2177 | if (regno_allocnos != NULL) |
2178 | ira_free (regno_allocnos); | |
47dd2e78 | 2179 | } |
2180 | ||
95c83f01 | 2181 | /* Remove allocnos from all loops but the root. */ |
47dd2e78 | 2182 | static void |
95c83f01 | 2183 | remove_low_level_allocnos (void) |
47dd2e78 | 2184 | { |
95c83f01 | 2185 | int regno; |
2186 | bool merged_p, propagate_p; | |
2187 | ira_allocno_t a, top_a; | |
2188 | ira_loop_tree_node_t a_node, parent; | |
95c83f01 | 2189 | ira_allocno_iterator ai; |
2190 | ||
2191 | merged_p = false; | |
2192 | FOR_EACH_ALLOCNO (a, ai) | |
2193 | { | |
2194 | a_node = ALLOCNO_LOOP_TREE_NODE (a); | |
2195 | if (a_node == ira_loop_tree_root || ALLOCNO_CAP_MEMBER (a) != NULL) | |
2196 | continue; | |
2197 | regno = ALLOCNO_REGNO (a); | |
2198 | if ((top_a = ira_loop_tree_root->regno_allocno_map[regno]) == NULL) | |
2199 | { | |
2200 | ALLOCNO_LOOP_TREE_NODE (a) = ira_loop_tree_root; | |
2201 | ira_loop_tree_root->regno_allocno_map[regno] = a; | |
2202 | continue; | |
2203 | } | |
2204 | propagate_p = a_node->parent->regno_allocno_map[regno] == NULL; | |
2205 | /* Remove the allocno and update info of allocno in the upper | |
2206 | region. */ | |
b4f5e198 | 2207 | move_allocno_live_ranges (a, top_a); |
95c83f01 | 2208 | merged_p = true; |
95c83f01 | 2209 | if (propagate_p) |
2210 | propagate_some_info_from_allocno (top_a, a); | |
2211 | } | |
2212 | FOR_EACH_ALLOCNO (a, ai) | |
2213 | { | |
2214 | a_node = ALLOCNO_LOOP_TREE_NODE (a); | |
2215 | if (a_node == ira_loop_tree_root) | |
2216 | continue; | |
2217 | parent = a_node->parent; | |
2218 | regno = ALLOCNO_REGNO (a); | |
2219 | if (ALLOCNO_CAP_MEMBER (a) != NULL) | |
2220 | ira_assert (ALLOCNO_CAP (a) != NULL); | |
2221 | else if (ALLOCNO_CAP (a) == NULL) | |
2222 | ira_assert (parent->regno_allocno_map[regno] != NULL); | |
2223 | } | |
2224 | FOR_EACH_ALLOCNO (a, ai) | |
2225 | { | |
2226 | regno = ALLOCNO_REGNO (a); | |
2227 | if (ira_loop_tree_root->regno_allocno_map[regno] == a) | |
2228 | { | |
be18556f | 2229 | ira_object_t obj; |
2230 | ira_allocno_object_iterator oi; | |
ae9587ed | 2231 | |
95c83f01 | 2232 | ira_regno_allocno_map[regno] = a; |
2233 | ALLOCNO_NEXT_REGNO_ALLOCNO (a) = NULL; | |
2234 | ALLOCNO_CAP_MEMBER (a) = NULL; | |
be18556f | 2235 | FOR_EACH_ALLOCNO_OBJECT (a, obj, oi) |
2236 | COPY_HARD_REG_SET (OBJECT_CONFLICT_HARD_REGS (obj), | |
2237 | OBJECT_TOTAL_CONFLICT_HARD_REGS (obj)); | |
95c83f01 | 2238 | #ifdef STACK_REGS |
2239 | if (ALLOCNO_TOTAL_NO_STACK_REG_P (a)) | |
2240 | ALLOCNO_NO_STACK_REG_P (a) = true; | |
2241 | #endif | |
2242 | } | |
2243 | else | |
2244 | finish_allocno (a); | |
2245 | } | |
2246 | if (merged_p) | |
2247 | ira_rebuild_start_finish_chains (); | |
2248 | } | |
2249 | ||
2250 | /* Remove loops from consideration. We remove all loops except for | |
2251 | root if ALL_P or loops for which a separate allocation will not | |
2252 | improve the result. We have to do this after allocno creation and | |
66d9a7b9 | 2253 | their costs and allocno class evaluation because only after that |
2254 | the register pressure can be known and is calculated. */ | |
95c83f01 | 2255 | static void |
2256 | remove_unnecessary_regions (bool all_p) | |
2257 | { | |
9f8ac546 | 2258 | if (current_loops == NULL) |
2259 | return; | |
95c83f01 | 2260 | if (all_p) |
2261 | mark_all_loops_for_removal (); | |
2262 | else | |
2263 | mark_loops_for_removal (); | |
47dd2e78 | 2264 | children_vec |
2265 | = VEC_alloc (ira_loop_tree_node_t, heap, | |
2266 | last_basic_block + VEC_length (loop_p, ira_loops.larray)); | |
2267 | removed_loop_vec | |
2268 | = VEC_alloc (ira_loop_tree_node_t, heap, | |
2269 | last_basic_block + VEC_length (loop_p, ira_loops.larray)); | |
2270 | remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_root) ; | |
2271 | VEC_free (ira_loop_tree_node_t, heap, children_vec); | |
95c83f01 | 2272 | if (all_p) |
2273 | remove_low_level_allocnos (); | |
2274 | else | |
2275 | remove_unnecessary_allocnos (); | |
47dd2e78 | 2276 | while (VEC_length (ira_loop_tree_node_t, removed_loop_vec) > 0) |
2277 | finish_loop_tree_node (VEC_pop (ira_loop_tree_node_t, removed_loop_vec)); | |
2278 | VEC_free (ira_loop_tree_node_t, heap, removed_loop_vec); | |
2279 | } | |
2280 | ||
2281 | \f | |
2282 | ||
68d4bdfb | 2283 | /* At this point true value of allocno attribute bad_spill_p means |
2284 | that there is an insn where allocno occurs and where the allocno | |
2285 | can not be used as memory. The function updates the attribute, now | |
2286 | it can be true only for allocnos which can not be used as memory in | |
2287 | an insn and in whose live ranges there is other allocno deaths. | |
2288 | Spilling allocnos with true value will not improve the code because | |
2289 | it will not make other allocnos colorable and additional reloads | |
2290 | for the corresponding pseudo will be generated in reload pass for | |
2291 | each insn it occurs. | |
2292 | ||
2293 | This is a trick mentioned in one classic article of Chaitin etc | |
2294 | which is frequently omitted in other implementations of RA based on | |
2295 | graph coloring. */ | |
2296 | static void | |
2297 | update_bad_spill_attribute (void) | |
2298 | { | |
2299 | int i; | |
2300 | ira_allocno_t a; | |
2301 | ira_allocno_iterator ai; | |
be18556f | 2302 | ira_allocno_object_iterator aoi; |
2303 | ira_object_t obj; | |
fbff82f4 | 2304 | live_range_t r; |
66d9a7b9 | 2305 | enum reg_class aclass; |
68d4bdfb | 2306 | bitmap_head dead_points[N_REG_CLASSES]; |
2307 | ||
66d9a7b9 | 2308 | for (i = 0; i < ira_allocno_classes_num; i++) |
68d4bdfb | 2309 | { |
66d9a7b9 | 2310 | aclass = ira_allocno_classes[i]; |
2311 | bitmap_initialize (&dead_points[aclass], ®_obstack); | |
68d4bdfb | 2312 | } |
2313 | FOR_EACH_ALLOCNO (a, ai) | |
2314 | { | |
66d9a7b9 | 2315 | aclass = ALLOCNO_CLASS (a); |
2316 | if (aclass == NO_REGS) | |
68d4bdfb | 2317 | continue; |
be18556f | 2318 | FOR_EACH_ALLOCNO_OBJECT (a, obj, aoi) |
2319 | for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next) | |
66d9a7b9 | 2320 | bitmap_set_bit (&dead_points[aclass], r->finish); |
68d4bdfb | 2321 | } |
2322 | FOR_EACH_ALLOCNO (a, ai) | |
2323 | { | |
66d9a7b9 | 2324 | aclass = ALLOCNO_CLASS (a); |
2325 | if (aclass == NO_REGS) | |
68d4bdfb | 2326 | continue; |
2327 | if (! ALLOCNO_BAD_SPILL_P (a)) | |
2328 | continue; | |
be18556f | 2329 | FOR_EACH_ALLOCNO_OBJECT (a, obj, aoi) |
68d4bdfb | 2330 | { |
be18556f | 2331 | for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next) |
2332 | { | |
2333 | for (i = r->start + 1; i < r->finish; i++) | |
66d9a7b9 | 2334 | if (bitmap_bit_p (&dead_points[aclass], i)) |
be18556f | 2335 | break; |
2336 | if (i < r->finish) | |
2337 | break; | |
2338 | } | |
2339 | if (r != NULL) | |
2340 | { | |
2341 | ALLOCNO_BAD_SPILL_P (a) = false; | |
68d4bdfb | 2342 | break; |
be18556f | 2343 | } |
68d4bdfb | 2344 | } |
68d4bdfb | 2345 | } |
66d9a7b9 | 2346 | for (i = 0; i < ira_allocno_classes_num; i++) |
68d4bdfb | 2347 | { |
66d9a7b9 | 2348 | aclass = ira_allocno_classes[i]; |
2349 | bitmap_clear (&dead_points[aclass]); | |
68d4bdfb | 2350 | } |
2351 | } | |
2352 | ||
2353 | \f | |
2354 | ||
47dd2e78 | 2355 | /* Set up minimal and maximal live range points for allocnos. */ |
2356 | static void | |
2357 | setup_min_max_allocno_live_range_point (void) | |
2358 | { | |
2359 | int i; | |
2360 | ira_allocno_t a, parent_a, cap; | |
2361 | ira_allocno_iterator ai; | |
be18556f | 2362 | #ifdef ENABLE_IRA_CHECKING |
2363 | ira_object_iterator oi; | |
2364 | ira_object_t obj; | |
2365 | #endif | |
fbff82f4 | 2366 | live_range_t r; |
47dd2e78 | 2367 | ira_loop_tree_node_t parent; |
2368 | ||
2369 | FOR_EACH_ALLOCNO (a, ai) | |
2370 | { | |
be18556f | 2371 | int n = ALLOCNO_NUM_OBJECTS (a); |
66d9a7b9 | 2372 | |
be18556f | 2373 | for (i = 0; i < n; i++) |
2374 | { | |
2375 | ira_object_t obj = ALLOCNO_OBJECT (a, i); | |
2376 | r = OBJECT_LIVE_RANGES (obj); | |
2377 | if (r == NULL) | |
2378 | continue; | |
2379 | OBJECT_MAX (obj) = r->finish; | |
2380 | for (; r->next != NULL; r = r->next) | |
2381 | ; | |
2382 | OBJECT_MIN (obj) = r->start; | |
2383 | } | |
47dd2e78 | 2384 | } |
2385 | for (i = max_reg_num () - 1; i >= FIRST_PSEUDO_REGISTER; i--) | |
2386 | for (a = ira_regno_allocno_map[i]; | |
2387 | a != NULL; | |
2388 | a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) | |
2389 | { | |
be18556f | 2390 | int j; |
2391 | int n = ALLOCNO_NUM_OBJECTS (a); | |
66d9a7b9 | 2392 | |
be18556f | 2393 | for (j = 0; j < n; j++) |
47dd2e78 | 2394 | { |
be18556f | 2395 | ira_object_t obj = ALLOCNO_OBJECT (a, j); |
2396 | ira_object_t parent_obj; | |
2397 | ||
2398 | if (OBJECT_MAX (obj) < 0) | |
2399 | continue; | |
2400 | ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL); | |
2401 | /* Accumulation of range info. */ | |
2402 | if (ALLOCNO_CAP (a) != NULL) | |
47dd2e78 | 2403 | { |
be18556f | 2404 | for (cap = ALLOCNO_CAP (a); cap != NULL; cap = ALLOCNO_CAP (cap)) |
2405 | { | |
2406 | ira_object_t cap_obj = ALLOCNO_OBJECT (cap, j); | |
2407 | if (OBJECT_MAX (cap_obj) < OBJECT_MAX (obj)) | |
2408 | OBJECT_MAX (cap_obj) = OBJECT_MAX (obj); | |
2409 | if (OBJECT_MIN (cap_obj) > OBJECT_MIN (obj)) | |
2410 | OBJECT_MIN (cap_obj) = OBJECT_MIN (obj); | |
2411 | } | |
2412 | continue; | |
47dd2e78 | 2413 | } |
be18556f | 2414 | if ((parent = ALLOCNO_LOOP_TREE_NODE (a)->parent) == NULL) |
2415 | continue; | |
2416 | parent_a = parent->regno_allocno_map[i]; | |
2417 | parent_obj = ALLOCNO_OBJECT (parent_a, j); | |
2418 | if (OBJECT_MAX (parent_obj) < OBJECT_MAX (obj)) | |
2419 | OBJECT_MAX (parent_obj) = OBJECT_MAX (obj); | |
2420 | if (OBJECT_MIN (parent_obj) > OBJECT_MIN (obj)) | |
2421 | OBJECT_MIN (parent_obj) = OBJECT_MIN (obj); | |
47dd2e78 | 2422 | } |
47dd2e78 | 2423 | } |
2424 | #ifdef ENABLE_IRA_CHECKING | |
be18556f | 2425 | FOR_EACH_OBJECT (obj, oi) |
47dd2e78 | 2426 | { |
ae9587ed | 2427 | if ((0 <= OBJECT_MIN (obj) && OBJECT_MIN (obj) <= ira_max_point) |
2428 | && (0 <= OBJECT_MAX (obj) && OBJECT_MAX (obj) <= ira_max_point)) | |
47dd2e78 | 2429 | continue; |
2430 | gcc_unreachable (); | |
2431 | } | |
2432 | #endif | |
2433 | } | |
2434 | ||
2435 | /* Sort allocnos according to their live ranges. Allocnos with | |
66d9a7b9 | 2436 | smaller allocno class are put first unless we use priority |
2437 | coloring. Allocnos with the same class are ordered according | |
2438 | their start (min). Allocnos with the same start are ordered | |
2439 | according their finish (max). */ | |
47dd2e78 | 2440 | static int |
be18556f | 2441 | object_range_compare_func (const void *v1p, const void *v2p) |
47dd2e78 | 2442 | { |
2443 | int diff; | |
ae9587ed | 2444 | ira_object_t obj1 = *(const ira_object_t *) v1p; |
2445 | ira_object_t obj2 = *(const ira_object_t *) v2p; | |
2446 | ira_allocno_t a1 = OBJECT_ALLOCNO (obj1); | |
2447 | ira_allocno_t a2 = OBJECT_ALLOCNO (obj2); | |
47dd2e78 | 2448 | |
ae9587ed | 2449 | if ((diff = OBJECT_MIN (obj1) - OBJECT_MIN (obj2)) != 0) |
47dd2e78 | 2450 | return diff; |
ae9587ed | 2451 | if ((diff = OBJECT_MAX (obj1) - OBJECT_MAX (obj2)) != 0) |
47dd2e78 | 2452 | return diff; |
2453 | return ALLOCNO_NUM (a1) - ALLOCNO_NUM (a2); | |
2454 | } | |
2455 | ||
ae9587ed | 2456 | /* Sort ira_object_id_map and set up conflict id of allocnos. */ |
47dd2e78 | 2457 | static void |
ae9587ed | 2458 | sort_conflict_id_map (void) |
47dd2e78 | 2459 | { |
2460 | int i, num; | |
2461 | ira_allocno_t a; | |
2462 | ira_allocno_iterator ai; | |
2463 | ||
2464 | num = 0; | |
2465 | FOR_EACH_ALLOCNO (a, ai) | |
be18556f | 2466 | { |
2467 | ira_allocno_object_iterator oi; | |
2468 | ira_object_t obj; | |
2469 | ||
2470 | FOR_EACH_ALLOCNO_OBJECT (a, obj, oi) | |
2471 | ira_object_id_map[num++] = obj; | |
2472 | } | |
ae9587ed | 2473 | qsort (ira_object_id_map, num, sizeof (ira_object_t), |
be18556f | 2474 | object_range_compare_func); |
47dd2e78 | 2475 | for (i = 0; i < num; i++) |
ae9587ed | 2476 | { |
2477 | ira_object_t obj = ira_object_id_map[i]; | |
66d9a7b9 | 2478 | |
ae9587ed | 2479 | gcc_assert (obj != NULL); |
2480 | OBJECT_CONFLICT_ID (obj) = i; | |
2481 | } | |
2482 | for (i = num; i < ira_objects_num; i++) | |
2483 | ira_object_id_map[i] = NULL; | |
47dd2e78 | 2484 | } |
2485 | ||
2486 | /* Set up minimal and maximal conflict ids of allocnos with which | |
2487 | given allocno can conflict. */ | |
2488 | static void | |
2489 | setup_min_max_conflict_allocno_ids (void) | |
2490 | { | |
66d9a7b9 | 2491 | int aclass; |
47dd2e78 | 2492 | int i, j, min, max, start, finish, first_not_finished, filled_area_start; |
2493 | int *live_range_min, *last_lived; | |
be18556f | 2494 | int word0_min, word0_max; |
47dd2e78 | 2495 | ira_allocno_t a; |
be18556f | 2496 | ira_allocno_iterator ai; |
47dd2e78 | 2497 | |
ae9587ed | 2498 | live_range_min = (int *) ira_allocate (sizeof (int) * ira_objects_num); |
66d9a7b9 | 2499 | aclass = -1; |
47dd2e78 | 2500 | first_not_finished = -1; |
ae9587ed | 2501 | for (i = 0; i < ira_objects_num; i++) |
47dd2e78 | 2502 | { |
ae9587ed | 2503 | ira_object_t obj = ira_object_id_map[i]; |
66d9a7b9 | 2504 | |
ae9587ed | 2505 | if (obj == NULL) |
47dd2e78 | 2506 | continue; |
ae9587ed | 2507 | |
2508 | a = OBJECT_ALLOCNO (obj); | |
2509 | ||
66d9a7b9 | 2510 | if (aclass < 0) |
47dd2e78 | 2511 | { |
66d9a7b9 | 2512 | aclass = ALLOCNO_CLASS (a); |
47dd2e78 | 2513 | min = i; |
2514 | first_not_finished = i; | |
2515 | } | |
2516 | else | |
2517 | { | |
ae9587ed | 2518 | start = OBJECT_MIN (obj); |
47dd2e78 | 2519 | /* If we skip an allocno, the allocno with smaller ids will |
2520 | be also skipped because of the secondary sorting the | |
2521 | range finishes (see function | |
be18556f | 2522 | object_range_compare_func). */ |
47dd2e78 | 2523 | while (first_not_finished < i |
ae9587ed | 2524 | && start > OBJECT_MAX (ira_object_id_map |
be18556f | 2525 | [first_not_finished])) |
47dd2e78 | 2526 | first_not_finished++; |
2527 | min = first_not_finished; | |
48e1416a | 2528 | } |
47dd2e78 | 2529 | if (min == i) |
2530 | /* We could increase min further in this case but it is good | |
2531 | enough. */ | |
2532 | min++; | |
ae9587ed | 2533 | live_range_min[i] = OBJECT_MIN (obj); |
2534 | OBJECT_MIN (obj) = min; | |
47dd2e78 | 2535 | } |
2536 | last_lived = (int *) ira_allocate (sizeof (int) * ira_max_point); | |
66d9a7b9 | 2537 | aclass = -1; |
47dd2e78 | 2538 | filled_area_start = -1; |
ae9587ed | 2539 | for (i = ira_objects_num - 1; i >= 0; i--) |
47dd2e78 | 2540 | { |
ae9587ed | 2541 | ira_object_t obj = ira_object_id_map[i]; |
66d9a7b9 | 2542 | |
ae9587ed | 2543 | if (obj == NULL) |
47dd2e78 | 2544 | continue; |
ae9587ed | 2545 | |
2546 | a = OBJECT_ALLOCNO (obj); | |
66d9a7b9 | 2547 | if (aclass < 0) |
47dd2e78 | 2548 | { |
66d9a7b9 | 2549 | aclass = ALLOCNO_CLASS (a); |
47dd2e78 | 2550 | for (j = 0; j < ira_max_point; j++) |
2551 | last_lived[j] = -1; | |
2552 | filled_area_start = ira_max_point; | |
2553 | } | |
2554 | min = live_range_min[i]; | |
ae9587ed | 2555 | finish = OBJECT_MAX (obj); |
47dd2e78 | 2556 | max = last_lived[finish]; |
2557 | if (max < 0) | |
2558 | /* We could decrease max further in this case but it is good | |
2559 | enough. */ | |
ae9587ed | 2560 | max = OBJECT_CONFLICT_ID (obj) - 1; |
2561 | OBJECT_MAX (obj) = max; | |
47dd2e78 | 2562 | /* In filling, we can go further A range finish to recognize |
2563 | intersection quickly because if the finish of subsequently | |
2564 | processed allocno (it has smaller conflict id) range is | |
2565 | further A range finish than they are definitely intersected | |
2566 | (the reason for this is the allocnos with bigger conflict id | |
2567 | have their range starts not smaller than allocnos with | |
2568 | smaller ids. */ | |
2569 | for (j = min; j < filled_area_start; j++) | |
2570 | last_lived[j] = i; | |
2571 | filled_area_start = min; | |
2572 | } | |
2573 | ira_free (last_lived); | |
2574 | ira_free (live_range_min); | |
be18556f | 2575 | |
2576 | /* For allocnos with more than one object, we may later record extra conflicts in | |
2577 | subobject 0 that we cannot really know about here. | |
2578 | For now, simply widen the min/max range of these subobjects. */ | |
2579 | ||
2580 | word0_min = INT_MAX; | |
2581 | word0_max = INT_MIN; | |
2582 | ||
2583 | FOR_EACH_ALLOCNO (a, ai) | |
2584 | { | |
2585 | int n = ALLOCNO_NUM_OBJECTS (a); | |
2586 | ira_object_t obj0; | |
66d9a7b9 | 2587 | |
be18556f | 2588 | if (n < 2) |
2589 | continue; | |
2590 | obj0 = ALLOCNO_OBJECT (a, 0); | |
2591 | if (OBJECT_CONFLICT_ID (obj0) < word0_min) | |
2592 | word0_min = OBJECT_CONFLICT_ID (obj0); | |
2593 | if (OBJECT_CONFLICT_ID (obj0) > word0_max) | |
2594 | word0_max = OBJECT_CONFLICT_ID (obj0); | |
2595 | } | |
2596 | FOR_EACH_ALLOCNO (a, ai) | |
2597 | { | |
2598 | int n = ALLOCNO_NUM_OBJECTS (a); | |
2599 | ira_object_t obj0; | |
66d9a7b9 | 2600 | |
be18556f | 2601 | if (n < 2) |
2602 | continue; | |
2603 | obj0 = ALLOCNO_OBJECT (a, 0); | |
2604 | if (OBJECT_MIN (obj0) > word0_min) | |
2605 | OBJECT_MIN (obj0) = word0_min; | |
2606 | if (OBJECT_MAX (obj0) < word0_max) | |
2607 | OBJECT_MAX (obj0) = word0_max; | |
2608 | } | |
47dd2e78 | 2609 | } |
2610 | ||
2611 | \f | |
2612 | ||
2613 | static void | |
2614 | create_caps (void) | |
2615 | { | |
2616 | ira_allocno_t a; | |
2617 | ira_allocno_iterator ai; | |
2618 | ira_loop_tree_node_t loop_tree_node; | |
2619 | ||
2620 | FOR_EACH_ALLOCNO (a, ai) | |
2621 | { | |
2622 | if (ALLOCNO_LOOP_TREE_NODE (a) == ira_loop_tree_root) | |
2623 | continue; | |
2624 | if (ALLOCNO_CAP_MEMBER (a) != NULL) | |
2625 | create_cap_allocno (a); | |
2626 | else if (ALLOCNO_CAP (a) == NULL) | |
2627 | { | |
2628 | loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a); | |
2629 | if (!bitmap_bit_p (loop_tree_node->border_allocnos, ALLOCNO_NUM (a))) | |
2630 | create_cap_allocno (a); | |
2631 | } | |
2632 | } | |
2633 | } | |
2634 | ||
2635 | \f | |
2636 | ||
2637 | /* The page contains code transforming more one region internal | |
2638 | representation (IR) to one region IR which is necessary for reload. | |
2639 | This transformation is called IR flattening. We might just rebuild | |
2640 | the IR for one region but we don't do it because it takes a lot of | |
2641 | time. */ | |
2642 | ||
76b340db | 2643 | /* Map: regno -> allocnos which will finally represent the regno for |
2644 | IR with one region. */ | |
2645 | static ira_allocno_t *regno_top_level_allocno_map; | |
2646 | ||
c58db480 | 2647 | /* Find the allocno that corresponds to A at a level one higher up in the |
2648 | loop tree. Returns NULL if A is a cap, or if it has no parent. */ | |
2649 | ira_allocno_t | |
2650 | ira_parent_allocno (ira_allocno_t a) | |
2651 | { | |
2652 | ira_loop_tree_node_t parent; | |
2653 | ||
2654 | if (ALLOCNO_CAP (a) != NULL) | |
2655 | return NULL; | |
2656 | ||
2657 | parent = ALLOCNO_LOOP_TREE_NODE (a)->parent; | |
2658 | if (parent == NULL) | |
2659 | return NULL; | |
2660 | ||
2661 | return parent->regno_allocno_map[ALLOCNO_REGNO (a)]; | |
2662 | } | |
2663 | ||
2664 | /* Find the allocno that corresponds to A at a level one higher up in the | |
2665 | loop tree. If ALLOCNO_CAP is set for A, return that. */ | |
2666 | ira_allocno_t | |
2667 | ira_parent_or_cap_allocno (ira_allocno_t a) | |
2668 | { | |
2669 | if (ALLOCNO_CAP (a) != NULL) | |
2670 | return ALLOCNO_CAP (a); | |
2671 | ||
2672 | return ira_parent_allocno (a); | |
2673 | } | |
2674 | ||
76b340db | 2675 | /* Process all allocnos originated from pseudo REGNO and copy live |
e3fe8cc4 | 2676 | ranges, hard reg conflicts, and allocno stack reg attributes from |
2677 | low level allocnos to final allocnos which are destinations of | |
2678 | removed stores at a loop exit. Return true if we copied live | |
2679 | ranges. */ | |
76b340db | 2680 | static bool |
e3fe8cc4 | 2681 | copy_info_to_removed_store_destinations (int regno) |
76b340db | 2682 | { |
8efd2ddb | 2683 | ira_allocno_t a; |
2684 | ira_allocno_t parent_a = NULL; | |
76b340db | 2685 | ira_loop_tree_node_t parent; |
76b340db | 2686 | bool merged_p; |
2687 | ||
2688 | merged_p = false; | |
2689 | for (a = ira_regno_allocno_map[regno]; | |
2690 | a != NULL; | |
2691 | a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) | |
2692 | { | |
66d9a7b9 | 2693 | if (a != regno_top_level_allocno_map[REGNO (allocno_emit_reg (a))]) |
76b340db | 2694 | /* This allocno will be removed. */ |
2695 | continue; | |
be18556f | 2696 | |
76b340db | 2697 | /* Caps will be removed. */ |
2698 | ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL); | |
2699 | for (parent = ALLOCNO_LOOP_TREE_NODE (a)->parent; | |
2700 | parent != NULL; | |
2701 | parent = parent->parent) | |
2702 | if ((parent_a = parent->regno_allocno_map[regno]) == NULL | |
66d9a7b9 | 2703 | || (parent_a |
2704 | == regno_top_level_allocno_map[REGNO | |
2705 | (allocno_emit_reg (parent_a))] | |
2706 | && ALLOCNO_EMIT_DATA (parent_a)->mem_optimized_dest_p)) | |
76b340db | 2707 | break; |
2708 | if (parent == NULL || parent_a == NULL) | |
2709 | continue; | |
be18556f | 2710 | |
b4f5e198 | 2711 | copy_allocno_live_ranges (a, parent_a); |
2712 | merge_hard_reg_conflicts (a, parent_a, true); | |
be18556f | 2713 | |
0b1329df | 2714 | ALLOCNO_CALL_FREQ (parent_a) += ALLOCNO_CALL_FREQ (a); |
2715 | ALLOCNO_CALLS_CROSSED_NUM (parent_a) | |
2716 | += ALLOCNO_CALLS_CROSSED_NUM (a); | |
c8010b80 | 2717 | ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a) |
2718 | += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a); | |
0b1329df | 2719 | ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a) |
2720 | += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a); | |
76b340db | 2721 | merged_p = true; |
2722 | } | |
2723 | return merged_p; | |
47dd2e78 | 2724 | } |
2725 | ||
2726 | /* Flatten the IR. In other words, this function transforms IR as if | |
2727 | it were built with one region (without loops). We could make it | |
2728 | much simpler by rebuilding IR with one region, but unfortunately it | |
2729 | takes a lot of time. MAX_REGNO_BEFORE_EMIT and | |
2730 | IRA_MAX_POINT_BEFORE_EMIT are correspondingly MAX_REG_NUM () and | |
2731 | IRA_MAX_POINT before emitting insns on the loop borders. */ | |
2732 | void | |
2733 | ira_flattening (int max_regno_before_emit, int ira_max_point_before_emit) | |
2734 | { | |
9d53e372 | 2735 | int i, j; |
0b1329df | 2736 | bool keep_p; |
47dd2e78 | 2737 | int hard_regs_num; |
76b340db | 2738 | bool new_pseudos_p, merged_p, mem_dest_p; |
47dd2e78 | 2739 | unsigned int n; |
66d9a7b9 | 2740 | enum reg_class aclass; |
47dd2e78 | 2741 | ira_allocno_t a, parent_a, first, second, node_first, node_second; |
47dd2e78 | 2742 | ira_copy_t cp; |
c58db480 | 2743 | ira_loop_tree_node_t node; |
fbff82f4 | 2744 | live_range_t r; |
47dd2e78 | 2745 | ira_allocno_iterator ai; |
2746 | ira_copy_iterator ci; | |
47dd2e78 | 2747 | |
2748 | regno_top_level_allocno_map | |
66d9a7b9 | 2749 | = (ira_allocno_t *) ira_allocate (max_reg_num () |
2750 | * sizeof (ira_allocno_t)); | |
47dd2e78 | 2751 | memset (regno_top_level_allocno_map, 0, |
2752 | max_reg_num () * sizeof (ira_allocno_t)); | |
47dd2e78 | 2753 | new_pseudos_p = merged_p = false; |
ad305e06 | 2754 | FOR_EACH_ALLOCNO (a, ai) |
2755 | { | |
be18556f | 2756 | ira_allocno_object_iterator oi; |
2757 | ira_object_t obj; | |
66d9a7b9 | 2758 | |
ad305e06 | 2759 | if (ALLOCNO_CAP_MEMBER (a) != NULL) |
2760 | /* Caps are not in the regno allocno maps and they are never | |
2761 | will be transformed into allocnos existing after IR | |
2762 | flattening. */ | |
2763 | continue; | |
be18556f | 2764 | FOR_EACH_ALLOCNO_OBJECT (a, obj, oi) |
2765 | COPY_HARD_REG_SET (OBJECT_TOTAL_CONFLICT_HARD_REGS (obj), | |
2766 | OBJECT_CONFLICT_HARD_REGS (obj)); | |
ad305e06 | 2767 | #ifdef STACK_REGS |
2768 | ALLOCNO_TOTAL_NO_STACK_REG_P (a) = ALLOCNO_NO_STACK_REG_P (a); | |
2769 | #endif | |
2770 | } | |
47dd2e78 | 2771 | /* Fix final allocno attributes. */ |
2772 | for (i = max_regno_before_emit - 1; i >= FIRST_PSEUDO_REGISTER; i--) | |
2773 | { | |
ad305e06 | 2774 | mem_dest_p = false; |
47dd2e78 | 2775 | for (a = ira_regno_allocno_map[i]; |
2776 | a != NULL; | |
2777 | a = ALLOCNO_NEXT_REGNO_ALLOCNO (a)) | |
2778 | { | |
66d9a7b9 | 2779 | ira_emit_data_t parent_data, data = ALLOCNO_EMIT_DATA (a); |
2780 | ||
47dd2e78 | 2781 | ira_assert (ALLOCNO_CAP_MEMBER (a) == NULL); |
66d9a7b9 | 2782 | if (data->somewhere_renamed_p) |
47dd2e78 | 2783 | new_pseudos_p = true; |
c58db480 | 2784 | parent_a = ira_parent_allocno (a); |
2785 | if (parent_a == NULL) | |
47dd2e78 | 2786 | { |
2787 | ALLOCNO_COPIES (a) = NULL; | |
66d9a7b9 | 2788 | regno_top_level_allocno_map[REGNO (data->reg)] = a; |
47dd2e78 | 2789 | continue; |
2790 | } | |
2791 | ira_assert (ALLOCNO_CAP_MEMBER (parent_a) == NULL); | |
48e1416a | 2792 | |
66d9a7b9 | 2793 | if (data->mem_optimized_dest != NULL) |
76b340db | 2794 | mem_dest_p = true; |
66d9a7b9 | 2795 | parent_data = ALLOCNO_EMIT_DATA (parent_a); |
2796 | if (REGNO (data->reg) == REGNO (parent_data->reg)) | |
47dd2e78 | 2797 | { |
b4f5e198 | 2798 | merge_hard_reg_conflicts (a, parent_a, true); |
2799 | move_allocno_live_ranges (a, parent_a); | |
47dd2e78 | 2800 | merged_p = true; |
66d9a7b9 | 2801 | parent_data->mem_optimized_dest_p |
2802 | = (parent_data->mem_optimized_dest_p | |
2803 | || data->mem_optimized_dest_p); | |
47dd2e78 | 2804 | continue; |
2805 | } | |
2806 | new_pseudos_p = true; | |
47dd2e78 | 2807 | for (;;) |
2808 | { | |
47dd2e78 | 2809 | ALLOCNO_NREFS (parent_a) -= ALLOCNO_NREFS (a); |
2810 | ALLOCNO_FREQ (parent_a) -= ALLOCNO_FREQ (a); | |
0b1329df | 2811 | ALLOCNO_CALL_FREQ (parent_a) -= ALLOCNO_CALL_FREQ (a); |
2812 | ALLOCNO_CALLS_CROSSED_NUM (parent_a) | |
2813 | -= ALLOCNO_CALLS_CROSSED_NUM (a); | |
c8010b80 | 2814 | ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a) |
2815 | -= ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a); | |
0b1329df | 2816 | ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a) |
2817 | -= ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a); | |
47dd2e78 | 2818 | ira_assert (ALLOCNO_CALLS_CROSSED_NUM (parent_a) >= 0 |
2819 | && ALLOCNO_NREFS (parent_a) >= 0 | |
2820 | && ALLOCNO_FREQ (parent_a) >= 0); | |
66d9a7b9 | 2821 | aclass = ALLOCNO_CLASS (parent_a); |
2822 | hard_regs_num = ira_class_hard_regs_num[aclass]; | |
47dd2e78 | 2823 | if (ALLOCNO_HARD_REG_COSTS (a) != NULL |
2824 | && ALLOCNO_HARD_REG_COSTS (parent_a) != NULL) | |
2825 | for (j = 0; j < hard_regs_num; j++) | |
2826 | ALLOCNO_HARD_REG_COSTS (parent_a)[j] | |
2827 | -= ALLOCNO_HARD_REG_COSTS (a)[j]; | |
2828 | if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a) != NULL | |
2829 | && ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a) != NULL) | |
2830 | for (j = 0; j < hard_regs_num; j++) | |
2831 | ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a)[j] | |
2832 | -= ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[j]; | |
66d9a7b9 | 2833 | ALLOCNO_CLASS_COST (parent_a) |
2834 | -= ALLOCNO_CLASS_COST (a); | |
47dd2e78 | 2835 | ALLOCNO_MEMORY_COST (parent_a) -= ALLOCNO_MEMORY_COST (a); |
c58db480 | 2836 | parent_a = ira_parent_allocno (parent_a); |
2837 | if (parent_a == NULL) | |
47dd2e78 | 2838 | break; |
2839 | } | |
47dd2e78 | 2840 | ALLOCNO_COPIES (a) = NULL; |
66d9a7b9 | 2841 | regno_top_level_allocno_map[REGNO (data->reg)] = a; |
47dd2e78 | 2842 | } |
e3fe8cc4 | 2843 | if (mem_dest_p && copy_info_to_removed_store_destinations (i)) |
76b340db | 2844 | merged_p = true; |
47dd2e78 | 2845 | } |
47dd2e78 | 2846 | ira_assert (new_pseudos_p || ira_max_point_before_emit == ira_max_point); |
2847 | if (merged_p || ira_max_point_before_emit != ira_max_point) | |
2848 | ira_rebuild_start_finish_chains (); | |
2849 | if (new_pseudos_p) | |
2850 | { | |
9d53e372 | 2851 | sparseset objects_live; |
2852 | ||
47dd2e78 | 2853 | /* Rebuild conflicts. */ |
2854 | FOR_EACH_ALLOCNO (a, ai) | |
2855 | { | |
be18556f | 2856 | ira_allocno_object_iterator oi; |
2857 | ira_object_t obj; | |
66d9a7b9 | 2858 | |
2859 | if (a != regno_top_level_allocno_map[REGNO (allocno_emit_reg (a))] | |
47dd2e78 | 2860 | || ALLOCNO_CAP_MEMBER (a) != NULL) |
2861 | continue; | |
be18556f | 2862 | FOR_EACH_ALLOCNO_OBJECT (a, obj, oi) |
2863 | { | |
2864 | for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next) | |
2865 | ira_assert (r->object == obj); | |
2866 | clear_conflicts (obj); | |
2867 | } | |
47dd2e78 | 2868 | } |
9d53e372 | 2869 | objects_live = sparseset_alloc (ira_objects_num); |
47dd2e78 | 2870 | for (i = 0; i < ira_max_point; i++) |
2871 | { | |
2872 | for (r = ira_start_point_ranges[i]; r != NULL; r = r->start_next) | |
2873 | { | |
9d53e372 | 2874 | ira_object_t obj = r->object; |
66d9a7b9 | 2875 | |
9d53e372 | 2876 | a = OBJECT_ALLOCNO (obj); |
66d9a7b9 | 2877 | if (a != regno_top_level_allocno_map[REGNO (allocno_emit_reg (a))] |
47dd2e78 | 2878 | || ALLOCNO_CAP_MEMBER (a) != NULL) |
2879 | continue; | |
be18556f | 2880 | |
66d9a7b9 | 2881 | aclass = ALLOCNO_CLASS (a); |
9d53e372 | 2882 | sparseset_set_bit (objects_live, OBJECT_CONFLICT_ID (obj)); |
2883 | EXECUTE_IF_SET_IN_SPARSESET (objects_live, n) | |
47dd2e78 | 2884 | { |
9d53e372 | 2885 | ira_object_t live_obj = ira_object_id_map[n]; |
2886 | ira_allocno_t live_a = OBJECT_ALLOCNO (live_obj); | |
66d9a7b9 | 2887 | enum reg_class live_aclass = ALLOCNO_CLASS (live_a); |
2888 | ||
2889 | if (ira_reg_classes_intersect_p[aclass][live_aclass] | |
47dd2e78 | 2890 | /* Don't set up conflict for the allocno with itself. */ |
9d53e372 | 2891 | && live_a != a) |
2892 | ira_add_conflict (obj, live_obj); | |
47dd2e78 | 2893 | } |
2894 | } | |
48e1416a | 2895 | |
47dd2e78 | 2896 | for (r = ira_finish_point_ranges[i]; r != NULL; r = r->finish_next) |
9d53e372 | 2897 | sparseset_clear_bit (objects_live, OBJECT_CONFLICT_ID (r->object)); |
47dd2e78 | 2898 | } |
9d53e372 | 2899 | sparseset_free (objects_live); |
47dd2e78 | 2900 | compress_conflict_vecs (); |
2901 | } | |
2902 | /* Mark some copies for removing and change allocnos in the rest | |
2903 | copies. */ | |
2904 | FOR_EACH_COPY (cp, ci) | |
2905 | { | |
2906 | if (ALLOCNO_CAP_MEMBER (cp->first) != NULL | |
2907 | || ALLOCNO_CAP_MEMBER (cp->second) != NULL) | |
2908 | { | |
2909 | if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL) | |
2910 | fprintf | |
2911 | (ira_dump_file, " Remove cp%d:%c%dr%d-%c%dr%d\n", | |
2912 | cp->num, ALLOCNO_CAP_MEMBER (cp->first) != NULL ? 'c' : 'a', | |
66d9a7b9 | 2913 | ALLOCNO_NUM (cp->first), |
2914 | REGNO (allocno_emit_reg (cp->first)), | |
47dd2e78 | 2915 | ALLOCNO_CAP_MEMBER (cp->second) != NULL ? 'c' : 'a', |
66d9a7b9 | 2916 | ALLOCNO_NUM (cp->second), |
2917 | REGNO (allocno_emit_reg (cp->second))); | |
47dd2e78 | 2918 | cp->loop_tree_node = NULL; |
2919 | continue; | |
2920 | } | |
66d9a7b9 | 2921 | first |
2922 | = regno_top_level_allocno_map[REGNO (allocno_emit_reg (cp->first))]; | |
2923 | second | |
2924 | = regno_top_level_allocno_map[REGNO (allocno_emit_reg (cp->second))]; | |
47dd2e78 | 2925 | node = cp->loop_tree_node; |
2926 | if (node == NULL) | |
2927 | keep_p = true; /* It copy generated in ira-emit.c. */ | |
2928 | else | |
2929 | { | |
2930 | /* Check that the copy was not propagated from level on | |
2931 | which we will have different pseudos. */ | |
2932 | node_first = node->regno_allocno_map[ALLOCNO_REGNO (cp->first)]; | |
2933 | node_second = node->regno_allocno_map[ALLOCNO_REGNO (cp->second)]; | |
66d9a7b9 | 2934 | keep_p = ((REGNO (allocno_emit_reg (first)) |
2935 | == REGNO (allocno_emit_reg (node_first))) | |
2936 | && (REGNO (allocno_emit_reg (second)) | |
2937 | == REGNO (allocno_emit_reg (node_second)))); | |
47dd2e78 | 2938 | } |
2939 | if (keep_p) | |
2940 | { | |
2941 | cp->loop_tree_node = ira_loop_tree_root; | |
2942 | cp->first = first; | |
2943 | cp->second = second; | |
2944 | } | |
2945 | else | |
2946 | { | |
2947 | cp->loop_tree_node = NULL; | |
2948 | if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL) | |
2949 | fprintf (ira_dump_file, " Remove cp%d:a%dr%d-a%dr%d\n", | |
2950 | cp->num, ALLOCNO_NUM (cp->first), | |
66d9a7b9 | 2951 | REGNO (allocno_emit_reg (cp->first)), |
2952 | ALLOCNO_NUM (cp->second), | |
2953 | REGNO (allocno_emit_reg (cp->second))); | |
47dd2e78 | 2954 | } |
2955 | } | |
2956 | /* Remove unnecessary allocnos on lower levels of the loop tree. */ | |
2957 | FOR_EACH_ALLOCNO (a, ai) | |
2958 | { | |
66d9a7b9 | 2959 | if (a != regno_top_level_allocno_map[REGNO (allocno_emit_reg (a))] |
47dd2e78 | 2960 | || ALLOCNO_CAP_MEMBER (a) != NULL) |
2961 | { | |
2962 | if (internal_flag_ira_verbose > 4 && ira_dump_file != NULL) | |
2963 | fprintf (ira_dump_file, " Remove a%dr%d\n", | |
66d9a7b9 | 2964 | ALLOCNO_NUM (a), REGNO (allocno_emit_reg (a))); |
47dd2e78 | 2965 | finish_allocno (a); |
2966 | continue; | |
2967 | } | |
2968 | ALLOCNO_LOOP_TREE_NODE (a) = ira_loop_tree_root; | |
66d9a7b9 | 2969 | ALLOCNO_REGNO (a) = REGNO (allocno_emit_reg (a)); |
47dd2e78 | 2970 | ALLOCNO_CAP (a) = NULL; |
df07a54c | 2971 | /* Restore updated costs for assignments from reload. */ |
47dd2e78 | 2972 | ALLOCNO_UPDATED_MEMORY_COST (a) = ALLOCNO_MEMORY_COST (a); |
66d9a7b9 | 2973 | ALLOCNO_UPDATED_CLASS_COST (a) = ALLOCNO_CLASS_COST (a); |
47dd2e78 | 2974 | if (! ALLOCNO_ASSIGNED_P (a)) |
2975 | ira_free_allocno_updated_costs (a); | |
2976 | ira_assert (ALLOCNO_UPDATED_HARD_REG_COSTS (a) == NULL); | |
2977 | ira_assert (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a) == NULL); | |
2978 | } | |
2979 | /* Remove unnecessary copies. */ | |
2980 | FOR_EACH_COPY (cp, ci) | |
2981 | { | |
2982 | if (cp->loop_tree_node == NULL) | |
2983 | { | |
2984 | ira_copies[cp->num] = NULL; | |
2985 | finish_copy (cp); | |
2986 | continue; | |
2987 | } | |
2988 | ira_assert | |
2989 | (ALLOCNO_LOOP_TREE_NODE (cp->first) == ira_loop_tree_root | |
2990 | && ALLOCNO_LOOP_TREE_NODE (cp->second) == ira_loop_tree_root); | |
2991 | ira_add_allocno_copy_to_list (cp); | |
2992 | ira_swap_allocno_copy_ends_if_necessary (cp); | |
2993 | } | |
2994 | rebuild_regno_allocno_maps (); | |
7f36fbdf | 2995 | if (ira_max_point != ira_max_point_before_emit) |
2996 | ira_compress_allocno_live_ranges (); | |
47dd2e78 | 2997 | ira_free (regno_top_level_allocno_map); |
2998 | } | |
2999 | ||
3000 | \f | |
3001 | ||
3002 | #ifdef ENABLE_IRA_CHECKING | |
3003 | /* Check creation of all allocnos. Allocnos on lower levels should | |
3004 | have allocnos or caps on all upper levels. */ | |
3005 | static void | |
3006 | check_allocno_creation (void) | |
3007 | { | |
3008 | ira_allocno_t a; | |
3009 | ira_allocno_iterator ai; | |
3010 | ira_loop_tree_node_t loop_tree_node; | |
3011 | ||
3012 | FOR_EACH_ALLOCNO (a, ai) | |
3013 | { | |
2bae4acc | 3014 | loop_tree_node = ALLOCNO_LOOP_TREE_NODE (a); |
3015 | ira_assert (bitmap_bit_p (loop_tree_node->all_allocnos, | |
3016 | ALLOCNO_NUM (a))); | |
3017 | if (loop_tree_node == ira_loop_tree_root) | |
47dd2e78 | 3018 | continue; |
3019 | if (ALLOCNO_CAP_MEMBER (a) != NULL) | |
2bae4acc | 3020 | ira_assert (ALLOCNO_CAP (a) != NULL); |
47dd2e78 | 3021 | else if (ALLOCNO_CAP (a) == NULL) |
2bae4acc | 3022 | ira_assert (loop_tree_node->parent |
3023 | ->regno_allocno_map[ALLOCNO_REGNO (a)] != NULL | |
3024 | && bitmap_bit_p (loop_tree_node->border_allocnos, | |
3025 | ALLOCNO_NUM (a))); | |
47dd2e78 | 3026 | } |
3027 | } | |
3028 | #endif | |
3029 | ||
1180227d | 3030 | /* Identify allocnos which prefer a register class with a single hard register. |
3031 | Adjust ALLOCNO_CONFLICT_HARD_REG_COSTS so that conflicting allocnos are | |
3032 | less likely to use the preferred singleton register. */ | |
3033 | static void | |
3034 | update_conflict_hard_reg_costs (void) | |
3035 | { | |
3036 | ira_allocno_t a; | |
3037 | ira_allocno_iterator ai; | |
3038 | int i, index, min; | |
3039 | ||
3040 | FOR_EACH_ALLOCNO (a, ai) | |
3041 | { | |
ade444a4 | 3042 | reg_class_t aclass = ALLOCNO_CLASS (a); |
3043 | reg_class_t pref = reg_preferred_class (ALLOCNO_REGNO (a)); | |
1180227d | 3044 | |
ade444a4 | 3045 | if (reg_class_size[(int) pref] != 1) |
1180227d | 3046 | continue; |
ade444a4 | 3047 | index = ira_class_hard_reg_index[(int) aclass] |
3048 | [ira_class_hard_regs[(int) pref][0]]; | |
1180227d | 3049 | if (index < 0) |
3050 | continue; | |
3051 | if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a) == NULL | |
3052 | || ALLOCNO_HARD_REG_COSTS (a) == NULL) | |
3053 | continue; | |
3054 | min = INT_MAX; | |
ade444a4 | 3055 | for (i = ira_class_hard_regs_num[(int) aclass] - 1; i >= 0; i--) |
66d9a7b9 | 3056 | if (ALLOCNO_HARD_REG_COSTS (a)[i] > ALLOCNO_CLASS_COST (a) |
1180227d | 3057 | && min > ALLOCNO_HARD_REG_COSTS (a)[i]) |
3058 | min = ALLOCNO_HARD_REG_COSTS (a)[i]; | |
3059 | if (min == INT_MAX) | |
3060 | continue; | |
3061 | ira_allocate_and_set_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a), | |
66d9a7b9 | 3062 | aclass, 0); |
1180227d | 3063 | ALLOCNO_CONFLICT_HARD_REG_COSTS (a)[index] |
66d9a7b9 | 3064 | -= min - ALLOCNO_CLASS_COST (a); |
1180227d | 3065 | } |
3066 | } | |
3067 | ||
47dd2e78 | 3068 | /* Create a internal representation (IR) for IRA (allocnos, copies, |
9f8ac546 | 3069 | loop tree nodes). The function returns TRUE if we generate loop |
3070 | structure (besides nodes representing all function and the basic | |
3071 | blocks) for regional allocation. A true return means that we | |
3072 | really need to flatten IR before the reload. */ | |
47dd2e78 | 3073 | bool |
9f8ac546 | 3074 | ira_build (void) |
47dd2e78 | 3075 | { |
9f8ac546 | 3076 | bool loops_p; |
47dd2e78 | 3077 | |
9f8ac546 | 3078 | df_analyze (); |
47dd2e78 | 3079 | initiate_cost_vectors (); |
3080 | initiate_allocnos (); | |
3081 | initiate_copies (); | |
9f8ac546 | 3082 | create_loop_tree_nodes (); |
47dd2e78 | 3083 | form_loop_tree (); |
3084 | create_allocnos (); | |
3085 | ira_costs (); | |
ae9587ed | 3086 | create_allocno_objects (); |
47dd2e78 | 3087 | ira_create_allocno_live_ranges (); |
95c83f01 | 3088 | remove_unnecessary_regions (false); |
7f36fbdf | 3089 | ira_compress_allocno_live_ranges (); |
68d4bdfb | 3090 | update_bad_spill_attribute (); |
47dd2e78 | 3091 | loops_p = more_one_region_p (); |
3092 | if (loops_p) | |
3093 | { | |
3094 | propagate_allocno_info (); | |
3095 | create_caps (); | |
3096 | } | |
66d9a7b9 | 3097 | ira_tune_allocno_costs (); |
47dd2e78 | 3098 | #ifdef ENABLE_IRA_CHECKING |
3099 | check_allocno_creation (); | |
3100 | #endif | |
3101 | setup_min_max_allocno_live_range_point (); | |
ae9587ed | 3102 | sort_conflict_id_map (); |
47dd2e78 | 3103 | setup_min_max_conflict_allocno_ids (); |
3104 | ira_build_conflicts (); | |
1180227d | 3105 | update_conflict_hard_reg_costs (); |
95c83f01 | 3106 | if (! ira_conflicts_p) |
3107 | { | |
3108 | ira_allocno_t a; | |
3109 | ira_allocno_iterator ai; | |
3110 | ||
3111 | /* Remove all regions but root one. */ | |
3112 | if (loops_p) | |
3113 | { | |
3114 | remove_unnecessary_regions (true); | |
3115 | loops_p = false; | |
3116 | } | |
3117 | /* We don't save hard registers around calls for fast allocation | |
3118 | -- add caller clobbered registers as conflicting ones to | |
3119 | allocno crossing calls. */ | |
3120 | FOR_EACH_ALLOCNO (a, ai) | |
3121 | if (ALLOCNO_CALLS_CROSSED_NUM (a) != 0) | |
be18556f | 3122 | ior_hard_reg_conflicts (a, &call_used_reg_set); |
95c83f01 | 3123 | } |
55c858c5 | 3124 | if (internal_flag_ira_verbose > 2 && ira_dump_file != NULL) |
3125 | print_copies (ira_dump_file); | |
47dd2e78 | 3126 | if (internal_flag_ira_verbose > 0 && ira_dump_file != NULL) |
3127 | { | |
be18556f | 3128 | int n, nr, nr_big; |
47dd2e78 | 3129 | ira_allocno_t a; |
fbff82f4 | 3130 | live_range_t r; |
47dd2e78 | 3131 | ira_allocno_iterator ai; |
3132 | ||
3133 | n = 0; | |
be18556f | 3134 | nr = 0; |
3135 | nr_big = 0; | |
47dd2e78 | 3136 | FOR_EACH_ALLOCNO (a, ai) |
ae9587ed | 3137 | { |
be18556f | 3138 | int j, nobj = ALLOCNO_NUM_OBJECTS (a); |
66d9a7b9 | 3139 | |
be18556f | 3140 | if (nobj > 1) |
3141 | nr_big++; | |
3142 | for (j = 0; j < nobj; j++) | |
3143 | { | |
3144 | ira_object_t obj = ALLOCNO_OBJECT (a, j); | |
3145 | n += OBJECT_NUM_CONFLICTS (obj); | |
3146 | for (r = OBJECT_LIVE_RANGES (obj); r != NULL; r = r->next) | |
3147 | nr++; | |
3148 | } | |
ae9587ed | 3149 | } |
47dd2e78 | 3150 | fprintf (ira_dump_file, " regions=%d, blocks=%d, points=%d\n", |
9f8ac546 | 3151 | current_loops == NULL ? 1 : VEC_length (loop_p, ira_loops.larray), |
3152 | n_basic_blocks, ira_max_point); | |
47dd2e78 | 3153 | fprintf (ira_dump_file, |
be18556f | 3154 | " allocnos=%d (big %d), copies=%d, conflicts=%d, ranges=%d\n", |
3155 | ira_allocnos_num, nr_big, ira_copies_num, n, nr); | |
47dd2e78 | 3156 | } |
3157 | return loops_p; | |
3158 | } | |
3159 | ||
3160 | /* Release the data created by function ira_build. */ | |
3161 | void | |
3162 | ira_destroy (void) | |
3163 | { | |
3164 | finish_loop_tree_nodes (); | |
3165 | finish_copies (); | |
3166 | finish_allocnos (); | |
3167 | finish_cost_vectors (); | |
3168 | ira_finish_allocno_live_ranges (); | |
3169 | } |