1 /* Building internal representation for IRA.
2 Copyright (C) 2006-2019 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
29 #include "insn-config.h"
35 #include "sparseset.h"
38 static ira_copy_t
find_allocno_copy (ira_allocno_t
, ira_allocno_t
, rtx_insn
*,
39 ira_loop_tree_node_t
);
41 /* The root of the loop tree corresponding to the all function. */
42 ira_loop_tree_node_t ira_loop_tree_root
;
44 /* Height of the loop tree. */
45 int ira_loop_tree_height
;
47 /* All nodes representing basic blocks are referred through the
48 following array. We cannot use basic block member `aux' for this
49 because it is used for insertion of insns on edges. */
50 ira_loop_tree_node_t ira_bb_nodes
;
52 /* All nodes representing loops are referred through the following
54 ira_loop_tree_node_t ira_loop_nodes
;
56 /* And size of the ira_loop_nodes array. */
57 unsigned int ira_loop_nodes_count
;
59 /* Map regno -> allocnos with given regno (see comments for
60 allocno member `next_regno_allocno'). */
61 ira_allocno_t
*ira_regno_allocno_map
;
63 /* Array of references to all allocnos. The order number of the
64 allocno corresponds to the index in the array. Removed allocnos
65 have NULL element value. */
66 ira_allocno_t
*ira_allocnos
;
68 /* Sizes of the previous array. */
71 /* Count of conflict record structures we've created, used when creating
75 /* Map a conflict id to its conflict record. */
76 ira_object_t
*ira_object_id_map
;
78 /* Array of references to all allocno preferences. The order number
79 of the preference corresponds to the index in the array. */
80 ira_pref_t
*ira_prefs
;
82 /* Size of the previous array. */
85 /* Array of references to all copies. The order number of the copy
86 corresponds to the index in the array. Removed copies have NULL
88 ira_copy_t
*ira_copies
;
90 /* Size of the previous array. */
95 /* LAST_BASIC_BLOCK before generating additional insns because of live
96 range splitting. Emitting insns on a critical edge creates a new
98 static int last_basic_block_before_change
;
100 /* Initialize some members in loop tree node NODE. Use LOOP_NUM for
101 the member loop_num. */
103 init_loop_tree_node (struct ira_loop_tree_node
*node
, int loop_num
)
105 int max_regno
= max_reg_num ();
107 node
->regno_allocno_map
108 = (ira_allocno_t
*) ira_allocate (sizeof (ira_allocno_t
) * max_regno
);
109 memset (node
->regno_allocno_map
, 0, sizeof (ira_allocno_t
) * max_regno
);
110 memset (node
->reg_pressure
, 0, sizeof (node
->reg_pressure
));
111 node
->all_allocnos
= ira_allocate_bitmap ();
112 node
->modified_regnos
= ira_allocate_bitmap ();
113 node
->border_allocnos
= ira_allocate_bitmap ();
114 node
->local_copies
= ira_allocate_bitmap ();
115 node
->loop_num
= loop_num
;
116 node
->children
= NULL
;
117 node
->subloops
= NULL
;
121 /* The following function allocates the loop tree nodes. If
122 CURRENT_LOOPS is NULL, the nodes corresponding to the loops (except
123 the root which corresponds the all function) will be not allocated
124 but nodes will still be allocated for basic blocks. */
126 create_loop_tree_nodes (void)
136 = ((struct ira_loop_tree_node
*)
137 ira_allocate (sizeof (struct ira_loop_tree_node
)
138 * last_basic_block_for_fn (cfun
)));
139 last_basic_block_before_change
= last_basic_block_for_fn (cfun
);
140 for (i
= 0; i
< (unsigned int) last_basic_block_for_fn (cfun
); i
++)
142 ira_bb_nodes
[i
].regno_allocno_map
= NULL
;
143 memset (ira_bb_nodes
[i
].reg_pressure
, 0,
144 sizeof (ira_bb_nodes
[i
].reg_pressure
));
145 ira_bb_nodes
[i
].all_allocnos
= NULL
;
146 ira_bb_nodes
[i
].modified_regnos
= NULL
;
147 ira_bb_nodes
[i
].border_allocnos
= NULL
;
148 ira_bb_nodes
[i
].local_copies
= NULL
;
150 if (current_loops
== NULL
)
152 ira_loop_nodes_count
= 1;
153 ira_loop_nodes
= ((struct ira_loop_tree_node
*)
154 ira_allocate (sizeof (struct ira_loop_tree_node
)));
155 init_loop_tree_node (ira_loop_nodes
, 0);
158 ira_loop_nodes_count
= number_of_loops (cfun
);
159 ira_loop_nodes
= ((struct ira_loop_tree_node
*)
160 ira_allocate (sizeof (struct ira_loop_tree_node
)
161 * ira_loop_nodes_count
));
162 FOR_EACH_VEC_SAFE_ELT (get_loops (cfun
), i
, loop
)
164 if (loop_outer (loop
) != NULL
)
166 ira_loop_nodes
[i
].regno_allocno_map
= NULL
;
168 FOR_EACH_EDGE (e
, ei
, loop
->header
->preds
)
169 if (e
->src
!= loop
->latch
170 && (e
->flags
& EDGE_ABNORMAL
) && EDGE_CRITICAL_P (e
))
177 edges
= get_loop_exit_edges (loop
);
178 FOR_EACH_VEC_ELT (edges
, j
, e
)
179 if ((e
->flags
& EDGE_ABNORMAL
) && EDGE_CRITICAL_P (e
))
188 init_loop_tree_node (&ira_loop_nodes
[i
], loop
->num
);
192 /* The function returns TRUE if there are more one allocation
195 more_one_region_p (void)
200 if (current_loops
!= NULL
)
201 FOR_EACH_VEC_SAFE_ELT (get_loops (cfun
), i
, loop
)
202 if (ira_loop_nodes
[i
].regno_allocno_map
!= NULL
203 && ira_loop_tree_root
!= &ira_loop_nodes
[i
])
208 /* Free the loop tree node of a loop. */
210 finish_loop_tree_node (ira_loop_tree_node_t loop
)
212 if (loop
->regno_allocno_map
!= NULL
)
214 ira_assert (loop
->bb
== NULL
);
215 ira_free_bitmap (loop
->local_copies
);
216 ira_free_bitmap (loop
->border_allocnos
);
217 ira_free_bitmap (loop
->modified_regnos
);
218 ira_free_bitmap (loop
->all_allocnos
);
219 ira_free (loop
->regno_allocno_map
);
220 loop
->regno_allocno_map
= NULL
;
224 /* Free the loop tree nodes. */
226 finish_loop_tree_nodes (void)
230 for (i
= 0; i
< ira_loop_nodes_count
; i
++)
231 finish_loop_tree_node (&ira_loop_nodes
[i
]);
232 ira_free (ira_loop_nodes
);
233 for (i
= 0; i
< (unsigned int) last_basic_block_before_change
; i
++)
235 if (ira_bb_nodes
[i
].local_copies
!= NULL
)
236 ira_free_bitmap (ira_bb_nodes
[i
].local_copies
);
237 if (ira_bb_nodes
[i
].border_allocnos
!= NULL
)
238 ira_free_bitmap (ira_bb_nodes
[i
].border_allocnos
);
239 if (ira_bb_nodes
[i
].modified_regnos
!= NULL
)
240 ira_free_bitmap (ira_bb_nodes
[i
].modified_regnos
);
241 if (ira_bb_nodes
[i
].all_allocnos
!= NULL
)
242 ira_free_bitmap (ira_bb_nodes
[i
].all_allocnos
);
243 if (ira_bb_nodes
[i
].regno_allocno_map
!= NULL
)
244 ira_free (ira_bb_nodes
[i
].regno_allocno_map
);
246 ira_free (ira_bb_nodes
);
251 /* The following recursive function adds LOOP to the loop tree
252 hierarchy. LOOP is added only once. If LOOP is NULL we adding
253 loop designating the whole function when CFG loops are not
256 add_loop_to_tree (class loop
*loop
)
260 ira_loop_tree_node_t loop_node
, parent_node
;
262 /* We cannot use loop node access macros here because of potential
263 checking and because the nodes are not initialized enough
265 if (loop
!= NULL
&& loop_outer (loop
) != NULL
)
266 add_loop_to_tree (loop_outer (loop
));
267 loop_num
= loop
!= NULL
? loop
->num
: 0;
268 if (ira_loop_nodes
[loop_num
].regno_allocno_map
!= NULL
269 && ira_loop_nodes
[loop_num
].children
== NULL
)
271 /* We have not added loop node to the tree yet. */
272 loop_node
= &ira_loop_nodes
[loop_num
];
273 loop_node
->loop
= loop
;
274 loop_node
->bb
= NULL
;
279 for (parent
= loop_outer (loop
);
281 parent
= loop_outer (parent
))
282 if (ira_loop_nodes
[parent
->num
].regno_allocno_map
!= NULL
)
287 loop_node
->next
= NULL
;
288 loop_node
->subloop_next
= NULL
;
289 loop_node
->parent
= NULL
;
293 parent_node
= &ira_loop_nodes
[parent
->num
];
294 loop_node
->next
= parent_node
->children
;
295 parent_node
->children
= loop_node
;
296 loop_node
->subloop_next
= parent_node
->subloops
;
297 parent_node
->subloops
= loop_node
;
298 loop_node
->parent
= parent_node
;
303 /* The following recursive function sets up levels of nodes of the
304 tree given its root LOOP_NODE. The enumeration starts with LEVEL.
305 The function returns maximal value of level in the tree + 1. */
307 setup_loop_tree_level (ira_loop_tree_node_t loop_node
, int level
)
309 int height
, max_height
;
310 ira_loop_tree_node_t subloop_node
;
312 ira_assert (loop_node
->bb
== NULL
);
313 loop_node
->level
= level
;
314 max_height
= level
+ 1;
315 for (subloop_node
= loop_node
->subloops
;
316 subloop_node
!= NULL
;
317 subloop_node
= subloop_node
->subloop_next
)
319 ira_assert (subloop_node
->bb
== NULL
);
320 height
= setup_loop_tree_level (subloop_node
, level
+ 1);
321 if (height
> max_height
)
327 /* Create the loop tree. The algorithm is designed to provide correct
328 order of loops (they are ordered by their last loop BB) and basic
329 blocks in the chain formed by member next. */
331 form_loop_tree (void)
335 ira_loop_tree_node_t bb_node
, loop_node
;
337 /* We cannot use loop/bb node access macros because of potential
338 checking and because the nodes are not initialized enough
340 FOR_EACH_BB_FN (bb
, cfun
)
342 bb_node
= &ira_bb_nodes
[bb
->index
];
344 bb_node
->loop
= NULL
;
345 bb_node
->subloops
= NULL
;
346 bb_node
->children
= NULL
;
347 bb_node
->subloop_next
= NULL
;
348 bb_node
->next
= NULL
;
349 if (current_loops
== NULL
)
353 for (parent
= bb
->loop_father
;
355 parent
= loop_outer (parent
))
356 if (ira_loop_nodes
[parent
->num
].regno_allocno_map
!= NULL
)
359 add_loop_to_tree (parent
);
360 loop_node
= &ira_loop_nodes
[parent
== NULL
? 0 : parent
->num
];
361 bb_node
->next
= loop_node
->children
;
362 bb_node
->parent
= loop_node
;
363 loop_node
->children
= bb_node
;
365 ira_loop_tree_root
= IRA_LOOP_NODE_BY_INDEX (0);
366 ira_loop_tree_height
= setup_loop_tree_level (ira_loop_tree_root
, 0);
367 ira_assert (ira_loop_tree_root
->regno_allocno_map
!= NULL
);
372 /* Rebuild IRA_REGNO_ALLOCNO_MAP and REGNO_ALLOCNO_MAPs of the loop
375 rebuild_regno_allocno_maps (void)
378 int max_regno
, regno
;
380 ira_loop_tree_node_t loop_tree_node
;
382 ira_allocno_iterator ai
;
384 ira_assert (current_loops
!= NULL
);
385 max_regno
= max_reg_num ();
386 FOR_EACH_VEC_SAFE_ELT (get_loops (cfun
), l
, loop
)
387 if (ira_loop_nodes
[l
].regno_allocno_map
!= NULL
)
389 ira_free (ira_loop_nodes
[l
].regno_allocno_map
);
390 ira_loop_nodes
[l
].regno_allocno_map
391 = (ira_allocno_t
*) ira_allocate (sizeof (ira_allocno_t
)
393 memset (ira_loop_nodes
[l
].regno_allocno_map
, 0,
394 sizeof (ira_allocno_t
) * max_regno
);
396 ira_free (ira_regno_allocno_map
);
397 ira_regno_allocno_map
398 = (ira_allocno_t
*) ira_allocate (max_regno
* sizeof (ira_allocno_t
));
399 memset (ira_regno_allocno_map
, 0, max_regno
* sizeof (ira_allocno_t
));
400 FOR_EACH_ALLOCNO (a
, ai
)
402 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
403 /* Caps are not in the regno allocno maps. */
405 regno
= ALLOCNO_REGNO (a
);
406 loop_tree_node
= ALLOCNO_LOOP_TREE_NODE (a
);
407 ALLOCNO_NEXT_REGNO_ALLOCNO (a
) = ira_regno_allocno_map
[regno
];
408 ira_regno_allocno_map
[regno
] = a
;
409 if (loop_tree_node
->regno_allocno_map
[regno
] == NULL
)
410 /* Remember that we can create temporary allocnos to break
411 cycles in register shuffle. */
412 loop_tree_node
->regno_allocno_map
[regno
] = a
;
417 /* Pools for allocnos, allocno live ranges and objects. */
418 static object_allocator
<live_range
> live_range_pool ("live ranges");
419 static object_allocator
<ira_allocno
> allocno_pool ("allocnos");
420 static object_allocator
<ira_object
> object_pool ("objects");
422 /* Vec containing references to all created allocnos. It is a
423 container of array allocnos. */
424 static vec
<ira_allocno_t
> allocno_vec
;
426 /* Vec containing references to all created ira_objects. It is a
427 container of ira_object_id_map. */
428 static vec
<ira_object_t
> ira_object_id_map_vec
;
430 /* Initialize data concerning allocnos. */
432 initiate_allocnos (void)
434 allocno_vec
.create (max_reg_num () * 2);
436 ira_allocnos_num
= 0;
438 ira_object_id_map_vec
.create (max_reg_num () * 2);
439 ira_object_id_map
= NULL
;
440 ira_regno_allocno_map
441 = (ira_allocno_t
*) ira_allocate (max_reg_num ()
442 * sizeof (ira_allocno_t
));
443 memset (ira_regno_allocno_map
, 0, max_reg_num () * sizeof (ira_allocno_t
));
446 /* Create and return an object corresponding to a new allocno A. */
448 ira_create_object (ira_allocno_t a
, int subword
)
450 enum reg_class aclass
= ALLOCNO_CLASS (a
);
451 ira_object_t obj
= object_pool
.allocate ();
453 OBJECT_ALLOCNO (obj
) = a
;
454 OBJECT_SUBWORD (obj
) = subword
;
455 OBJECT_CONFLICT_ID (obj
) = ira_objects_num
;
456 OBJECT_CONFLICT_VEC_P (obj
) = false;
457 OBJECT_CONFLICT_ARRAY (obj
) = NULL
;
458 OBJECT_NUM_CONFLICTS (obj
) = 0;
459 OBJECT_CONFLICT_HARD_REGS (obj
) = ira_no_alloc_regs
;
460 OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
) = ira_no_alloc_regs
;
461 OBJECT_CONFLICT_HARD_REGS (obj
) |= ~reg_class_contents
[aclass
];
462 OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
) |= ~reg_class_contents
[aclass
];
463 OBJECT_MIN (obj
) = INT_MAX
;
464 OBJECT_MAX (obj
) = -1;
465 OBJECT_LIVE_RANGES (obj
) = NULL
;
467 ira_object_id_map_vec
.safe_push (obj
);
469 = ira_object_id_map_vec
.address ();
470 ira_objects_num
= ira_object_id_map_vec
.length ();
475 /* Create and return the allocno corresponding to REGNO in
476 LOOP_TREE_NODE. Add the allocno to the list of allocnos with the
477 same regno if CAP_P is FALSE. */
479 ira_create_allocno (int regno
, bool cap_p
,
480 ira_loop_tree_node_t loop_tree_node
)
484 a
= allocno_pool
.allocate ();
485 ALLOCNO_REGNO (a
) = regno
;
486 ALLOCNO_LOOP_TREE_NODE (a
) = loop_tree_node
;
489 ALLOCNO_NEXT_REGNO_ALLOCNO (a
) = ira_regno_allocno_map
[regno
];
490 ira_regno_allocno_map
[regno
] = a
;
491 if (loop_tree_node
->regno_allocno_map
[regno
] == NULL
)
492 /* Remember that we can create temporary allocnos to break
493 cycles in register shuffle on region borders (see
495 loop_tree_node
->regno_allocno_map
[regno
] = a
;
497 ALLOCNO_CAP (a
) = NULL
;
498 ALLOCNO_CAP_MEMBER (a
) = NULL
;
499 ALLOCNO_NUM (a
) = ira_allocnos_num
;
500 bitmap_set_bit (loop_tree_node
->all_allocnos
, ALLOCNO_NUM (a
));
501 ALLOCNO_NREFS (a
) = 0;
502 ALLOCNO_FREQ (a
) = 0;
503 ALLOCNO_HARD_REGNO (a
) = -1;
504 ALLOCNO_CALL_FREQ (a
) = 0;
505 ALLOCNO_CALLS_CROSSED_NUM (a
) = 0;
506 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
) = 0;
507 ALLOCNO_CROSSED_CALLS_ABIS (a
) = 0;
508 CLEAR_HARD_REG_SET (ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
));
510 ALLOCNO_NO_STACK_REG_P (a
) = false;
511 ALLOCNO_TOTAL_NO_STACK_REG_P (a
) = false;
513 ALLOCNO_DONT_REASSIGN_P (a
) = false;
514 ALLOCNO_BAD_SPILL_P (a
) = false;
515 ALLOCNO_ASSIGNED_P (a
) = false;
516 ALLOCNO_MODE (a
) = (regno
< 0 ? VOIDmode
: PSEUDO_REGNO_MODE (regno
));
517 ALLOCNO_WMODE (a
) = ALLOCNO_MODE (a
);
518 ALLOCNO_PREFS (a
) = NULL
;
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
;
524 ALLOCNO_CLASS (a
) = NO_REGS
;
525 ALLOCNO_UPDATED_CLASS_COST (a
) = 0;
526 ALLOCNO_CLASS_COST (a
) = 0;
527 ALLOCNO_MEMORY_COST (a
) = 0;
528 ALLOCNO_UPDATED_MEMORY_COST (a
) = 0;
529 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
) = 0;
530 ALLOCNO_NUM_OBJECTS (a
) = 0;
532 ALLOCNO_ADD_DATA (a
) = NULL
;
533 allocno_vec
.safe_push (a
);
534 ira_allocnos
= allocno_vec
.address ();
535 ira_allocnos_num
= allocno_vec
.length ();
540 /* Set up register class for A and update its conflict hard
543 ira_set_allocno_class (ira_allocno_t a
, enum reg_class aclass
)
545 ira_allocno_object_iterator oi
;
548 ALLOCNO_CLASS (a
) = aclass
;
549 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
551 OBJECT_CONFLICT_HARD_REGS (obj
) |= ~reg_class_contents
[aclass
];
552 OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
) |= ~reg_class_contents
[aclass
];
556 /* Determine the number of objects we should associate with allocno A
557 and allocate them. */
559 ira_create_allocno_objects (ira_allocno_t a
)
561 machine_mode mode
= ALLOCNO_MODE (a
);
562 enum reg_class aclass
= ALLOCNO_CLASS (a
);
563 int n
= ira_reg_class_max_nregs
[aclass
][mode
];
566 if (n
!= 2 || maybe_ne (GET_MODE_SIZE (mode
), n
* UNITS_PER_WORD
))
569 ALLOCNO_NUM_OBJECTS (a
) = n
;
570 for (i
= 0; i
< n
; i
++)
571 ALLOCNO_OBJECT (a
, i
) = ira_create_object (a
, i
);
574 /* For each allocno, set ALLOCNO_NUM_OBJECTS and create the
575 ALLOCNO_OBJECT structures. This must be called after the allocno
576 classes are known. */
578 create_allocno_objects (void)
581 ira_allocno_iterator ai
;
583 FOR_EACH_ALLOCNO (a
, ai
)
584 ira_create_allocno_objects (a
);
587 /* Merge hard register conflict information for all objects associated with
588 allocno TO into the corresponding objects associated with FROM.
589 If TOTAL_ONLY is true, we only merge OBJECT_TOTAL_CONFLICT_HARD_REGS. */
591 merge_hard_reg_conflicts (ira_allocno_t from
, ira_allocno_t to
,
595 gcc_assert (ALLOCNO_NUM_OBJECTS (to
) == ALLOCNO_NUM_OBJECTS (from
));
596 for (i
= 0; i
< ALLOCNO_NUM_OBJECTS (to
); i
++)
598 ira_object_t from_obj
= ALLOCNO_OBJECT (from
, i
);
599 ira_object_t to_obj
= ALLOCNO_OBJECT (to
, i
);
602 OBJECT_CONFLICT_HARD_REGS (to_obj
)
603 |= OBJECT_CONFLICT_HARD_REGS (from_obj
);
604 OBJECT_TOTAL_CONFLICT_HARD_REGS (to_obj
)
605 |= OBJECT_TOTAL_CONFLICT_HARD_REGS (from_obj
);
608 if (!total_only
&& ALLOCNO_NO_STACK_REG_P (from
))
609 ALLOCNO_NO_STACK_REG_P (to
) = true;
610 if (ALLOCNO_TOTAL_NO_STACK_REG_P (from
))
611 ALLOCNO_TOTAL_NO_STACK_REG_P (to
) = true;
615 /* Update hard register conflict information for all objects associated with
616 A to include the regs in SET. */
618 ior_hard_reg_conflicts (ira_allocno_t a
, const_hard_reg_set set
)
620 ira_allocno_object_iterator i
;
623 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, i
)
625 OBJECT_CONFLICT_HARD_REGS (obj
) |= set
;
626 OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
) |= set
;
630 /* Return TRUE if a conflict vector with NUM elements is more
631 profitable than a conflict bit vector for OBJ. */
633 ira_conflict_vector_profitable_p (ira_object_t obj
, int num
)
636 int max
= OBJECT_MAX (obj
);
637 int min
= OBJECT_MIN (obj
);
640 /* We prefer a bit vector in such case because it does not result
644 nw
= (max
- min
+ IRA_INT_BITS
) / IRA_INT_BITS
;
645 return (2 * sizeof (ira_object_t
) * (num
+ 1)
646 < 3 * nw
* sizeof (IRA_INT_TYPE
));
649 /* Allocates and initialize the conflict vector of OBJ for NUM
650 conflicting objects. */
652 ira_allocate_conflict_vec (ira_object_t obj
, int num
)
657 ira_assert (OBJECT_CONFLICT_ARRAY (obj
) == NULL
);
658 num
++; /* for NULL end marker */
659 size
= sizeof (ira_object_t
) * num
;
660 OBJECT_CONFLICT_ARRAY (obj
) = ira_allocate (size
);
661 vec
= (ira_object_t
*) OBJECT_CONFLICT_ARRAY (obj
);
663 OBJECT_NUM_CONFLICTS (obj
) = 0;
664 OBJECT_CONFLICT_ARRAY_SIZE (obj
) = size
;
665 OBJECT_CONFLICT_VEC_P (obj
) = true;
668 /* Allocate and initialize the conflict bit vector of OBJ. */
670 allocate_conflict_bit_vec (ira_object_t obj
)
674 ira_assert (OBJECT_CONFLICT_ARRAY (obj
) == NULL
);
675 size
= ((OBJECT_MAX (obj
) - OBJECT_MIN (obj
) + IRA_INT_BITS
)
676 / IRA_INT_BITS
* sizeof (IRA_INT_TYPE
));
677 OBJECT_CONFLICT_ARRAY (obj
) = ira_allocate (size
);
678 memset (OBJECT_CONFLICT_ARRAY (obj
), 0, size
);
679 OBJECT_CONFLICT_ARRAY_SIZE (obj
) = size
;
680 OBJECT_CONFLICT_VEC_P (obj
) = false;
683 /* Allocate and initialize the conflict vector or conflict bit vector
684 of OBJ for NUM conflicting allocnos whatever is more profitable. */
686 ira_allocate_object_conflicts (ira_object_t obj
, int num
)
688 if (ira_conflict_vector_profitable_p (obj
, num
))
689 ira_allocate_conflict_vec (obj
, num
);
691 allocate_conflict_bit_vec (obj
);
694 /* Add OBJ2 to the conflicts of OBJ1. */
696 add_to_conflicts (ira_object_t obj1
, ira_object_t obj2
)
701 if (OBJECT_CONFLICT_VEC_P (obj1
))
703 ira_object_t
*vec
= OBJECT_CONFLICT_VEC (obj1
);
704 int curr_num
= OBJECT_NUM_CONFLICTS (obj1
);
706 if (OBJECT_CONFLICT_ARRAY_SIZE (obj1
) < num
* sizeof (ira_object_t
))
708 ira_object_t
*newvec
;
709 size
= (3 * num
/ 2 + 1) * sizeof (ira_allocno_t
);
710 newvec
= (ira_object_t
*) ira_allocate (size
);
711 memcpy (newvec
, vec
, curr_num
* sizeof (ira_object_t
));
714 OBJECT_CONFLICT_ARRAY (obj1
) = vec
;
715 OBJECT_CONFLICT_ARRAY_SIZE (obj1
) = size
;
719 OBJECT_NUM_CONFLICTS (obj1
)++;
723 int nw
, added_head_nw
, id
;
724 IRA_INT_TYPE
*vec
= OBJECT_CONFLICT_BITVEC (obj1
);
726 id
= OBJECT_CONFLICT_ID (obj2
);
727 if (OBJECT_MIN (obj1
) > id
)
729 /* Expand head of the bit vector. */
730 added_head_nw
= (OBJECT_MIN (obj1
) - id
- 1) / IRA_INT_BITS
+ 1;
731 nw
= (OBJECT_MAX (obj1
) - OBJECT_MIN (obj1
)) / IRA_INT_BITS
+ 1;
732 size
= (nw
+ added_head_nw
) * sizeof (IRA_INT_TYPE
);
733 if (OBJECT_CONFLICT_ARRAY_SIZE (obj1
) >= size
)
735 memmove ((char *) vec
+ added_head_nw
* sizeof (IRA_INT_TYPE
),
736 vec
, nw
* sizeof (IRA_INT_TYPE
));
737 memset (vec
, 0, added_head_nw
* sizeof (IRA_INT_TYPE
));
742 = (3 * (nw
+ added_head_nw
) / 2 + 1) * sizeof (IRA_INT_TYPE
);
743 vec
= (IRA_INT_TYPE
*) ira_allocate (size
);
744 memcpy ((char *) vec
+ added_head_nw
* sizeof (IRA_INT_TYPE
),
745 OBJECT_CONFLICT_ARRAY (obj1
), nw
* sizeof (IRA_INT_TYPE
));
746 memset (vec
, 0, added_head_nw
* sizeof (IRA_INT_TYPE
));
748 + (nw
+ added_head_nw
) * sizeof (IRA_INT_TYPE
),
749 0, size
- (nw
+ added_head_nw
) * sizeof (IRA_INT_TYPE
));
750 ira_free (OBJECT_CONFLICT_ARRAY (obj1
));
751 OBJECT_CONFLICT_ARRAY (obj1
) = vec
;
752 OBJECT_CONFLICT_ARRAY_SIZE (obj1
) = size
;
754 OBJECT_MIN (obj1
) -= added_head_nw
* IRA_INT_BITS
;
756 else if (OBJECT_MAX (obj1
) < id
)
758 nw
= (id
- OBJECT_MIN (obj1
)) / IRA_INT_BITS
+ 1;
759 size
= nw
* sizeof (IRA_INT_TYPE
);
760 if (OBJECT_CONFLICT_ARRAY_SIZE (obj1
) < size
)
762 /* Expand tail of the bit vector. */
763 size
= (3 * nw
/ 2 + 1) * sizeof (IRA_INT_TYPE
);
764 vec
= (IRA_INT_TYPE
*) ira_allocate (size
);
765 memcpy (vec
, OBJECT_CONFLICT_ARRAY (obj1
), OBJECT_CONFLICT_ARRAY_SIZE (obj1
));
766 memset ((char *) vec
+ OBJECT_CONFLICT_ARRAY_SIZE (obj1
),
767 0, size
- OBJECT_CONFLICT_ARRAY_SIZE (obj1
));
768 ira_free (OBJECT_CONFLICT_ARRAY (obj1
));
769 OBJECT_CONFLICT_ARRAY (obj1
) = vec
;
770 OBJECT_CONFLICT_ARRAY_SIZE (obj1
) = size
;
772 OBJECT_MAX (obj1
) = id
;
774 SET_MINMAX_SET_BIT (vec
, id
, OBJECT_MIN (obj1
), OBJECT_MAX (obj1
));
778 /* Add OBJ1 to the conflicts of OBJ2 and vice versa. */
780 ira_add_conflict (ira_object_t obj1
, ira_object_t obj2
)
782 add_to_conflicts (obj1
, obj2
);
783 add_to_conflicts (obj2
, obj1
);
786 /* Clear all conflicts of OBJ. */
788 clear_conflicts (ira_object_t obj
)
790 if (OBJECT_CONFLICT_VEC_P (obj
))
792 OBJECT_NUM_CONFLICTS (obj
) = 0;
793 OBJECT_CONFLICT_VEC (obj
)[0] = NULL
;
795 else if (OBJECT_CONFLICT_ARRAY_SIZE (obj
) != 0)
799 nw
= (OBJECT_MAX (obj
) - OBJECT_MIN (obj
)) / IRA_INT_BITS
+ 1;
800 memset (OBJECT_CONFLICT_BITVEC (obj
), 0, nw
* sizeof (IRA_INT_TYPE
));
804 /* The array used to find duplications in conflict vectors of
806 static int *conflict_check
;
808 /* The value used to mark allocation presence in conflict vector of
809 the current allocno. */
810 static int curr_conflict_check_tick
;
812 /* Remove duplications in conflict vector of OBJ. */
814 compress_conflict_vec (ira_object_t obj
)
816 ira_object_t
*vec
, conflict_obj
;
819 ira_assert (OBJECT_CONFLICT_VEC_P (obj
));
820 vec
= OBJECT_CONFLICT_VEC (obj
);
821 curr_conflict_check_tick
++;
822 for (i
= j
= 0; (conflict_obj
= vec
[i
]) != NULL
; i
++)
824 int id
= OBJECT_CONFLICT_ID (conflict_obj
);
825 if (conflict_check
[id
] != curr_conflict_check_tick
)
827 conflict_check
[id
] = curr_conflict_check_tick
;
828 vec
[j
++] = conflict_obj
;
831 OBJECT_NUM_CONFLICTS (obj
) = j
;
835 /* Remove duplications in conflict vectors of all allocnos. */
837 compress_conflict_vecs (void)
840 ira_object_iterator oi
;
842 conflict_check
= (int *) ira_allocate (sizeof (int) * ira_objects_num
);
843 memset (conflict_check
, 0, sizeof (int) * ira_objects_num
);
844 curr_conflict_check_tick
= 0;
845 FOR_EACH_OBJECT (obj
, oi
)
847 if (OBJECT_CONFLICT_VEC_P (obj
))
848 compress_conflict_vec (obj
);
850 ira_free (conflict_check
);
853 /* This recursive function outputs allocno A and if it is a cap the
854 function outputs its members. */
856 ira_print_expanded_allocno (ira_allocno_t a
)
860 fprintf (ira_dump_file
, " a%d(r%d", ALLOCNO_NUM (a
), ALLOCNO_REGNO (a
));
861 if ((bb
= ALLOCNO_LOOP_TREE_NODE (a
)->bb
) != NULL
)
862 fprintf (ira_dump_file
, ",b%d", bb
->index
);
864 fprintf (ira_dump_file
, ",l%d", ALLOCNO_LOOP_TREE_NODE (a
)->loop_num
);
865 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
867 fprintf (ira_dump_file
, ":");
868 ira_print_expanded_allocno (ALLOCNO_CAP_MEMBER (a
));
870 fprintf (ira_dump_file
, ")");
873 /* Create and return the cap representing allocno A in the
876 create_cap_allocno (ira_allocno_t a
)
879 ira_loop_tree_node_t parent
;
880 enum reg_class aclass
;
882 parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
;
883 cap
= ira_create_allocno (ALLOCNO_REGNO (a
), true, parent
);
884 ALLOCNO_MODE (cap
) = ALLOCNO_MODE (a
);
885 ALLOCNO_WMODE (cap
) = ALLOCNO_WMODE (a
);
886 aclass
= ALLOCNO_CLASS (a
);
887 ira_set_allocno_class (cap
, aclass
);
888 ira_create_allocno_objects (cap
);
889 ALLOCNO_CAP_MEMBER (cap
) = a
;
890 ALLOCNO_CAP (a
) = cap
;
891 ALLOCNO_CLASS_COST (cap
) = ALLOCNO_CLASS_COST (a
);
892 ALLOCNO_MEMORY_COST (cap
) = ALLOCNO_MEMORY_COST (a
);
893 ira_allocate_and_copy_costs
894 (&ALLOCNO_HARD_REG_COSTS (cap
), aclass
, ALLOCNO_HARD_REG_COSTS (a
));
895 ira_allocate_and_copy_costs
896 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (cap
), aclass
,
897 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
));
898 ALLOCNO_BAD_SPILL_P (cap
) = ALLOCNO_BAD_SPILL_P (a
);
899 ALLOCNO_NREFS (cap
) = ALLOCNO_NREFS (a
);
900 ALLOCNO_FREQ (cap
) = ALLOCNO_FREQ (a
);
901 ALLOCNO_CALL_FREQ (cap
) = ALLOCNO_CALL_FREQ (a
);
903 merge_hard_reg_conflicts (a
, cap
, false);
905 ALLOCNO_CALLS_CROSSED_NUM (cap
) = ALLOCNO_CALLS_CROSSED_NUM (a
);
906 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (cap
) = ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
);
907 ALLOCNO_CROSSED_CALLS_ABIS (cap
) = ALLOCNO_CROSSED_CALLS_ABIS (a
);
908 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (cap
)
909 = ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
);
910 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
912 fprintf (ira_dump_file
, " Creating cap ");
913 ira_print_expanded_allocno (cap
);
914 fprintf (ira_dump_file
, "\n");
919 /* Create and return a live range for OBJECT with given attributes. */
921 ira_create_live_range (ira_object_t obj
, int start
, int finish
,
926 p
= live_range_pool
.allocate ();
934 /* Create a new live range for OBJECT and queue it at the head of its
937 ira_add_live_range_to_object (ira_object_t object
, int start
, int finish
)
940 p
= ira_create_live_range (object
, start
, finish
,
941 OBJECT_LIVE_RANGES (object
));
942 OBJECT_LIVE_RANGES (object
) = p
;
945 /* Copy allocno live range R and return the result. */
947 copy_live_range (live_range_t r
)
951 p
= live_range_pool
.allocate ();
956 /* Copy allocno live range list given by its head R and return the
959 ira_copy_live_range_list (live_range_t r
)
961 live_range_t p
, first
, last
;
965 for (first
= last
= NULL
; r
!= NULL
; r
= r
->next
)
967 p
= copy_live_range (r
);
977 /* Merge ranges R1 and R2 and returns the result. The function
978 maintains the order of ranges and tries to minimize number of the
981 ira_merge_live_ranges (live_range_t r1
, live_range_t r2
)
983 live_range_t first
, last
;
989 for (first
= last
= NULL
; r1
!= NULL
&& r2
!= NULL
;)
991 if (r1
->start
< r2
->start
)
993 if (r1
->start
<= r2
->finish
+ 1)
995 /* Intersected ranges: merge r1 and r2 into r1. */
996 r1
->start
= r2
->start
;
997 if (r1
->finish
< r2
->finish
)
998 r1
->finish
= r2
->finish
;
999 live_range_t temp
= r2
;
1001 ira_finish_live_range (temp
);
1004 /* To try to merge with subsequent ranges in r1. */
1011 /* Add r1 to the result. */
1022 /* To try to merge with subsequent ranges in r2. */
1034 ira_assert (r1
->next
== NULL
);
1036 else if (r2
!= NULL
)
1042 ira_assert (r2
->next
== NULL
);
1046 ira_assert (last
->next
== NULL
);
1051 /* Return TRUE if live ranges R1 and R2 intersect. */
1053 ira_live_ranges_intersect_p (live_range_t r1
, live_range_t r2
)
1055 /* Remember the live ranges are always kept ordered. */
1056 while (r1
!= NULL
&& r2
!= NULL
)
1058 if (r1
->start
> r2
->finish
)
1060 else if (r2
->start
> r1
->finish
)
1068 /* Free allocno live range R. */
1070 ira_finish_live_range (live_range_t r
)
1072 live_range_pool
.remove (r
);
1075 /* Free list of allocno live ranges starting with R. */
1077 ira_finish_live_range_list (live_range_t r
)
1079 live_range_t next_r
;
1081 for (; r
!= NULL
; r
= next_r
)
1084 ira_finish_live_range (r
);
1088 /* Free updated register costs of allocno A. */
1090 ira_free_allocno_updated_costs (ira_allocno_t a
)
1092 enum reg_class aclass
;
1094 aclass
= ALLOCNO_CLASS (a
);
1095 if (ALLOCNO_UPDATED_HARD_REG_COSTS (a
) != NULL
)
1096 ira_free_cost_vector (ALLOCNO_UPDATED_HARD_REG_COSTS (a
), aclass
);
1097 ALLOCNO_UPDATED_HARD_REG_COSTS (a
) = NULL
;
1098 if (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) != NULL
)
1099 ira_free_cost_vector (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
),
1101 ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) = NULL
;
1104 /* Free and nullify all cost vectors allocated earlier for allocno
1107 ira_free_allocno_costs (ira_allocno_t a
)
1109 enum reg_class aclass
= ALLOCNO_CLASS (a
);
1111 ira_allocno_object_iterator oi
;
1113 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
1115 ira_finish_live_range_list (OBJECT_LIVE_RANGES (obj
));
1116 ira_object_id_map
[OBJECT_CONFLICT_ID (obj
)] = NULL
;
1117 if (OBJECT_CONFLICT_ARRAY (obj
) != NULL
)
1118 ira_free (OBJECT_CONFLICT_ARRAY (obj
));
1119 object_pool
.remove (obj
);
1122 ira_allocnos
[ALLOCNO_NUM (a
)] = NULL
;
1123 if (ALLOCNO_HARD_REG_COSTS (a
) != NULL
)
1124 ira_free_cost_vector (ALLOCNO_HARD_REG_COSTS (a
), aclass
);
1125 if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) != NULL
)
1126 ira_free_cost_vector (ALLOCNO_CONFLICT_HARD_REG_COSTS (a
), aclass
);
1127 if (ALLOCNO_UPDATED_HARD_REG_COSTS (a
) != NULL
)
1128 ira_free_cost_vector (ALLOCNO_UPDATED_HARD_REG_COSTS (a
), aclass
);
1129 if (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) != NULL
)
1130 ira_free_cost_vector (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
),
1132 ALLOCNO_HARD_REG_COSTS (a
) = NULL
;
1133 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) = NULL
;
1134 ALLOCNO_UPDATED_HARD_REG_COSTS (a
) = NULL
;
1135 ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) = NULL
;
1138 /* Free the memory allocated for allocno A. */
1140 finish_allocno (ira_allocno_t a
)
1142 ira_free_allocno_costs (a
);
1143 allocno_pool
.remove (a
);
1146 /* Free the memory allocated for all allocnos. */
1148 finish_allocnos (void)
1151 ira_allocno_iterator ai
;
1153 FOR_EACH_ALLOCNO (a
, ai
)
1155 ira_free (ira_regno_allocno_map
);
1156 ira_object_id_map_vec
.release ();
1157 allocno_vec
.release ();
1158 allocno_pool
.release ();
1159 object_pool
.release ();
1160 live_range_pool
.release ();
1165 /* Pools for allocno preferences. */
1166 static object_allocator
<ira_allocno_pref
> pref_pool ("prefs");
1168 /* Vec containing references to all created preferences. It is a
1169 container of array ira_prefs. */
1170 static vec
<ira_pref_t
> pref_vec
;
1172 /* The function initializes data concerning allocno prefs. */
1174 initiate_prefs (void)
1176 pref_vec
.create (get_max_uid ());
1181 /* Return pref for A and HARD_REGNO if any. */
1183 find_allocno_pref (ira_allocno_t a
, int hard_regno
)
1187 for (pref
= ALLOCNO_PREFS (a
); pref
!= NULL
; pref
= pref
->next_pref
)
1188 if (pref
->allocno
== a
&& pref
->hard_regno
== hard_regno
)
1193 /* Create and return pref with given attributes A, HARD_REGNO, and FREQ. */
1195 ira_create_pref (ira_allocno_t a
, int hard_regno
, int freq
)
1199 pref
= pref_pool
.allocate ();
1200 pref
->num
= ira_prefs_num
;
1202 pref
->hard_regno
= hard_regno
;
1204 pref_vec
.safe_push (pref
);
1205 ira_prefs
= pref_vec
.address ();
1206 ira_prefs_num
= pref_vec
.length ();
1210 /* Attach a pref PREF to the corresponding allocno. */
1212 add_allocno_pref_to_list (ira_pref_t pref
)
1214 ira_allocno_t a
= pref
->allocno
;
1216 pref
->next_pref
= ALLOCNO_PREFS (a
);
1217 ALLOCNO_PREFS (a
) = pref
;
1220 /* Create (or update frequency if the pref already exists) the pref of
1221 allocnos A preferring HARD_REGNO with frequency FREQ. */
1223 ira_add_allocno_pref (ira_allocno_t a
, int hard_regno
, int freq
)
1229 if ((pref
= find_allocno_pref (a
, hard_regno
)) != NULL
)
1234 pref
= ira_create_pref (a
, hard_regno
, freq
);
1235 ira_assert (a
!= NULL
);
1236 add_allocno_pref_to_list (pref
);
1239 /* Print info about PREF into file F. */
1241 print_pref (FILE *f
, ira_pref_t pref
)
1243 fprintf (f
, " pref%d:a%d(r%d)<-hr%d@%d\n", pref
->num
,
1244 ALLOCNO_NUM (pref
->allocno
), ALLOCNO_REGNO (pref
->allocno
),
1245 pref
->hard_regno
, pref
->freq
);
1248 /* Print info about PREF into stderr. */
1250 ira_debug_pref (ira_pref_t pref
)
1252 print_pref (stderr
, pref
);
1255 /* Print info about all prefs into file F. */
1257 print_prefs (FILE *f
)
1260 ira_pref_iterator pi
;
1262 FOR_EACH_PREF (pref
, pi
)
1263 print_pref (f
, pref
);
1266 /* Print info about all prefs into stderr. */
1268 ira_debug_prefs (void)
1270 print_prefs (stderr
);
1273 /* Print info about prefs involving allocno A into file F. */
1275 print_allocno_prefs (FILE *f
, ira_allocno_t a
)
1279 fprintf (f
, " a%d(r%d):", ALLOCNO_NUM (a
), ALLOCNO_REGNO (a
));
1280 for (pref
= ALLOCNO_PREFS (a
); pref
!= NULL
; pref
= pref
->next_pref
)
1281 fprintf (f
, " pref%d:hr%d@%d", pref
->num
, pref
->hard_regno
, pref
->freq
);
1285 /* Print info about prefs involving allocno A into stderr. */
1287 ira_debug_allocno_prefs (ira_allocno_t a
)
1289 print_allocno_prefs (stderr
, a
);
1292 /* The function frees memory allocated for PREF. */
1294 finish_pref (ira_pref_t pref
)
1296 ira_prefs
[pref
->num
] = NULL
;
1297 pref_pool
.remove (pref
);
1300 /* Remove PREF from the list of allocno prefs and free memory for
1303 ira_remove_pref (ira_pref_t pref
)
1305 ira_pref_t cpref
, prev
;
1307 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
1308 fprintf (ira_dump_file
, " Removing pref%d:hr%d@%d\n",
1309 pref
->num
, pref
->hard_regno
, pref
->freq
);
1310 for (prev
= NULL
, cpref
= ALLOCNO_PREFS (pref
->allocno
);
1312 prev
= cpref
, cpref
= cpref
->next_pref
)
1315 ira_assert (cpref
!= NULL
);
1317 ALLOCNO_PREFS (pref
->allocno
) = pref
->next_pref
;
1319 prev
->next_pref
= pref
->next_pref
;
1323 /* Remove all prefs of allocno A. */
1325 ira_remove_allocno_prefs (ira_allocno_t a
)
1327 ira_pref_t pref
, next_pref
;
1329 for (pref
= ALLOCNO_PREFS (a
); pref
!= NULL
; pref
= next_pref
)
1331 next_pref
= pref
->next_pref
;
1334 ALLOCNO_PREFS (a
) = NULL
;
1337 /* Free memory allocated for all prefs. */
1342 ira_pref_iterator pi
;
1344 FOR_EACH_PREF (pref
, pi
)
1346 pref_vec
.release ();
1347 pref_pool
.release ();
1352 /* Pools for copies. */
1353 static object_allocator
<ira_allocno_copy
> copy_pool ("copies");
1355 /* Vec containing references to all created copies. It is a
1356 container of array ira_copies. */
1357 static vec
<ira_copy_t
> copy_vec
;
1359 /* The function initializes data concerning allocno copies. */
1361 initiate_copies (void)
1363 copy_vec
.create (get_max_uid ());
1368 /* Return copy connecting A1 and A2 and originated from INSN of
1369 LOOP_TREE_NODE if any. */
1371 find_allocno_copy (ira_allocno_t a1
, ira_allocno_t a2
, rtx_insn
*insn
,
1372 ira_loop_tree_node_t loop_tree_node
)
1374 ira_copy_t cp
, next_cp
;
1375 ira_allocno_t another_a
;
1377 for (cp
= ALLOCNO_COPIES (a1
); cp
!= NULL
; cp
= next_cp
)
1379 if (cp
->first
== a1
)
1381 next_cp
= cp
->next_first_allocno_copy
;
1382 another_a
= cp
->second
;
1384 else if (cp
->second
== a1
)
1386 next_cp
= cp
->next_second_allocno_copy
;
1387 another_a
= cp
->first
;
1391 if (another_a
== a2
&& cp
->insn
== insn
1392 && cp
->loop_tree_node
== loop_tree_node
)
1398 /* Create and return copy with given attributes LOOP_TREE_NODE, FIRST,
1399 SECOND, FREQ, CONSTRAINT_P, and INSN. */
1401 ira_create_copy (ira_allocno_t first
, ira_allocno_t second
, int freq
,
1402 bool constraint_p
, rtx_insn
*insn
,
1403 ira_loop_tree_node_t loop_tree_node
)
1407 cp
= copy_pool
.allocate ();
1408 cp
->num
= ira_copies_num
;
1410 cp
->second
= second
;
1412 cp
->constraint_p
= constraint_p
;
1414 cp
->loop_tree_node
= loop_tree_node
;
1415 copy_vec
.safe_push (cp
);
1416 ira_copies
= copy_vec
.address ();
1417 ira_copies_num
= copy_vec
.length ();
1421 /* Attach a copy CP to allocnos involved into the copy. */
1423 add_allocno_copy_to_list (ira_copy_t cp
)
1425 ira_allocno_t first
= cp
->first
, second
= cp
->second
;
1427 cp
->prev_first_allocno_copy
= NULL
;
1428 cp
->prev_second_allocno_copy
= NULL
;
1429 cp
->next_first_allocno_copy
= ALLOCNO_COPIES (first
);
1430 if (cp
->next_first_allocno_copy
!= NULL
)
1432 if (cp
->next_first_allocno_copy
->first
== first
)
1433 cp
->next_first_allocno_copy
->prev_first_allocno_copy
= cp
;
1435 cp
->next_first_allocno_copy
->prev_second_allocno_copy
= cp
;
1437 cp
->next_second_allocno_copy
= ALLOCNO_COPIES (second
);
1438 if (cp
->next_second_allocno_copy
!= NULL
)
1440 if (cp
->next_second_allocno_copy
->second
== second
)
1441 cp
->next_second_allocno_copy
->prev_second_allocno_copy
= cp
;
1443 cp
->next_second_allocno_copy
->prev_first_allocno_copy
= cp
;
1445 ALLOCNO_COPIES (first
) = cp
;
1446 ALLOCNO_COPIES (second
) = cp
;
1449 /* Make a copy CP a canonical copy where number of the
1450 first allocno is less than the second one. */
1452 swap_allocno_copy_ends_if_necessary (ira_copy_t cp
)
1454 if (ALLOCNO_NUM (cp
->first
) <= ALLOCNO_NUM (cp
->second
))
1457 std::swap (cp
->first
, cp
->second
);
1458 std::swap (cp
->prev_first_allocno_copy
, cp
->prev_second_allocno_copy
);
1459 std::swap (cp
->next_first_allocno_copy
, cp
->next_second_allocno_copy
);
1462 /* Create (or update frequency if the copy already exists) and return
1463 the copy of allocnos FIRST and SECOND with frequency FREQ
1464 corresponding to move insn INSN (if any) and originated from
1467 ira_add_allocno_copy (ira_allocno_t first
, ira_allocno_t second
, int freq
,
1468 bool constraint_p
, rtx_insn
*insn
,
1469 ira_loop_tree_node_t loop_tree_node
)
1473 if ((cp
= find_allocno_copy (first
, second
, insn
, loop_tree_node
)) != NULL
)
1478 cp
= ira_create_copy (first
, second
, freq
, constraint_p
, insn
,
1480 ira_assert (first
!= NULL
&& second
!= NULL
);
1481 add_allocno_copy_to_list (cp
);
1482 swap_allocno_copy_ends_if_necessary (cp
);
1486 /* Print info about copy CP into file F. */
1488 print_copy (FILE *f
, ira_copy_t cp
)
1490 fprintf (f
, " cp%d:a%d(r%d)<->a%d(r%d)@%d:%s\n", cp
->num
,
1491 ALLOCNO_NUM (cp
->first
), ALLOCNO_REGNO (cp
->first
),
1492 ALLOCNO_NUM (cp
->second
), ALLOCNO_REGNO (cp
->second
), cp
->freq
,
1494 ? "move" : cp
->constraint_p
? "constraint" : "shuffle");
1498 debug (ira_allocno_copy
&ref
)
1500 print_copy (stderr
, &ref
);
1504 debug (ira_allocno_copy
*ptr
)
1509 fprintf (stderr
, "<nil>\n");
1512 /* Print info about copy CP into stderr. */
1514 ira_debug_copy (ira_copy_t cp
)
1516 print_copy (stderr
, cp
);
1519 /* Print info about all copies into file F. */
1521 print_copies (FILE *f
)
1524 ira_copy_iterator ci
;
1526 FOR_EACH_COPY (cp
, ci
)
1530 /* Print info about all copies into stderr. */
1532 ira_debug_copies (void)
1534 print_copies (stderr
);
1537 /* Print info about copies involving allocno A into file F. */
1539 print_allocno_copies (FILE *f
, ira_allocno_t a
)
1541 ira_allocno_t another_a
;
1542 ira_copy_t cp
, next_cp
;
1544 fprintf (f
, " a%d(r%d):", ALLOCNO_NUM (a
), ALLOCNO_REGNO (a
));
1545 for (cp
= ALLOCNO_COPIES (a
); cp
!= NULL
; cp
= next_cp
)
1549 next_cp
= cp
->next_first_allocno_copy
;
1550 another_a
= cp
->second
;
1552 else if (cp
->second
== a
)
1554 next_cp
= cp
->next_second_allocno_copy
;
1555 another_a
= cp
->first
;
1559 fprintf (f
, " cp%d:a%d(r%d)@%d", cp
->num
,
1560 ALLOCNO_NUM (another_a
), ALLOCNO_REGNO (another_a
), cp
->freq
);
1566 debug (ira_allocno
&ref
)
1568 print_allocno_copies (stderr
, &ref
);
1572 debug (ira_allocno
*ptr
)
1577 fprintf (stderr
, "<nil>\n");
1581 /* Print info about copies involving allocno A into stderr. */
1583 ira_debug_allocno_copies (ira_allocno_t a
)
1585 print_allocno_copies (stderr
, a
);
1588 /* The function frees memory allocated for copy CP. */
1590 finish_copy (ira_copy_t cp
)
1592 copy_pool
.remove (cp
);
1596 /* Free memory allocated for all copies. */
1598 finish_copies (void)
1601 ira_copy_iterator ci
;
1603 FOR_EACH_COPY (cp
, ci
)
1605 copy_vec
.release ();
1606 copy_pool
.release ();
1611 /* Pools for cost vectors. It is defined only for allocno classes. */
1612 static pool_allocator
*cost_vector_pool
[N_REG_CLASSES
];
1614 /* The function initiates work with hard register cost vectors. It
1615 creates allocation pool for each allocno class. */
1617 initiate_cost_vectors (void)
1620 enum reg_class aclass
;
1622 for (i
= 0; i
< ira_allocno_classes_num
; i
++)
1624 aclass
= ira_allocno_classes
[i
];
1625 cost_vector_pool
[aclass
] = new pool_allocator
1626 ("cost vectors", sizeof (int) * (ira_class_hard_regs_num
[aclass
]));
1630 /* Allocate and return a cost vector VEC for ACLASS. */
1632 ira_allocate_cost_vector (reg_class_t aclass
)
1634 return (int*) cost_vector_pool
[(int) aclass
]->allocate ();
1637 /* Free a cost vector VEC for ACLASS. */
1639 ira_free_cost_vector (int *vec
, reg_class_t aclass
)
1641 ira_assert (vec
!= NULL
);
1642 cost_vector_pool
[(int) aclass
]->remove (vec
);
1645 /* Finish work with hard register cost vectors. Release allocation
1646 pool for each allocno class. */
1648 finish_cost_vectors (void)
1651 enum reg_class aclass
;
1653 for (i
= 0; i
< ira_allocno_classes_num
; i
++)
1655 aclass
= ira_allocno_classes
[i
];
1656 delete cost_vector_pool
[aclass
];
1662 /* Compute a post-ordering of the reverse control flow of the loop body
1663 designated by the children nodes of LOOP_NODE, whose body nodes in
1664 pre-order are input as LOOP_PREORDER. Return a VEC with a post-order
1665 of the reverse loop body.
1667 For the post-order of the reverse CFG, we visit the basic blocks in
1668 LOOP_PREORDER array in the reverse order of where they appear.
1669 This is important: We do not just want to compute a post-order of
1670 the reverse CFG, we want to make a best-guess for a visiting order that
1671 minimizes the number of chain elements per allocno live range. If the
1672 blocks would be visited in a different order, we would still compute a
1673 correct post-ordering but it would be less likely that two nodes
1674 connected by an edge in the CFG are neighbors in the topsort. */
1676 static vec
<ira_loop_tree_node_t
>
1677 ira_loop_tree_body_rev_postorder (ira_loop_tree_node_t loop_node ATTRIBUTE_UNUSED
,
1678 vec
<ira_loop_tree_node_t
> loop_preorder
)
1680 vec
<ira_loop_tree_node_t
> topsort_nodes
= vNULL
;
1681 unsigned int n_loop_preorder
;
1683 n_loop_preorder
= loop_preorder
.length ();
1684 if (n_loop_preorder
!= 0)
1686 ira_loop_tree_node_t subloop_node
;
1688 auto_vec
<ira_loop_tree_node_t
> dfs_stack
;
1690 /* This is a bit of strange abuse of the BB_VISITED flag: We use
1691 the flag to mark blocks we still have to visit to add them to
1692 our post-order. Define an alias to avoid confusion. */
1693 #define BB_TO_VISIT BB_VISITED
1695 FOR_EACH_VEC_ELT (loop_preorder
, i
, subloop_node
)
1697 gcc_checking_assert (! (subloop_node
->bb
->flags
& BB_TO_VISIT
));
1698 subloop_node
->bb
->flags
|= BB_TO_VISIT
;
1701 topsort_nodes
.create (n_loop_preorder
);
1702 dfs_stack
.create (n_loop_preorder
);
1704 FOR_EACH_VEC_ELT_REVERSE (loop_preorder
, i
, subloop_node
)
1706 if (! (subloop_node
->bb
->flags
& BB_TO_VISIT
))
1709 subloop_node
->bb
->flags
&= ~BB_TO_VISIT
;
1710 dfs_stack
.quick_push (subloop_node
);
1711 while (! dfs_stack
.is_empty ())
1716 ira_loop_tree_node_t n
= dfs_stack
.last ();
1717 FOR_EACH_EDGE (e
, ei
, n
->bb
->preds
)
1719 ira_loop_tree_node_t pred_node
;
1720 basic_block pred_bb
= e
->src
;
1722 if (e
->src
== ENTRY_BLOCK_PTR_FOR_FN (cfun
))
1725 pred_node
= IRA_BB_NODE_BY_INDEX (pred_bb
->index
);
1727 && (pred_node
->bb
->flags
& BB_TO_VISIT
))
1729 pred_node
->bb
->flags
&= ~BB_TO_VISIT
;
1730 dfs_stack
.quick_push (pred_node
);
1733 if (n
== dfs_stack
.last ())
1736 topsort_nodes
.quick_push (n
);
1744 gcc_assert (topsort_nodes
.length () == n_loop_preorder
);
1745 return topsort_nodes
;
1748 /* The current loop tree node and its regno allocno map. */
1749 ira_loop_tree_node_t ira_curr_loop_tree_node
;
1750 ira_allocno_t
*ira_curr_regno_allocno_map
;
1752 /* This recursive function traverses loop tree with root LOOP_NODE
1753 calling non-null functions PREORDER_FUNC and POSTORDER_FUNC
1754 correspondingly in preorder and postorder. The function sets up
1755 IRA_CURR_LOOP_TREE_NODE and IRA_CURR_REGNO_ALLOCNO_MAP. If BB_P,
1756 basic block nodes of LOOP_NODE is also processed (before its
1759 If BB_P is set and POSTORDER_FUNC is given, the basic blocks in
1760 the loop are passed in the *reverse* post-order of the *reverse*
1761 CFG. This is only used by ira_create_allocno_live_ranges, which
1762 wants to visit basic blocks in this order to minimize the number
1763 of elements per live range chain.
1764 Note that the loop tree nodes are still visited in the normal,
1765 forward post-order of the loop tree. */
1768 ira_traverse_loop_tree (bool bb_p
, ira_loop_tree_node_t loop_node
,
1769 void (*preorder_func
) (ira_loop_tree_node_t
),
1770 void (*postorder_func
) (ira_loop_tree_node_t
))
1772 ira_loop_tree_node_t subloop_node
;
1774 ira_assert (loop_node
->bb
== NULL
);
1775 ira_curr_loop_tree_node
= loop_node
;
1776 ira_curr_regno_allocno_map
= ira_curr_loop_tree_node
->regno_allocno_map
;
1778 if (preorder_func
!= NULL
)
1779 (*preorder_func
) (loop_node
);
1783 auto_vec
<ira_loop_tree_node_t
> loop_preorder
;
1786 /* Add all nodes to the set of nodes to visit. The IRA loop tree
1787 is set up such that nodes in the loop body appear in a pre-order
1788 of their place in the CFG. */
1789 for (subloop_node
= loop_node
->children
;
1790 subloop_node
!= NULL
;
1791 subloop_node
= subloop_node
->next
)
1792 if (subloop_node
->bb
!= NULL
)
1793 loop_preorder
.safe_push (subloop_node
);
1795 if (preorder_func
!= NULL
)
1796 FOR_EACH_VEC_ELT (loop_preorder
, i
, subloop_node
)
1797 (*preorder_func
) (subloop_node
);
1799 if (postorder_func
!= NULL
)
1801 vec
<ira_loop_tree_node_t
> loop_rev_postorder
=
1802 ira_loop_tree_body_rev_postorder (loop_node
, loop_preorder
);
1803 FOR_EACH_VEC_ELT_REVERSE (loop_rev_postorder
, i
, subloop_node
)
1804 (*postorder_func
) (subloop_node
);
1805 loop_rev_postorder
.release ();
1809 for (subloop_node
= loop_node
->subloops
;
1810 subloop_node
!= NULL
;
1811 subloop_node
= subloop_node
->subloop_next
)
1813 ira_assert (subloop_node
->bb
== NULL
);
1814 ira_traverse_loop_tree (bb_p
, subloop_node
,
1815 preorder_func
, postorder_func
);
1818 ira_curr_loop_tree_node
= loop_node
;
1819 ira_curr_regno_allocno_map
= ira_curr_loop_tree_node
->regno_allocno_map
;
1821 if (postorder_func
!= NULL
)
1822 (*postorder_func
) (loop_node
);
1827 /* The basic block currently being processed. */
1828 static basic_block curr_bb
;
1830 /* This recursive function creates allocnos corresponding to
1831 pseudo-registers containing in X. True OUTPUT_P means that X is
1832 an lvalue. PARENT corresponds to the parent expression of X. */
1834 create_insn_allocnos (rtx x
, rtx outer
, bool output_p
)
1838 enum rtx_code code
= GET_CODE (x
);
1844 if ((regno
= REGNO (x
)) >= FIRST_PSEUDO_REGISTER
)
1848 if ((a
= ira_curr_regno_allocno_map
[regno
]) == NULL
)
1850 a
= ira_create_allocno (regno
, false, ira_curr_loop_tree_node
);
1851 if (outer
!= NULL
&& GET_CODE (outer
) == SUBREG
)
1853 machine_mode wmode
= GET_MODE (outer
);
1854 if (partial_subreg_p (ALLOCNO_WMODE (a
), wmode
))
1855 ALLOCNO_WMODE (a
) = wmode
;
1859 ALLOCNO_NREFS (a
)++;
1860 ALLOCNO_FREQ (a
) += REG_FREQ_FROM_BB (curr_bb
);
1862 bitmap_set_bit (ira_curr_loop_tree_node
->modified_regnos
, regno
);
1866 else if (code
== SET
)
1868 create_insn_allocnos (SET_DEST (x
), NULL
, true);
1869 create_insn_allocnos (SET_SRC (x
), NULL
, false);
1872 else if (code
== CLOBBER
)
1874 create_insn_allocnos (XEXP (x
, 0), NULL
, true);
1877 else if (code
== MEM
)
1879 create_insn_allocnos (XEXP (x
, 0), NULL
, false);
1882 else if (code
== PRE_DEC
|| code
== POST_DEC
|| code
== PRE_INC
||
1883 code
== POST_INC
|| code
== POST_MODIFY
|| code
== PRE_MODIFY
)
1885 create_insn_allocnos (XEXP (x
, 0), NULL
, true);
1886 create_insn_allocnos (XEXP (x
, 0), NULL
, false);
1890 fmt
= GET_RTX_FORMAT (code
);
1891 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1894 create_insn_allocnos (XEXP (x
, i
), x
, output_p
);
1895 else if (fmt
[i
] == 'E')
1896 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
1897 create_insn_allocnos (XVECEXP (x
, i
, j
), x
, output_p
);
1901 /* Create allocnos corresponding to pseudo-registers living in the
1902 basic block represented by the corresponding loop tree node
1905 create_bb_allocnos (ira_loop_tree_node_t bb_node
)
1912 curr_bb
= bb
= bb_node
->bb
;
1913 ira_assert (bb
!= NULL
);
1914 FOR_BB_INSNS_REVERSE (bb
, insn
)
1915 if (NONDEBUG_INSN_P (insn
))
1916 create_insn_allocnos (PATTERN (insn
), NULL
, false);
1917 /* It might be a allocno living through from one subloop to
1919 EXECUTE_IF_SET_IN_REG_SET (df_get_live_in (bb
), FIRST_PSEUDO_REGISTER
, i
, bi
)
1920 if (ira_curr_regno_allocno_map
[i
] == NULL
)
1921 ira_create_allocno (i
, false, ira_curr_loop_tree_node
);
1924 /* Create allocnos corresponding to pseudo-registers living on edge E
1925 (a loop entry or exit). Also mark the allocnos as living on the
1928 create_loop_allocnos (edge e
)
1931 bitmap live_in_regs
, border_allocnos
;
1933 ira_loop_tree_node_t parent
;
1935 live_in_regs
= df_get_live_in (e
->dest
);
1936 border_allocnos
= ira_curr_loop_tree_node
->border_allocnos
;
1937 EXECUTE_IF_SET_IN_REG_SET (df_get_live_out (e
->src
),
1938 FIRST_PSEUDO_REGISTER
, i
, bi
)
1939 if (bitmap_bit_p (live_in_regs
, i
))
1941 if (ira_curr_regno_allocno_map
[i
] == NULL
)
1943 /* The order of creations is important for right
1944 ira_regno_allocno_map. */
1945 if ((parent
= ira_curr_loop_tree_node
->parent
) != NULL
1946 && parent
->regno_allocno_map
[i
] == NULL
)
1947 ira_create_allocno (i
, false, parent
);
1948 ira_create_allocno (i
, false, ira_curr_loop_tree_node
);
1950 bitmap_set_bit (border_allocnos
,
1951 ALLOCNO_NUM (ira_curr_regno_allocno_map
[i
]));
1955 /* Create allocnos corresponding to pseudo-registers living in loop
1956 represented by the corresponding loop tree node LOOP_NODE. This
1957 function is called by ira_traverse_loop_tree. */
1959 create_loop_tree_node_allocnos (ira_loop_tree_node_t loop_node
)
1961 if (loop_node
->bb
!= NULL
)
1962 create_bb_allocnos (loop_node
);
1963 else if (loop_node
!= ira_loop_tree_root
)
1970 ira_assert (current_loops
!= NULL
);
1971 FOR_EACH_EDGE (e
, ei
, loop_node
->loop
->header
->preds
)
1972 if (e
->src
!= loop_node
->loop
->latch
)
1973 create_loop_allocnos (e
);
1975 edges
= get_loop_exit_edges (loop_node
->loop
);
1976 FOR_EACH_VEC_ELT (edges
, i
, e
)
1977 create_loop_allocnos (e
);
1982 /* Propagate information about allocnos modified inside the loop given
1983 by its LOOP_TREE_NODE to its parent. */
1985 propagate_modified_regnos (ira_loop_tree_node_t loop_tree_node
)
1987 if (loop_tree_node
== ira_loop_tree_root
)
1989 ira_assert (loop_tree_node
->bb
== NULL
);
1990 bitmap_ior_into (loop_tree_node
->parent
->modified_regnos
,
1991 loop_tree_node
->modified_regnos
);
1994 /* Propagate new info about allocno A (see comments about accumulated
1995 info in allocno definition) to the corresponding allocno on upper
1996 loop tree level. So allocnos on upper levels accumulate
1997 information about the corresponding allocnos in nested regions.
1998 The new info means allocno info finally calculated in this
2001 propagate_allocno_info (void)
2004 ira_allocno_t a
, parent_a
;
2005 ira_loop_tree_node_t parent
;
2006 enum reg_class aclass
;
2008 if (flag_ira_region
!= IRA_REGION_ALL
2009 && flag_ira_region
!= IRA_REGION_MIXED
)
2011 for (i
= max_reg_num () - 1; i
>= FIRST_PSEUDO_REGISTER
; i
--)
2012 for (a
= ira_regno_allocno_map
[i
];
2014 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
2015 if ((parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
) != NULL
2016 && (parent_a
= parent
->regno_allocno_map
[i
]) != NULL
2017 /* There are no caps yet at this point. So use
2018 border_allocnos to find allocnos for the propagation. */
2019 && bitmap_bit_p (ALLOCNO_LOOP_TREE_NODE (a
)->border_allocnos
,
2022 if (! ALLOCNO_BAD_SPILL_P (a
))
2023 ALLOCNO_BAD_SPILL_P (parent_a
) = false;
2024 ALLOCNO_NREFS (parent_a
) += ALLOCNO_NREFS (a
);
2025 ALLOCNO_FREQ (parent_a
) += ALLOCNO_FREQ (a
);
2026 ALLOCNO_CALL_FREQ (parent_a
) += ALLOCNO_CALL_FREQ (a
);
2027 merge_hard_reg_conflicts (a
, parent_a
, true);
2028 ALLOCNO_CALLS_CROSSED_NUM (parent_a
)
2029 += ALLOCNO_CALLS_CROSSED_NUM (a
);
2030 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a
)
2031 += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
);
2032 ALLOCNO_CROSSED_CALLS_ABIS (parent_a
)
2033 |= ALLOCNO_CROSSED_CALLS_ABIS (a
);
2034 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (parent_a
)
2035 |= ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
);
2036 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a
)
2037 += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
);
2038 aclass
= ALLOCNO_CLASS (a
);
2039 ira_assert (aclass
== ALLOCNO_CLASS (parent_a
));
2040 ira_allocate_and_accumulate_costs
2041 (&ALLOCNO_HARD_REG_COSTS (parent_a
), aclass
,
2042 ALLOCNO_HARD_REG_COSTS (a
));
2043 ira_allocate_and_accumulate_costs
2044 (&ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a
),
2046 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
));
2047 ALLOCNO_CLASS_COST (parent_a
)
2048 += ALLOCNO_CLASS_COST (a
);
2049 ALLOCNO_MEMORY_COST (parent_a
) += ALLOCNO_MEMORY_COST (a
);
2053 /* Create allocnos corresponding to pseudo-registers in the current
2054 function. Traverse the loop tree for this. */
2056 create_allocnos (void)
2058 /* We need to process BB first to correctly link allocnos by member
2059 next_regno_allocno. */
2060 ira_traverse_loop_tree (true, ira_loop_tree_root
,
2061 create_loop_tree_node_allocnos
, NULL
);
2063 ira_traverse_loop_tree (false, ira_loop_tree_root
, NULL
,
2064 propagate_modified_regnos
);
2069 /* The page contains function to remove some regions from a separate
2070 register allocation. We remove regions whose separate allocation
2071 will hardly improve the result. As a result we speed up regional
2072 register allocation. */
2074 /* The function changes the object in range list given by R to OBJ. */
2076 change_object_in_range_list (live_range_t r
, ira_object_t obj
)
2078 for (; r
!= NULL
; r
= r
->next
)
2082 /* Move all live ranges associated with allocno FROM to allocno TO. */
2084 move_allocno_live_ranges (ira_allocno_t from
, ira_allocno_t to
)
2087 int n
= ALLOCNO_NUM_OBJECTS (from
);
2089 gcc_assert (n
== ALLOCNO_NUM_OBJECTS (to
));
2091 for (i
= 0; i
< n
; i
++)
2093 ira_object_t from_obj
= ALLOCNO_OBJECT (from
, i
);
2094 ira_object_t to_obj
= ALLOCNO_OBJECT (to
, i
);
2095 live_range_t lr
= OBJECT_LIVE_RANGES (from_obj
);
2097 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
2099 fprintf (ira_dump_file
,
2100 " Moving ranges of a%dr%d to a%dr%d: ",
2101 ALLOCNO_NUM (from
), ALLOCNO_REGNO (from
),
2102 ALLOCNO_NUM (to
), ALLOCNO_REGNO (to
));
2103 ira_print_live_range_list (ira_dump_file
, lr
);
2105 change_object_in_range_list (lr
, to_obj
);
2106 OBJECT_LIVE_RANGES (to_obj
)
2107 = ira_merge_live_ranges (lr
, OBJECT_LIVE_RANGES (to_obj
));
2108 OBJECT_LIVE_RANGES (from_obj
) = NULL
;
2113 copy_allocno_live_ranges (ira_allocno_t from
, ira_allocno_t to
)
2116 int n
= ALLOCNO_NUM_OBJECTS (from
);
2118 gcc_assert (n
== ALLOCNO_NUM_OBJECTS (to
));
2120 for (i
= 0; i
< n
; i
++)
2122 ira_object_t from_obj
= ALLOCNO_OBJECT (from
, i
);
2123 ira_object_t to_obj
= ALLOCNO_OBJECT (to
, i
);
2124 live_range_t lr
= OBJECT_LIVE_RANGES (from_obj
);
2126 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
2128 fprintf (ira_dump_file
, " Copying ranges of a%dr%d to a%dr%d: ",
2129 ALLOCNO_NUM (from
), ALLOCNO_REGNO (from
),
2130 ALLOCNO_NUM (to
), ALLOCNO_REGNO (to
));
2131 ira_print_live_range_list (ira_dump_file
, lr
);
2133 lr
= ira_copy_live_range_list (lr
);
2134 change_object_in_range_list (lr
, to_obj
);
2135 OBJECT_LIVE_RANGES (to_obj
)
2136 = ira_merge_live_ranges (lr
, OBJECT_LIVE_RANGES (to_obj
));
2140 /* Return TRUE if NODE represents a loop with low register
2143 low_pressure_loop_node_p (ira_loop_tree_node_t node
)
2146 enum reg_class pclass
;
2148 if (node
->bb
!= NULL
)
2151 for (i
= 0; i
< ira_pressure_classes_num
; i
++)
2153 pclass
= ira_pressure_classes
[i
];
2154 if (node
->reg_pressure
[pclass
] > ira_class_hard_regs_num
[pclass
]
2155 && ira_class_hard_regs_num
[pclass
] > 1)
2162 /* Return TRUE if LOOP has a complex enter or exit edge. We don't
2163 form a region from such loop if the target use stack register
2164 because reg-stack.c cannot deal with such edges. */
2166 loop_with_complex_edge_p (class loop
*loop
)
2174 FOR_EACH_EDGE (e
, ei
, loop
->header
->preds
)
2175 if (e
->flags
& EDGE_EH
)
2177 edges
= get_loop_exit_edges (loop
);
2179 FOR_EACH_VEC_ELT (edges
, i
, e
)
2180 if (e
->flags
& EDGE_COMPLEX
)
2190 /* Sort loops for marking them for removal. We put already marked
2191 loops first, then less frequent loops next, and then outer loops
2194 loop_compare_func (const void *v1p
, const void *v2p
)
2197 ira_loop_tree_node_t l1
= *(const ira_loop_tree_node_t
*) v1p
;
2198 ira_loop_tree_node_t l2
= *(const ira_loop_tree_node_t
*) v2p
;
2200 ira_assert (l1
->parent
!= NULL
&& l2
->parent
!= NULL
);
2201 if (l1
->to_remove_p
&& ! l2
->to_remove_p
)
2203 if (! l1
->to_remove_p
&& l2
->to_remove_p
)
2205 if ((diff
= l1
->loop
->header
->count
.to_frequency (cfun
)
2206 - l2
->loop
->header
->count
.to_frequency (cfun
)) != 0)
2208 if ((diff
= (int) loop_depth (l1
->loop
) - (int) loop_depth (l2
->loop
)) != 0)
2210 /* Make sorting stable. */
2211 return l1
->loop_num
- l2
->loop_num
;
2214 /* Mark loops which should be removed from regional allocation. We
2215 remove a loop with low register pressure inside another loop with
2216 register pressure. In this case a separate allocation of the loop
2217 hardly helps (for irregular register file architecture it could
2218 help by choosing a better hard register in the loop but we prefer
2219 faster allocation even in this case). We also remove cheap loops
2220 if there are more than IRA_MAX_LOOPS_NUM of them. Loop with EH
2221 exit or enter edges are removed too because the allocation might
2222 require put pseudo moves on the EH edges (we could still do this
2223 for pseudos with caller saved hard registers in some cases but it
2224 is impossible to say here or during top-down allocation pass what
2225 hard register the pseudos get finally). */
2227 mark_loops_for_removal (void)
2230 ira_loop_tree_node_t
*sorted_loops
;
2233 ira_assert (current_loops
!= NULL
);
2235 = (ira_loop_tree_node_t
*) ira_allocate (sizeof (ira_loop_tree_node_t
)
2236 * number_of_loops (cfun
));
2237 for (n
= i
= 0; vec_safe_iterate (get_loops (cfun
), i
, &loop
); i
++)
2238 if (ira_loop_nodes
[i
].regno_allocno_map
!= NULL
)
2240 if (ira_loop_nodes
[i
].parent
== NULL
)
2242 /* Don't remove the root. */
2243 ira_loop_nodes
[i
].to_remove_p
= false;
2246 sorted_loops
[n
++] = &ira_loop_nodes
[i
];
2247 ira_loop_nodes
[i
].to_remove_p
2248 = ((low_pressure_loop_node_p (ira_loop_nodes
[i
].parent
)
2249 && low_pressure_loop_node_p (&ira_loop_nodes
[i
]))
2251 || loop_with_complex_edge_p (ira_loop_nodes
[i
].loop
)
2255 qsort (sorted_loops
, n
, sizeof (ira_loop_tree_node_t
), loop_compare_func
);
2256 for (i
= 0; i
< n
- IRA_MAX_LOOPS_NUM
; i
++)
2258 sorted_loops
[i
]->to_remove_p
= true;
2259 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
2262 " Mark loop %d (header %d, freq %d, depth %d) for removal (%s)\n",
2263 sorted_loops
[i
]->loop_num
, sorted_loops
[i
]->loop
->header
->index
,
2264 sorted_loops
[i
]->loop
->header
->count
.to_frequency (cfun
),
2265 loop_depth (sorted_loops
[i
]->loop
),
2266 low_pressure_loop_node_p (sorted_loops
[i
]->parent
)
2267 && low_pressure_loop_node_p (sorted_loops
[i
])
2268 ? "low pressure" : "cheap loop");
2270 ira_free (sorted_loops
);
2273 /* Mark all loops but root for removing. */
2275 mark_all_loops_for_removal (void)
2280 ira_assert (current_loops
!= NULL
);
2281 FOR_EACH_VEC_SAFE_ELT (get_loops (cfun
), i
, loop
)
2282 if (ira_loop_nodes
[i
].regno_allocno_map
!= NULL
)
2284 if (ira_loop_nodes
[i
].parent
== NULL
)
2286 /* Don't remove the root. */
2287 ira_loop_nodes
[i
].to_remove_p
= false;
2290 ira_loop_nodes
[i
].to_remove_p
= true;
2291 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
2294 " Mark loop %d (header %d, freq %d, depth %d) for removal\n",
2295 ira_loop_nodes
[i
].loop_num
,
2296 ira_loop_nodes
[i
].loop
->header
->index
,
2297 ira_loop_nodes
[i
].loop
->header
->count
.to_frequency (cfun
),
2298 loop_depth (ira_loop_nodes
[i
].loop
));
2302 /* Definition of vector of loop tree nodes. */
2304 /* Vec containing references to all removed loop tree nodes. */
2305 static vec
<ira_loop_tree_node_t
> removed_loop_vec
;
2307 /* Vec containing references to all children of loop tree nodes. */
2308 static vec
<ira_loop_tree_node_t
> children_vec
;
2310 /* Remove subregions of NODE if their separate allocation will not
2311 improve the result. */
2313 remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_node_t node
)
2317 ira_loop_tree_node_t subnode
;
2319 remove_p
= node
->to_remove_p
;
2321 children_vec
.safe_push (node
);
2322 start
= children_vec
.length ();
2323 for (subnode
= node
->children
; subnode
!= NULL
; subnode
= subnode
->next
)
2324 if (subnode
->bb
== NULL
)
2325 remove_uneccesary_loop_nodes_from_loop_tree (subnode
);
2327 children_vec
.safe_push (subnode
);
2328 node
->children
= node
->subloops
= NULL
;
2331 removed_loop_vec
.safe_push (node
);
2334 while (children_vec
.length () > start
)
2336 subnode
= children_vec
.pop ();
2337 subnode
->parent
= node
;
2338 subnode
->next
= node
->children
;
2339 node
->children
= subnode
;
2340 if (subnode
->bb
== NULL
)
2342 subnode
->subloop_next
= node
->subloops
;
2343 node
->subloops
= subnode
;
2348 /* Return TRUE if NODE is inside PARENT. */
2350 loop_is_inside_p (ira_loop_tree_node_t node
, ira_loop_tree_node_t parent
)
2352 for (node
= node
->parent
; node
!= NULL
; node
= node
->parent
)
2358 /* Sort allocnos according to their order in regno allocno list. */
2360 regno_allocno_order_compare_func (const void *v1p
, const void *v2p
)
2362 ira_allocno_t a1
= *(const ira_allocno_t
*) v1p
;
2363 ira_allocno_t a2
= *(const ira_allocno_t
*) v2p
;
2364 ira_loop_tree_node_t n1
= ALLOCNO_LOOP_TREE_NODE (a1
);
2365 ira_loop_tree_node_t n2
= ALLOCNO_LOOP_TREE_NODE (a2
);
2367 if (loop_is_inside_p (n1
, n2
))
2369 else if (loop_is_inside_p (n2
, n1
))
2371 /* If allocnos are equally good, sort by allocno numbers, so that
2372 the results of qsort leave nothing to chance. We put allocnos
2373 with higher number first in the list because it is the original
2374 order for allocnos from loops on the same levels. */
2375 return ALLOCNO_NUM (a2
) - ALLOCNO_NUM (a1
);
2378 /* This array is used to sort allocnos to restore allocno order in
2379 the regno allocno list. */
2380 static ira_allocno_t
*regno_allocnos
;
2382 /* Restore allocno order for REGNO in the regno allocno list. */
2384 ira_rebuild_regno_allocno_list (int regno
)
2389 for (n
= 0, a
= ira_regno_allocno_map
[regno
];
2391 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
2392 regno_allocnos
[n
++] = a
;
2394 qsort (regno_allocnos
, n
, sizeof (ira_allocno_t
),
2395 regno_allocno_order_compare_func
);
2396 for (i
= 1; i
< n
; i
++)
2397 ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos
[i
- 1]) = regno_allocnos
[i
];
2398 ALLOCNO_NEXT_REGNO_ALLOCNO (regno_allocnos
[n
- 1]) = NULL
;
2399 ira_regno_allocno_map
[regno
] = regno_allocnos
[0];
2400 if (internal_flag_ira_verbose
> 1 && ira_dump_file
!= NULL
)
2401 fprintf (ira_dump_file
, " Rebuilding regno allocno list for %d\n", regno
);
2404 /* Propagate info from allocno FROM_A to allocno A. */
2406 propagate_some_info_from_allocno (ira_allocno_t a
, ira_allocno_t from_a
)
2408 enum reg_class aclass
;
2410 merge_hard_reg_conflicts (from_a
, a
, false);
2411 ALLOCNO_NREFS (a
) += ALLOCNO_NREFS (from_a
);
2412 ALLOCNO_FREQ (a
) += ALLOCNO_FREQ (from_a
);
2413 ALLOCNO_CALL_FREQ (a
) += ALLOCNO_CALL_FREQ (from_a
);
2414 ALLOCNO_CALLS_CROSSED_NUM (a
) += ALLOCNO_CALLS_CROSSED_NUM (from_a
);
2415 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
)
2416 += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (from_a
);
2417 ALLOCNO_CROSSED_CALLS_ABIS (a
) |= ALLOCNO_CROSSED_CALLS_ABIS (from_a
);
2418 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
)
2419 |= ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (from_a
);
2421 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
)
2422 += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (from_a
);
2423 if (! ALLOCNO_BAD_SPILL_P (from_a
))
2424 ALLOCNO_BAD_SPILL_P (a
) = false;
2425 aclass
= ALLOCNO_CLASS (from_a
);
2426 ira_assert (aclass
== ALLOCNO_CLASS (a
));
2427 ira_allocate_and_accumulate_costs (&ALLOCNO_HARD_REG_COSTS (a
), aclass
,
2428 ALLOCNO_HARD_REG_COSTS (from_a
));
2429 ira_allocate_and_accumulate_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a
),
2431 ALLOCNO_CONFLICT_HARD_REG_COSTS (from_a
));
2432 ALLOCNO_CLASS_COST (a
) += ALLOCNO_CLASS_COST (from_a
);
2433 ALLOCNO_MEMORY_COST (a
) += ALLOCNO_MEMORY_COST (from_a
);
2436 /* Remove allocnos from loops removed from the allocation
2439 remove_unnecessary_allocnos (void)
2442 bool merged_p
, rebuild_p
;
2443 ira_allocno_t a
, prev_a
, next_a
, parent_a
;
2444 ira_loop_tree_node_t a_node
, parent
;
2447 regno_allocnos
= NULL
;
2448 for (regno
= max_reg_num () - 1; regno
>= FIRST_PSEUDO_REGISTER
; regno
--)
2451 for (prev_a
= NULL
, a
= ira_regno_allocno_map
[regno
];
2455 next_a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
);
2456 a_node
= ALLOCNO_LOOP_TREE_NODE (a
);
2457 if (! a_node
->to_remove_p
)
2461 for (parent
= a_node
->parent
;
2462 (parent_a
= parent
->regno_allocno_map
[regno
]) == NULL
2463 && parent
->to_remove_p
;
2464 parent
= parent
->parent
)
2466 if (parent_a
== NULL
)
2468 /* There are no allocnos with the same regno in
2469 upper region -- just move the allocno to the
2472 ALLOCNO_LOOP_TREE_NODE (a
) = parent
;
2473 parent
->regno_allocno_map
[regno
] = a
;
2474 bitmap_set_bit (parent
->all_allocnos
, ALLOCNO_NUM (a
));
2479 /* Remove the allocno and update info of allocno in
2480 the upper region. */
2482 ira_regno_allocno_map
[regno
] = next_a
;
2484 ALLOCNO_NEXT_REGNO_ALLOCNO (prev_a
) = next_a
;
2485 move_allocno_live_ranges (a
, parent_a
);
2487 propagate_some_info_from_allocno (parent_a
, a
);
2488 /* Remove it from the corresponding regno allocno
2489 map to avoid info propagation of subsequent
2490 allocno into this already removed allocno. */
2491 a_node
->regno_allocno_map
[regno
] = NULL
;
2492 ira_remove_allocno_prefs (a
);
2498 /* We need to restore the order in regno allocno list. */
2500 if (regno_allocnos
== NULL
)
2502 = (ira_allocno_t
*) ira_allocate (sizeof (ira_allocno_t
)
2503 * ira_allocnos_num
);
2504 ira_rebuild_regno_allocno_list (regno
);
2508 ira_rebuild_start_finish_chains ();
2509 if (regno_allocnos
!= NULL
)
2510 ira_free (regno_allocnos
);
2513 /* Remove allocnos from all loops but the root. */
2515 remove_low_level_allocnos (void)
2518 bool merged_p
, propagate_p
;
2519 ira_allocno_t a
, top_a
;
2520 ira_loop_tree_node_t a_node
, parent
;
2521 ira_allocno_iterator ai
;
2524 FOR_EACH_ALLOCNO (a
, ai
)
2526 a_node
= ALLOCNO_LOOP_TREE_NODE (a
);
2527 if (a_node
== ira_loop_tree_root
|| ALLOCNO_CAP_MEMBER (a
) != NULL
)
2529 regno
= ALLOCNO_REGNO (a
);
2530 if ((top_a
= ira_loop_tree_root
->regno_allocno_map
[regno
]) == NULL
)
2532 ALLOCNO_LOOP_TREE_NODE (a
) = ira_loop_tree_root
;
2533 ira_loop_tree_root
->regno_allocno_map
[regno
] = a
;
2536 propagate_p
= a_node
->parent
->regno_allocno_map
[regno
] == NULL
;
2537 /* Remove the allocno and update info of allocno in the upper
2539 move_allocno_live_ranges (a
, top_a
);
2542 propagate_some_info_from_allocno (top_a
, a
);
2544 FOR_EACH_ALLOCNO (a
, ai
)
2546 a_node
= ALLOCNO_LOOP_TREE_NODE (a
);
2547 if (a_node
== ira_loop_tree_root
)
2549 parent
= a_node
->parent
;
2550 regno
= ALLOCNO_REGNO (a
);
2551 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
2552 ira_assert (ALLOCNO_CAP (a
) != NULL
);
2553 else if (ALLOCNO_CAP (a
) == NULL
)
2554 ira_assert (parent
->regno_allocno_map
[regno
] != NULL
);
2556 FOR_EACH_ALLOCNO (a
, ai
)
2558 regno
= ALLOCNO_REGNO (a
);
2559 if (ira_loop_tree_root
->regno_allocno_map
[regno
] == a
)
2562 ira_allocno_object_iterator oi
;
2564 ira_regno_allocno_map
[regno
] = a
;
2565 ALLOCNO_NEXT_REGNO_ALLOCNO (a
) = NULL
;
2566 ALLOCNO_CAP_MEMBER (a
) = NULL
;
2567 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
2568 OBJECT_CONFLICT_HARD_REGS (obj
)
2569 = OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
);
2571 if (ALLOCNO_TOTAL_NO_STACK_REG_P (a
))
2572 ALLOCNO_NO_STACK_REG_P (a
) = true;
2577 ira_remove_allocno_prefs (a
);
2582 ira_rebuild_start_finish_chains ();
2585 /* Remove loops from consideration. We remove all loops except for
2586 root if ALL_P or loops for which a separate allocation will not
2587 improve the result. We have to do this after allocno creation and
2588 their costs and allocno class evaluation because only after that
2589 the register pressure can be known and is calculated. */
2591 remove_unnecessary_regions (bool all_p
)
2593 if (current_loops
== NULL
)
2596 mark_all_loops_for_removal ();
2598 mark_loops_for_removal ();
2599 children_vec
.create (last_basic_block_for_fn (cfun
)
2600 + number_of_loops (cfun
));
2601 removed_loop_vec
.create (last_basic_block_for_fn (cfun
)
2602 + number_of_loops (cfun
));
2603 remove_uneccesary_loop_nodes_from_loop_tree (ira_loop_tree_root
);
2604 children_vec
.release ();
2606 remove_low_level_allocnos ();
2608 remove_unnecessary_allocnos ();
2609 while (removed_loop_vec
.length () > 0)
2610 finish_loop_tree_node (removed_loop_vec
.pop ());
2611 removed_loop_vec
.release ();
2616 /* At this point true value of allocno attribute bad_spill_p means
2617 that there is an insn where allocno occurs and where the allocno
2618 cannot be used as memory. The function updates the attribute, now
2619 it can be true only for allocnos which cannot be used as memory in
2620 an insn and in whose live ranges there is other allocno deaths.
2621 Spilling allocnos with true value will not improve the code because
2622 it will not make other allocnos colorable and additional reloads
2623 for the corresponding pseudo will be generated in reload pass for
2624 each insn it occurs.
2626 This is a trick mentioned in one classic article of Chaitin etc
2627 which is frequently omitted in other implementations of RA based on
2630 update_bad_spill_attribute (void)
2634 ira_allocno_iterator ai
;
2635 ira_allocno_object_iterator aoi
;
2638 enum reg_class aclass
;
2639 bitmap_head dead_points
[N_REG_CLASSES
];
2641 for (i
= 0; i
< ira_allocno_classes_num
; i
++)
2643 aclass
= ira_allocno_classes
[i
];
2644 bitmap_initialize (&dead_points
[aclass
], ®_obstack
);
2646 FOR_EACH_ALLOCNO (a
, ai
)
2648 aclass
= ALLOCNO_CLASS (a
);
2649 if (aclass
== NO_REGS
)
2651 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, aoi
)
2652 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
2653 bitmap_set_bit (&dead_points
[aclass
], r
->finish
);
2655 FOR_EACH_ALLOCNO (a
, ai
)
2657 aclass
= ALLOCNO_CLASS (a
);
2658 if (aclass
== NO_REGS
)
2660 if (! ALLOCNO_BAD_SPILL_P (a
))
2662 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, aoi
)
2664 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
2666 for (i
= r
->start
+ 1; i
< r
->finish
; i
++)
2667 if (bitmap_bit_p (&dead_points
[aclass
], i
))
2674 ALLOCNO_BAD_SPILL_P (a
) = false;
2679 for (i
= 0; i
< ira_allocno_classes_num
; i
++)
2681 aclass
= ira_allocno_classes
[i
];
2682 bitmap_clear (&dead_points
[aclass
]);
2688 /* Set up minimal and maximal live range points for allocnos. */
2690 setup_min_max_allocno_live_range_point (void)
2693 ira_allocno_t a
, parent_a
, cap
;
2694 ira_allocno_iterator ai
;
2695 #ifdef ENABLE_IRA_CHECKING
2696 ira_object_iterator oi
;
2700 ira_loop_tree_node_t parent
;
2702 FOR_EACH_ALLOCNO (a
, ai
)
2704 int n
= ALLOCNO_NUM_OBJECTS (a
);
2706 for (i
= 0; i
< n
; i
++)
2708 ira_object_t obj
= ALLOCNO_OBJECT (a
, i
);
2709 r
= OBJECT_LIVE_RANGES (obj
);
2712 OBJECT_MAX (obj
) = r
->finish
;
2713 for (; r
->next
!= NULL
; r
= r
->next
)
2715 OBJECT_MIN (obj
) = r
->start
;
2718 for (i
= max_reg_num () - 1; i
>= FIRST_PSEUDO_REGISTER
; i
--)
2719 for (a
= ira_regno_allocno_map
[i
];
2721 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
2724 int n
= ALLOCNO_NUM_OBJECTS (a
);
2726 for (j
= 0; j
< n
; j
++)
2728 ira_object_t obj
= ALLOCNO_OBJECT (a
, j
);
2729 ira_object_t parent_obj
;
2731 if (OBJECT_MAX (obj
) < 0)
2733 /* The object is not used and hence does not live. */
2734 ira_assert (OBJECT_LIVE_RANGES (obj
) == NULL
);
2735 OBJECT_MAX (obj
) = 0;
2736 OBJECT_MIN (obj
) = 1;
2739 ira_assert (ALLOCNO_CAP_MEMBER (a
) == NULL
);
2740 /* Accumulation of range info. */
2741 if (ALLOCNO_CAP (a
) != NULL
)
2743 for (cap
= ALLOCNO_CAP (a
); cap
!= NULL
; cap
= ALLOCNO_CAP (cap
))
2745 ira_object_t cap_obj
= ALLOCNO_OBJECT (cap
, j
);
2746 if (OBJECT_MAX (cap_obj
) < OBJECT_MAX (obj
))
2747 OBJECT_MAX (cap_obj
) = OBJECT_MAX (obj
);
2748 if (OBJECT_MIN (cap_obj
) > OBJECT_MIN (obj
))
2749 OBJECT_MIN (cap_obj
) = OBJECT_MIN (obj
);
2753 if ((parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
) == NULL
)
2755 parent_a
= parent
->regno_allocno_map
[i
];
2756 parent_obj
= ALLOCNO_OBJECT (parent_a
, j
);
2757 if (OBJECT_MAX (parent_obj
) < OBJECT_MAX (obj
))
2758 OBJECT_MAX (parent_obj
) = OBJECT_MAX (obj
);
2759 if (OBJECT_MIN (parent_obj
) > OBJECT_MIN (obj
))
2760 OBJECT_MIN (parent_obj
) = OBJECT_MIN (obj
);
2763 #ifdef ENABLE_IRA_CHECKING
2764 FOR_EACH_OBJECT (obj
, oi
)
2766 if ((OBJECT_MIN (obj
) >= 0 && OBJECT_MIN (obj
) <= ira_max_point
)
2767 && (OBJECT_MAX (obj
) >= 0 && OBJECT_MAX (obj
) <= ira_max_point
))
2774 /* Sort allocnos according to their live ranges. Allocnos with
2775 smaller allocno class are put first unless we use priority
2776 coloring. Allocnos with the same class are ordered according
2777 their start (min). Allocnos with the same start are ordered
2778 according their finish (max). */
2780 object_range_compare_func (const void *v1p
, const void *v2p
)
2783 ira_object_t obj1
= *(const ira_object_t
*) v1p
;
2784 ira_object_t obj2
= *(const ira_object_t
*) v2p
;
2785 ira_allocno_t a1
= OBJECT_ALLOCNO (obj1
);
2786 ira_allocno_t a2
= OBJECT_ALLOCNO (obj2
);
2788 if ((diff
= OBJECT_MIN (obj1
) - OBJECT_MIN (obj2
)) != 0)
2790 if ((diff
= OBJECT_MAX (obj1
) - OBJECT_MAX (obj2
)) != 0)
2792 return ALLOCNO_NUM (a1
) - ALLOCNO_NUM (a2
);
2795 /* Sort ira_object_id_map and set up conflict id of allocnos. */
2797 sort_conflict_id_map (void)
2801 ira_allocno_iterator ai
;
2804 FOR_EACH_ALLOCNO (a
, ai
)
2806 ira_allocno_object_iterator oi
;
2809 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
2810 ira_object_id_map
[num
++] = obj
;
2813 qsort (ira_object_id_map
, num
, sizeof (ira_object_t
),
2814 object_range_compare_func
);
2815 for (i
= 0; i
< num
; i
++)
2817 ira_object_t obj
= ira_object_id_map
[i
];
2819 gcc_assert (obj
!= NULL
);
2820 OBJECT_CONFLICT_ID (obj
) = i
;
2822 for (i
= num
; i
< ira_objects_num
; i
++)
2823 ira_object_id_map
[i
] = NULL
;
2826 /* Set up minimal and maximal conflict ids of allocnos with which
2827 given allocno can conflict. */
2829 setup_min_max_conflict_allocno_ids (void)
2832 int i
, j
, min
, max
, start
, finish
, first_not_finished
, filled_area_start
;
2833 int *live_range_min
, *last_lived
;
2834 int word0_min
, word0_max
;
2836 ira_allocno_iterator ai
;
2838 live_range_min
= (int *) ira_allocate (sizeof (int) * ira_objects_num
);
2840 first_not_finished
= -1;
2841 for (i
= 0; i
< ira_objects_num
; i
++)
2843 ira_object_t obj
= ira_object_id_map
[i
];
2848 a
= OBJECT_ALLOCNO (obj
);
2852 aclass
= ALLOCNO_CLASS (a
);
2854 first_not_finished
= i
;
2858 start
= OBJECT_MIN (obj
);
2859 /* If we skip an allocno, the allocno with smaller ids will
2860 be also skipped because of the secondary sorting the
2861 range finishes (see function
2862 object_range_compare_func). */
2863 while (first_not_finished
< i
2864 && start
> OBJECT_MAX (ira_object_id_map
2865 [first_not_finished
]))
2866 first_not_finished
++;
2867 min
= first_not_finished
;
2870 /* We could increase min further in this case but it is good
2873 live_range_min
[i
] = OBJECT_MIN (obj
);
2874 OBJECT_MIN (obj
) = min
;
2876 last_lived
= (int *) ira_allocate (sizeof (int) * ira_max_point
);
2878 filled_area_start
= -1;
2879 for (i
= ira_objects_num
- 1; i
>= 0; i
--)
2881 ira_object_t obj
= ira_object_id_map
[i
];
2886 a
= OBJECT_ALLOCNO (obj
);
2889 aclass
= ALLOCNO_CLASS (a
);
2890 for (j
= 0; j
< ira_max_point
; j
++)
2892 filled_area_start
= ira_max_point
;
2894 min
= live_range_min
[i
];
2895 finish
= OBJECT_MAX (obj
);
2896 max
= last_lived
[finish
];
2898 /* We could decrease max further in this case but it is good
2900 max
= OBJECT_CONFLICT_ID (obj
) - 1;
2901 OBJECT_MAX (obj
) = max
;
2902 /* In filling, we can go further A range finish to recognize
2903 intersection quickly because if the finish of subsequently
2904 processed allocno (it has smaller conflict id) range is
2905 further A range finish than they are definitely intersected
2906 (the reason for this is the allocnos with bigger conflict id
2907 have their range starts not smaller than allocnos with
2909 for (j
= min
; j
< filled_area_start
; j
++)
2911 filled_area_start
= min
;
2913 ira_free (last_lived
);
2914 ira_free (live_range_min
);
2916 /* For allocnos with more than one object, we may later record extra conflicts in
2917 subobject 0 that we cannot really know about here.
2918 For now, simply widen the min/max range of these subobjects. */
2920 word0_min
= INT_MAX
;
2921 word0_max
= INT_MIN
;
2923 FOR_EACH_ALLOCNO (a
, ai
)
2925 int n
= ALLOCNO_NUM_OBJECTS (a
);
2930 obj0
= ALLOCNO_OBJECT (a
, 0);
2931 if (OBJECT_CONFLICT_ID (obj0
) < word0_min
)
2932 word0_min
= OBJECT_CONFLICT_ID (obj0
);
2933 if (OBJECT_CONFLICT_ID (obj0
) > word0_max
)
2934 word0_max
= OBJECT_CONFLICT_ID (obj0
);
2936 FOR_EACH_ALLOCNO (a
, ai
)
2938 int n
= ALLOCNO_NUM_OBJECTS (a
);
2943 obj0
= ALLOCNO_OBJECT (a
, 0);
2944 if (OBJECT_MIN (obj0
) > word0_min
)
2945 OBJECT_MIN (obj0
) = word0_min
;
2946 if (OBJECT_MAX (obj0
) < word0_max
)
2947 OBJECT_MAX (obj0
) = word0_max
;
2957 ira_allocno_iterator ai
;
2958 ira_loop_tree_node_t loop_tree_node
;
2960 FOR_EACH_ALLOCNO (a
, ai
)
2962 if (ALLOCNO_LOOP_TREE_NODE (a
) == ira_loop_tree_root
)
2964 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
2965 create_cap_allocno (a
);
2966 else if (ALLOCNO_CAP (a
) == NULL
)
2968 loop_tree_node
= ALLOCNO_LOOP_TREE_NODE (a
);
2969 if (!bitmap_bit_p (loop_tree_node
->border_allocnos
, ALLOCNO_NUM (a
)))
2970 create_cap_allocno (a
);
2977 /* The page contains code transforming more one region internal
2978 representation (IR) to one region IR which is necessary for reload.
2979 This transformation is called IR flattening. We might just rebuild
2980 the IR for one region but we don't do it because it takes a lot of
2983 /* Map: regno -> allocnos which will finally represent the regno for
2984 IR with one region. */
2985 static ira_allocno_t
*regno_top_level_allocno_map
;
2987 /* Find the allocno that corresponds to A at a level one higher up in the
2988 loop tree. Returns NULL if A is a cap, or if it has no parent. */
2990 ira_parent_allocno (ira_allocno_t a
)
2992 ira_loop_tree_node_t parent
;
2994 if (ALLOCNO_CAP (a
) != NULL
)
2997 parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
;
3001 return parent
->regno_allocno_map
[ALLOCNO_REGNO (a
)];
3004 /* Find the allocno that corresponds to A at a level one higher up in the
3005 loop tree. If ALLOCNO_CAP is set for A, return that. */
3007 ira_parent_or_cap_allocno (ira_allocno_t a
)
3009 if (ALLOCNO_CAP (a
) != NULL
)
3010 return ALLOCNO_CAP (a
);
3012 return ira_parent_allocno (a
);
3015 /* Process all allocnos originated from pseudo REGNO and copy live
3016 ranges, hard reg conflicts, and allocno stack reg attributes from
3017 low level allocnos to final allocnos which are destinations of
3018 removed stores at a loop exit. Return true if we copied live
3021 copy_info_to_removed_store_destinations (int regno
)
3024 ira_allocno_t parent_a
= NULL
;
3025 ira_loop_tree_node_t parent
;
3029 for (a
= ira_regno_allocno_map
[regno
];
3031 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
3033 if (a
!= regno_top_level_allocno_map
[REGNO (allocno_emit_reg (a
))])
3034 /* This allocno will be removed. */
3037 /* Caps will be removed. */
3038 ira_assert (ALLOCNO_CAP_MEMBER (a
) == NULL
);
3039 for (parent
= ALLOCNO_LOOP_TREE_NODE (a
)->parent
;
3041 parent
= parent
->parent
)
3042 if ((parent_a
= parent
->regno_allocno_map
[regno
]) == NULL
3044 == regno_top_level_allocno_map
[REGNO
3045 (allocno_emit_reg (parent_a
))]
3046 && ALLOCNO_EMIT_DATA (parent_a
)->mem_optimized_dest_p
))
3048 if (parent
== NULL
|| parent_a
== NULL
)
3051 copy_allocno_live_ranges (a
, parent_a
);
3052 merge_hard_reg_conflicts (a
, parent_a
, true);
3054 ALLOCNO_CALL_FREQ (parent_a
) += ALLOCNO_CALL_FREQ (a
);
3055 ALLOCNO_CALLS_CROSSED_NUM (parent_a
)
3056 += ALLOCNO_CALLS_CROSSED_NUM (a
);
3057 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a
)
3058 += ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
);
3059 ALLOCNO_CROSSED_CALLS_ABIS (parent_a
)
3060 |= ALLOCNO_CROSSED_CALLS_ABIS (a
);
3061 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (parent_a
)
3062 |= ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS (a
);
3063 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a
)
3064 += ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
);
3070 /* Flatten the IR. In other words, this function transforms IR as if
3071 it were built with one region (without loops). We could make it
3072 much simpler by rebuilding IR with one region, but unfortunately it
3073 takes a lot of time. MAX_REGNO_BEFORE_EMIT and
3074 IRA_MAX_POINT_BEFORE_EMIT are correspondingly MAX_REG_NUM () and
3075 IRA_MAX_POINT before emitting insns on the loop borders. */
3077 ira_flattening (int max_regno_before_emit
, int ira_max_point_before_emit
)
3082 bool new_pseudos_p
, merged_p
, mem_dest_p
;
3084 enum reg_class aclass
;
3085 ira_allocno_t a
, parent_a
, first
, second
, node_first
, node_second
;
3087 ira_loop_tree_node_t node
;
3089 ira_allocno_iterator ai
;
3090 ira_copy_iterator ci
;
3092 regno_top_level_allocno_map
3093 = (ira_allocno_t
*) ira_allocate (max_reg_num ()
3094 * sizeof (ira_allocno_t
));
3095 memset (regno_top_level_allocno_map
, 0,
3096 max_reg_num () * sizeof (ira_allocno_t
));
3097 new_pseudos_p
= merged_p
= false;
3098 FOR_EACH_ALLOCNO (a
, ai
)
3100 ira_allocno_object_iterator oi
;
3103 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
3104 /* Caps are not in the regno allocno maps and they are never
3105 will be transformed into allocnos existing after IR
3108 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
3109 OBJECT_TOTAL_CONFLICT_HARD_REGS (obj
)
3110 = OBJECT_CONFLICT_HARD_REGS (obj
);
3112 ALLOCNO_TOTAL_NO_STACK_REG_P (a
) = ALLOCNO_NO_STACK_REG_P (a
);
3115 /* Fix final allocno attributes. */
3116 for (i
= max_regno_before_emit
- 1; i
>= FIRST_PSEUDO_REGISTER
; i
--)
3119 for (a
= ira_regno_allocno_map
[i
];
3121 a
= ALLOCNO_NEXT_REGNO_ALLOCNO (a
))
3123 ira_emit_data_t parent_data
, data
= ALLOCNO_EMIT_DATA (a
);
3125 ira_assert (ALLOCNO_CAP_MEMBER (a
) == NULL
);
3126 if (data
->somewhere_renamed_p
)
3127 new_pseudos_p
= true;
3128 parent_a
= ira_parent_allocno (a
);
3129 if (parent_a
== NULL
)
3131 ALLOCNO_COPIES (a
) = NULL
;
3132 regno_top_level_allocno_map
[REGNO (data
->reg
)] = a
;
3135 ira_assert (ALLOCNO_CAP_MEMBER (parent_a
) == NULL
);
3137 if (data
->mem_optimized_dest
!= NULL
)
3139 parent_data
= ALLOCNO_EMIT_DATA (parent_a
);
3140 if (REGNO (data
->reg
) == REGNO (parent_data
->reg
))
3142 merge_hard_reg_conflicts (a
, parent_a
, true);
3143 move_allocno_live_ranges (a
, parent_a
);
3145 parent_data
->mem_optimized_dest_p
3146 = (parent_data
->mem_optimized_dest_p
3147 || data
->mem_optimized_dest_p
);
3150 new_pseudos_p
= true;
3153 ALLOCNO_NREFS (parent_a
) -= ALLOCNO_NREFS (a
);
3154 ALLOCNO_FREQ (parent_a
) -= ALLOCNO_FREQ (a
);
3155 ALLOCNO_CALL_FREQ (parent_a
) -= ALLOCNO_CALL_FREQ (a
);
3156 ALLOCNO_CALLS_CROSSED_NUM (parent_a
)
3157 -= ALLOCNO_CALLS_CROSSED_NUM (a
);
3158 ALLOCNO_CHEAP_CALLS_CROSSED_NUM (parent_a
)
3159 -= ALLOCNO_CHEAP_CALLS_CROSSED_NUM (a
);
3160 /* Assume that ALLOCNO_CROSSED_CALLS_ABIS and
3161 ALLOCNO_CROSSED_CALLS_CLOBBERED_REGS stay the same.
3162 We'd need to rebuild the IR to do better. */
3163 ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (parent_a
)
3164 -= ALLOCNO_EXCESS_PRESSURE_POINTS_NUM (a
);
3165 ira_assert (ALLOCNO_CALLS_CROSSED_NUM (parent_a
) >= 0
3166 && ALLOCNO_NREFS (parent_a
) >= 0
3167 && ALLOCNO_FREQ (parent_a
) >= 0);
3168 aclass
= ALLOCNO_CLASS (parent_a
);
3169 hard_regs_num
= ira_class_hard_regs_num
[aclass
];
3170 if (ALLOCNO_HARD_REG_COSTS (a
) != NULL
3171 && ALLOCNO_HARD_REG_COSTS (parent_a
) != NULL
)
3172 for (j
= 0; j
< hard_regs_num
; j
++)
3173 ALLOCNO_HARD_REG_COSTS (parent_a
)[j
]
3174 -= ALLOCNO_HARD_REG_COSTS (a
)[j
];
3175 if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) != NULL
3176 && ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a
) != NULL
)
3177 for (j
= 0; j
< hard_regs_num
; j
++)
3178 ALLOCNO_CONFLICT_HARD_REG_COSTS (parent_a
)[j
]
3179 -= ALLOCNO_CONFLICT_HARD_REG_COSTS (a
)[j
];
3180 ALLOCNO_CLASS_COST (parent_a
)
3181 -= ALLOCNO_CLASS_COST (a
);
3182 ALLOCNO_MEMORY_COST (parent_a
) -= ALLOCNO_MEMORY_COST (a
);
3183 parent_a
= ira_parent_allocno (parent_a
);
3184 if (parent_a
== NULL
)
3187 ALLOCNO_COPIES (a
) = NULL
;
3188 regno_top_level_allocno_map
[REGNO (data
->reg
)] = a
;
3190 if (mem_dest_p
&& copy_info_to_removed_store_destinations (i
))
3193 ira_assert (new_pseudos_p
|| ira_max_point_before_emit
== ira_max_point
);
3194 if (merged_p
|| ira_max_point_before_emit
!= ira_max_point
)
3195 ira_rebuild_start_finish_chains ();
3198 sparseset objects_live
;
3200 /* Rebuild conflicts. */
3201 FOR_EACH_ALLOCNO (a
, ai
)
3203 ira_allocno_object_iterator oi
;
3206 if (a
!= regno_top_level_allocno_map
[REGNO (allocno_emit_reg (a
))]
3207 || ALLOCNO_CAP_MEMBER (a
) != NULL
)
3209 FOR_EACH_ALLOCNO_OBJECT (a
, obj
, oi
)
3211 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
3212 ira_assert (r
->object
== obj
);
3213 clear_conflicts (obj
);
3216 objects_live
= sparseset_alloc (ira_objects_num
);
3217 for (i
= 0; i
< ira_max_point
; i
++)
3219 for (r
= ira_start_point_ranges
[i
]; r
!= NULL
; r
= r
->start_next
)
3221 ira_object_t obj
= r
->object
;
3223 a
= OBJECT_ALLOCNO (obj
);
3224 if (a
!= regno_top_level_allocno_map
[REGNO (allocno_emit_reg (a
))]
3225 || ALLOCNO_CAP_MEMBER (a
) != NULL
)
3228 aclass
= ALLOCNO_CLASS (a
);
3229 EXECUTE_IF_SET_IN_SPARSESET (objects_live
, n
)
3231 ira_object_t live_obj
= ira_object_id_map
[n
];
3232 ira_allocno_t live_a
= OBJECT_ALLOCNO (live_obj
);
3233 enum reg_class live_aclass
= ALLOCNO_CLASS (live_a
);
3235 if (ira_reg_classes_intersect_p
[aclass
][live_aclass
]
3236 /* Don't set up conflict for the allocno with itself. */
3238 ira_add_conflict (obj
, live_obj
);
3240 sparseset_set_bit (objects_live
, OBJECT_CONFLICT_ID (obj
));
3243 for (r
= ira_finish_point_ranges
[i
]; r
!= NULL
; r
= r
->finish_next
)
3244 sparseset_clear_bit (objects_live
, OBJECT_CONFLICT_ID (r
->object
));
3246 sparseset_free (objects_live
);
3247 compress_conflict_vecs ();
3249 /* Mark some copies for removing and change allocnos in the rest
3251 FOR_EACH_COPY (cp
, ci
)
3253 if (ALLOCNO_CAP_MEMBER (cp
->first
) != NULL
3254 || ALLOCNO_CAP_MEMBER (cp
->second
) != NULL
)
3256 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
3258 (ira_dump_file
, " Remove cp%d:%c%dr%d-%c%dr%d\n",
3259 cp
->num
, ALLOCNO_CAP_MEMBER (cp
->first
) != NULL
? 'c' : 'a',
3260 ALLOCNO_NUM (cp
->first
),
3261 REGNO (allocno_emit_reg (cp
->first
)),
3262 ALLOCNO_CAP_MEMBER (cp
->second
) != NULL
? 'c' : 'a',
3263 ALLOCNO_NUM (cp
->second
),
3264 REGNO (allocno_emit_reg (cp
->second
)));
3265 cp
->loop_tree_node
= NULL
;
3269 = regno_top_level_allocno_map
[REGNO (allocno_emit_reg (cp
->first
))];
3271 = regno_top_level_allocno_map
[REGNO (allocno_emit_reg (cp
->second
))];
3272 node
= cp
->loop_tree_node
;
3274 keep_p
= true; /* It copy generated in ira-emit.c. */
3277 /* Check that the copy was not propagated from level on
3278 which we will have different pseudos. */
3279 node_first
= node
->regno_allocno_map
[ALLOCNO_REGNO (cp
->first
)];
3280 node_second
= node
->regno_allocno_map
[ALLOCNO_REGNO (cp
->second
)];
3281 keep_p
= ((REGNO (allocno_emit_reg (first
))
3282 == REGNO (allocno_emit_reg (node_first
)))
3283 && (REGNO (allocno_emit_reg (second
))
3284 == REGNO (allocno_emit_reg (node_second
))));
3288 cp
->loop_tree_node
= ira_loop_tree_root
;
3290 cp
->second
= second
;
3294 cp
->loop_tree_node
= NULL
;
3295 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
3296 fprintf (ira_dump_file
, " Remove cp%d:a%dr%d-a%dr%d\n",
3297 cp
->num
, ALLOCNO_NUM (cp
->first
),
3298 REGNO (allocno_emit_reg (cp
->first
)),
3299 ALLOCNO_NUM (cp
->second
),
3300 REGNO (allocno_emit_reg (cp
->second
)));
3303 /* Remove unnecessary allocnos on lower levels of the loop tree. */
3304 FOR_EACH_ALLOCNO (a
, ai
)
3306 if (a
!= regno_top_level_allocno_map
[REGNO (allocno_emit_reg (a
))]
3307 || ALLOCNO_CAP_MEMBER (a
) != NULL
)
3309 if (internal_flag_ira_verbose
> 4 && ira_dump_file
!= NULL
)
3310 fprintf (ira_dump_file
, " Remove a%dr%d\n",
3311 ALLOCNO_NUM (a
), REGNO (allocno_emit_reg (a
)));
3312 ira_remove_allocno_prefs (a
);
3316 ALLOCNO_LOOP_TREE_NODE (a
) = ira_loop_tree_root
;
3317 ALLOCNO_REGNO (a
) = REGNO (allocno_emit_reg (a
));
3318 ALLOCNO_CAP (a
) = NULL
;
3319 /* Restore updated costs for assignments from reload. */
3320 ALLOCNO_UPDATED_MEMORY_COST (a
) = ALLOCNO_MEMORY_COST (a
);
3321 ALLOCNO_UPDATED_CLASS_COST (a
) = ALLOCNO_CLASS_COST (a
);
3322 if (! ALLOCNO_ASSIGNED_P (a
))
3323 ira_free_allocno_updated_costs (a
);
3324 ira_assert (ALLOCNO_UPDATED_HARD_REG_COSTS (a
) == NULL
);
3325 ira_assert (ALLOCNO_UPDATED_CONFLICT_HARD_REG_COSTS (a
) == NULL
);
3327 /* Remove unnecessary copies. */
3328 FOR_EACH_COPY (cp
, ci
)
3330 if (cp
->loop_tree_node
== NULL
)
3332 ira_copies
[cp
->num
] = NULL
;
3337 (ALLOCNO_LOOP_TREE_NODE (cp
->first
) == ira_loop_tree_root
3338 && ALLOCNO_LOOP_TREE_NODE (cp
->second
) == ira_loop_tree_root
);
3339 add_allocno_copy_to_list (cp
);
3340 swap_allocno_copy_ends_if_necessary (cp
);
3342 rebuild_regno_allocno_maps ();
3343 if (ira_max_point
!= ira_max_point_before_emit
)
3344 ira_compress_allocno_live_ranges ();
3345 ira_free (regno_top_level_allocno_map
);
3350 #ifdef ENABLE_IRA_CHECKING
3351 /* Check creation of all allocnos. Allocnos on lower levels should
3352 have allocnos or caps on all upper levels. */
3354 check_allocno_creation (void)
3357 ira_allocno_iterator ai
;
3358 ira_loop_tree_node_t loop_tree_node
;
3360 FOR_EACH_ALLOCNO (a
, ai
)
3362 loop_tree_node
= ALLOCNO_LOOP_TREE_NODE (a
);
3363 ira_assert (bitmap_bit_p (loop_tree_node
->all_allocnos
,
3365 if (loop_tree_node
== ira_loop_tree_root
)
3367 if (ALLOCNO_CAP_MEMBER (a
) != NULL
)
3368 ira_assert (ALLOCNO_CAP (a
) != NULL
);
3369 else if (ALLOCNO_CAP (a
) == NULL
)
3370 ira_assert (loop_tree_node
->parent
3371 ->regno_allocno_map
[ALLOCNO_REGNO (a
)] != NULL
3372 && bitmap_bit_p (loop_tree_node
->border_allocnos
,
3378 /* Identify allocnos which prefer a register class with a single hard register.
3379 Adjust ALLOCNO_CONFLICT_HARD_REG_COSTS so that conflicting allocnos are
3380 less likely to use the preferred singleton register. */
3382 update_conflict_hard_reg_costs (void)
3385 ira_allocno_iterator ai
;
3388 FOR_EACH_ALLOCNO (a
, ai
)
3390 reg_class_t aclass
= ALLOCNO_CLASS (a
);
3391 reg_class_t pref
= reg_preferred_class (ALLOCNO_REGNO (a
));
3392 int singleton
= ira_class_singleton
[pref
][ALLOCNO_MODE (a
)];
3395 index
= ira_class_hard_reg_index
[(int) aclass
][singleton
];
3398 if (ALLOCNO_CONFLICT_HARD_REG_COSTS (a
) == NULL
3399 || ALLOCNO_HARD_REG_COSTS (a
) == NULL
)
3402 for (i
= ira_class_hard_regs_num
[(int) aclass
] - 1; i
>= 0; i
--)
3403 if (ALLOCNO_HARD_REG_COSTS (a
)[i
] > ALLOCNO_CLASS_COST (a
)
3404 && min
> ALLOCNO_HARD_REG_COSTS (a
)[i
])
3405 min
= ALLOCNO_HARD_REG_COSTS (a
)[i
];
3408 ira_allocate_and_set_costs (&ALLOCNO_CONFLICT_HARD_REG_COSTS (a
),
3410 ALLOCNO_CONFLICT_HARD_REG_COSTS (a
)[index
]
3411 -= min
- ALLOCNO_CLASS_COST (a
);
3415 /* Create a internal representation (IR) for IRA (allocnos, copies,
3416 loop tree nodes). The function returns TRUE if we generate loop
3417 structure (besides nodes representing all function and the basic
3418 blocks) for regional allocation. A true return means that we
3419 really need to flatten IR before the reload. */
3426 initiate_cost_vectors ();
3427 initiate_allocnos ();
3430 create_loop_tree_nodes ();
3434 create_allocno_objects ();
3435 ira_create_allocno_live_ranges ();
3436 remove_unnecessary_regions (false);
3437 ira_compress_allocno_live_ranges ();
3438 update_bad_spill_attribute ();
3439 loops_p
= more_one_region_p ();
3442 propagate_allocno_info ();
3445 ira_tune_allocno_costs ();
3446 #ifdef ENABLE_IRA_CHECKING
3447 check_allocno_creation ();
3449 setup_min_max_allocno_live_range_point ();
3450 sort_conflict_id_map ();
3451 setup_min_max_conflict_allocno_ids ();
3452 ira_build_conflicts ();
3453 update_conflict_hard_reg_costs ();
3454 if (! ira_conflicts_p
)
3457 ira_allocno_iterator ai
;
3459 /* Remove all regions but root one. */
3462 remove_unnecessary_regions (true);
3465 /* We don't save hard registers around calls for fast allocation
3466 -- add caller clobbered registers as conflicting ones to
3467 allocno crossing calls. */
3468 FOR_EACH_ALLOCNO (a
, ai
)
3469 if (ALLOCNO_CALLS_CROSSED_NUM (a
) != 0)
3470 ior_hard_reg_conflicts (a
, ira_need_caller_save_regs (a
));
3472 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
3473 print_copies (ira_dump_file
);
3474 if (internal_flag_ira_verbose
> 2 && ira_dump_file
!= NULL
)
3475 print_prefs (ira_dump_file
);
3476 if (internal_flag_ira_verbose
> 0 && ira_dump_file
!= NULL
)
3481 ira_allocno_iterator ai
;
3486 FOR_EACH_ALLOCNO (a
, ai
)
3488 int j
, nobj
= ALLOCNO_NUM_OBJECTS (a
);
3492 for (j
= 0; j
< nobj
; j
++)
3494 ira_object_t obj
= ALLOCNO_OBJECT (a
, j
);
3495 n
+= OBJECT_NUM_CONFLICTS (obj
);
3496 for (r
= OBJECT_LIVE_RANGES (obj
); r
!= NULL
; r
= r
->next
)
3500 fprintf (ira_dump_file
, " regions=%d, blocks=%d, points=%d\n",
3501 current_loops
== NULL
? 1 : number_of_loops (cfun
),
3502 n_basic_blocks_for_fn (cfun
), ira_max_point
);
3503 fprintf (ira_dump_file
,
3504 " allocnos=%d (big %d), copies=%d, conflicts=%d, ranges=%d\n",
3505 ira_allocnos_num
, nr_big
, ira_copies_num
, n
, nr
);
3510 /* Release the data created by function ira_build. */
3514 finish_loop_tree_nodes ();
3518 finish_cost_vectors ();
3519 ira_finish_allocno_live_ranges ();